public override void ProcessRequest(HttpContext context) { if (!CheckAuthentication(context)) { return; } var resp = context.Response; resp.StatusCode = 200; resp.ContentType = "application/json"; resp.ContentEncoding = System.Text.Encoding.UTF8; var statuses = Readiness.CheckDependencies(); var output = new Dictionary <string, object>(); foreach (var status in statuses) { if (!status.IsReady) { // The whole thing is no good. resp.TrySkipIisCustomErrors = true; resp.StatusCode = 503; } output[status.Dependency.Name] = new { ready = status.IsReady, message = status.Message, }; } var serializer = new JsonSerializer(); serializer.Serialize(resp.Output, output); }
public void Get(string paramOne) { if (paramOne.ToLower() == "reset") { Log.Append("GET - Reset Email Sync Parameters"); Global.isSyncing = false; Readiness.DeleteBlockerFile(); } //if (!Permissions.ValidAPIKey(APIKey)) return new Email[] {}; paramOne = AESGCM.SimpleDecryptWithPassword(paramOne.Replace("_", "/").Replace("-", "+"), AESGCM.AES256Key); if (paramOne.ToLower() == "sync") { Log.Append("GET - Sync PST Files"); PSTImporter.SyncPSTFiles(); } if (paramOne.ToLower() == "validate") { Log.Append("GET - Validating email and file integrity"); Task.Run(() => Global.ValidateMessages()); } if (paramOne.ToLower() == "refresh") { Log.Append("GET - Refresh Email List requested"); // Reload settings before getting emails Global.LoadSettings(); EmailRepository.CacheInfo(Global.GetAllEmails().ToArray()); } //return new Email[] { }; }
protected void Application_Start() { JsonSerializerSettings jsSettings = new JsonSerializerSettings(); jsSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; AreaRegistration.RegisterAllAreas(); // Initialize background worker components Hangfire.GlobalConfiguration.Configuration.UseMemoryStorage(); RecurringJob.AddOrUpdate(() => Readiness.MinutelyTaskChecker(), Cron.Minutely()); RecurringJob.AddOrUpdate(() => Readiness.TerminationCheck(), Cron.Minutely()); server = new BackgroundJobServer(); // Web API routes System.Web.Http.GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); if (initialized) { return; } Log.AppendBlankLine(); Global.LoadInitializers(); initialized = true; }
// ========================================================================================== // =====================================[ EMAILS ]=========================================== // ========================================================================================== public static List <Email> GetAllEmails(bool forceUpdate = false) { #if DEBUG Readiness.DeleteBlockerFile(); #endif Log.Append("Pulling emails from email servers..."); TimeSpan startTime = DateTime.Now.TimeOfDay; List <Email> newEmails = new List <Email>(); if (isSyncing || !Readiness.EmailSyncReady()) { Log.Append("ERROR: Existing sync in progress"); return(new List <Email>()); } Readiness.CreateBlockerFile(); // If force update, set last update time to new DateTime (year = 1800) if (forceUpdate) { UserList.ForEach(x => x.LastUpdateTime = new DateTime()); } foreach (User user in UserList.Where(x => x.SyncEmails)) { newEmails.AddRange(user.GetEmails()); if (Readiness.CheckTerminationStatus()) { break; } } // Remove emails from last update date (prevent redundancy) ClearDuplicateMailByID(); Readiness.DeleteBlockerFile(); Log.Append(String.Format("All inboxes completed. Total of {0} emails cached ({2} new emails). Process took {1}", EmailList.Count, Arithmetic.GetStopWatchStr((DateTime.Now.TimeOfDay - startTime).TotalMilliseconds), newEmails.Count)); ExportEmailFile(); // Remove non-validated and unmapped messages in the background Task.Run(() => ValidateMessages(true)); SaveSettings(); return(newEmails); }
/// <summary> /// Creates a new document node. /// </summary> internal Document() { _owner = this; _type = NodeType.Document; Async = true; _referrer = string.Empty; _ready = Readiness.Complete; _name = "#document"; _implementation = new DOMImplementation(); _styleSheets = new StyleSheetList(); _quirksMode = QuirksMode.Off; }
internal static void LoadInitializers() { ArchivesChecker.GetEntireArchive(); LoadSettings(); ImportEmailFile(); Readiness.DeleteBlockerFile(); if (!Environment.MachineName.Contains("ROBIN")) { //Global.GetAllEmails(); } }
/// <summary> /// Creates a new document node. /// </summary> internal Document() { _owner = this; _type = NodeType.Document; Async = true; _referrer = string.Empty; _ready = Readiness.Complete; _name = "#document"; _styleSheets = new StyleSheetList(this); _quirksMode = QuirksMode.Off; _location = new Location("file://localhost/"); _options = Configuration.Default; }
/// <summary> /// Verify that every message has an associated email object (if not, remove) /// </summary> public static void ValidateMessages(bool postSyncCheck = false) { if (isSyncing && !postSyncCheck) { Log.Append("ERROR: Sync in progress. Cannot validate information"); return; } TimeSpan startTime = DateTime.Now.TimeOfDay; int startingCount = PurgeDuplicates(); Log.Append("Validating email & data integrity..."); int removedMessages = 0; startingCount += EmailList.Count; EmailList = EmailList.Where(x => File.Exists(messagesDirectoryPath + x.ID + ".eml") && UserList.Any(y => y.Email.ToLower() == x.To.ToLower())).ToList(); string[] messageFiles = Directory.GetFiles(messagesDirectoryPath, "*.eml*"); foreach (string filePath in messageFiles) { if (!EmailList.Any(x => x.ID == Path.GetFileName(filePath).Substring(0, 9))) { File.Delete(filePath); removedMessages++; } } removedMessages += startingCount - EmailList.Count; Log.Append(String.Format("Validation completed. Found and removed {0} unverified messages. Process took {1}", removedMessages, Arithmetic.GetStopWatchStr((DateTime.Now.TimeOfDay - startTime).TotalMilliseconds))); // Save again after verification if removed anything if (removedMessages > 0) { ExportEmailFile(); } Readiness.DeleteBlockerFile(); }
public static void RegenerateCacheFile() { Log.Append("ERROR: Could not parse email file. Recovering cache file..."); TimeSpan startTime = DateTime.Now.TimeOfDay; EmailList = new List <Email>(); string[] messageFiles = Directory.GetFiles(messagesDirectoryPath, "*.eml*"); int emailCount = 0; int totalEmailCount = messageFiles.Length; foreach (string filePath in messageFiles) { CDO.Message CDOMessage = Email.GetEmlFromFile(filePath); Email email = new Email() { ID = Path.GetFileName(filePath).Substring(0, 9), UID = "0", To = CDOMessage.To + (CDOMessage.CC.Length > 0 ? "," + CDOMessage.CC : ""), From = CDOMessage.From, Subject = CDOMessage.Subject, EmailMessage = "", // prevent nullification MailDate = CDOMessage.ReceivedTime }; emailCount++; email.ParseToEmail(); AppendEmail(email, String.Format("{0}/{1}", emailCount, totalEmailCount)); email.MapNameFromEmail(); } // Save regenerated files ExportEmailFile(); isSyncing = false; Readiness.DeleteBlockerFile(); Log.Append(String.Format("Cache regeneration completed. Process took {0}", Arithmetic.GetStopWatchStr((DateTime.Now.TimeOfDay - startTime).TotalMilliseconds))); }