Beispiel #1
0
        private static IEnumerable <Schedule> CalculateNextRun(IEnumerable <Schedule> schedules)
        {
            foreach (var schedule in schedules)
            {
                if (schedule.CalculateNextRun == null)
                {
                    if (schedule.DelayRunFor > TimeSpan.Zero)
                    {
                        // delayed job
                        schedule.NextRun = Now.Add(schedule.DelayRunFor);
                        _schedules.Add(schedule);
                    }
                    else
                    {
                        // run immediately
                        yield return(schedule);
                    }
                    var hasAdded = false;
                    foreach (var child in schedule.AdditionalSchedules.Where(x => x.CalculateNextRun != null))
                    {
                        var nextRun = child.CalculateNextRun(Now.Add(child.DelayRunFor).AddMilliseconds(1));
                        if (!hasAdded || schedule.NextRun > nextRun)
                        {
                            schedule.NextRun = nextRun;
                            hasAdded         = true;
                        }
                    }
                }
                else
                {
                    schedule.NextRun = schedule.CalculateNextRun(Now.Add(schedule.DelayRunFor));
                    _schedules.Add(schedule);
                }

                foreach (var childSchedule in schedule.AdditionalSchedules)
                {
                    if (childSchedule.CalculateNextRun == null)
                    {
                        if (childSchedule.DelayRunFor > TimeSpan.Zero)
                        {
                            // delayed job
                            childSchedule.NextRun = Now.Add(childSchedule.DelayRunFor);
                            _schedules.Add(childSchedule);
                        }
                        else
                        {
                            // run immediately
                            yield return(childSchedule);

                            continue;
                        }
                    }
                    else
                    {
                        childSchedule.NextRun = childSchedule.CalculateNextRun(Now.Add(childSchedule.DelayRunFor));
                        _schedules.Add(childSchedule);
                    }
                }
            }
        }
Beispiel #2
0
    public DateTime StringToDateTime(string dateTime)
    {
        TimeSpan ts        = TimeSpan.Parse(dateTime);
        TimeSpan ts_offset = ts - Now.TimeOfDay;

        return(Now.Add(ts_offset));
    }
 public void ShouldSuspend_WhenFirstAttemptIsWithinConnectionStateTtl_ShouldReturnFalse()
 {
     _info.Attempts.Add(new ConnectionAttempt(Config.Now()));
     //Move now to default ConnetionStatettl - 1 second
     Now = Now.Add(Defaults.ConnectionStateTtl.Add(TimeSpan.FromSeconds(-1)));
     _info.ShouldSuspend().Should().BeFalse();
 }
 public void ShouldSuspend_WhenFirstAttemptEqualOrGreaterThanConnectionStateTtl_ShouldReturnTrue()
 {
     Now = DateTimeOffset.Now;
     _info.Attempts.Add(new ConnectionAttempt(Now));
     //Move now to default ConnetionStatettl - 1 second
     Now = Now.Add(Defaults.ConnectionStateTtl);
     _info.ShouldSuspend().Should().BeTrue("When time is equal");        // =
     Now = Now.AddSeconds(1);
     _info.ShouldSuspend().Should().BeTrue("When time is greater than"); // >
 }
Beispiel #5
0
            public async void RequestMissed_RequestAgain()
            {
                var missedDeadline = Now.Add(-DeviceSyncConstants.PushMissed);
                var service        = new PushSyncService(MockPushSyncStore(new[] { new SyncAction()
                                                                                   {
                                                                                       Id       = "test",
                                                                                       Deadline = missedDeadline
                                                                                   } }).Object, MockDigitPushServiceCLient(),
                                                         Mock.Of <IFocusStore>());

                var res = await service.RequestLocationSync(userId, Now.AddSeconds(1), Now.AddSeconds(1));

                Assert.True(res.SyncRequested);
                Assert.Null(res.SyncPendingFor);
            }
Beispiel #6
0
        /// <summary>
        /// Creates a new time model, optionally providing a starting time and increment
        /// </summary>
        /// <param name="increment">The amount of time to increment on each iteration, defaults to one 100 nanosecond tick</param>
        /// <param name="now">The starting time, defaults to zero</param>
        public Time(TimeSpan?increment = null, TimeSpan?now = null) : base()
        {
            this.Name = "TimeThread";
            Increment = increment.HasValue ? increment.Value : TimeSpan.FromTicks(1);
            Now       = now.HasValue ? now.Value : TimeSpan.Zero;
            InvokeNextCycle(() => current = this);

            EndOfCycle.SubscribeForLifetime(() => Now = Now.Add(Increment), this);

            this.OnDisposed(() =>
            {
                foreach (var func in Functions)
                {
                    func.Lifetime.TryDispose();
                }
            });
        }
Beispiel #7
0
 static public DateTime GetTimeForFutureTime(double delta)
 {
     try
     {
         if (syncToClock)
         {
             DateTime future = Now.Add(new TimeSpan((long)((delta * 10000000) * timeRate)));
             return(future);
         }
         else
         {
             return(Now);
         }
     }
     catch
     {
         return(Now);
     }
 }
Beispiel #8
0
 public void AddTime(TimeSpan time)
 {
     SetDateTime(Now.Add(time));
 }
Beispiel #9
0
 public void AddTime(TimeSpan addedTime)
 {
     Now = Now.Add(addedTime);
 }