protected void UpdateDaysCollection <T>(DayOfWeek startDay, DayOfWeek endDay) where T : CalendarDay
        {
            if (ParentScheduleSettings.FlightDateStart.HasValue && ParentScheduleSettings.FlightDateEnd.HasValue)
            {
                var days = new List <CalendarDay>();

                var startDate = new DateTime(ParentScheduleSettings.FlightDateStart.Value.Year, ParentScheduleSettings.FlightDateStart.Value.Month, 1);
                while (startDate.DayOfWeek != startDay)
                {
                    startDate = startDate.AddDays(-1);
                }

                var endDate = new DateTime(
                    ParentScheduleSettings.FlightDateEnd.Value.Month < 12 ? ParentScheduleSettings.FlightDateEnd.Value.Year : (ParentScheduleSettings.FlightDateEnd.Value.Year + 1),
                    (ParentScheduleSettings.FlightDateEnd.Value.Month < 12 ? ParentScheduleSettings.FlightDateEnd.Value.Month + 1 : 1),
                    1)
                              .AddDays(-1);
                while (endDate.DayOfWeek != endDay)
                {
                    endDate = endDate.AddDays(1);
                }

                while (startDate <= endDate)
                {
                    var day = Days.FirstOrDefault(x => x.Date.Equals(startDate));
                    if (day == null)
                    {
                        day      = (T)Activator.CreateInstance(typeof(T), this);
                        day.Date = startDate;
                    }
                    day.BelongsToSchedules = day.Date >= ParentScheduleSettings.FlightDateStart & day.Date <= ParentScheduleSettings.FlightDateEnd;
                    days.Add(day);
                    startDate = startDate.AddDays(1);
                }
                Days.Clear();
                Days.AddRange(days);
            }
            else
            {
                Days.Clear();
            }
        }
        private void LoadStrategy()
        {
            SlideHeaders.Clear();
            SourcePrograms.Clear();
            Lengths.Clear();
            Stations.Clear();
            CustomDemos.Clear();
            Dayparts.Clear();
            Times.Clear();

            if (ResourceManager.Instance.MediaListsFile.ExistsLocal())
            {
                var document = new XmlDocument();
                document.Load(ResourceManager.Instance.MediaListsFile.LocalPath);

                XmlNode node = document.SelectSingleNode(String.Format(@"/{0}Strategy", XmlRootPrefix));
                if (node != null)
                {
                    foreach (XmlNode childeNode in node.ChildNodes)
                    {
                        switch (childeNode.Name)
                        {
                        case "SlideHeader":
                            foreach (XmlAttribute attribute in childeNode.Attributes)
                            {
                                switch (attribute.Name)
                                {
                                case "Value":
                                    if (!string.IsNullOrEmpty(attribute.Value) && !SlideHeaders.Contains(attribute.Value))
                                    {
                                        SlideHeaders.Add(attribute.Value);
                                    }
                                    break;
                                }
                            }
                            break;

                        case "FlexFlightDatesAllowed":
                        {
                            bool temp;
                            if (Boolean.TryParse(childeNode.InnerText, out temp))
                            {
                                FlexFlightDatesAllowed = temp;
                            }
                        }
                        break;

                        case "Daypart":
                            var daypart = new Daypart();
                            foreach (XmlAttribute attribute in childeNode.Attributes)
                            {
                                switch (attribute.Name)
                                {
                                case "Name":
                                    daypart.Name = attribute.Value;
                                    break;

                                case "Code":
                                    daypart.Code = attribute.Value;
                                    break;
                                }
                            }
                            if (!string.IsNullOrEmpty(daypart.Name))
                            {
                                Dayparts.Add(daypart);
                            }
                            break;

                        case "CustomDemo":
                            foreach (XmlAttribute attribute in childeNode.Attributes)
                            {
                                switch (attribute.Name)
                                {
                                case "Value":
                                    if (!CustomDemos.Contains(attribute.Value))
                                    {
                                        CustomDemos.Add(attribute.Value);
                                    }
                                    break;
                                }
                            }
                            break;

                        case "Lenght":
                            foreach (XmlAttribute attribute in childeNode.Attributes)
                            {
                                switch (attribute.Name)
                                {
                                case "Value":
                                    if (!string.IsNullOrEmpty(attribute.Value) && !SlideHeaders.Contains(attribute.Value))
                                    {
                                        Lengths.Add(attribute.Value);
                                    }
                                    break;
                                }
                            }
                            break;

                        case "Station":
                            var station = new Station();
                            foreach (XmlAttribute attribute in childeNode.Attributes)
                            {
                                switch (attribute.Name)
                                {
                                case "Name":
                                    station.Name = attribute.Value;
                                    break;

                                case "Logo":
                                    if (!string.IsNullOrEmpty(attribute.Value))
                                    {
                                        station.Logo = new Bitmap(new MemoryStream(Convert.FromBase64String(attribute.Value)));
                                    }
                                    break;
                                }
                            }
                            if (!string.IsNullOrEmpty(station.Name))
                            {
                                Stations.Add(station);
                            }
                            break;

                        case "Program":
                            var sourceProgram = new SourceProgram();
                            GetProgramProperties(childeNode, ref sourceProgram);
                            if (!string.IsNullOrEmpty(sourceProgram.Name))
                            {
                                SourcePrograms.Add(sourceProgram);
                            }
                            break;

                        case "Status":
                            foreach (XmlAttribute attribute in childeNode.Attributes)
                            {
                                switch (attribute.Name)
                                {
                                case "Value":
                                    if (!Statuses.Contains(attribute.Value))
                                    {
                                        Statuses.Add(attribute.Value);
                                    }
                                    break;
                                }
                            }
                            break;

                        case "BroadcastMonthTemplate":
                            var monthTemplate = new MediaMonthTemplate();
                            monthTemplate.Deserialize(childeNode);
                            MonthTemplatesMondayBased.Add(monthTemplate);
                            MonthTemplatesSundayBased.Add(monthTemplate);
                            break;

                        case "DefaultWeeklyScheduleSettings":
                            DefaultWeeklyScheduleSettings.Deserialize(childeNode);
                            break;

                        case "DefaultMonthlyScheduleSettings":
                            DefaultMonthlyScheduleSettings.Deserialize(childeNode);
                            break;

                        case "DefaultSnapshotSettings":
                            DefaultSnapshotSettings.Deserialize(childeNode);
                            break;

                        case "DefaultSnapshotSummarySettings":
                            DefaultSnapshotSummarySettings.Deserialize(childeNode);
                            break;

                        case "DefaultOptionsSettings":
                            DefaultOptionsSettings.Deserialize(childeNode);
                            break;

                        case "DefaultOptionsSummarySettings":
                            DefaultOptionsSummarySettings.Deserialize(childeNode);
                            break;

                        case "DefaultBroadcastCalendarSettings":
                            DefaultBroadcastCalendarSettings.Deserialize(childeNode);
                            break;

                        case "DefaultCustomCalendarSettings":
                            DefaultCustomCalendarSettings.Deserialize(childeNode);
                            break;
                        }
                    }
                }
            }

            if (SourcePrograms.Count > 0)
            {
                Times.AddRange(SourcePrograms.Select(x => x.Time).Distinct().ToArray());
                Days.AddRange(SourcePrograms.Select(x => x.Day).Distinct().ToArray());
            }
        }
Beispiel #3
0
 private void LoadData()
 {
     Days.AddRange(_eatingDayRepository.GetAll());
 }