Ejemplo n.º 1
0
        /// <summary>
        /// Check for any Overdue uploads and email if necessary
        /// </summary>
        private static void CheckForOverdueUploads()
        {
            try
            {
                AddDebugInfo(new DebugInfo("CheckForOverdueUploads called.", DebugInfoTypeEnum.Developer));

                var overdueSchemas = _dataSetSchemaService.GetOverDue();
                //send reminder emails
                if (overdueSchemas.Count > 0)
                {
                    AddDebugInfo(new DebugInfo(overdueSchemas.Count + " overdue reminder emails will be sent.", DebugInfoTypeEnum.EmailSent));
                }
                foreach (var schema in overdueSchemas)
                {
                    var template  = String.Format("{0}\\EmailTemplates\\UploadReminder.txt", ConfigurationManager.AppSettings["FileRoot"]);
                    var emailText = new System.Text.StringBuilder();
                    emailText.Append(File.ReadAllText(template));
                    emailText.Replace("#Schema#", schema.Title);
                    emailText.Replace("#LastUploadDate#", schema.DateLastUploadedTo.ToString());
                    emailText.Replace("#DatashareURL#", ConfigurationManager.AppSettings["DatashareURL"]);

                    SendEmail(schema.OwnerEmail, emailText.ToString(), true, "Overdue upload reminder");
                    AddDebugInfo(new DebugInfo(String.Format(@"Schema: {0}. Overdue upload reminder sent to:""{1}""", schema.Title, schema.OwnerEmail), DebugInfoTypeEnum.EmailSent));
                    schema.DateLastReminded = DateTime.Now;
                    _dataSetSchemaService.Save(schema);
                }
            }
            catch (Exception ex)
            {
                AddDebugInfo(new DebugInfo(String.Format(@"CheckForOverdueUploads threw an error: {0}", ex.Message), DebugInfoTypeEnum.Error), ex);
                RestartService("DataShare.Service", 10000);
            }
        }