private bool Register(string ClientID, string emailAddress, string Password) { if (LogEvent != null) { LogEvent("Registering User"); } using (var db = new DamoclesEntities()) { System.Data.Entity.DbSet <User> users = db.Users; var eu = Users.CreateUser(ClientID, emailAddress, Password); users.Add(eu); int rows = db.SaveChanges(); if (rows < 1) { if (LogEvent != null) { LogEvent("Failed to Add user: " + emailAddress); } return(false); } else { login.UpdateLoginHistory(emailAddress); return(true); } } }
public void Login(string emailAddress, string Password) { if (LogEvent != null) { LogEvent(emailAddress + " Is Logging in"); } // Does the User Exist in the Database? using (var db = new DamoclesEntities()) { AddClient(emailAddress); // Add the User's Client for this logon var uid = User.GetUserID(emailAddress); var user = db.Users.First(u => u.UserId == uid); user.IsOnline = true; // Set the User to Online int rows = db.SaveChanges(); UpdateLoginHistory(emailAddress); // Add the User's Logon History if (rows == 1) { LogEvent(emailAddress + " is Logged In"); LoginResultEvent(true); } else { LogEvent(emailAddress + " Failed to Log In"); LoginResultEvent(false); } } }
public void LogOffUser(string Cid) { if (LogEvent != null) { LogEvent(Cid + " Is Being Logged Off"); } //TODO: We need to store the User Clients IDs when they Utils.Log on so we can Utils.Log them off properly at the end! if (Cid.Contains("-")) // Internally generated IDs do not contains hyphens. { using (var db = new DamoclesEntities()) { var user = db.Users.First(u => u.CurrentClientID == Cid); user.IsOnline = false; int rows = db.SaveChanges(); string emailAddress = User.GetUserEmailAddressByID(Cid); UpdateLogOffHistory(emailAddress); if (rows == 1) { LogEvent(emailAddress + " is Logged Out"); } else { LogEvent(emailAddress + " Failed to Log Out"); } } } }
internal void SaveUrl(string URL) { using (var db = new DamoclesEntities()) { var urls = db.URLS; string newurl = Utils.DecodeUrlString(URL); //TODO: ADD NEW EVENT ADD URL AddUrl(URL); int row = db.SaveChanges(); if (row > 1) { if (LogEvent != null) { LogEvent("Saved URL To Database " + URL); } } else { if (LogEvent != null) { LogEvent("Failed to Save URL To Database " + URL); } } } }
public void DeleteAllUsers(DamoclesEntities db) { if (LogEvent != null) { LogEvent("Deleting All Users."); } var all = from c in db.Users select c; db.Users.RemoveRange(all); db.SaveChanges(); }
private void UpdateLogOffHistory(string emailAddress) { if (LogEvent != null) { LogEvent("Updating Users LogOff History"); } using (var db = new DamoclesEntities()) { var uid = User.GetUserID(emailAddress); var loh = db.LogonHistories.First(lh => lh.LoggedOffDate == null && lh.UserId == uid); loh.LoggedOffDate = DateTime.UtcNow; db.SaveChanges(); var us = db.Users.First(u => u.UserId == uid); us.IsOnline = false; us.CurrentClientID = null; db.SaveChanges(); } }
internal void DeleteAllURLS(DamoclesEntities db) { if (LogEvent != null) { LogEvent("Deleting All URLS"); } var all = from c in db.URLS select c; db.URLS.RemoveRange(all); db.SaveChanges(); }
private void saveLicenseNumber(string ln, string emailAddress) { using (var db = new DamoclesEntities()) { var lnumber = db.LicenseNumbers; var newlicense = new LicenseNumber(); newlicense.emailAddress = emailAddress; newlicense.LicenseNumber1 = ln; lnumber.Add(newlicense); db.SaveChanges(); if (LogEvent != null) { LogEvent("Saved License Number"); } } }
internal void UpdateUrlInQueueStatus(string url) { if (!string.IsNullOrEmpty(url)) { using (var db = new DamoclesEntities()) { var urls = db.URLS; var result = urls.FirstOrDefault(u => u.URLPath == url); result.IsInProcessingQueue = true; int rows = db.SaveChanges(); if (rows < 1) { LogEvent("Failed to Set Url to IsInProcessingQueue = True " + url); } } } }
private void SeedAdminUser(DamoclesEntities db, System.Data.Entity.DbSet<User> usrs, User su, string em) { if (LogEvent != null) LogEvent("Seeding Admin User"); su.emailAddress = em; su.UserPasswordHash = "097dfd905dfa0e078883b7afcf7e653dde569bb1ed2ce3384d9c9ed7b85741d6e8d1b1a356318805d3c8b31b36a9916936d005d8134fb015d0392cf75cd7fa24"; su.RegisteredDate = DateTime.UtcNow; su.CountryId = 3; su.StateId = 2; su.JurisidictionId = 4; su.LanguagesId = 1; su.IsOnline = false; su.AccountStatusId = 3; // su.LicenseNumber = license.GenerateTemporaryLicenseNumber(em); su.emailAddress = em; su.UserClientID = null; su.CurrentClientID = null; usrs.Add(su); db.SaveChanges(); }
public void UpdateLoginHistory(string emailAddress) { if (LogEvent != null) { LogEvent("User's Logon History is being Created."); } using (var db = new DamoclesEntities()) { var loh = db.LogonHistories; var lohe = new LogonHistory(); lohe.LoggedOnDate = DateTime.UtcNow; lohe.UserId = User.GetUserID(emailAddress); loh.Add(lohe); int rows = db.SaveChanges(); if (rows < 1) { LogEvent(emailAddress + " Failed to Add User's Logon History Record "); } } }
private int AddClient(string emailAddress) { if (LogEvent != null) { LogEvent(emailAddress + " Is Being Added in"); } int rid = 0; using (var db = new DamoclesEntities()) { var c = db.Clients; var nclient = new Client(); nclient.RaptorClientID = emailAddress; nclient.UserId = User.GetUserID(emailAddress); c.Add(nclient); db.SaveChanges(); rid = nclient.ClientsID; return(rid); } }
internal void PopulateURLQueue(long numberOfUrlsToGet) { StopURLMonitor(); long toprocess = UrlsToProcessCount(); if (toprocess > 0) { if (toprocess < numberOfUrlsToGet) { numberOfUrlsToGet = toprocess; } if (LogEvent != null) { LogEvent("Populating URL Queue, Adding " + numberOfUrlsToGet); } if (ProgressMaximumChangedEvent != null) { ProgressMaximumChangedEvent(int.Parse(numberOfUrlsToGet.ToString())); } using (var db = new DamoclesEntities()) { var urls = db.URLS; for (int idx = 0; idx < numberOfUrlsToGet; idx++) { var result = urls.FirstOrDefault(u => u.IsInProcessingQueue == false); var urlp = result.URLPath; result.JoinedProcessingQueueDate = DateTime.UtcNow; urlQueue.Enqueue(urlp); if (ProgressMaximumChangedEvent != null && ProgressChangedEvent != null) { ProgressChangedEvent(idx); } SetUrlToInProcessingQueue(urlp); db.SaveChanges(); } } if (ProgressMaximumChangedEvent != null && ProgressChangedEvent != null) { ProgressChangedEvent(0); } if (LogEvent != null) { LogEvent("Populating URL Queue Completed "); } if (MoreUrlsLeftToProcessEvent != null) { MoreUrlsLeftToProcessEvent(); // Tell the main program it can start sending URLS again } } else { // This is a FATAL Problem, It may require // Manually Adding more URLS // Returning URLS that have been in the processing queue for a shorter than normal period of time to be returned to the processing queue // This event should not be fired in normal operations but can occur during debugging. if (LogEvent != null) { LogEvent("Failed to Populate URL Queue - there are no URLS left to Process"); } if (NoUrlsLeftToProcessEvent != null) { NoUrlsLeftToProcessEvent(); } StartURLMonitor(); } }