Пример #1
0
 public void ScheduleStart(DateTime timeToStart)
 {
     DateTime now = DateTime.Now;
     if (timeToStart <= now && !IsRunning)
         StartRoundControl();
     else
     {
         AspnetCache cache = new AspnetCache();
         TimeSpan ts = timeToStart - DateTime.Now;
         cache.Insert("Schedule", "1", now.AddMinutes(ts.Minutes), TimeSpan.Zero, CacheItemPriority.Normal, ScheduleCallback);
     }
 }
Пример #2
0
        public void CheckRoundAction()
        {
            DateTime now = DateTime.Now;
            //var cache = HttpRuntime.Cache;
            AspnetCache cache = new AspnetCache();
            bool hasRun = CurrentRoundHasRun(now);
            string comment = string.Empty;
            if (now.Minute % MinutesPerRound == 0 && !hasRun)
            {
                //TODO create logic to allow rollback
                //TODO block actions during round calculation

                //Execute round
                if (OnRoundExecution != null)
                    try { OnRoundExecution(); }
                    catch (Exception error) { comment = error.Message; }
                    //finally { IsRunning = false; }

                //Save now on lastExecutionDate
                DateTime lastExecutionDate = now;

                now = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0, 0);
                xmlLogger.Write(lastExecutionDate, DateTime.Now, comment);

                //Sleep minutesPerRound minutes
                //cache.Insert(CacheKey, "1", null, now.AddMinutes(MinutesPerRound), TimeSpan.Zero, CacheItemPriority.Normal, RoundCallback);
                cache.Insert(CacheKey, "1", now.AddMinutes(MinutesPerRound), TimeSpan.Zero, CacheItemPriority.Normal, RoundCallback);
            }
            else
            {
                //xmlLogger.Write(now, DateTime.Now, "Not executed");
                //cache.Insert(CacheKey, "1", null, now.AddMinutes(now.Minute % MinutesPerRound).AddSeconds(-1 * now.Second), TimeSpan.Zero, CacheItemPriority.Normal, RoundCallback);
                cache.Insert(CacheKey, "1", now.AddMinutes(now.Minute % MinutesPerRound).AddSeconds(-1 * now.Second), TimeSpan.Zero, CacheItemPriority.Normal, RoundCallback);
            }
        }