recently i've been trying to set up a connection to my Firestore database. I followed the instructions given in this video only that there is a runtime exception when it tries to get the data base via GetDatabase()
public static FirebaseFirestore GetDatabase()
{
FirebaseFirestore database;
var app = Firebase.FirebaseApp.InitializeApp(Application.Context);
if (app == null)
{
var options = new Firebase.FirebaseOptions.Builder()
.SetProjectId("fulcrum-7c537")
.SetApplicationId("fulcrum-7c537")
.SetApiKey("AIzaSyA8lo7k0EFPNR32-g4xdBnMkQnycn_v4G8")
.SetDatabaseUrl("https://fulcrum-7c537.firebaseio.com")
.SetStorageBucket("fulcrum-7c537.appspot.com")
.Build();
app = Firebase.FirebaseApp.InitializeApp(Application.Context , options);
}
database = FirebaseFirestore.GetInstance(app);
return database;
}
The Exception :
Java.Lang.NoClassDefFoundError
Message=Failed resolution of: Lcom/google/common/io/BaseEncoding;
I have been trying for a while to find out why it happens but found nothing. May someone has a solution?
Thanks!
I had exactly the same issue. I downloaded the code provided by Ufinix (the creator of the video). I downgraded the Xamarin.Google.Guava current version 28.2.0 I used, to the 27.1.0.1 version he used in his example. And finally, it worked.
Related
what is the best way to get daily bytes-out and byte-in report for every user in hotspot list(without the user manager).i found the tik4net but i couldn't use it and i found almost no documentation on this reference.
i have tried the mk.cs and tik4net already but no luck so far.
this was the sample on using torch tool :
using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api))
{
connection.Open("IP", "USR", "PW");
var loadingContext = connection.LoadAsync<ToolTorch>(
torchItem => Console.WriteLine(torchItem.ToString()),
error => Console.WriteLine(error.ToString()),
connection.CreateParameter("interface", "DSL"),
connection.CreateParameter("port", "any"),
connection.CreateParameter("src-address", "0.0.0.0/0"),
connection.CreateParameter("dst-address", "0.0.0.0/0"));
Console.ReadLine();
loadingContext.Cancel();
{
so the question is:
what is the best reference in c# to get user reports without the user manager in c#?
can anyone please provide some sample code ?
UPDATE :
i just worked around and played with the code a little bit and got here :
using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api))
{
connection.Open("IP", "USR", "PW");
var hs = connection.LoadAll<HotspotActive>();
foreach (var user in hs)
{
var ids = user.Id;
listBox1.Items.Add(ids);
connection.Delete<HotspotActive>(user);
}
}
but i get an exception error on connection.Delete<HotspotActive>(user); , i dont know if i went the correct way.
I have a piece of code (.NET Framework 4.5.2, Enterprise Library 5.0.505.0) where I need to connect to a SQL Server database. However, the DB name may keep changing depending on user's requirement. So, I have the following piece of code to write the connection string dynamically to the app.config file.
public void CreateNewConnectionStringInConfig(string initialCatalog)
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = ConfigurationManager.AppSettings["Data Source"];
builder.PersistSecurityInfo = true;
builder.InitialCatalog = initialCatalog; //This is the DB name
builder.UserID = ConfigurationManager.AppSettings["User ID"];
builder.Password = ConfigurationManager.AppSettings["Password"];
// Get the application configuration file.
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// Create a connection string element.
ConnectionStringSettings csSettings = new ConnectionStringSettings("UserSelectedConnectionString", builder.ConnectionString, "System.Data.SqlClient");
// Get the connection strings section.
ConnectionStringsSection csSection = config.ConnectionStrings;
// Add the new element.
csSection.ConnectionStrings.Add(csSettings);
// Save the configuration file.
config.Save(ConfigurationSaveMode.Modified);
// Refresh the section so the new configuration can be re-read
ConfigurationManager.RefreshSection("connectionStrings");
}
I checked and the connection string is getting created fine in the vshost.exe.Config file while debugging. However, when I am trying to create the Database object, I am getting an error. The code used to create the DB object is as shown below.
public class MyDac
{
private readonly Database _db;
public MyDac()
{
DatabaseProviderFactory factory = new DatabaseProviderFactory();
_db = factory.Create("UserSelectedConnectionString");
}
}
I am getting the following error while trying to create the _db object.
Activation error occured while trying to get instance of type Database, key "UserSelectedConnectionString"
Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type Database, key "UserSelectedConnectionString" ---> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Data.Database", name = "UserSelectedConnectionString".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type Database does not have an accessible constructor.
Things that I have tried:
1) Upgrading the Enterprise Library version to 6.0.0.0 resolves the issue but that is not an option for me. I have to keep it to version 5.0.505.0.
2) When I hard code the connection string in the App.config file from before hand (rather than writing it during run time), the app works fine. However, I can't do that in real life because the database name will keep on changing.
Any help will be much appreciated. Thanks!
I changed my code as shown below and that started working. However, I do not have any explanation for it:
public class MyDac
{
private readonly Database _db;
public MyDac()
{
_db = new SqlDatabase("UserSelectedConnectionString");
}
}
In new version of TeamFoundation 2013 default build templates, the Workspace variable is missing. It is needed as intput parameter for few key activities like ConvertWorkspaceItem. How do I get current workspace for TfvcTemplate.12.xaml templates? I've tried to use this msdn thread but it's not working for me (returns null workspace name). Any suggestions?
There's a new activity in 2013 called GetLocalPath that replaces ConvertWorkspaceItem.
The activity is under the Microsoft.TeamFoundation.Build.Activities.Core namespace in the Microsoft.TeamFoundation.Build.Activities assembly.
It uses the LocalPathProvider class that aggregates all workspaces used in the build and exposes path translation for all of them in one place. This basically removes the dependency of knowing the workspace in order to translate server paths to local paths and allows you to use as many workspaces as you want without worrying about breaking something down the line.
When MS takes something away, it's usually for a good reason. "hacking" is really not necessary.
I went with a hack using internal classes from Microsoft.TeamFoundation.Build.Activities.dll (used by microsoft to create workspace name). You need to create custom activity with following code:
public sealed class GetDefaultWorkspace : BaseActivity<Workspace>
{
public override Activity CreateBody()
{
var type = typeof(TfGetSources).Assembly.GetType("Microsoft.TeamFoundation.Build.Activities.TeamFoundation.TfGetSources+GetDefaultWorkspaceName");
var activity = (CodeActivity<string>)Activator.CreateInstance(type);
var sequence = new Sequence();
var workspaceName = new Variable<string>();
sequence.Variables.Add(workspaceName);
sequence.Activities.Add(activity);
activity.Result = (OutArgument<string>) workspaceName;
sequence.Activities.Add(new GetWorkspace
{
Name = workspaceName,
Result = new LambdaReference<Workspace>(ctx => Result.Get(ctx))
});
return sequence;
}
}
This answer might work better for some people. ghord's answer works well, and passes the Workspace back where it can be used in the XAML. However, for my purposes I only want the workspace in my custom TFS activities, so I ended up with this alternative...
public sealed class CustomActivity : CodeActivity
{
protected override void Execute(CodeActivityContext context)
{
// get workspace
var buildDetail = context.GetExtension<IBuildDetail>();
var buildAgent = context.GetExtension<IBuildAgent>();
var buildDirectory = buildAgent.GetExpandedBuildDirectory(buildDetail.BuildDefinition);
var workspacePath = Path.Combine(buildDirectory, "src");
var wsInfo = Workstation.Current.GetLocalWorkspaceInfo(workspacePath);
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(wsInfo.ServerUri);
tfs.Connect(ConnectOptions.None);
var vcs = tfs.GetService<VersionControlServer>();
// finally can get to the workspace here
var workspace = vcs.GetWorkspace(workspacePath);
}
}
Using this method, I don't have to have an activity that just returns the workspace, and then have to pass the workspace into other TFS activities. I just get the workspace from within my own activity while it runs.
I believe the method employed here will use the already downloaded workspace. Keep in mind, that this approach will only work within the scope of "Run on agent" sequence after "Initialize Environment" and before ResetEnvironment within the finally statement of Try Compile, Test, Publish. Else, the workflow will have no knowledge of a sources directory.
http://social.msdn.microsoft.com/Forums/vstudio/en-US/420ba073-bdf5-4ab4-88da-c84561d1a1ba/creating-dynamic-working-folder-in-tfs2013-defaulttemplate?forum=tfsbuild
I'm using fluent migrator to manage my database migrations, but what I'd like to do is have the migrations run at app start. The closest I have managed is this:
public static void MigrateToLatest(string connectionString)
{
using (var announcer = new TextWriterAnnouncer(Console.Out)
{
ShowElapsedTime = true,
ShowSql = true
})
{
var assembly = typeof(Runner).Assembly.GetName().Name;
var migrationContext = new RunnerContext(announcer)
{
Connection = connectionString,
Database = "SqlServer2008",
Target = assembly
};
var executor = new TaskExecutor(migrationContext);
executor.Execute();
}
}
I'm sure I had this working, but I've not looked at it for sometime (hobby project) and it's now throwing null reference exceptions when it gets to the Execute line. Sadly there are no docs for this and I've been banging my head on it for ages.
Has anyone managed to get this kind of thing working with FluentMigrator?
PM> Install-Package FluentMigrator.Tools
Manually add a reference to:
packages\FluentMigrator.Tools.1.6.1\tools\AnyCPU\40\FluentMigrator.Runner.dll
Note that the folder name will vary on version number, this illustration uses the current 1.6.1 release. If you need the .NET 3.5 runner use the \35\ directory.
public static class Runner
{
public class MigrationOptions : IMigrationProcessorOptions
{
public bool PreviewOnly { get; set; }
public string ProviderSwitches { get; set; }
public int Timeout { get; set; }
}
public static void MigrateToLatest(string connectionString)
{
// var announcer = new NullAnnouncer();
var announcer = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s));
var assembly = Assembly.GetExecutingAssembly();
var migrationContext = new RunnerContext(announcer)
{
Namespace = "MyApp.Sql.Migrations"
};
var options = new MigrationOptions { PreviewOnly=false, Timeout=60 };
var factory =
new FluentMigrator.Runner.Processors.SqlServer.SqlServer2008ProcessorFactory();
using (var processor = factory.Create(connectionString, announcer, options))
{
var runner = new MigrationRunner(assembly, migrationContext, processor);
runner.MigrateUp(true);
}
}
}
Note the SqlServer2008ProcessorFactory this is configurable dependent upon your database, there is support for: 2000, 2005, 2008, 2012, and 2014.
I have actually accomplished running migrations in the application_start however it is hard to tell from that code what could be wrong... Since it is open source I would just grab the code and pull it into your solution and build it to find out what the Execute method is complaining about. I found that the source code for Fluent Migrator is organized pretty well.
One thing that you might have to be concerned about if this is a web app is making sure that no one uses the database while you are migrating. I used a strategy of establishing a connection, setting the database to single user mode, running the migrations, setting the database to multi user mode, then closing the connection. This also handles the scenario of a load balanced web application on multiple servers so 2 servers don't try to run migrations against the same database.
I'm using Microsoft code to create a new Organisation in the User Profile Server, as per http://msdn.microsoft.com/en-us/library/ms545122.aspx.
Every time I call CreateOrganizationProfile I get the following:
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Office.Server.UserProfiles.OrganizationProfile.set_Parent(ProfileBase value)
The exact code I'm using is:
[WebMethod]
public void CreateOrganisation(string OrganisationName)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(_serverName))
{
// Removing this will cause the error "Operation is not valid due to the current state of the object".
HttpContext.Current = null;
SPServiceContext context = SPServiceContext.GetContext(site);
ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);
// choose default organization profile subtype as the subtype
string subtypeName = ProfileSubtypeManager.GetDefaultProfileName(ProfileType.Organization);
ProfileSubtype subType = psm.GetProfileSubtype(subtypeName);
OrganizationProfileManager opm = new OrganizationProfileManager(context);
// choose Root Organization as the parent
OrganizationProfile parentOrg = opm.RootOrganization;
// create an organization profile and set its display name
OrganizationProfile profile = opm.CreateOrganizationProfile(subType, parentOrg);
profile.DisplayName = "Test Org1";
// commit to save changes
profile.Commit();
}
});
return;
}
Curiously, somebody else ran into the exact problem here http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/7b5101fd-0ea6-4716-82b1-ac4609b9973c/, but it was never resolved.
I've confirmed the User Profile Service is running and responding. Also, parentOrg and subtypeName are not null when calling CreateOrganizationProfile.
Does anybody have anything I can try, or can anybody spot what might be the problem?
Very grateful!
I had the same problem and I fixed it by changing the line
OrganizationProfile parentOrg = opm.RootOrganization;
To
OrganizationProfile parentOrg = (OrganizationProfile)opm.GetProfile(1);
GetProfile(1) returned the RootOrganization in my case.
Hope this helps someone!
I am no sharepoint expert but this http://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.organizationprofilemanager.createorganizationprofile.aspx states that you need user profile administrative permissions and this http://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.organizationprofile.parent.aspx could be hint that you need user profile manager permission to do what you are trying to do.
EDIT:
since your code try to "write" something this seems relevant http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx
basically it says you are missing a call to SPUtility.ValidateFormDigest() or SPWeb.ValidateFormDigest() before calling SPSecurity.RunWithElevatedPrivileges