public void AppendChannelsRule(ScheduleRules rules, bool notOnChannels, IList channelIds)
 {
     ScheduleRule channelsRule = new ScheduleRule(notOnChannels ? ScheduleRuleType.NotOnChannels : ScheduleRuleType.Channels);
     foreach (Guid channel in channelIds)
     {
         channelsRule.Arguments.Add(channel);
     }
     if (channelsRule.Arguments.Count > 0)
     {
         rules.Add(channelsRule);
     }
 }
예제 #2
0
 public ExportSchedule(Schedule schedule)
 {
     _isActive = schedule.IsActive;
     _name = schedule.Name;
     _channelType = schedule.ChannelType;
     _keepUntilMode = schedule.KeepUntilMode;
     _keepUntilValue = schedule.KeepUntilValue;
     _preRecordSeconds = schedule.PreRecordSeconds;
     _postRecordSeconds = schedule.PostRecordSeconds;
     _schedulePriority = schedule.SchedulePriority;
     _scheduleType = schedule.ScheduleType;
     foreach (ScheduleRule rule in schedule.Rules)
     {
         if (rule.Type == ScheduleRuleType.Channels
             || rule.Type == ScheduleRuleType.NotOnChannels)
         {
             List<string> channelNames = new List<string>();
             foreach (Guid channelId in rule.Arguments)
             {
                 Channel channel = Proxies.SchedulerService.GetChannelById(channelId).Result;
                 if (channel != null)
                 {
                     channelNames.Add(channel.DisplayName);
                 }
             }
             if (channelNames.Count > 0)
             {
                 ScheduleRule channelsRule = new ScheduleRule(rule.Type);
                 foreach (string channelName in channelNames)
                 {
                     channelsRule.Arguments.Add(channelName);
                 }
                 _rules.Add(channelsRule);
             }
         }
         else
         {
             _rules.Add(rule);
         }
     }
     _history = new List<ScheduleRecordedProgram>(Proxies.ControlService.GetPreviouslyRecordedHistory(schedule.ScheduleId).Result);
 }
 private static void AppendStringArgumentsRule(ScheduleRules rules, ScheduleRuleType ruleType, IList arguments)
 {
     ScheduleRule rule = new ScheduleRule(ruleType);
     foreach (string arg in arguments)
     {
         rule.Arguments.Add(arg);
     }
     if (rule.Arguments.Count > 0)
     {
         rules.Add(rule);
     }
 }
예제 #4
0
 public ImportSchedule Convert(List<string> errors)
 {
     Schedule schedule = new Schedule();
     schedule.IsActive = this.IsActive;
     schedule.Name = this.Name;
     schedule.ChannelType = this.ChannelType;
     schedule.KeepUntilMode = this.KeepUntilMode;
     schedule.KeepUntilValue = this.KeepUntilValue;
     schedule.PreRecordSeconds = this.PreRecordSeconds;
     schedule.PostRecordSeconds = this.PostRecordSeconds;
     schedule.SchedulePriority = this.SchedulePriority;
     schedule.ScheduleType = this.ScheduleType;
     foreach (ScheduleRule rule in this.Rules)
     {
         if (rule.Type == ScheduleRuleType.TvChannels)
         {
             rule.Type = ScheduleRuleType.Channels; /* For backwards compatibility. */
         }
         if (rule.Type == ScheduleRuleType.Channels
             || rule.Type == ScheduleRuleType.NotOnChannels)
         {
             List<Guid> tvChannelIds = new List<Guid>();
             foreach (string channelName in rule.Arguments)
             {
                 Channel tvChannel = Proxies.SchedulerService.GetChannelByDisplayName(schedule.ChannelType, channelName).Result;
                 if (tvChannel == null)
                 {
                     errors.Add(String.Format(CultureInfo.CurrentCulture, "Channel '{0}' not found.", channelName));
                 }
                 else
                 {
                     tvChannelIds.Add(tvChannel.ChannelId);
                 }
             }
             if (tvChannelIds.Count > 0)
             {
                 ScheduleRule channelsRule = new ScheduleRule(rule.Type);
                 foreach (Guid tvChannelId in tvChannelIds)
                 {
                     channelsRule.Arguments.Add(tvChannelId);
                 }
                 schedule.Rules.Add(channelsRule);
             }
         }
         else
         {
             schedule.Rules.Add(rule);
         }
     }
     return new ImportSchedule(schedule, _history.ToArray());
 }
예제 #5
0
        private static ScheduleRule ToRule(this SerializableSchedule.SerializableRule from)
        {
            ScheduleRule result = null;

            if (from != null)
            {
                result = new ScheduleRule((ScheduleRuleType)Enum.Parse(typeof(ScheduleRuleType), from.Type));
                switch (result.Type)
                {
                case ScheduleRuleType.Channels:
                case ScheduleRuleType.NotOnChannels:
                    from.Arguments.ForEach(a => result.Arguments.Add(new Guid(a)));
                    break;

                case ScheduleRuleType.AroundTime:
                case ScheduleRuleType.StartingBetween:
                    from.Arguments.ForEach(a => result.Arguments.Add(ParseScheduleTime(a)));
                    break;

                case ScheduleRuleType.OnDate:
                    if (from.Arguments.Count > 0)
                    {
                        result.Arguments.Add(ParseIsoDate(from.Arguments[0]));
                    }
                    break;

                case ScheduleRuleType.ManualSchedule:
                    if (from.Arguments.Count > 0)
                    {
                        result.Arguments.Add(ParseIsoDate(from.Arguments[0]));
                    }
                    if (from.Arguments.Count > 1)
                    {
                        result.Arguments.Add(ParseScheduleTime(from.Arguments[1]));
                    }
                    break;

                case ScheduleRuleType.DaysOfWeek:
                    if (from.Arguments.Count > 0)
                    {
                        result.Arguments.Add(Enum.Parse(typeof(ScheduleDaysOfWeek), from.Arguments[0]));
                    }
                    if (from.Arguments.Count > 1)
                    {
                        result.Arguments.Add(ParseIsoDate(from.Arguments[1]));
                    }
                    break;

                case ScheduleRuleType.TitleDoesNotContain:
                case ScheduleRuleType.SubTitleDoesNotContain:
                case ScheduleRuleType.EpisodeNumberDoesNotContain:
                case ScheduleRuleType.DescriptionDoesNotContain:
                case ScheduleRuleType.ProgramInfoDoesNotContain:
                case ScheduleRuleType.TitleStartsWith:
                case ScheduleRuleType.SubTitleStartsWith:
                case ScheduleRuleType.EpisodeNumberStartsWith:
                case ScheduleRuleType.TitleEquals:
                case ScheduleRuleType.SubTitleEquals:
                case ScheduleRuleType.EpisodeNumberEquals:
                case ScheduleRuleType.TitleContains:
                case ScheduleRuleType.SubTitleContains:
                case ScheduleRuleType.EpisodeNumberContains:
                case ScheduleRuleType.DescriptionContains:
                case ScheduleRuleType.ProgramInfoContains:
                case ScheduleRuleType.CategoryEquals:
                case ScheduleRuleType.CategoryDoesNotEqual:
                case ScheduleRuleType.DirectedBy:
                case ScheduleRuleType.WithActor:
                    from.Arguments.ForEach(a => result.Arguments.Add(a));
                    break;

                case ScheduleRuleType.SkipRepeats:
                case ScheduleRuleType.NewEpisodesOnly:
                case ScheduleRuleType.NewTitlesOnly:
                    from.Arguments.ForEach(a => result.Arguments.Add(bool.Parse(a)));
                    break;
                }
            }
            return(result);
        }
예제 #6
0
 private static void ArgumentsToSerializable <T>(SerializableSchedule.SerializableRule to, ScheduleRule from)
 {
     foreach (object arg in from.Arguments)
     {
         to.Arguments.Add(((T)arg).ToString());
     }
 }
예제 #7
0
        private static SerializableSchedule.SerializableRule ToSerializableRule(this ScheduleRule from)
        {
            SerializableSchedule.SerializableRule result = null;
            if (from != null)
            {
                result = new SerializableSchedule.SerializableRule()
                {
                    Type      = from.Type.ToString(),
                    Arguments = new List <string>()
                };
                switch (from.Type)
                {
                case ScheduleRuleType.Channels:
                case ScheduleRuleType.NotOnChannels:
                    ArgumentsToSerializable <Guid>(result, from);
                    break;

                case ScheduleRuleType.AroundTime:
                case ScheduleRuleType.StartingBetween:
                    from.Arguments.ForEach(a => result.Arguments.Add(new DateTime(((ScheduleTime)a).Ticks, DateTimeKind.Local).ToString("HH:mm:ss")));
                    break;

                case ScheduleRuleType.ManualSchedule:
                    if (from.Arguments.Count > 0)
                    {
                        result.Arguments.Add(((DateTime)from.Arguments[0]).ToString("yyyy-MM-ddTHH:mm:sszzz"));
                    }
                    if (from.Arguments.Count > 1)
                    {
                        result.Arguments.Add(new DateTime(((ScheduleTime)from.Arguments[1]).Ticks, DateTimeKind.Local).ToString("HH:mm:ss"));
                    }
                    break;

                case ScheduleRuleType.OnDate:
                    if (from.Arguments.Count > 0)
                    {
                        result.Arguments.Add(((DateTime)from.Arguments[0]).ToString("yyyy-MM-ddTHH:mm:sszzz"));
                    }
                    break;

                case ScheduleRuleType.DaysOfWeek:
                    if (from.Arguments.Count > 0)
                    {
                        result.Arguments.Add(((int)from.Arguments[0]).ToString());
                    }
                    if (from.Arguments.Count > 1)
                    {
                        result.Arguments.Add(((DateTime)from.Arguments[1]).ToString("yyyy-MM-ddTHH:mm:sszzz"));
                    }
                    break;

                case ScheduleRuleType.TitleDoesNotContain:
                case ScheduleRuleType.SubTitleDoesNotContain:
                case ScheduleRuleType.EpisodeNumberDoesNotContain:
                case ScheduleRuleType.DescriptionDoesNotContain:
                case ScheduleRuleType.ProgramInfoDoesNotContain:
                case ScheduleRuleType.TitleStartsWith:
                case ScheduleRuleType.SubTitleStartsWith:
                case ScheduleRuleType.EpisodeNumberStartsWith:
                case ScheduleRuleType.TitleEquals:
                case ScheduleRuleType.SubTitleEquals:
                case ScheduleRuleType.EpisodeNumberEquals:
                case ScheduleRuleType.TitleContains:
                case ScheduleRuleType.SubTitleContains:
                case ScheduleRuleType.EpisodeNumberContains:
                case ScheduleRuleType.DescriptionContains:
                case ScheduleRuleType.ProgramInfoContains:
                case ScheduleRuleType.CategoryEquals:
                case ScheduleRuleType.CategoryDoesNotEqual:
                case ScheduleRuleType.DirectedBy:
                case ScheduleRuleType.WithActor:
                    ArgumentsToSerializable <string>(result, from);
                    break;

                case ScheduleRuleType.SkipRepeats:
                case ScheduleRuleType.NewEpisodesOnly:
                case ScheduleRuleType.NewTitlesOnly:
                    ArgumentsToSerializable <bool>(result, from);
                    break;
                }
            }
            return(result);
        }