Exemple #1
0
        public int UpdateInstances_Recurrent()
        {
            // find the first occurrence starting with yesterday (this morning)

            // daily schedule is an exception, it's not a search and starts today
            DateTime current = (RecurrencePattern == RecurrencePattern.Daily_EveryNDays)
                ? mInstance.StartDateTime
                : GetNextRecurrence(mInstance.StartDateTime.AddDays(-1));

            int instance = 0;

            while (!IsRecurrentPastDate(current, instance))
            {
                ScheduleInstance si = GetOrCreateScheduleInstance(instance);
                // starts on the date, with a timeofday delta (days may have 23 hours for daylight saving)
                si.StartDateTime = current.Date.Add(mInstance.StartDateTime.TimeOfDay);
                // add the duration of the recurrent event
                si.EndDateTime = current.Add(mInstance.EndDateTime.TimeOfDay - mInstance.StartDateTime.TimeOfDay);
                // instance number
                si.Instance = instance;
                // save
                Session.Save(si);
                // next occurence + every N days
                current = GetNextRecurrence(current);
                instance++;
            }

            return(instance);
        }
Exemple #2
0
        public async Task <IActionResult> Edit(long id, [Bind("ScheduleInstanceId,ScheduleMasterId,ScheduledDateUtc,ScheduledDateTimeOffset,ActiveYn")] ScheduleInstance scheduleInstance)
        {
            if (id != scheduleInstance.ScheduleInstanceId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(scheduleInstance);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ScheduleInstanceExists(scheduleInstance.ScheduleInstanceId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(IndexDataTable)));
            }
            ViewData["ScheduleMasterId"] = new SelectList(_context.ScheduleMaster.OrderBy(x => x.ScheduleDesciption), "ScheduleMasterId", "ScheduleDesciption", scheduleInstance.ScheduleMasterId);
            return(View(scheduleInstance));
        }
Exemple #3
0
        private int UpdateInstances_None()
        {
            ScheduleInstance instance = GetOrCreateScheduleInstance(0);

            instance.StartDateTime = mInstance.StartDateTime;
            if (mInstance.AllDay)
            {
                instance.EndDateTime = mInstance.EndDateTime.AddDays(1);
            }
            else if (mInstance.NoEndDateTime)
            {
                instance.EndDateTime = mInstance.StartDateTime.Date.AddDays(1);
            }
            else
            {
                instance.EndDateTime = mInstance.EndDateTime;
            }

            if (instance.EndDateTime < instance.StartDateTime)
            {
                // BUGBUG: this should never happen
            }

            Session.Save(instance);
            return(1);
        }
        // GET: ScheduleInstance/Create
        public IActionResult Create()
        {
            ViewData["ScheduleMasterId"] = new SelectList(_context.ScheduleMaster.OrderBy(x => x.ScheduleDesciption), "ScheduleMasterId", "ScheduleDesciption");
            ScheduleInstance scheduleInstance = new ScheduleInstance();

            scheduleInstance.ActiveYn = true;
            return(View(scheduleInstance));
        }
Exemple #5
0
 /// <summary>
 /// Инициализирует экземпляр задания в соответствии с заданным правилом работы планировщика.
 /// </summary>
 /// <param name="schema">Конфигурация параметров планировщика служб.</param>
 public EndpointsLauncher(ScheduleExecutionSchema schema)
 {
     _executionSchema = schema;
     Id                = schema.Id;
     _heart            = new ScheduleInstance(TimeSpan.FromSeconds(schema.DueTime), TimeSpan.FromSeconds(schema.Period));
     _heart.Tripped   += HeartTripped;
     _heart.Completed += (obj, args) => OnCompleted(this, args);
     State             = TaskExecutionType.Idle;
 }
Exemple #6
0
        public static void InitComponents()
        {
            ScheduleInstance = Bootstrap.Container.Resolve <SchedulerInstance>();
            ScheduleInstance.Start(Bootstrap.Container);

            ServiceBinding = new ServiceBinding(Bootstrap.Container);
            ServiceBinding.Start();

            log.Debug("Components initialized");
        }
        public void TestNoRecurrence_StartEnd()
        {
            Console.WriteLine("TestNoRecurrence_StartEnd");

            ManagedAccount a = new ManagedAccount(Session);

            try
            {
                a.Create("Test User", "testpassword", "*****@*****.**", DateTime.UtcNow, AdminSecurityContext);

                TransitSchedule ts = new TransitSchedule();

                ts.AccountId         = a.Id;
                ts.StartDateTime     = DateTime.UtcNow;
                ts.RecurrencePattern = RecurrencePattern.None;
                ts.EndDateTime       = ts.StartDateTime.AddHours(1);

                ManagedSchedule m_s         = new ManagedSchedule(Session);
                int             schedule_id = m_s.CreateOrUpdate(ts, AdminSecurityContext);

                Schedule s = Session.Load <Schedule>(schedule_id);

                Assert.AreEqual(s.ScheduleInstances.Count, 1, "There's more than one instance on a non-recurrent schedule.");

                {
                    ScheduleInstance ts_instance = s.ScheduleInstances[0];

                    Assert.AreEqual(ts_instance.StartDateTime, s.StartDateTime, "Schedule instance start date/time doesn't match.");
                    Assert.AreEqual(ts_instance.EndDateTime, s.EndDateTime, "Schedule instance end date/time doesn't match.");
                    Assert.AreEqual(ts_instance.Schedule, s, "Schedule instance schedule object doesn't match.");
                    Assert.AreEqual(ts_instance.Instance, 0, "Instance index is not zero.");
                    Assert.AreEqual(ts_instance.Modified, s.Created, "Instance creation date/time doesn't match schedule.");
                }

                // force update again
                Assert.AreEqual(m_s.UpdateInstances(), 1, "More than one event instance has been generated.");

                {
                    Assert.AreEqual(s.ScheduleInstances.Count, 1, "There's more than one instance on a non-recurrent schedule.");

                    ScheduleInstance ts_instance = (ScheduleInstance)s.ScheduleInstances[0];

                    Assert.AreEqual(ts_instance.StartDateTime, s.StartDateTime, "Schedule instance start date/time doesn't match.");
                    Assert.AreEqual(ts_instance.EndDateTime, s.EndDateTime, "Schedule instance end date/time doesn't match.");
                    Assert.AreEqual(ts_instance.Schedule, s, "Schedule instance schedule object doesn't match.");
                    Assert.AreEqual(ts_instance.Instance, 0, "Instance index is not zero.");
                    Assert.AreEqual(ts_instance.Modified, s.Created, "Instance creation date/time doesn't match schedule.");
                }
            }
            finally
            {
                a.Delete(AdminSecurityContext);
            }
        }
Exemple #8
0
        public async Task <IActionResult> Create([Bind("ScheduleInstanceId,ScheduleMasterId,ScheduledDateUtc,ScheduledDateTimeOffset,ActiveYn")] ScheduleInstance scheduleInstance)
        {
            if (ModelState.IsValid)
            {
                _context.Add(scheduleInstance);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(IndexDataTable)));
            }
            ViewData["ScheduleMasterId"] = new SelectList(_context.ScheduleMaster.OrderBy(x => x.ScheduleDesciption), "ScheduleMasterId", "ScheduleDesciption", scheduleInstance.ScheduleMasterId);
            return(View(scheduleInstance));
        }
        public void TestRecurrence_Monthly_DayNOfEveryNMonths()
        {
            Console.WriteLine("TestRecurrence_Monthly_DayNOfEveryNMonths");

            // event occurs weekly on tuesday and friday

            ManagedAccount a = new ManagedAccount(Session);

            try
            {
                a.Create("Test User", "testpassword", "*****@*****.**", DateTime.UtcNow, AdminSecurityContext);

                TransitSchedule ts = new TransitSchedule();

                ts.AccountId         = a.Id;
                ts.StartDateTime     = DateTime.UtcNow;
                ts.RecurrencePattern = RecurrencePattern.Monthly_DayNOfEveryNMonths;
                ts.MonthlyDay        = 3;
                ts.MonthlyMonth      = 2;
                ts.Endless           = true;
                ts.EndDateTime       = DateTime.UtcNow.AddHours(1);

                ManagedSchedule m_s         = new ManagedSchedule(Session);
                int             schedule_id = m_s.CreateOrUpdate(ts, AdminSecurityContext);

                Schedule s = Session.Load <Schedule>(schedule_id);

                Assert.IsNotNull(s.ScheduleInstances, "Schedule instances cannot be null.");

                ScheduleInstance ts_previous_instance = null;
                foreach (ScheduleInstance ts_instance in s.ScheduleInstances)
                {
                    Console.WriteLine(string.Format("Event on {0}.", ts_instance.StartDateTime.ToLongDateString()));
                    Assert.AreEqual(ts_instance.StartDateTime.Day, ts.MonthlyDay, "Day of month is wrong.");
                    if (ts_previous_instance != null)
                    {
                        Assert.AreEqual(
                            ts_instance.StartDateTime, ts_previous_instance.StartDateTime.AddMonths(ts.MonthlyMonth),
                            "Previous instance delta is incorrect.");
                    }
                    ts_previous_instance = ts_instance;
                }
            }
            finally
            {
                a.Delete(AdminSecurityContext);
            }
        }
        public void TestRecurrence_Daily_EveryNDays()
        {
            Console.WriteLine("TestRecurrence_Daily_EveryNDays");

            ManagedAccount a = new ManagedAccount(Session);

            try
            {
                a.Create("Test User", "testpassword", "*****@*****.**", DateTime.UtcNow, AdminSecurityContext);

                TransitSchedule ts = new TransitSchedule();

                ts.AccountId         = a.Id;
                ts.StartDateTime     = DateTime.UtcNow;
                ts.RecurrencePattern = RecurrencePattern.Daily_EveryNDays;
                ts.Endless           = false;
                ts.DailyEveryNDays   = 2;
                ts.EndOccurrences    = 10;
                ts.EndDateTime       = DateTime.UtcNow.AddHours(1);

                ManagedSchedule m_s         = new ManagedSchedule(Session);
                int             schedule_id = m_s.CreateOrUpdate(ts, AdminSecurityContext);

                Schedule s = Session.Load <Schedule>(schedule_id);

                Assert.AreEqual(ts.EndOccurrences, s.ScheduleInstances.Count, "There's more than ten instance on this schedule.");

                ScheduleInstance ts_instance = (ScheduleInstance)s.ScheduleInstances[0];

                Assert.AreEqual(ts_instance.StartDateTime.TimeOfDay, s.StartDateTime.TimeOfDay, "Schedule instance start date/time doesn't match.");
                Assert.AreEqual(ts_instance.EndDateTime.TimeOfDay, s.EndDateTime.TimeOfDay, "Schedule instance end date/time doesn't match.");
                Assert.AreEqual(ts_instance.Schedule, s, "Schedule instance schedule object doesn't match.");
                Assert.AreEqual(ts_instance.Instance, 0, "Instance index is not zero.");
                Assert.AreEqual(ts_instance.Modified, s.Modified, "Instance creation date/time doesn't match schedule.");

                ScheduleInstance ts_instance_1 = (ScheduleInstance)s.ScheduleInstances[5];
                ScheduleInstance ts_instance_2 = (ScheduleInstance)s.ScheduleInstances[6];

                Assert.AreEqual(ts_instance_1.StartDateTime.TimeOfDay, ts_instance_2.StartDateTime.TimeOfDay, "Schedule instance start date/time doesn't match.");
                Assert.AreEqual(ts_instance_1.Instance + 1, ts_instance_2.Instance, "Sequent schedule instance indexes are wrong.");
                Assert.AreEqual(ts_instance_2.StartDateTime.Subtract(ts_instance_1.StartDateTime), new TimeSpan(2, 0, 0, 0), "Schedule interval is wrong.");
            }
            finally
            {
                a.Delete(AdminSecurityContext);
            }
        }
Exemple #11
0
        public void DailyAt14_30()
        {
            var dateTemplate = new DailyScheduleTemplate();
            var timeTemplate = new ExactTimeScheduleTemplate(14, 30);
            var template     = new ScheduleTemplate(dateTemplate, timeTemplate);

            var startDate = new DateTime(2019, 10, 23, 04, 34, 56);

            var schedule = new ScheduleInstance(template, startDate);

            schedule.Take(5).Should().Equal(new DateTime[] {
                new DateTime(2019, 10, 23, 14, 30, 00),
                new DateTime(2019, 10, 24, 14, 30, 00),
                new DateTime(2019, 10, 25, 14, 30, 00),
                new DateTime(2019, 10, 26, 14, 30, 00),
                new DateTime(2019, 10, 27, 14, 30, 00)
            });
        }
Exemple #12
0
        public void WeeklyEveryMondayAt17_30()
        {
            var dateTemplate = new WeeklyScheduleTemplate(1);

            dateTemplate[DayOfWeek.Monday] = true;
            var timeTemplate = new ExactTimeScheduleTemplate(17, 30);

            var template = new ScheduleTemplate(dateTemplate, timeTemplate);

            var startDate = new DateTime(2019, 10, 23, 04, 34, 56);

            var schedule = new ScheduleInstance(template, startDate);

            schedule.Take(5).Should().Equal(new DateTime[] {
                new DateTime(2019, 10, 28, 17, 30, 00),
                new DateTime(2019, 11, 04, 17, 30, 00),
                new DateTime(2019, 11, 11, 17, 30, 00),
                new DateTime(2019, 11, 18, 17, 30, 00),
                new DateTime(2019, 11, 25, 17, 30, 00)
            });
        }
        public void TestNoRecurrence_AllDay()
        {
            Console.WriteLine("TestNoRecurrence_AllDay");

            ManagedAccount a = new ManagedAccount(Session);

            try
            {
                a.Create("Test User", "testpassword", "*****@*****.**", DateTime.UtcNow, AdminSecurityContext);

                TransitSchedule ts = new TransitSchedule();
                ts.AccountId         = a.Id;
                ts.StartDateTime     = DateTime.UtcNow;
                ts.RecurrencePattern = RecurrencePattern.None;
                ts.AllDay            = true;
                ts.EndDateTime       = ts.StartDateTime; // all that day, will be adjusted +1 and end within 24 hours

                ManagedSchedule m_s         = new ManagedSchedule(Session);
                int             schedule_id = m_s.CreateOrUpdate(ts, AdminSecurityContext);

                Schedule s = Session.Load <Schedule>(schedule_id);

                m_s.UpdateInstances();

                Assert.AreEqual(s.ScheduleInstances.Count, 1, "There's more than one instance on a non-recurrent schedule.");

                ScheduleInstance ts_instance = (ScheduleInstance)s.ScheduleInstances[0];

                Assert.AreEqual(s.StartDateTime, ts_instance.StartDateTime, "Schedule instance start date/time doesn't match.");
                Assert.AreEqual(s.EndDateTime.AddDays(1), ts_instance.EndDateTime, "Schedule instance end date/time doesn't match.");
                Assert.AreEqual(s, ts_instance.Schedule, "Schedule instance schedule object doesn't match.");
                Assert.AreEqual(0, ts_instance.Instance, "Instance index is not zero.");
                Assert.AreEqual(s.Created, ts_instance.Modified, "Instance creation date/time doesn't match schedule.");
            }
            finally
            {
                a.Delete(AdminSecurityContext);
            }
        }
 protected SchedulingEntity(int id)
 {
     _id = id;
     using (ISession session = NHibernateHelper.SessionManager.GetSessionFor <WebEnvironmentFiact>().SessionFactory.OpenSession())
     {
         Sheduler sheduler       = session.Get <TSheduler>(id);
         var      isSynchronized = CorrectTime(sheduler);
         DateTime?fixedTime      = sheduler.NextRun;
         if (isSynchronized || !fixedTime.HasValue)
         {
             session.Save(sheduler);
             session.Flush();
             if (!fixedTime.HasValue)
             {
                 return;
             }
         }
         TimeSpan launch = fixedTime.Value.Subtract(DateTime.Now);
         State  = TaskExecutionType.Idle;
         _heart = new ScheduleInstance(launch);
     }
     _heart.Tripped   += InstanceTripped;
     _heart.Completed += (obj, args) => OnCompleted(this, args);
 }
Exemple #15
0
        /// <summary>
        /// Get or create a schedule instance.
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        private ScheduleInstance GetOrCreateScheduleInstance(int index)
        {
            if (mInstance.ScheduleInstances == null)
            {
                mInstance.ScheduleInstances = new List <ScheduleInstance>();
            }

            if (index < mInstance.ScheduleInstances.Count)
            {
                ScheduleInstance instance = (ScheduleInstance)mInstance.ScheduleInstances[index];
                instance.Modified = mInstance.Modified;
                return(instance);
            }

            ScheduleInstance result = new ScheduleInstance();

            result.Schedule = mInstance;
            result.Instance = index;
            result.Created  = result.Modified = mInstance.Modified;

            mInstance.ScheduleInstances.Add(result);

            return(result);
        }
Exemple #16
0
        public void DailyEvery3HoursFrom9To19()
        {
            var dateTemplate = new DailyScheduleTemplate();
            var timeTemplate = new HourlyScheduleTemplate(3);

            timeTemplate.From(9, 00);
            timeTemplate.To(19, 00);
            var template = new ScheduleTemplate(dateTemplate, timeTemplate);

            var startDate = new DateTime(2019, 10, 23, 04, 34, 56);

            var schedule = new ScheduleInstance(template, startDate);

            schedule.Take(8).Should().Equal(new DateTime[] {
                new DateTime(2019, 10, 23, 09, 00, 00),
                new DateTime(2019, 10, 23, 12, 00, 00),
                new DateTime(2019, 10, 23, 15, 00, 00),
                new DateTime(2019, 10, 23, 18, 00, 00),
                new DateTime(2019, 10, 24, 09, 00, 00),
                new DateTime(2019, 10, 24, 12, 00, 00),
                new DateTime(2019, 10, 24, 15, 00, 00),
                new DateTime(2019, 10, 24, 18, 00, 00)
            });
        }
Exemple #17
0
 public static void DisposeComponents()
 {
     ServiceBinding.Stop();
     ScheduleInstance.Stop();
     log.Debug("Components disposed");
 }