//TODO: This should be retrieved from a Queue via API or Messaging. //TODO: ReportProcessingCount should be retrieved from a settings table on the server and not hard coded. internal static EUReported GetNextUnprocessedRecord() { Damocles2Entities de = new Damocles2Entities(); EUReported eur = de.EUReporteds.Where(r => r.Processed == false && r.ReportProcessingCount < 11).FirstOrDefault(); return(eur); }
internal static string GetUsersOnlineCount() { Damocles2Entities de = new Damocles2Entities(); var ur = de.Users.Where(p => p.IsOnline == true); return(ur.Count().ToString("N0")); }
internal static string GetImagesInvestigated() { Damocles2Entities de = new Damocles2Entities(); HashingHelper hh = new HashingHelper(); string passwordHash = hh.GetSHA512(CurrentUser.UserPassword); User u = de.Users.Where(usr => usr.Username == CurrentUser.Username && usr.UserPassword == passwordHash).FirstOrDefault(); var pr = de.ProcessingResults.Where(pi => pi.UserId == u.Id); int iCount = 0; foreach (ProcessingResult p in pr) { if (p.ASrcResultId != null) { iCount++; } if (p.CSrcResultId != null) { iCount++; } if (p.RSrcResultId != null) { iCount++; } } return(iCount.ToString("N0")); }
internal static string GetPendingReportCount() { Damocles2Entities de = new Damocles2Entities(); var eur = de.EUReporteds.Where(p => p.Processed == false); return(eur.Count().ToString("N0")); }
private User GetUser(Damocles2Entities de) { string pHash = hh.GetSHA512(CurrentUser.UserPassword); User usr = de.Users.Where(u => u.Username == CurrentUser.Username && u.UserPassword == pHash).FirstOrDefault(); return(usr); }
/// <summary> /// Tells us if the Report was of a A R C or X type /// </summary> /// <param name="reportId"> /// nnt: The ReportId we are looking up /// </param> /// <returns> /// string: A R C or X Where X = GoneButNotForgotten /// </returns> /// <remarks> /// The ReportId can be derived from: Convert.ToInt32(Properties.Settings.Default.ProfileReportNumber) /// </remarks> internal static string GetLinkARCRating(int reportId) { Damocles2Entities de = new Damocles2Entities(); var gbResult = de.GoneButNotForgottenLinks.Where(gid => gid.Id == reportId).FirstOrDefault(); // If it exists //TODO: Really need the error code saved in GoneButNotForgotten if (gbResult != null) { return("X"); } ProcessingResult pr = de.ProcessingResults.Where(pid => pid.id == reportId).FirstOrDefault(); if (pr.ASrcResultId != null) { return("A"); } if (pr.RSrcResultId != null) { return("R"); } if (pr.CSrcResultId != null) { return("C"); } return(string.Empty); // We May not have a Src - it may be the whole page that has been reported, or only a link! }
internal double GetUserLifetimeSessionTime() { Damocles2Entities de = new Damocles2Entities(); if (de.Database.Connection.State == System.Data.ConnectionState.Closed) { de.Database.Connection.Open(); } User user = de.Users.Where(u => u.Username == userName && u.UserPassword == userPasswordHash).FirstOrDefault(); if (user == null) { return(0); } var aus = de.UsersSessions.Where(auss => auss.id == user.Id); double t = 0; foreach (UsersSession userS in aus) { TotalSessions++; CurrentUser.SessionSecondsTotal += userS.SessionSeconds; t += userS.SessionSeconds; } return(t); }
internal bool Login(string username, string password) { string passwordHash = utils.HashPassword(password); userName = username; userPasswordHash = passwordHash; Damocles2Entities de = new Damocles2Entities(); User user = de.Users.Where(u => u.Username == username && u.UserPassword == passwordHash).FirstOrDefault(); if (user == null) { return(false); } CurrentUser.UserId = user.Id; //TODO: This is not functioning correctly - simply want the User's current rank. UserRank ur = de.UserRanks.Where(usr => usr.UserId == user.Id).FirstOrDefault(); user.IsOnline = true; UserRank = ur.Rank.RankNameEnglish; UserJurisdiction uj = de.UserJurisdictions.Where(usrj => usrj.UserId == user.Id).FirstOrDefault(); if (uj != null) { if (uj.Jurisidction.Country == uj.Jurisidction.State) { UJurisdiction = uj.Jurisidction.Country; } else { UJurisdiction = uj.Jurisidction.State.Trim() + " in " + uj.Jurisidction.Country.Trim(); } } else { UJurisdiction = "Unknown"; } var aus = de.UsersSessions.Where(auss => auss.id == user.Id); foreach (UsersSession userS in aus) { CurrentUser.SessionSecondsTotal += userS.SessionSeconds; } UsersSession us = new UsersSession(); us.LoggedOnAt = DateTime.UtcNow; us.id = user.Id; de.UsersSessions.Add(us); de.SaveChanges(); return(true); }
internal static ProcessingResult GetProcessingResultById(int reportId) { Damocles2Entities de = new Damocles2Entities(); var gbResult = de.ProcessingResults.Where(gid => gid.id == reportId).FirstOrDefault(); // If it exists //TODO: Really need the error code saved in GoneButNotForgotten return(gbResult); }
//TODO: Not completed Yet // LinkARCRating will be in either - the GoneButNotForgotten table (files that are no longer available) // or ... Processing Results internal static string GetSrcARCRating(int reportId) { Damocles2Entities de = new Damocles2Entities(); var gbResult = de.GoneButNotForgottenLinks.Where(gid => gid.Id == reportId).FirstOrDefault(); // If it exists //TODO: Really need the error code saved in GoneButNotForgotten if (gbResult != null) { return("Src Url Contents Not Available " + gbResult.LastCheckedOn); } return(string.Empty); }
internal void SaveMD5Hash(string fMd5) { Damocles2Entities de = new Damocles2Entities(); Hash h = new Hash(); h.CreatedOn = DateTime.UtcNow; h.HashType = "MD5"; h.HashValue = fMd5; h.id = GetRecordId(); h.UpdatedOn = DateTime.UtcNow; de.Hashes.Add(h); de.SaveChanges(); }
internal void SaveSha256Hash(string fSha256) { Damocles2Entities de = new Damocles2Entities(); Hash h = new Hash(); h.CreatedOn = DateTime.UtcNow; h.HashType = "SHA256"; h.HashValue = fSha256; h.id = GetRecordId(); h.UpdatedOn = DateTime.UtcNow; de.Hashes.Add(h); de.SaveChanges(); }
internal void LogOff() { Damocles2Entities de = new Damocles2Entities(); string passwordHash = utils.HashPassword(CurrentUser.UserPassword); User u = de.Users.Where(usr => usr.Username == CurrentUser.Username && usr.UserPassword == passwordHash).FirstOrDefault(); // UsersSession us = de.UsersSessions.Where(uss => uss.id == u.Id && uss.loggedOffAt == null) // v1.OrderByDescending(rec => rec.Id).FirstOrDefault(); UsersSession us = de.UsersSessions.Where(uss => uss.id == u.Id && uss.loggedOffAt == null).OrderByDescending(ob => ob.LoggedOnAt).FirstOrDefault(); us.loggedOffAt = DateTime.UtcNow; us.SessionSeconds = CurrentUser.ThisSessionSeconds; u.IsOnline = false; de.SaveChanges(); }
// This is a 404 or some other error - do a check for a month to see if it returns // This can be done within Imogen as Background House keeping internal void SetLinkToGoneButNotForgotten(string url) { Damocles2Entities de = new Damocles2Entities(); string pHash = hh.GetSHA512(CurrentUser.UserPassword); User usr = de.Users.Where(u => u.Username == CurrentUser.Username && u.UserPassword == pHash).FirstOrDefault(); EUReported eu = de.EUReporteds.Where(l => l.LinkUrl == url).FirstOrDefault(); if (!string.IsNullOrEmpty(CurrentInternalReport.TrueLinkUrl)) { eu.TrueLinkUrl = CurrentInternalReport.TrueLinkUrl; } if (!string.IsNullOrEmpty(CurrentInternalReport.TrueLinkUrlHash)) { eu.TrueLinkUrlHash = CurrentInternalReport.TrueLinkUrlHash; } eu.UpdatedOn = DateTime.UtcNow; GoneButNotForgottenLink gb = new GoneButNotForgottenLink(); gb.CreatedOn = DateTime.UtcNow; gb.Id = eu.id; gb.LastCheckedOn = DateTime.UtcNow; gb.LinkUrlHash = eu.LinkUrlHash; gb.ReportedBy = usr.Id; //TODO: This won't work - we don't know which link is GoneButNotForgotten - the redirection link or the TrueLink. if (!string.IsNullOrEmpty(CurrentInternalReport.TrueLinkUrlHash)) { eu.TrueLinkUrlHash = CurrentInternalReport.TrueLinkUrlHash; } de.GoneButNotForgottenLinks.Add(gb); try { de.SaveChanges(); } catch (Exception) { } de.Dispose(); gb = null; eu = null; usr = null; }
internal bool RegisterUser(string username, string password, string email, string displayName) { try { string passwordHash = utils.HashPassword(password); Damocles2Entities de = new Damocles2Entities(); User u = new User(); u.CreatedOn = DateTime.UtcNow; u.UpdatedOn = DateTime.UtcNow; u.Username = username; u.UserPassword = passwordHash; u.EmailAddress = email; u.UserDisplayName = displayName; u.IsOnline = false; // Just registered Not logged in yet! de.Users.Add(u); de.SaveChanges(); return(true); } catch (Exception) { //TODO: Better logging than this is required. return(false); } }
internal void SetSrcToGoneButNotForgotten(string url) { Damocles2Entities de = new Damocles2Entities(); User usr = GetUser(de); EUReported eu = de.EUReporteds.Where(l => l.SrcUrl == url).FirstOrDefault(); eu.UpdatedOn = DateTime.UtcNow; GoneButNotForgottenLink gb = new GoneButNotForgottenLink(); gb.CreatedOn = DateTime.UtcNow; gb.Id = eu.id; gb.LastCheckedOn = DateTime.UtcNow; gb.SrcUrlHash = eu.SrcUrlHash; gb.ReportedBy = usr.Id; de.GoneButNotForgottenLinks.Add(gb); de.SaveChanges(); de.Dispose(); gb = null; eu = null; usr = null; }
internal static void SaveCurrentReport() { bool update = false; Damocles2Entities de = new Damocles2Entities(); //TODO: Maybe this should be a Static? CurrentReport ce = de.CurrentReports.Where(cr => cr.ReportNumber == Reporting.CurrentInternalReport.ReportNumber).FirstOrDefault(); if (ce == null) // Generate New Report { ce = new CurrentReport(); ce.ReportStartedOn = DateTime.UtcNow; } else { update = true; ce.UpdatedOn = DateTime.UtcNow; } if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.ImagePath)) { ce.ImagePath = Reporting.CurrentInternalReport.ImagePath; } if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.LinkUrl)) { ce.LinkUrl = Reporting.CurrentInternalReport.LinkUrl; } ce.LinkUrlARCXRating = (int)Reporting.CurrentInternalReport.LinkUrlARCXRating; if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.LinkUrlFilename)) { ce.LinkUrlFilename = Reporting.CurrentInternalReport.LinkUrlFilename; } if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.LinkUrl)) { ce.LinkUrl = Reporting.CurrentInternalReport.LinkUrl; } ce.LinkUrlARCXRating = (int)Reporting.CurrentInternalReport.LinkUrlARCXRating; if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.LinkUrlFilename)) { ce.LinkUrlFilename = Reporting.CurrentInternalReport.LinkUrlFilename; } if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.LinkUrlHash)) { ce.LinkUrlHash = Reporting.CurrentInternalReport.LinkUrlHash; } if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.PageUrl)) { ce.PageUrl = Reporting.CurrentInternalReport.PageUrl; } if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.PageUrlFilename)) { ce.PageUrlFilename = Reporting.CurrentInternalReport.PageUrlFilename; } if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.PageUrlHash)) { ce.PageUrlHash = Reporting.CurrentInternalReport.PageUrlHash; } ce.ProcessingBy = Reporting.CurrentUser.UserId; ce.ReportedBy = Reporting.CurrentInternalReport.ReportedBy; ce.ReportedOn = Reporting.CurrentInternalReport.ReportedOn; if (Reporting.CurrentInternalReport.Completed) { ce.ReportEndedOn = DateTime.UtcNow; } ce.ReportNumber = Reporting.CurrentInternalReport.ReportNumber; ce.ReportProcessed = Reporting.CurrentInternalReport.Completed; ce.ReportSessionTime = Reporting.CurrentInternalReport.ReportSessionTime; if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.SrcUrl)) { ce.SrcUrl = Reporting.CurrentInternalReport.SrcUrl; } ce.SrcUrlARCXRating = (int)Reporting.CurrentInternalReport.SrcUrlARCXRating; if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.SrcUrlFilename)) { ce.SrcUrlFilename = Reporting.CurrentInternalReport.SrcUrlFilename; } if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.SrcUrlHash)) { ce.SrcUrlHash = Reporting.CurrentInternalReport.SrcUrlHash; } if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.TrueLinkUrl)) { ce.TrueLinkUrl = Reporting.CurrentInternalReport.TrueLinkUrl; } if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.TrueLinkUrlFilename)) { ce.TrueLinkUrlFilename = Reporting.CurrentInternalReport.TrueLinkUrlFilename; } if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.TrueLinkUrlHash)) { ce.TrueLinkUrlHash = Reporting.CurrentInternalReport.TrueLinkUrlHash; } if (!update) { de.CurrentReports.Add(ce); } de.SaveChanges(); //TODO: Probably should be using Asynchronous calls for all these }
internal static void LoadCurrentReport() { Damocles2Entities de = new Damocles2Entities(); //TODO: Maybe this should be a Static? CurrentReport ce = de.CurrentReports.Where(cr => cr.ReportProcessed == false).FirstOrDefault(); if (ce == null) // Generate New Report { return; } if (!string.IsNullOrEmpty(ce.ImagePath)) { Reporting.CurrentInternalReport.ImagePath = ce.ImagePath; } if (!string.IsNullOrEmpty(ce.LinkUrl)) { Reporting.CurrentInternalReport.LinkUrl = ce.LinkUrl; } Reporting.CurrentInternalReport.LinkUrlARCXRating = (Reporting.CurrentInternalReport.ARCXRating)ce.LinkUrlARCXRating; if (!string.IsNullOrEmpty(ce.LinkUrlFilename)) { Reporting.CurrentInternalReport.LinkUrlFilename = ce.LinkUrlFilename; } if (!string.IsNullOrEmpty(ce.LinkUrl)) { Reporting.CurrentInternalReport.LinkUrl = ce.LinkUrl; } Reporting.CurrentInternalReport.LinkUrlARCXRating = (Reporting.CurrentInternalReport.ARCXRating)ce.LinkUrlARCXRating; if (!string.IsNullOrEmpty(ce.LinkUrlFilename)) { Reporting.CurrentInternalReport.LinkUrlFilename = ce.LinkUrlFilename; } if (!string.IsNullOrEmpty(ce.LinkUrlHash)) { Reporting.CurrentInternalReport.LinkUrlHash = ce.LinkUrlHash; } if (!string.IsNullOrEmpty(ce.PageUrl)) { Reporting.CurrentInternalReport.PageUrl = ce.PageUrl; } if (!string.IsNullOrEmpty(ce.PageUrlFilename)) { Reporting.CurrentInternalReport.PageUrlFilename = ce.PageUrlFilename; } if (!string.IsNullOrEmpty(ce.PageUrlHash)) { Reporting.CurrentInternalReport.PageUrlHash = ce.PageUrlHash; } Reporting.CurrentUser.UserId = ce.ProcessingBy; Reporting.CurrentInternalReport.ReportedBy = ce.ReportedBy; Reporting.CurrentInternalReport.ReportedOn = ce.ReportedOn; Reporting.CurrentInternalReport.ReportNumber = ce.ReportNumber; Reporting.CurrentInternalReport.ReportSessionTime = ce.ReportSessionTime; if (!string.IsNullOrEmpty(ce.SrcUrl)) { Reporting.CurrentInternalReport.SrcUrl = ce.SrcUrl; } Reporting.CurrentInternalReport.SrcUrlARCXRating = (Reporting.CurrentInternalReport.ARCXRating)ce.SrcUrlARCXRating; if (!string.IsNullOrEmpty(ce.SrcUrlFilename)) { Reporting.CurrentInternalReport.SrcUrlFilename = ce.SrcUrlFilename; } if (!string.IsNullOrEmpty(ce.SrcUrlHash)) { Reporting.CurrentInternalReport.SrcUrlHash = ce.SrcUrlHash; } if (!string.IsNullOrEmpty(ce.TrueLinkUrl)) { Reporting.CurrentInternalReport.TrueLinkUrl = ce.TrueLinkUrl; } if (!string.IsNullOrEmpty(ce.TrueLinkUrlFilename)) { Reporting.CurrentInternalReport.TrueLinkUrlFilename = ce.TrueLinkUrlFilename; } if (!string.IsNullOrEmpty(ce.TrueLinkUrlHash)) { Reporting.CurrentInternalReport.TrueLinkUrlHash = ce.TrueLinkUrlHash; } }
internal void SetSrcToCriminal(string url) { Damocles2Entities de = new Damocles2Entities(); User usr = GetUser(de); EUReported eu = de.EUReporteds.Where(l => l.SrcUrl == url).FirstOrDefault(); // Create ProcessingResult table if it does not already exist! var pr = de.ProcessingResults.Where(prr => prr.id == eu.id).FirstOrDefault(); bool Update = true; if (pr == null) { Update = false; pr = new ProcessingResult(); } pr.id = eu.id; var uju = de.UserJurisdictions.Where(uj => uj.UserId == usr.Id).FirstOrDefault(); pr.JurisdictionId = uju.JurisdictionID; pr.CreatedOn = DateTime.UtcNow; pr.UpdatedOn = DateTime.UtcNow; pr.UserId = usr.Id; // Only add records if they have not already been created (for just now) //if (pr.ASrcResultId == null) //{ // A aRecord = new A(); // aRecord.ResultCount = aRecord.ResultCount + 1; // aRecord.UpdatedOn = DateTime.UtcNow; // aRecord.CreatedOn = DateTime.UtcNow; // aRecord.IsAllowed = true; // de.A.Add(aRecord); // pr.ASrcResultId = aRecord.pid; //} //if (pr.RSrcResultId == null) //{ // R rRecord = new R(); // rRecord.ResultCount = rRecord.ResultCount + 1; // rRecord.UpdatedOn = DateTime.UtcNow; // rRecord.CreatedOn = DateTime.UtcNow; // rRecord.IsRestricted = true; // de.R.Add(rRecord); // pr.RSrcResultId = rRecord.pid; //} if (pr.CSrcResultId == null) { C cRecord = new C(); cRecord.ResultCount = cRecord.ResultCount + 1; cRecord.UpdatedOn = DateTime.UtcNow; cRecord.CreatedOn = DateTime.UtcNow; cRecord.IsCriminal = true; de.C.Add(cRecord); pr.CSrcResultId = cRecord.pid; } if (!Update) { de.ProcessingResults.Add(pr); } // Check to see if the LinkUrl is GoneButNotForgotten var gbnf = de.GoneButNotForgottenLinks.Where(gbn => gbn.LinkUrlHash == eu.LinkUrlHash).FirstOrDefault(); if (gbnf != null) { eu.Processed = true; } else { // this record had already been created so we may have to mark EU as processed - check now if (pr.ALinkResultId != null || pr.RLinkResultId != null || pr.CLinkResultId != null) { eu.Processed = true; } } eu.UpdatedOn = DateTime.UtcNow; de.SaveChanges(); //TODO: Implement this // if eu.Processed == true then raise Event to tell frmMain to go to the next unprocessed Report }
internal static void SaveIndividualsBasicInformation(string Name, string Age, string Sex, string SpokenLanguage, string WrittenLanguage, string Nationality, string Ethnicity, Image image) { Utils.Utils utils = new Utils.Utils(); Damocles2Entities de = new Damocles2Entities(); FaceARC farc = new FaceARC(); Face face = new Face(); // Possible Return Values = X, A, R, C, String.Empty var pr = GetProcessingResultById(CurrentInternalReport.ReportNumber); if (pr != null) { if (pr.CSrcResultId != null) // Theoretically the most common result { farc.CId = pr.CSrcResultId; } if (pr.RSrcResultId != null) { farc.RId = pr.RSrcResultId; } if (pr.ASrcResultId != null) // Theoretically the least common result { farc.AId = pr.ASrcResultId; } farc.FaceId = face.id; face.FaceData = utils.BytesToString(utils.imageToByteArray(image)); face.CreatedOn = DateTime.UtcNow; face.UpdatedOn = DateTime.UtcNow; face.CreatedBy = CurrentUser.UserId; if (!string.IsNullOrEmpty(Name)) { face.Name = Name; } if (!string.IsNullOrEmpty(Age)) { face.Age = Convert.ToInt32(Age); } if (!string.IsNullOrEmpty(Sex)) { face.Sex = Sex; } if (!string.IsNullOrEmpty(SpokenLanguage)) { face.SpokenLanguage = SpokenLanguage; } if (!string.IsNullOrEmpty(WrittenLanguage)) { face.WrittenLanguage = WrittenLanguage; } if (!string.IsNullOrEmpty(Nationality)) { face.Nationality = Nationality; } if (!string.IsNullOrEmpty(Ethnicity)) { face.Ethnicity = Ethnicity; } de.Faces.Add(face); de.FaceARCs.Add(farc); de.SaveChanges(); } else { // Need to save the Profile results before trying to get them from ProcessingResults. } }