Example #1
0
        public bool ExecuteProcess()
        {
            var settings = GetSettings(typeof(TrelloReportSettings)) as TrelloReportSettings;

            var serializer = new ManateeSerializer();

            TrelloConfiguration.Serializer         = serializer;
            TrelloConfiguration.Deserializer       = serializer;
            TrelloConfiguration.JsonFactory        = new ManateeFactory();
            TrelloConfiguration.RestClientProvider = new WebApiClientProvider();
            TrelloAuthorization.Default.AppKey     = settings.TrelloAppKey;
            TrelloAuthorization.Default.UserToken  = settings.TrelloUserToken;

            var organization = new Organization(settings.OrganizationID);
            var report       = new Report(organization, settings.CountLastListCardsAsCompleted);

            var subject = $"Отчет Trello от {DateTime.Now.ToLocalTime().ToLongDateString()} { DateTime.Now.ToLocalTime().ToLongTimeString()}";

            if (string.IsNullOrEmpty(settings.AddressToSendReport))
            {
                ReportMailSender.SendReportMail(subject, report.GetReport().ToString());
            }
            else
            {
                ReportMailSender.SendMail(settings.AddressToSendReport, subject, report.GetReport().ToString());
            }
            return(true);
        }
Example #2
0
 public Scheduler()
 {
     try
     {
         InitializeComponent();
     }
     catch (Exception e)
     {
         _serviceLogger.CreateLogRecord(e);
         ReportMailSender.SendLog(_serviceLogger);
         throw;
     }
 }
Example #3
0
        public void ExecuteTask(string groupName = "", bool createEmailReport = true, int sendReportIntervalInSeconds = 0, EventLogEntryType reportInformationLevel = EventLogEntryType.Error, uint maxErrorCount = 0)
        {
            var errorAccured = false;

            GroupName         = groupName;
            SettingsGroupDict = new SettingsGroupRepresentDictionary(GroupName, TaskSettings);
            var lastErrorLogsCount = this.Count(t => t.IsErrorMessage);

            while (maxErrorCount + 1 > 0)
            {
                try
                {
                    ExecutuionMethod();
                    if (lastErrorLogsCount == this.Count(t => t.IsErrorMessage))
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    CreateLogRecord(e);
                }
                lastErrorLogsCount = this.Count(t => t.IsErrorMessage);
                maxErrorCount--;
            }
            if (!createEmailReport)
            {
                return;
            }
            {
                try
                {
                    var messageGroup = Logging.SqlLogger.AddLogRecords(this, $"{TaskName}.{GroupName}");
                    Logging.SqlLogger.ExcludeUnnecessaryLogGroups(messageGroup, reportInformationLevel);
                }
                catch (Exception e)
                {
                    ReportMailSender.SendLog(this);
                    CreateLogRecord(e);
                    return;
                }
                try
                {
                    Logging.SqlLogger.SendLogRecords($"{TaskName}.{GroupName}", sendReportIntervalInSeconds, reportInformationLevel);
                }
                catch (Exception e)
                {
                    CreateLogRecord(e);
                }
            }
        }
Example #4
0
 protected override void OnStart(string[] args)
 {
     try
     {
         InitializeScheduler();
         StartShceduler();
         _serviceLogger.CreateLogRecord("Service started");
     }
     catch (Exception e)
     {
         _serviceLogger.CreateLogRecord(e);
         ReportMailSender.SendLog(_serviceLogger);
         throw;
     }
 }
Example #5
0
        public static void SendLogRecords(string taskName, int sendReportIntervalInSeconds, EventLogEntryType ReportInformationLevel = EventLogEntryType.Error)
        {
            using (var connection = Connection)
            {
                var task = GetTask(connection, taskName);
                var lastReportSentDateTime = GetLastGroupReportSent(task);
                if (lastReportSentDateTime.AddSeconds(sendReportIntervalInSeconds) > DateTime.Now)
                {
                    return;
                }
                var messageGroups   = connection.GetCollection <MessageGroup>(nameof(MessageGroup)).FindAll().Where(t => t.Task.Id == task.Id && t.EntryType <= ReportInformationLevel && !t.MessageSent);
                var taskLoggingList = (from messageGroup in messageGroups
                                       select connection.GetCollection <Message>(nameof(Message)).FindAll().Where(t => t.MessageGroup.Id == messageGroup.Id && t.EntryType <= ReportInformationLevel).OrderBy(t => t.DateTime)
                                       into messagesList
                                       select messagesList.Select(t => new LogMessage.MessageStruct()
                {
                    Message = $"ID {t.Id} {t.MessageText}",
                    EntryType = t.EntryType,
                    DateTime = t.DateTime
                })
                                       into messages
                                       select TaskLogging.GetTaskLogging(task.TaskName, messages)).ToList();
                if (taskLoggingList.Count == 0)
                {
                    return;
                }
                var result = ReportMailSender.SendLogArray(taskLoggingList);

                if (!result)
                {
                    return;
                }

                foreach (var messageGroup in messageGroups)
                {
                    messageGroup.MessageSent = true;
                    connection.GetCollection <MessageGroup>(nameof(MessageGroup)).Update(messageGroup);
                }
            }
        }
Example #6
0
 private bool ExecuteProcess()
 {
     CreateLogRecord("Sending report.");
     ReportMailSender.SendLog(this);
     return(true);
 }