I have just started to explore Graph databases and Neo4jClient library for Neo4J. I am using Neo4JClient v1.1.0.11 downloaded from NuGet in Visual Studio. I want to create a Node in Neo4J and for that I am using this code (C#):
var client = new GraphClient(new Uri("http://localhost:7474/db/data"), "user", "pass");
client.Connect();
client.Cypher.Create();
But on Cypher.Create Intellisense shows that it is deprecated. My question is what is the alternate way of creating a Node? An example would be appreciated.
In this particular case I have a User that I want to create in the database. The class looks like:
public class User
{
public Int32 ID { get; set; }
public String UserName { get; set; }
public String Name { get; set; }
public Boolean Active { get; set; }
public String Email { get; set; }
public String Password { get; set; }
}
Thanks
I believe only one overload on the Create method has been marked as obsolete - unless there is something I am not aware of. The following code should do what you need and does not show as being deprecated.
var client = new GraphClient(new Uri("http://localhost:7474/db/data"), "user", "pass");
client.Connect();
var user = new User
{
// initialise properties
};
client.Cypher
.Create("(u:User {user})")
.WithParams(new { user = user })
.ExecuteWithoutResults();
There are a number of variations on this that will work but it should get you started.
As an aside, were you to use the first overload on the Create method you would indeed see it marked as deprecated. For example, this code
client.Cypher
.Create("(u:User {0})", user)
.ExecuteWithoutResults();
would give you the following warning in Visual Studio
'Neo4jClient.Cypher.ICypherFluentQuery.Create(string, params object[])' is obsolete: 'Use Create(string) with explicitly named params instead. For example, instead of Create("(c:Customer {0})", customer), use Create("(c:Customer {customer})").WithParams(new { customer }).'
Related
Ok, so I am building xamarin.android applicationon in Visual Studio and there is quite a lot of questions of this type, but I really didn't find anything regarding xamarin.android, everything is Java based. I tried following those tutorials and answers but there was always something missing or not working on Xamarin android.
I have made authentication and it works great, no problems there. And i tried storing user information (info that user types in while registering) into database. It kind of worked, but with one problem. Here is code:
public void OnComplete(Task task)
{
if (task.IsSuccessful)
{
Toast.MakeText(this, "Successful", ToastLength.Long).Show();
FirebaseUser user = FirebaseAuth.GetInstance(app).CurrentUser;
id = user.Uid;
CreateUser();
buttonSignIn.PerformClick();
progressBar.Visibility = ViewStates.Invisible;
}
else
{
//something
}
}
And here is CreateUser() method:
private void CreateUser ()
{
Account user = new Account();
user.uid = id;
user.name = signup_inputName;
user.lastName = signup_inputLastName;
user.email = signup_inputEmail;
user.phone = signup_inputPhoneNumber;
var firebase = new FirebaseClient(FirebaseURL);
var item = firebase.Child("users").PostAsync<Account>(user);
}
Here is Account class code:
public class Account
{
public string uid { get; set; }
public string name { get; set; }
public string lastName { get; set; }
public string email { get; set; }
public string phone { get; set; }
}
This code stores user information under "users" node in database. But there is one more node under "user" with some random value and below are information about user (including uid). Here is output:
- Users
-LBGFtYFTfD3l1hmwHVn
email: "testuser#test.com"
lastName:"peric"
name: "pero"
phone: "12321"
uid: "18puc5CzSZfzbdflzekzNCHGHR62"
So, my question is, shouldn't this random value below "users" node be uid? If yes, how to set it that way?
I tried with this:
Account user = new Account();
user.uid = id;
user.name = signup_inputName;
user.lastName = signup_inputLastName;
user.email = signup_inputEmail;
user.phone = signup_inputPhoneNumber;
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("users").Child(uid).SetValue(user)
But that didn't work, I was getting this error:
Firebase No properties to serialize found on class
Even though I have set public getters and setters in users class.
I need to get that user info and show it on some places in my app, but I just can't get it to work. This is my first time using Firebase and I am used to SQL database so this is really confusing to me. Also, there is very little information online about xamarin.android and firebase, plus I am actually new to programming in general. Any help would be appreciate. This is my last try before switching to SQL online database.
When you call PostAsync the client creates a new child node under the location that you call it on. This is similar to the HTTP POST verb, and the push() method in most other Firebase SDKs.
To write data to a location that you exactly specify, use PutAsync:
var item = firebase.Child("users").Child(uid).PutAsync<Account>(user);
See the example from the Readme of Firebase.Xamarin.
I want to access to ActiveDirectory using LINQ to LDAP and I want to Get List of All users in that
how can I do that?
You can try something like below.
using ActiveDs;
using BdsSoft.DirectoryServices.Linq;
using System.Linq.Expressions;
using System.DirectoryServices;
[DirectorySchema( "user", typeof( IADsUser ) )]
class User
{
public string Name { get; set; }
public string sAMAccountName { get; set; }
public string objectCategory { get; set; }
public string mail { get; set; }
public string Description { get; set; }
[DirectoryAttribute( "PasswordLastChanged", DirectoryAttributeType.ActiveDs )]
public DateTime PasswordLastSet { get; set; }
[DirectoryAttribute("distinguishedName")]
public string Dn { get; set; }
[DirectoryAttribute("memberOf")]
public string[] Groups { get; set; }
}
Use this code to access AD from a console app, placing your AD server in the below code:
static void Main( string[] args )
{
IEnumerable<User> users = GetADUsers();
Console.WriteLine( "Users: " + users.Count().ToString() );
}
static DirectoryEntry ROOT = new DirectoryEntry( "LDAP://MyADDomainLocation.com" );
private static IEnumerable<User> GetADUsers()
{
IEnumerable<User> users;
var usersDS = new DirectorySource<User>( ROOT, SearchScope.Subtree );
users = from usr in usersDS
where usr.Name == "A*" // FIlter A then any character(s)
select usr;
users = users.OrderBy( user => user.Name ).ToList(); // Sort them alphabetically by name.
return users;
}
For more information check Get All Users using C# with Linq To Active Directory
and LINQ to LDAP
For .NET Core or Standard, please see Chris D's answer, below.
For get comprehensive knowledge about this subject check (Almost) Everything In Active Directory via C#
I hope this will help to you.
Sorry to reply to such an old question, but I felt it needed an updated answer. I wrote a .NET Standard library for this:
Linq2Ldap.Core (NuGet, GitHub) The platform-independent core library that can translate from Expressions into LDAP filters, and parse them back out, again.
It has two wrapper libraries for Active Directory:
Linq2Ldap.Protocols (NuGet, GitHub) - A thin wrapper around Linq2Ldap.Core + System.DirectoryServices.Protocols.
Linq2Ldap (NuGet, GitHub) - A thin wrapper for System.DirectoryServices.
The heart of it can transpile between Expression<Func<T, bool>>s and LDAP filters. The models (T) referenced by the Expressions must implement an interface, IEntry, that basically defines a fancy indexer class that you'd use like this: m => m["cn"] == "someuser". You can also create special properties to alias your directory attributes, too. Please see the project wiki for more info.
I'm trying to use Azure Mobile Services to create a backend for an asynchronous multiplayer game. I'm using a sql database and a .NET backend on WAMS, calling the service from the .NET client (Xamarin.iOS specifically atm).
The class for the item being into the db:
public class Match {
public string Id { get; set; }
public int Challengers { get; set; }
string GameData { get; set; }
public List<string> Players { get; set; }
public string LastPlayer { get; set; }
public string Message { get; set; }
public string NextPlayer { get; set; }
public int PlayerGroup { get; set; }
}
I'm inserting it into the database using:
var matchtable = MobileService.GetTable <Match> ();
CurrentMatch = new Match {
Message = variant.ToString () + ", " + CurrentUser + " vs ??",
NextPlayer = CurrentUser,
Players = players,
PlayerGroup = playerGroup,
Challengers = 0,
Game = null,
LastPlayer = null
};
await matchtable.InsertAsync (CurrentMatch);
I'm then doing other things that will affect the match and need to update it again later, but I don't have an Id field for the CurrentMatch to be able to do the update. Everything I can find tells me that I should get the Id field back after the insert (either the method returning something or updating CurrentMatch itself with it), but it must all be talking about a javascript backend or different client or something. The InsertAsync method in the .NET client has no return value (well, technically returns Task) and the CurrentMatch doesn't get updated with the Id field from the call (also makes sense since it's not a ref or out parameter).
How on earth am I supposed to get the Id field for an object I just inserted into the database?
I'm assuming you are using the latest version of the Mobile Services client SDK, in which case you are calling this InsertAsync method here.
You're right that the parameter is not a ref or out parameter, but it can modify the fields of the object you passed in. In this case, it will modify the contents of the Match object.
My guess is that there is another code issue that's interfering. Or, if that code snippet is in a method, make sure it returns a Task and you await it before you check the contents of Id. A simple console log should help here.
If this doesn't solve the problem, then please include more context, otherwise the code you've written should behave as I've said.
Hello im trying to create a login using wcf but somehow looks like my program dont work as I wanted ;(
public class UserService : IUserService
{
[DataMember]
public string Login { get; set; }
[DataMember]
public string Password { get; set; }
[DataMember]
public string Type { get; set; }
[DataMember]
public int ID { get; set; }
public List<UserInfo> GetUserInformation()
{
QuizDBEntities contex = new QuizDBEntities();
var UserInfo = from a in contex.UserInfoes select a;
return UserInfo.ToList();
}
}
I created
protected void Button1_Click(object sender, EventArgs e)
{
string username = TextBox1.Text;
string password = TextBox2.Text;
UserService vs = new UserService();
List<UserInfo> alfa = new List<UserInfo>();
}
I used few foreach/if loop but every time I do something wrong and my list act like its empty ( I tried grindwiev and did get all data ;( ) Anyone can help me and give hint how can I compare List to login/password ?
A WCF service isn't actually a service until it's hosted somewhere (IIS, self-hosted, etc). Simply adding the attributes [ServiceContract] and [OperationContract] do not magically make it a service.
SOAP Web services like WCF are not directly accessed by the client - the client goes through a proxy to interact with the service. This proxy can be generated automatically by Visual Studio through either Add Service Reference or the command line svcutil.exe. An easy way to do this is to create a new WCF Service Application - this will be hosted in IIS. There are different (and in my opinion better) ways to host the service, but for simplicity and sake of illustration we'll go with this one.
So let's assume you have a WCF service application up and running, and it has the code you posted above. You could then choose Add Service Reference in the VS Solution Explorer to add a service reference to your service. This will generate a proxy for you to use. The name of the proxy is usually UserServiceClient (i.e., Visual Studio adds Client to the end).
To call a method in your service with this proxy, you would do this:
UserServiceClient proxy = new UserServiceClient();
List<UserInfo> users = proxy.GetUserInformation;
This would give you a list of all the users in your database. You would probably want to either markup the UserInfo entity as a DataContract, or create a new class that has the properties in it as a DataContract - your current code doesn't do anything to set the properties it has in it, and services themselves don't do anything with properties (not to mention your code isn't setting any values for them anyway).
Now for your other question - "how can I compare List to login/password"? In a nutshell, you can't. Your List<UserInfo> is a list of UserInfo objects, and you're attempting to compare a string to this list. That won't work.
What you could do, however, is create another method in your service that would accept a username and a password and return that user's information if it is found. It might look something like below, but first let's make a DataContract to hold the UserInfo (basically moving the DataMembers from the service to a separate class:
[DataContract]
public class UserInformation
{
[DataMember]
public string Login { get; set; }
[DataMember]
public string Password { get; set; }
[DataMember]
public string Type { get; set; }
[DataMember]
public int ID { get; set; }
}
public UserInformation GetUser(string userName, string password)
{
UserInformation user = new UserInformation();
using (QuizDBEntities context = new QuizDBEntities())
{
user = (from a in context.UserInfoes
where a.UserName == userName && a.Password == password
select new UserInformation() {
Login = a.UserName,
Password = a.Password,
Type = a.Type,
ID = a.ID}).SingleOrDefault();
}
return user;
}
The UserInformation class contains the DataMembers you originally had in your service. The LINQ query selects the user that has the matching UserName and Password and populates the UserInformation class (property names are conjecture as I don't know what your UserInfo entity looks like). The SingleOrDefault() at the end selects one matching result, or if no match is found returns the default value - which in this case will be null.
You could then use it like this:
UserServiceClient proxy = new UserServiceClient();
UserInformation user = proxy.GetUser("someName", "somePassword");
proxy.Close();
if (user == null)
{
// No match was found, so do something
}
else
{
// Match was found, so proceed with what you were doing
}
All of the above is primarily for illustration purposes, but you should be able to adapt to your program's needs. I would also suggest Googling for some good tutorials on how to create and host a WCF service.
I want to access to ActiveDirectory using LINQ to LDAP and I want to Get List of All users in that
how can I do that?
You can try something like below.
using ActiveDs;
using BdsSoft.DirectoryServices.Linq;
using System.Linq.Expressions;
using System.DirectoryServices;
[DirectorySchema( "user", typeof( IADsUser ) )]
class User
{
public string Name { get; set; }
public string sAMAccountName { get; set; }
public string objectCategory { get; set; }
public string mail { get; set; }
public string Description { get; set; }
[DirectoryAttribute( "PasswordLastChanged", DirectoryAttributeType.ActiveDs )]
public DateTime PasswordLastSet { get; set; }
[DirectoryAttribute("distinguishedName")]
public string Dn { get; set; }
[DirectoryAttribute("memberOf")]
public string[] Groups { get; set; }
}
Use this code to access AD from a console app, placing your AD server in the below code:
static void Main( string[] args )
{
IEnumerable<User> users = GetADUsers();
Console.WriteLine( "Users: " + users.Count().ToString() );
}
static DirectoryEntry ROOT = new DirectoryEntry( "LDAP://MyADDomainLocation.com" );
private static IEnumerable<User> GetADUsers()
{
IEnumerable<User> users;
var usersDS = new DirectorySource<User>( ROOT, SearchScope.Subtree );
users = from usr in usersDS
where usr.Name == "A*" // FIlter A then any character(s)
select usr;
users = users.OrderBy( user => user.Name ).ToList(); // Sort them alphabetically by name.
return users;
}
For more information check Get All Users using C# with Linq To Active Directory
and LINQ to LDAP
For .NET Core or Standard, please see Chris D's answer, below.
For get comprehensive knowledge about this subject check (Almost) Everything In Active Directory via C#
I hope this will help to you.
Sorry to reply to such an old question, but I felt it needed an updated answer. I wrote a .NET Standard library for this:
Linq2Ldap.Core (NuGet, GitHub) The platform-independent core library that can translate from Expressions into LDAP filters, and parse them back out, again.
It has two wrapper libraries for Active Directory:
Linq2Ldap.Protocols (NuGet, GitHub) - A thin wrapper around Linq2Ldap.Core + System.DirectoryServices.Protocols.
Linq2Ldap (NuGet, GitHub) - A thin wrapper for System.DirectoryServices.
The heart of it can transpile between Expression<Func<T, bool>>s and LDAP filters. The models (T) referenced by the Expressions must implement an interface, IEntry, that basically defines a fancy indexer class that you'd use like this: m => m["cn"] == "someuser". You can also create special properties to alias your directory attributes, too. Please see the project wiki for more info.