public SimpleMembershipInitializer() { Database.SetInitializer<UsersContext>(null); try { using (var context = new UsersContext()) { if (!context.Database.Exists()) { // Create the SimpleMembership database without Entity Framework migration schema ((IObjectContextAdapter)context).ObjectContext.CreateDatabase(); } } WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true); } catch (Exception ex) { throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex); } }
// TODO: log /// <summary> /// A client has started connection /// </summary> /// <returns></returns> public override Task OnConnected() { var username = Context.User.Identity.Name; // Get the logged in username var context = new UsersContext(); var profile = context // Find the userprofile by the username(is it uniqe?) .UserProfiles .SingleOrDefault(up => up.UserName == username); if(profile != null && !UserManager.IsUserLoggedIn(profile.UserName)) // If the userprofile exists, and the user is not logged in with other windows/browser { Clients.Caller.receiveUsers(UserManager.GetUsers()); // Send the client the users currently logged in TODO: and not in game(or currently invited?) profile.ConnectionId = Context.ConnectionId; // Store the connectionid in the userprofile (not mapped) for performance UserManager.AddUser(Context.ConnectionId, profile); // Add the user to the static userlist Clients.Others.receiveUser(profile, Context.ConnectionId); // Alert the other clients about the new user } else { Clients.Caller.alertDuplicate(); // Alert the client about his fail } return base.OnConnected(); }