private void WriteReport(ReportType type)
 {
     Logger.Debug($"WriteReport\t{type}");
     if (DateTime.Now.Hour > 14 && !Config.TryGet(type.ToString(), true))
     {
         Config.Set(type.ToString(), true);
         var result = HttpHelper.Post(Config.Get <string>("Url"), new PostBody(DateTime.Now.ToString("yyyy-MM-dd"), new string[] { "占座占座" }, (int)type));
         Logger.Debug(result);
         SmtpHelper.SendMail(type.ToString(), result);
     }
 }
Esempio n. 2
0
 private static void RunScheduler(TimeSpan interval, Func <CancellationToken, Task> action, CancellationTokenSource token)
 {
     Task.Run(async() =>
     {
         while (!token.IsCancellationRequested)
         {
             try
             {
                 await Task.Delay(interval, token.Token).ConfigureAwait(false);
                 try
                 {
                     await action(token.Token).ConfigureAwait(false);
                 }
                 catch (Exception x)
                 {
                     Logger.Error($"Error while executing action scheduler.\r\n{x.ToString()}");
                     SmtpHelper.SendMail("error", x.ToString());
                     token.Cancel();
                 }
             }
             catch (TaskCanceledException) { }
         }
     }, token.Token);
 }