Ejemplo n.º 1
0
        private void Test(object sender, System.EventArgs e)
        {
            MessageBox.Show("Test will now create all types of schedules and opens Schedules View");

            // create and add different types of schedules
            Schedule s = new IntervalSchedule("Test_Interval", DateTime.Now.AddMinutes(1), 45, TimeSpan.Zero, new TimeSpan(TimeSpan.TicksPerDay));

            s.OnTrigger += new EventScheduler.Invoke(ScheduleCallBack);
            Scheduler.AddSchedule(s);
            s            = new OneTimeSchedule("Test_Onetime", DateTime.Now.AddMinutes(1.5));
            s.OnTrigger += new EventScheduler.Invoke(ScheduleCallBack);
            Scheduler.AddSchedule(s);
            s            = new DailySchedule("Test_daily", DateTime.Now.AddMinutes(2));
            s.OnTrigger += new EventScheduler.Invoke(ScheduleCallBack);
            Scheduler.AddSchedule(s);
            s            = new WeeklySchedule("Test_weekly", DateTime.Now.AddMinutes(2.5));
            s.OnTrigger += new EventScheduler.Invoke(ScheduleCallBack);
            Scheduler.AddSchedule(s);
            s            = new MonthlySchedule("Test_monthly", DateTime.Now.AddMinutes(3));
            s.OnTrigger += new EventScheduler.Invoke(ScheduleCallBack);
            Scheduler.AddSchedule(s);

            // kick off the Schedules View
            SchedulerUI.ShowSchedules();
        }
Ejemplo n.º 2
0
 private void btnDone_Click(object sender, EventArgs e)
 {
     if (patientHome != null && dialogResult == DialogResult.Yes)
     {
         try
         {
             patientHome.AppointmentSchedule = this.schedule();
             string period           = String.Format("Day: {0};    Time: {1}", schedule()["day"], schedule()["time"]);
             int    appointSetResult = patientHome.Patient.setAppointment(doctorID, period);
             if (appointSetResult > 0)
             {
                 label.Text = "BUSY";
                 int result = WeeklySchedule.updateWeeklySchedule(doctorID, row, col, label.Text);
                 if (result == 0)
                 {
                     MessageBox.Show("Update not successful");
                 }
                 else
                 {
                     MessageBox.Show("Appointment successful");
                 }
             }
             else
             {
                 MessageBox.Show("Appointment could not be set.");
             }
         }
         catch (Exception exp)
         {
             throw new Exception(exp.Message);
         }
     }
     this.Close();
 }
Ejemplo n.º 3
0
        private static void Main(string[] args)
        {
            var startup = new Startup();
            IServiceCollection services = new ServiceCollection();

            startup.ConfigureServices(services);

            ServiceProvider       serviceBuilder = services.BuildServiceProvider();
            ICourseScheduleReader reader         = serviceBuilder.GetRequiredService <ICourseScheduleReader>();

            string filePath = args[0];
            IEnumerable <Course> courses = reader.ReadFromFile(filePath);

            IMapper             mapper  = serviceBuilder.GetRequiredService <IMapper>();
            IEnumerable <Class> classes = mapper.Map <IEnumerable <Class> >(courses);

            var weeklySchedule = new WeeklySchedule("Fall 2018", DateTime.Parse("August 16, 2018"), DateTime.Parse("December 7, 2018"));

            foreach (Class @class in classes)
            {
                weeklySchedule.AddClass(@class);
            }

            IWeeklyScheduleWriter writer = serviceBuilder.GetRequiredService <IWeeklyScheduleWriter>();
            string outputFileName        = args[1];

            outputFileName = writer.WriteAsHtml(weeklySchedule, outputFileName);
        }
        private DailySchedule GetDailyScheduleForName(WeeklySchedule weeklySchedule, string day)
        {
            switch (day.ToLower())
            {
            case "sunday":
                return(db.DailySchedules.FirstOrDefault(d => d.Id == weeklySchedule.SundayScheduleId));

            case "monday":
                return(db.DailySchedules.FirstOrDefault(d => d.Id == weeklySchedule.MondayScheduleId));

            case "tuesday":
                return(db.DailySchedules.FirstOrDefault(d => d.Id == weeklySchedule.TuesdayScheduleId));

            case "wednesday":
                return(db.DailySchedules.FirstOrDefault(d => d.Id == weeklySchedule.WednesdayScheduleId));

            case "thursday":
                return(db.DailySchedules.FirstOrDefault(d => d.Id == weeklySchedule.ThursdayScheduleId));

            case "friday":
                return(db.DailySchedules.FirstOrDefault(d => d.Id == weeklySchedule.FridayScheduleId));

            case "saturday":
                return(db.DailySchedules.FirstOrDefault(d => d.Id == weeklySchedule.SaturdayScheduleId));

            default:
                return(null);
            }
        }
Ejemplo n.º 5
0
        public void UpdateNumberLeaseConfig()
        {
            const string number = "12132041238";
            var          config = Client.NumberLeasesApi.GetConfig(number, "number,configType,callTrackingConfig");

            Assert.IsNull(config.IvrInboundConfig);
            Assert.AreEqual(NumberConfig.NumberConfigType.TRACKING, config.ConfigType);
            CallTrackingConfig callTrackingConfig = new CallTrackingConfig();

            callTrackingConfig.Recorded        = true;
            callTrackingConfig.Screen          = true;
            callTrackingConfig.TransferNumbers = new List <string> {
                "12132212384"
            };
            callTrackingConfig.Voicemail             = true;
            callTrackingConfig.IntroSoundId          = 9643523003;
            callTrackingConfig.VoicemailSoundId      = 9643523003;
            callTrackingConfig.FailedTransferSoundId = 9643523003;
            callTrackingConfig.WhisperSoundId        = 9643523003;

            WeeklySchedule weeklySchedule = new WeeklySchedule
            {
                StartTimeOfDay = new LocalTime {
                    Hour = 1, Minute = 1, Second = 1
                },
                StopTimeOfDay = new LocalTime {
                    Hour = 2, Minute = 2, Second = 2
                },
                TimeZone   = "America/New_York",
                DaysOfWeek = new HashSet <DayOfWeek> {
                    DayOfWeek.MONDAY, DayOfWeek.FRIDAY, DayOfWeek.SATURDAY
                }
            };

            callTrackingConfig.WeeklySchedule = weeklySchedule;

            GoogleAnalytics googleAnalytics = new GoogleAnalytics
            {
                Category        = "Sales",
                GoogleAccountId = "UA-12345-26",
                Domain          = "testDomain"
            };

            callTrackingConfig.GoogleAnalytics = googleAnalytics;

            config.CallTrackingConfig = callTrackingConfig;
            config.ConfigType         = NumberConfig.NumberConfigType.TRACKING;

            Client.NumberLeasesApi.UpdateConfig(config);
            config = Client.NumberLeasesApi.GetConfig(number);
            Assert.AreEqual(config.ConfigType, NumberConfig.NumberConfigType.TRACKING);
            Assert.AreEqual(config.Number, number);
            Assert.NotNull(config.CallTrackingConfig);
            System.Console.WriteLine(config);

            config = Client.NumberLeasesApi.GetConfig(number, "callTrackingConfig,configType");
            Assert.IsNotNull(config.CallTrackingConfig);
            Assert.IsNull(config.Number);
            Assert.AreEqual(NumberConfig.NumberConfigType.TRACKING, config.ConfigType);
        }
        public void TestEveryWeekOnSaturdays()
        {
            //Arrange
            int            numberOfRecurrences = 3;
            WeeklySchedule item = new WeeklySchedule
            {
                RecurrenceType                = WeeklySchedule.RecurrenceTypeEnum.Weekly,
                WeeklyEveryNWeeks             = 1,
                WeeklyDayOfWeekSunday         = false,
                WeeklyDayOfWeekMonday         = false,
                WeeklyDayOfWeekTuesday        = false,
                WeeklyDayOfWeekWednesday      = false,
                WeeklyDayOfWeekThursday       = false,
                WeeklyDayOfWeekFriday         = false,
                WeeklyDayOfWeekSaturday       = true,
                RecurrenceStartDate           = new DateTime(2019, 1, 5),
                RecurrenceEndAfterNSelected   = true,
                RecurrenceEndAfterNOccurences = numberOfRecurrences
            };
            int      numberOfDaysSelected = 1;
            DateTime lastDate             = item.NormalizeDate(item.RecurrenceStartDate.AddDays(((item.WeeklyEveryNWeeks * 7) * item.RecurrenceEndAfterNOccurences) - (item.WeeklyEveryNWeeks * 7) + numberOfDaysSelected - 1));

            //Act
            item.ProcessFutureDates();

            //Assert
            Assert.AreEqual(item.Name, "Weekly every " + item.WeeklyEveryNWeeks + " weeks, on Saturdays, for a total of " + item.RecurrenceEndAfterNOccurences * numberOfDaysSelected + " FutureDates");
            DateTime[] dates = item.FutureDates.ToArray();
            Assert.AreEqual(lastDate, dates[dates.Length - 1]);
        }
        public IHttpActionResult PutWeeklySchedule(int id, WeeklySchedule weeklySchedule)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != weeklySchedule.Id)
            {
                return(BadRequest());
            }

            db.Entry(weeklySchedule).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WeeklyScheduleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 8
0
        public void WeeklySchedule_CanCreateInstance()
        {
            // Arrange
            const int    expectedSchoolDaysCount   = 5;
            const int    expectedSchoolTimesCount  = 157;
            const string expectedSemesterName      = "Fall 2019";
            var          expectedSemesterStartDate = DateTime.Parse("August 16, 2018");
            var          expectedSemesterEndDate   = DateTime.Parse("December 7, 2018");

            // Act
            var weeklySchedule = new WeeklySchedule(expectedSemesterName, expectedSemesterStartDate, expectedSemesterEndDate);

            // Assert
            Assert.NotNull(weeklySchedule);
            int actualSchoolDaysCount  = weeklySchedule.SchoolDays.ToList().Count;
            int actualSchoolTimesCount = weeklySchedule.SchoolTimes.ToList().Count;

            string   actualSemesterName      = weeklySchedule.SemesterName;
            DateTime actualSemesterStartDate = weeklySchedule.SemesterStartDate;
            DateTime actualSemesterEndDate   = weeklySchedule.SemesterEndDate;
            IEnumerable <TimeSlot> timeSlots = weeklySchedule.TimeSlots;

            Assert.Equal(expectedSchoolDaysCount, actualSchoolDaysCount);
            Assert.Equal(expectedSchoolTimesCount, actualSchoolTimesCount);

            Assert.Equal(expectedSemesterName, actualSemesterName);
            Assert.Equal(expectedSemesterStartDate, actualSemesterStartDate);
            Assert.Equal(expectedSemesterEndDate, actualSemesterEndDate);
        }
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName == ParentObjectParameterSet)
            {
                ResourceGroupName = AccountObject.ResourceGroupName;
                Location          = AccountObject.Location;
                var NameParts = AccountObject.Name.Split('/');
                AccountName = NameParts[0];
            }

            var snapshotPolicyBody = new Management.NetApp.Models.SnapshotPolicy()
            {
                Location        = Location,
                Enabled         = Enabled,
                HourlySchedule  = (HourlySchedule != null) ? HourlySchedule.ConvertFromPs() : null,
                DailySchedule   = (DailySchedule != null) ? DailySchedule.ConvertFromPs() : null,
                WeeklySchedule  = (WeeklySchedule != null) ? WeeklySchedule.ConvertFromPs() : null,
                MonthlySchedule = (MonthlySchedule != null) ? MonthlySchedule.ConvertFromPs() : null
            };

            if (ShouldProcess(Name, string.Format(PowerShell.Cmdlets.NetAppFiles.Properties.Resources.CreateResourceMessage, ResourceGroupName)))
            {
                var anfSnapshotPolicy = AzureNetAppFilesManagementClient.SnapshotPolicies.Create(snapshotPolicyBody, ResourceGroupName, AccountName, snapshotPolicyName: Name);
                WriteObject(anfSnapshotPolicy.ConvertToPs());
            }
        }
        private void VerifySchedule(Tuple <DayOfWeek, TimeSpan>[] scheduleData, DateTime now)
        {
            WeeklySchedule schedule = new WeeklySchedule();

            foreach (var occurrence in scheduleData)
            {
                schedule.Add(occurrence.Item1, occurrence.Item2);
            }

            var expectedSchedule = scheduleData.GroupBy(p => p.Item1);

            // loop through the full schedule a few times, ensuring we cross over
            // a month boundary ensuring day handling is correct
            for (int i = 0; i < 10; i++)
            {
                // run through the entire schedule once, ordering the expected times per day
                foreach (var expectedScheduleDay in expectedSchedule)
                {
                    foreach (TimeSpan time in expectedScheduleDay.OrderBy(p => p.Item2).Select(p => p.Item2))
                    {
                        DateTime nextOccurrence = schedule.GetNextOccurrence(now);
                        Assert.Equal(expectedScheduleDay.Key, nextOccurrence.DayOfWeek);
                        Assert.Equal(time, nextOccurrence.TimeOfDay);
                        now = nextOccurrence + TimeSpan.FromSeconds(1);
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> PutWeeklySchedule([FromRoute] int id, [FromBody] WeeklySchedule WeeklySchedule)
        {
            var _context = new ServicesDbContext();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != WeeklySchedule.Id)
            {
                return(BadRequest());
            }

            _context.Entry(WeeklySchedule).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WeeklyScheduleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 12
0
 private string SetPageHeader(WeeklySchedule weeklySchedule, string weeklyScheduleHtmlPage)
 {
     weeklyScheduleHtmlPage = weeklyScheduleHtmlPage
                              .Replace("#SemesterName#", weeklySchedule.SemesterName)
                              .Replace("#SemesterStartDate#", weeklySchedule.SemesterStartDate.ToString("MMMM dd, yyyy"))
                              .Replace("#SemesterEndDate#", weeklySchedule.SemesterEndDate.ToString("MMMM dd, yyyy"));
     return(weeklyScheduleHtmlPage);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Allow 2 weeks to show up as "Fortnightly", otherwise return the base implementation of a week description.
 /// </summary>
 public override string Format(WeeklySchedule s)
 {
     if (s.Frequency == 2)
     {
         return("Fortnightly"); // to be complete this should output which days that occur fortnightly
     }
     return(base.Format(s));
 }
Ejemplo n.º 14
0
        public WeeklyScheduleTests()
        {
            string semesterName      = "Fall 2018";
            var    semesterStartDate = DateTime.Parse("August 16, 2018");
            var    semesterEndDate   = DateTime.Parse("December 7, 2018");

            _weeklySchedule = new WeeklySchedule(semesterName, semesterStartDate, semesterEndDate);
        }
 public void Occurrences_before_start()
 {
     // 1/4 -> 12/4, 15/4 -> 26/4, 29/4
     WeeklySchedule week = new WeeklySchedule { Frequency = 2, Monday = true, Thursday = true };
     IList<DateTime> occurrences = Convert(week.GetOccurrences(_start, new DateTime(2010, 3, 1), new DateTime(2010, 3, 31)));
     
     Assert.AreEqual(0, occurrences.Count);
 }
        public void Next_occurrence_before_start()
        {
            // 1/4 -> 12/4, 15/4 -> 26/4, 29/4
            WeeklySchedule week = new WeeklySchedule {Frequency = 2, Monday = true, Thursday = true };
            DateTime? next = week.NextOccurrence(_start, new DateTime(2010, 1, 1));

            Assert.IsTrue(next.HasValue);
            Assert.AreEqual(new DateTime(2010, 4, 1), next.Value);
        }
            public void Visit(ScheduledAccessRule rule)
            {
                var schedule = new WeeklySchedule(rule.TimeZone);

                rule.Entries.ForEach(x => schedule.DailyTimeRange.Add(x.Day, new TimeRange(x.FromTime, x.ToTime)));
                var dto = AccessRule.Scheduled(rule.AccessPoint.AccessPointId, schedule);

                Scheduled.Add(dto);
            }
        public void Occurrences_before_start()
        {
            // 1/4 -> 12/4, 15/4 -> 26/4, 29/4
            WeeklySchedule week = new WeeklySchedule {
                Frequency = 2, Monday = true, Thursday = true
            };
            IList <DateTime> occurrences = Convert(week.GetOccurrences(_start, new DateTime(2010, 3, 1), new DateTime(2010, 3, 31)));

            Assert.AreEqual(0, occurrences.Count);
        }
        public void Occurrences_stress_test()
        {
            var d = new DateTime(1900, 1, 1);
            WeeklySchedule week = new WeeklySchedule { Frequency = 3, Sunday = true, Monday = true, Tuesday = true, Wednesday = true, Thursday = true, Friday = true, Saturday = true };

            // 1/1/1900 (Monday) -> 31/12/1999 (Friday) = 36524 total days; 7 days in every 21 for 100 years; 36524 - 14 days = 36510 / 3 = 12170
            IList<DateTime> occurrences = Convert(week.GetOccurrences(d, d, new DateTime(1999, 12, 31)));

            Assert.AreEqual(12178, occurrences.Count);
        }
Ejemplo n.º 20
0
        private int CalculateRowsDaySpans(DayOfWeek day, WeeklySchedule weeklySchedule)
        {
            IEnumerable <TimeSlot> timeSlots = weeklySchedule.TimeSlots.Where(timeSlot => timeSlot.Day == day);

            if (timeSlots.Count() == 0)
            {
                return(0);
            }
            return(timeSlots.Max(timeSlot => timeSlot.Classes.Count()));
        }
Ejemplo n.º 21
0
        public ActionResult Index(WeeklySchedule weekly)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            database.Schedule.AddRange(weekly.ParseToList());
            return(RedirectToAction("Daily"));
        }
        public void ToString_ReturnsCorrectValue()
        {
            WeeklySchedule schedule = new WeeklySchedule();

            schedule.Add(DayOfWeek.Monday, new TimeSpan(9, 0, 0));
            schedule.Add(DayOfWeek.Wednesday, new TimeSpan(8, 30, 0));
            schedule.Add(DayOfWeek.Wednesday, new TimeSpan(18, 0, 0));
            schedule.Add(DayOfWeek.Friday, new TimeSpan(10, 0, 0));

            Assert.Equal("Weekly: 4 occurrences", schedule.ToString());
        }
Ejemplo n.º 23
0
 public ActionResult EditWeekly(WeeklySchedule schedule, string selectedToolID, string selectedContactID, List <string> selectedDevices)
 {
     if (ModelState.IsValid)
     {
         unitOfWork.ScheduleRepository.Update(schedule);
         UpdateScheduleGraph(schedule, selectedToolID, selectedContactID, selectedDevices);
         unitOfWork.Save();
         return(RedirectToAction("Index"));
     }
     return(View(schedule));
 }
Ejemplo n.º 24
0
        public ActionResult CreateWeekly(WeeklySchedule schedule)
        {
            if (ModelState.IsValid)
            {
                unitOfWork.ScheduleRepository.Insert(schedule);
                unitOfWork.ScheduleRepository.Save();
                return(RedirectToAction("Index"));
            }

            return(View(schedule));
        }
        public void Occurrences_within_period()
        {
            // 1/4 -> 12/4, 15/4 -> 26/4, 29/4
            WeeklySchedule week = new WeeklySchedule { Frequency = 2, Monday = true, Thursday = true };
            IList<DateTime> occurrences = Convert(week.GetOccurrences(_start, new DateTime(2010, 4, 9), new DateTime(2010, 4, 28)));

            Assert.AreEqual(3, occurrences.Count);
            Assert.AreEqual(occurrences[0], new DateTime(2010, 4, 12));
            Assert.AreEqual(occurrences[1], new DateTime(2010, 4, 15));
            Assert.AreEqual(occurrences[2], new DateTime(2010, 4, 26));
        }
        public void Next_occurrence_before_start()
        {
            // 1/4 -> 12/4, 15/4 -> 26/4, 29/4
            WeeklySchedule week = new WeeklySchedule {
                Frequency = 2, Monday = true, Thursday = true
            };
            DateTime?next = week.NextOccurrence(_start, new DateTime(2010, 1, 1));

            Assert.IsTrue(next.HasValue);
            Assert.AreEqual(new DateTime(2010, 4, 1), next.Value);
        }
        public Schedule GetSchedule(Content content)
        {
            WeeklySchedule weeklySchedule = new WeeklySchedule(content.SearchApplication)
            {
                WeeksInterval = this.CrawlScheduleRunEveryInterval,
                DaysOfWeek    = this.DaysOfWeek,
                StartHour     = this.CrawlScheduleStartDateTime
            };

            return(weeklySchedule);
        }
        public IHttpActionResult GetWeeklySchedule(int id)
        {
            WeeklySchedule weeklySchedule = db.WeeklySchedules.Find(id);

            if (weeklySchedule == null)
            {
                return(NotFound());
            }

            return(Ok(weeklySchedule));
        }
Ejemplo n.º 29
0
        private string SetHtmlTableHeaderRow(WeeklySchedule weeklySchedule, string weeklyScheduleHtmlPage)
        {
            string theadContent = $"<th>Date</th>";

            foreach (DateTime time in weeklySchedule.SchoolTimes)
            {
                theadContent += $"<th>{time.ToShortTimeString()}</th>";
            }
            ;
            weeklyScheduleHtmlPage = weeklyScheduleHtmlPage.Replace("#TableHeader#", theadContent);
            return(weeklyScheduleHtmlPage);
        }
Ejemplo n.º 30
0
        public void FormatNextOccurrences_ReturnsExpectedString()
        {
            DateTime  now       = new DateTime(2015, 9, 16, 10, 30, 00);
            TimerInfo timerInfo = new TimerInfo(new CronSchedule("0 0 * * * *"), null);
            string    result    = timerInfo.FormatNextOccurrences(10, now);

            string expected =
                "The next 10 occurrences of the schedule will be:\r\n" +
                "9/16/2015 11:00:00 AM\r\n" +
                "9/16/2015 12:00:00 PM\r\n" +
                "9/16/2015 1:00:00 PM\r\n" +
                "9/16/2015 2:00:00 PM\r\n" +
                "9/16/2015 3:00:00 PM\r\n" +
                "9/16/2015 4:00:00 PM\r\n" +
                "9/16/2015 5:00:00 PM\r\n" +
                "9/16/2015 6:00:00 PM\r\n" +
                "9/16/2015 7:00:00 PM\r\n" +
                "9/16/2015 8:00:00 PM\r\n";

            Assert.Equal(expected, result);

            timerInfo = new TimerInfo(new DailySchedule("2:00:00"), null);
            result    = timerInfo.FormatNextOccurrences(5, now);

            expected =
                "The next 5 occurrences of the schedule will be:\r\n" +
                "9/17/2015 2:00:00 AM\r\n" +
                "9/18/2015 2:00:00 AM\r\n" +
                "9/19/2015 2:00:00 AM\r\n" +
                "9/20/2015 2:00:00 AM\r\n" +
                "9/21/2015 2:00:00 AM\r\n";
            Assert.Equal(expected, result);

            WeeklySchedule weeklySchedule = new WeeklySchedule();

            weeklySchedule.Add(DayOfWeek.Monday, new TimeSpan(8, 0, 0));
            weeklySchedule.Add(DayOfWeek.Wednesday, new TimeSpan(9, 30, 0));
            weeklySchedule.Add(DayOfWeek.Wednesday, new TimeSpan(21, 30, 0));
            weeklySchedule.Add(DayOfWeek.Friday, new TimeSpan(10, 0, 0));

            timerInfo = new TimerInfo(weeklySchedule, null);

            result = timerInfo.FormatNextOccurrences(5, now);

            expected =
                "The next 5 occurrences of the schedule will be:\r\n" +
                "9/16/2015 9:30:00 PM\r\n" +
                "9/18/2015 10:00:00 AM\r\n" +
                "9/21/2015 8:00:00 AM\r\n" +
                "9/23/2015 9:30:00 AM\r\n" +
                "9/23/2015 9:30:00 PM\r\n";
            Assert.Equal(expected, result);
        }
        public void Occurrences_stress_test()
        {
            var            d    = new DateTime(1900, 1, 1);
            WeeklySchedule week = new WeeklySchedule {
                Frequency = 3, Sunday = true, Monday = true, Tuesday = true, Wednesday = true, Thursday = true, Friday = true, Saturday = true
            };

            // 1/1/1900 (Monday) -> 31/12/1999 (Friday) = 36524 total days; 7 days in every 21 for 100 years; 36524 - 14 days = 36510 / 3 = 12170
            IList <DateTime> occurrences = Convert(week.GetOccurrences(d, d, new DateTime(1999, 12, 31)));

            Assert.AreEqual(12178, occurrences.Count);
        }
Ejemplo n.º 32
0
        public async Task <ActionResult> Create([Bind(Include = "Id,Time,Duration,Type,MaxAttendance,StartDate,EndDate,SelectedDays")] WeeklyClassSetup weeklyClass)
        {
            List <DayOfWeek>      chosenDays = weeklyClass.SelectedDays.Select(x => (DayOfWeek)Enum.Parse(typeof(DayOfWeek), x)).ToList();
            List <DayOfWeekModel> days       = db.DaysOfWeek.Where(d => chosenDays.Contains(d.Day)).ToList();

            weeklyClass.Days = days;
            foreach (var day in days)
            {
                day.WeeklyClassSetups.Add(weeklyClass);
            }

            // Create Classes
            WeeklySchedule weeklySchedule = new WeeklySchedule
            {
                TimeOfDay       = weeklyClass.Time,
                SchedulingRange = new Period(weeklyClass.StartDate, weeklyClass.EndDate)
            };

            weeklySchedule.SetDays(chosenDays);
            var schedules = new List <Schedule>()
            {
                weeklySchedule
            };
            List <Class> classes = _calendarGenerator.GenerateCalendar(Utilities.Constants.calendarPeriod, schedules).ToList();

            foreach (var item in classes)
            {
                item.Duration      = weeklyClass.Duration;
                item.MaxAttendance = weeklyClass.MaxAttendance;
                item.Type          = weeklyClass.Type;
                item.WeeklyClass   = weeklyClass;
                item.Attendance    = new List <Athlete>();
            }

            weeklyClass.GeneratedClasses = classes;

            ModelState.Remove("Days");
            ModelState.Remove("GeneratedClasses");
            if (ModelState.IsValid)
            {
                db.WeeklyClasses.Add(weeklyClass);
                db.Classes.AddRange(classes);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            else
            {
                var errors = ModelState.Select(x => x.Value.Errors).Where(y => y.Count > 0).ToList();
            }

            return(View(weeklyClass));
        }
        public IHttpActionResult PostWeeklySchedule(WeeklySchedule weeklySchedule)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.WeeklySchedules.Add(weeklySchedule);
            db.SaveChanges();

            return(Ok(weeklySchedule));
        }
        public static WeeklySchedule ConvertFromPs(this  PSNetAppFilesWeeklySchedule psWeeklySchedule)
        {
            var weeklySchedule = new WeeklySchedule
            {
                Minute          = psWeeklySchedule.Minute,
                Hour            = psWeeklySchedule.Hour,
                Day             = psWeeklySchedule.Day,
                SnapshotsToKeep = psWeeklySchedule.SnapshotsToKeep,
                UsedBytes       = psWeeklySchedule.UsedBytes
            };

            return(weeklySchedule);
        }
        public void Occurrences_with_time()
        {
            // 17/8 14:30, 19/8 14:30 -> 22/8 14:30
            WeeklySchedule week = new WeeklySchedule { Frequency = 1, Monday = true, Wednesday = true, Friday = true };
            IList<DateTime> occurrences = Convert(week.GetOccurrences(
                new DateTime(2011, 8, 1, 14, 30, 0), 
                new DateTime(2011, 8, 17, 0, 0, 0), 
                new DateTime(2011, 8, 24, 11, 0, 0)));

            Assert.AreEqual(3, occurrences.Count);
            Assert.AreEqual(occurrences[0], new DateTime(2011, 8, 17, 14, 30, 0));
            Assert.AreEqual(occurrences[1], new DateTime(2011, 8, 19, 14, 30, 0));
            Assert.AreEqual(occurrences[2], new DateTime(2011, 8, 22, 14, 30, 0));
        }
        public void Occurrences_without_time()
        {
            // 17/8, 19/8 -> 22/8, 24/8
            WeeklySchedule week = new WeeklySchedule { Frequency = 1, Monday = true, Wednesday = true, Friday = true };
            IList<DateTime> occurrences = Convert(week.GetOccurrences(
                new DateTime(2011, 8, 1), 
                new DateTime(2011, 8, 17),
                new DateTime(2011, 8, 24)));

            Assert.AreEqual(4, occurrences.Count);
            Assert.AreEqual(occurrences[0], new DateTime(2011, 8, 17));
            Assert.AreEqual(occurrences[1], new DateTime(2011, 8, 19));
            Assert.AreEqual(occurrences[2], new DateTime(2011, 8, 22));
            Assert.AreEqual(occurrences[3], new DateTime(2011, 8, 24));
        }
Ejemplo n.º 37
0
 /// <summary>
 /// Visitor pattern for generating description for this schedule.  Will update Description and fire events.
 /// </summary>
 public virtual void Visit(WeeklySchedule s) { OnDescriptionChanged(s, Format(s)); }
Ejemplo n.º 38
0
        /// <summary>
        /// Gets the generated description for the schedule.  Will not update Description or fire events.
        /// </summary>
        public virtual string Format(WeeklySchedule s)
        {
            // Weekly
            // Weekly on Sunday, Monday and Thursday
            // Weekly on all days
            // Weekdays
            // Weekends
            // Every 3 weeks
            // Every 3 weeks on Sunday, Monday and Thursday
            // Every 3 weeks on all days
            // Every 3 weeks on weekdays
            // Every 3 weeks on weekends

            bool append = false;
            StringBuilder sb = new StringBuilder();
            if (s.Frequency == 1)
            {
                if (s.Saturday && s.Sunday && !(s.Monday || s.Tuesday || s.Wednesday || s.Thursday || s.Friday))
                    sb.Append("Weekends");
                else if (s.Monday && s.Tuesday && s.Wednesday && s.Thursday && s.Friday && !(s.Saturday || s.Sunday))
                    sb.Append("Weekdays");
                else
                {
                    sb.Append("Weekly");
                    append = true;
                }
            }
            else
            {
                sb.AppendFormat("Every {0} weeks", s.Frequency);
                append = true;
            }

            if (append && s.TotalDays > 0)
            {
                sb.Append(" on ");
                if (s.Saturday && s.Sunday && !(s.Monday || s.Tuesday || s.Wednesday || s.Thursday || s.Friday))
                    sb.Append("weekends");
                else if (s.Monday && s.Tuesday && s.Wednesday && s.Thursday && s.Friday && !(s.Saturday || s.Sunday))
                    sb.Append("weekdays");
                else if (s.TotalDays == 7)
                    sb.Append("all days");
                else
                {
                    List<string> days = new List<string>();
                    if (s.Sunday) days.Add("Sunday");
                    if (s.Monday) days.Add("Monday");
                    if (s.Tuesday) days.Add("Tuesday");
                    if (s.Wednesday) days.Add("Wednesday");
                    if (s.Thursday) days.Add("Thursday");
                    if (s.Friday) days.Add("Friday");
                    if (s.Saturday) days.Add("Saturday");
                    sb.Append(Strings.Join(", ", " and ", days));
                }
            }

            return sb.ToString();
        }