Unable to execute cypher statement - c#

I am using VS 2013 and the Neo4j client in an MVC application and can't get past building the query.
In the following code, I can connect to my server but on the var newUser line I get an error over the new User statement saying it's a property but used like a type, that can bee seen in this screen shot:
var client = new GraphClient(new System.Uri("http://localhost:7474/db/data"));
client.Connect();
var newUser = new User { Id = 456, Name = "Jim" };
client.Cypher
.Merge("(user:User { Id: {id} })")
.OnCreate("user")
.Set("user = {newUser}")
.WithParams(new
{
id = newUser.Id,
newUser
})
.ExecuteWithoutResults();
I think I need to add or remove a reference but I a not sure what it is.

If you read the error, you'll see User is a property of Controller, so it's not recognized as a type.
You'll need to prefix the namespace, like new Neo4j.User() or whatever its documentation states it uses.

Related

How do I add a structured ODBC data source to a tabular model using the AMO tabular library

Adding a structured ODBC data source to my model results in an error.
I want to generate a tabular model on a SQL Analysis Services server with compatibility level 1400 using the Microsoft.AnalysisServices.Tabular library using structured (ie. M / Power Query), non-legacy (ie. ProviderDataSource) data sources.
I installed the library using NuGet package Microsoft.AnalysisServices.retail.amd64 (16.3.0).
Here's my data source definition.
myDatabase.Model.DataSources.Add(new StructuredDataSource()
{
Name = "ODBC",
Description = "An structured ODBC data source definition",
ConnectionDetails = new ConnectionDetails()
{
Protocol = DataSourceProtocol.Odbc
},
Credential = new Credential()
{
AuthenticationKind = AuthenticationKind.UsernamePassword,
EncryptConnection = false,
Username = "MYUSERNAME",
Password = "MYPASSWORD"
}
}
When I run this code, I get:
COM error: Microsoft.Data.Mashup; The given data source reference is not a valid data source.
It doesn't give me any pointers where to look or what is wrong specifically. I suspected the definition needed a server address, but the address property of the ConnectionDetails object cannot be set according to the documentation.
ConnectionDetails.Address Property
Address of this connection. It can't be set, instead it should be modified directly.
When reviewing my question and off course further investigating the documentation, I constructed this solution. For those who struggle with the same problem, I figured it'd be nice to post it here.
Credential credential = new Credential()
{
AuthenticationKind = AuthenticationKind.UsernamePassword,
EncryptConnection = false,
Username = "MYUSERNAME",
Password = "MYPASSWORD" // Please note that this won't persist.
};
ConnectionDetails connectionDetails = new ConnectionDetails("{ 'protocol': 'odbc', 'address': { 'options': { 'dsn': 'MYODBCDSN' } }, 'authentication': null, 'query': null }");
dbWithDataSource.Model.DataSources.Add(new StructuredDataSource()
{
Name = "ODBC",
Description = "An ODBC structured (ie. non-legacy) data source definition",
ConnectionDetails = connectionDetails,
Credential = credential,
Options = new DataSourceOptions( "{ 'hierarchicalNavigation': true }" )
}
What I basically did, was pass in a JSON string in the ConnectionDetails constructor, setting the 'read-only' address property as well.

SubscriptionNotFound: The subscription 'resourceGroups' could not be found

I'm trying to follow the Resource group authenticate service principal to be able to access some resource manager stuff. But when trying to do anything, I get the following error:
SubscriptionNotFound: The subscription 'resourceGroups' could not be found.
Using the C# code in the article to get an access token, and then calling the follow methods:
var dnsClient = new DnsManagementClient(new Microsoft.Azure.TokenCloudCredentials(result.AccessToken));
var zone = dnsClient.Zones.CreateOrUpdate("someresourcegroup", "mydomain.com", new Microsoft.Azure.Management.Dns.Models.ZoneCreateOrUpdateParameters {
IfNoneMatch = "*",
Zone = new Microsoft.Azure.Management.Dns.Models.Zone {
Name = "mydomain.com",
Location = "northeurope"
}
});
Any idea what I'm doing wrong? I've created a service principal as a Contributor, so permissions shouldn't be a problem?
The error message says The subscription 'resourceGroups' could not be found, please try specify your subscriptionid when creating the TokenCloudCredentials object.
var dnsClient = new DnsManagementClient(new Microsoft.Azure.TokenCloudCredentials("your_subscriptionid", result.AccessToken));
Tested from my side and it works.

Connect CouchDB with asp.net C# application

How to connect couchDB with ASP.NET C# application? If any one can you give a sample application.
I had the same need and after evaluating the options available, to meet the requirements of my application, I created any components that helped me a lot and maybe they can help you and also others. I make it clear that I have no intention of promoting myself here, just sharing something that may be useful.
The detailed explanation of how to configure and use it is on Github.
Link: Nuget Package |
Github
Example of use for retrieving documents with mango-querie:
IList<User> users;
var sts = new List<String> { "ACTIVE", "LOCKED" };
using (UserRepository db = new UserRepository())
{
var query = db.FindOf("list-status", new { id = "OwnerIdloop.user.7", statuses = sts });
users = db.List<User>(query);
}
Array.ForEach(users.ToArray(), Console.WriteLine);
Example of adding documents:
User user = createUser("email#email.com");
using (UserRepository db = new UserRepository())
{
var result = db.Insert<User>(user); // add document and return instance changed with operation revision id
Console.WriteLine(result.Revision);
}
Example of changing documents:
using (UserRepository db = new UserRepository())
{
// Load document data by ID
var user = db.Get<User>("email#email.com");
user.Name = user.Name + "::CHANGED";
var result = db.Update<User>(user); // update document and return instance changed with operation revision id
Console.WriteLine(result.Revision);
}
Example of deleting documents:
using (UserRepository db = new UserRepository())
{
// Load document data by ID
var user = db.Get<User>("email#email.com");
var result = db.Delete<User>(user); // delete document from database. Return true case sucess or false case not deleted
Console.WriteLine($"Sucesso: {result}");
}
After installing the NuGet, just create an instance of MyCouch.Client and pass it the URL of your database.
using (var client = new MyCouchClient("http://127.0.0.1:5984/test"))
{
//Consume here
}
The format is: {scheme}://[{username}:{password}]/{authority}/{localpath}. From v0.11.0, there's a specific MyCouchUriBuilder that you can use for building the Uri. It will automatically e.g. apply Uri.EscapeDataString to username and password when calling SetBasicCredentials.
var uriBuilder = new MyCouchUriBuilder("http://localhost:5984/")
.SetDbName(TestConstants.TestDbName)
.SetBasicCredentials("foob#r", "p#ssword");
return new MyCouchClient(uriBuilder.Build());
For more details Click Here

What is the proper way to fetch the Owner Name of a Rally Task?

I'm using the RallyRestToolkitFor.NET and I'm pulling information from Rally tasks into our back office system. It is all working well except I'm having trouble fetching the name of the "Owner" of the task.
In fact, I can't seem to pull any information from the Owner. Below is a code snippet so you can see what I'm doing. It works great for the Description and FormattedID but the Owner name returned in the QueryResult is blank when it's actually set in Rally.
I've tried "Owner", "User", "User.Name", and nothing has worked. I guess I'm just stumped on how to retrieve the Owner Name on a task. However, I can query on Owner.Name just fine, but I'm not able to fetch it in the list. Does anyone have any ideas?
Request request = new Request("task");
request.Fetch = new List<string>() {"Owner.Name", "Description", "FormattedID" };
request.Query = new Query("Project.Name", Query.Operator.Equals, "My Project");
QueryResult queryResult = restApi.Query(request);
foreach (var result in queryResult.Results)
{
ownerName = result["Owner.Name"];
}
You can just fetch Owner and then also include individual fields from the User object type right in the same fetch:
request.Fetch = new List<string>() {"Owner", "UserName", "DisplayName" };
and then in the response:
owner = result["Owner"]
if(owner != null)
{
ownerName = owner["UserName"]
}
This same concept should work for any child object sub types in WSAPI.

How can I get the picture of a Facebook event using server side code?

I'm writing a web app that pulls events data from Facebook, and I can get a lot of the information using an app token, but not the picture, which requires a client token, as documented here: https://developers.facebook.com/docs/graph-api/reference/v2.2/event/picture
I want the code that grabs the event data to run automatically on a server at regular intervals, without requiring a user to log in to their Facebook account.
Is there a way I can get a client token without user intervention? If not, is there another way I can get the event picture?
This is the code I am using to get the event data, using C# and JSON.Net (This gets a list of events created by the specified user - ResortStudios):
var fb = new FacebookClient();
dynamic result = fb.Get( "oauth/access_token", new
{
client_id = "XXXXXXXXXXX",
client_secret = "XXXXXXXXXXXXXXXXXXXXXXXXX",
grant_type = "client_credentials"
} );
var apptoken = result.access_token;
fb = new FacebookClient(apptoken);
result = fb.Get("ResortStudios/events");
JObject events = JObject.Parse(result.ToString());
JArray aEvents = (JArray)events["data"];
string s = aEvents.ToString();
List<fbEvent> lEvents = JsonConvert.DeserializeObject<List<fbEvent>>(s);
I've not tried this but something occurred to me that might work for you. Have you considered something like storing it a non-persistent data store like session state? Then, using the Facebook SDK for .NET, you create an ActionResult for UserInfo, like below. (I know this isn't directly applicable but I hoped it might get you thinking.)
//http://facebooksdk.net/docs/web/ajax-requests/
public ActionResult UserInfo()
{
var accessToken = Session["AccessToken"].ToString();
var client = new FacebookClient(accessToken);
dynamic result = client.Get("me", new { fields = "name,id" });
return Json(new
{
id = result.id,
name = result.name,
});
}

Categories

Resources