/// <summary>
        /// Erstellt eine neue Ausnahmebeschreibung.
        /// </summary>
        /// <param name="exception">Die Ausnahmedaten.</param>
        /// <param name="schedule">Die zugehörige Aufzeichnung.</param>
        private PlanException(VCRScheduleException exception, VCRSchedule schedule)
        {
            // Remember
            ExceptionDurationDelta = exception.Duration.GetValueOrDefault(schedule.Duration) - schedule.Duration;
            ExceptionDate          = new DateTime(exception.When.Date.Ticks, DateTimeKind.Utc);
            ExceptionStartShift    = exception.ShiftTime.GetValueOrDefault(0);

            // Start berechnen
            PlannedStart    = (new DateTime(exception.When.Date.Ticks, DateTimeKind.Local) + schedule.FirstStart.ToLocalTime().TimeOfDay).ToUniversalTime();
            PlannedDuration = schedule.Duration;
        }
 /// <summary>
 /// Legt eine neue Information an.
 /// </summary>
 /// <param name="job">Der Auftrag.</param>
 /// <param name="schedule">Die Aufzeichnung.</param>
 /// <param name="guide">Ein Eintrag der Programmzeitschrift.</param>
 /// <param name="profile">Vorgabe für das Geräteprofil.</param>
 /// <returns>Die Information.</returns>
 public static JobScheduleInfo Create(VCRJob job, VCRSchedule schedule, ProgramGuideEntry guide, string profile)
 {
     // Process
     return
         (new JobScheduleInfo
     {
         ScheduleIdentifier = (schedule == null) ? null : schedule.UniqueID.Value.ToString("N"),
         JobIdentifier = (job == null) ? null : job.UniqueID.Value.ToString("N"),
         Schedule = EditSchedule.Create(schedule, job, guide),
         Job = EditJob.Create(job, guide, profile),
     });
 }
Beispiel #3
0
        public void FutureStartIsActive()
        {
            var cut =
                new VCRSchedule
            {
                FirstStart = DateTime.UtcNow.AddDays(1),
                UniqueID   = Guid.NewGuid(),
                Duration   = 10,
            };

            Assert.IsTrue(cut.IsActive);
        }
        /// <summary>
        /// Erstellt die Beschreibung der Aufzeichnung für die persistente Ablage.
        /// </summary>
        /// <param name="scheduleIdentifier">Die eindeutige Kennung der Aufzeichnung.</param>
        /// <param name="job">Der zugehörige Auftrag.</param>
        /// <returns>Die gewünschte Beschreibung.</returns>
        public VCRSchedule CreateSchedule(Guid scheduleIdentifier, VCRJob job)
        {
            // Create
            var schedule =
                new VCRSchedule
            {
                UniqueID   = scheduleIdentifier,
                FirstStart = FirstStart,
                Days       = RepeatPattern,
                Duration   = Duration,
                LastDay    = LastDay,
                Name       = Name,
            };

            // See if we have a source
            var sourceName = Source;

            if (string.IsNullOrEmpty(sourceName))
            {
                return(schedule);
            }

            // See if there is a profile
            var jobSource = job.Source;

            if (jobSource == null)
            {
                return(schedule);
            }

            // Locate the source
            schedule.Source = ServerRuntime.VCRServer.FindSource(jobSource.ProfileName, sourceName);
            if (schedule.Source == null)
            {
                return(schedule);
            }

            // Configure streams
            schedule.Streams = new StreamSelection();

            // Set all - oder of audio settings is relevant, dolby MUST come last
            schedule.Streams.SetUsesAllAudio(AllLanguages);
            schedule.Streams.SetUsesDolbyAudio(DolbyDigital);
            schedule.Streams.SetUsesSubtitles(DVBSubtitles);
            schedule.Streams.SetUsesVideotext(Videotext);
            schedule.Streams.ProgramGuide = true;

            // Report
            return(schedule);
        }
 /// <summary>
 /// Meldet die Daten zu einer Aufzeichnung.
 /// </summary>
 /// <param name="schedule">Die Aufzeichnung.</param>
 /// <param name="job">Der zugehörige Auftrag.</param>
 /// <returns></returns>
 public static InfoSchedule Create(VCRSchedule schedule, VCRJob job)
 {
     // Create
     return
         (new InfoSchedule
     {
         Source = (schedule.Source ?? job.Source).GetUniqueName(),
         WebId = ServerRuntime.GetUniqueWebId(job, schedule),
         StartTime = schedule.FirstStart,
         RepeatPattern = schedule.Days,
         Duration = schedule.Duration,
         Name = schedule.Name,
     });
 }
        /// <summary>
        /// Erstellt eine neue Ausnahmebeschreibung.
        /// </summary>
        /// <param name="exception">Die Ausnahmedaten.</param>
        /// <param name="schedule">Die zugehörige Aufzeichnung.</param>
        /// <returns>Die neue Ausnahmebeschreibung.</returns>
        public static PlanException Create(VCRScheduleException exception, VCRSchedule schedule)
        {
            // Validate
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }
            if (schedule == null)
            {
                throw new ArgumentNullException("schedule");
            }

            // Forward
            return(new PlanException(exception, schedule));
        }
Beispiel #7
0
 /// <summary>
 /// Ermittelt eine Referenz für eine bestimmte Aufzeichung in einem Auftrag, so dass diese
 /// auch in einer URL verwendet werden kann.
 /// </summary>
 /// <param name="job">Ein Auftrag.</param>
 /// <param name="schedule">Eine Aufzeichnung.</param>
 /// <returns>Die eindeutige Referenz.</returns>
 public static string GetUniqueWebId(VCRJob job, VCRSchedule schedule)
 {
     // Forward
     if (job == null)
     {
         return("*");
     }
     else if (schedule == null)
     {
         return(string.Format("*{0:N}", job.UniqueID.Value));
     }
     else
     {
         return(GetUniqueWebId(job.UniqueID.Value, schedule.UniqueID.Value));
     }
 }
Beispiel #8
0
        public void FutureStartWithRepeatIsActive()
        {
            foreach (DayOfWeek day in Enum.GetValues(typeof(DayOfWeek)))
            {
                var cut =
                    new VCRSchedule
                {
                    FirstStart = DateTime.UtcNow.AddDays(1),
                    Days       = VCRSchedule.GetDay(day),
                    UniqueID   = Guid.NewGuid(),
                    Duration   = 10,
                };

                cut.LastDay = cut.FirstStart.ToLocalTime().Date.AddDays(14);

                Assert.IsTrue(cut.IsActive, "{0}", day);
            }
        }
        /// <summary>
        /// Versucht zu einer Aufzeichnung den zugehörigen Auftrag zu finden.
        /// </summary>
        /// <param name="schedule">Eine Aufzeichnung.</param>
        /// <returns>Der zugehörige Auftrag oder <i>null</i>.</returns>
        public VCRJob TryFindJob(VCRSchedule schedule)
        {
            // Validate
            if (schedule == null)
            {
                throw new ArgumentNullException(nameof(schedule));
            }

            // Skip on missing identifier
            var scheduleIdentifier = schedule.UniqueID;

            if (!scheduleIdentifier.HasValue)
            {
                return(null);
            }

            // Forward
            return(TryFindJob(scheduleIdentifier.Value));
        }
        /// <summary>
        /// Ergänz die Abbildung von einer Aufzeichnung auf einen Auftrag.
        /// </summary>
        /// <param name="schedule">Eine Aufzeichnung.</param>
        /// <param name="job">Der zugehörige Auftrag.</param>
        public void RegisterSchedule(VCRSchedule schedule, VCRJob job)
        {
            // Validate
            if (schedule == null)
            {
                throw new ArgumentNullException(nameof(schedule));
            }
            if (job == null)
            {
                throw new ArgumentNullException(nameof(job));
            }

            // Skip on missing identifier
            var scheduleIdentifier = schedule.UniqueID;

            if (scheduleIdentifier.HasValue)
            {
                m_jobsBySchedule.Add(scheduleIdentifier.Value, job);
            }
        }
Beispiel #11
0
        public void FutureStartWithRepeatIsInactive()
        {
            for (var delta = 10; delta-- > 0;)
            {
                foreach (DayOfWeek day in Enum.GetValues(typeof(DayOfWeek)))
                {
                    var cut =
                        new VCRSchedule
                    {
                        FirstStart = DateTime.UtcNow.AddDays(1 + 40 * delta),
                        Days       = VCRSchedule.GetDay(day),
                        UniqueID   = Guid.NewGuid(),
                        Duration   = 10,
                    };

                    cut.LastDay = cut.FirstStart.ToLocalTime().Date.AddDays(5);

                    Assert.AreEqual(day != cut.FirstStart.ToLocalTime().AddDays(-1).DayOfWeek, cut.IsActive, "{0} {1}", delta, day);
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// Erstellt einen neuen Eintrag.
        /// </summary>
        /// <param name="schedule">Die zugehörige Beschreibung der geplanten Aktivität.</param>
        /// <param name="context">Die Abbildung auf die Aufträge.</param>
        /// <param name="profiles">Die Verwaltung der Geräteprofile.</param>
        /// <returns>Die angeforderte Repräsentation.</returns>
        public static PlanActivity Create(IScheduleInformation schedule, PlanContext context, ProfileStateCollection profiles)
        {
            // Request context information
            var definition   = schedule.Definition;
            var runningInfo  = context.GetRunState(definition.UniqueIdentifier);
            var isAllocation = definition is IResourceAllocationInformation;

            // Maybe it's an resource allocation
            if (isAllocation)
            {
                if (runningInfo != null)
                {
                    definition = runningInfo.Schedule.Definition;
                }
                else
                {
                    return(null);
                }
            }

            // Create initial entry
            var time     = schedule.Time;
            var start    = time.Start;
            var end      = time.End;
            var activity =
                new PlanActivity
            {
                IsHidden = (schedule.Resource == null),
                IsLate   = schedule.StartsLate,
            };

            // May need some correction
            if (runningInfo != null)
            {
                if (end == runningInfo.Schedule.Time.End)
                {
                    // Only report the allocation itself
                    if (!isAllocation)
                    {
                        return(null);
                    }

                    // Reload the real start and times - just in case someone manipulated
                    start = runningInfo.Schedule.Time.Start;
                    end   = runningInfo.RealTime.End;

                    // Never report as late - actually since we have some spin up time most of the time the recording is late
                    activity.IsLate = false;
                }
            }

            // Get the beautified range
            start = PlanCurrent.RoundToSecond(start);
            end   = PlanCurrent.RoundToSecond(end);

            // Set times
            activity.Duration  = end - start;
            activity.StartTime = start;

            // Set name
            if (definition != null)
            {
                activity.FullName = definition.Name;
            }

            // Set resource
            var resource = schedule.Resource;

            if (resource != null)
            {
                activity.Device = resource.Name;
            }

            // Schedule to process
            VCRSchedule vcrSchedule = null;
            VCRJob      vcrJob      = null;

            // Analyse definition
            var scheduleDefinition = definition as IScheduleDefinition <VCRSchedule>;

            if (scheduleDefinition != null)
            {
                // Regular plan
                vcrSchedule = scheduleDefinition.Context;
                vcrJob      = context.TryFindJob(vcrSchedule);
            }

            // Process if we found one
            if (vcrSchedule != null)
            {
                // See if we have a job
                if (vcrJob != null)
                {
                    activity.LegacyReference = ServerRuntime.GetUniqueWebId(vcrJob, vcrSchedule);
                }

                // Find the source to use - stream selection is always bound to the context of the source
                var streams = vcrSchedule.Streams;
                var source  = vcrSchedule.Source;
                if (source == null)
                {
                    if (vcrJob != null)
                    {
                        // Try job
                        source = vcrJob.Source;

                        // Adjust stream flags to use
                        if (source == null)
                        {
                            streams = null;
                        }
                        else
                        {
                            streams = vcrJob.Streams;
                        }
                    }
                }

                // Copy station name
                if (source != null)
                {
                    // Remember
                    activity.Source  = SourceIdentifier.ToString(source.Source).Replace(" ", "");
                    activity.Station = source.DisplayName;

                    // Load the profile
                    var profile = profiles[activity.GuideEntryDevice = source.ProfileName];
                    if (profile != null)
                    {
                        activity.HasGuideEntry = profile.ProgramGuide.HasEntry(source.Source, activity.StartTime, activity.StartTime + activity.Duration);
                    }
                }

                // Apply special settings
                activity.CurrentProgramGuide = streams.GetUsesProgramGuide();
                activity.AllLanguages        = streams.GetUsesAllAudio();
                activity.SubTitles           = streams.GetUsesSubtitles();
                activity.VideoText           = streams.GetUsesVideotext();
                activity.Dolby = streams.GetUsesDolbyAudio();

                // Check for exception rule on the day
                var exception = vcrSchedule.FindException(time.End);
                if (exception != null)
                {
                    activity.ExceptionRule = PlanException.Create(exception, vcrSchedule);
                }

                // May want to add end time checks
                if (!isAllocation)
                {
                    if (!activity.IsLate)
                    {
                        if (!activity.IsHidden)
                        {
                            if ((exception == null) || exception.IsEmpty)
                            {
                                activity.EndTimeCouldBeWrong = activity.CheckEndTime(vcrSchedule.FirstStart);
                            }
                        }
                    }
                }
            }
            else if (definition is ProgramGuideTask)
            {
                activity.Station = VCRJob.ProgramGuideName;
            }
            else if (definition is SourceListTask)
            {
                activity.Station = VCRJob.SourceScanName;
            }

            // Report
            return(activity);
        }
        /// <summary>
        /// Erstellt eine Beschreibung zu dieser Aufzeichnung.
        /// </summary>
        /// <param name="schedule">Eine Aufzeichnung.</param>
        /// <param name="job">Der bereits vorhandene Auftrag.</param>
        /// <param name="guide">Ein Eintrag aus der Programmzeitschrift.</param>
        /// <returns>Die gewünschte Beschreibung.</returns>
        public static EditSchedule Create(VCRSchedule schedule, VCRJob job, ProgramGuideEntry guide)
        {
            // None
            if (schedule == null)
            {
                // No hope
                if (guide == null)
                {
                    return(null);
                }

                // Calculate
                var start    = guide.StartTime - TimeSpan.FromMinutes(UserProfileSettings.EPGPreTime);
                var duration = checked ((int)(UserProfileSettings.EPGPreTime + (guide.Duration / 60) + UserProfileSettings.EPGPostTime));

                // Partial - we have a brand new job which is pre-initialized with the source
                if (job == null)
                {
                    return new EditSchedule {
                               FirstStart = start, Duration = duration
                    }
                }
                ;

                // Full monty - we have to overwrite the jobs settings since we are not the first schedule
                return
                    (new EditSchedule
                {
                    Source = ServerRuntime.VCRServer.GetUniqueName(new SourceSelection {
                        ProfileName = job.Source.ProfileName, Source = guide.Source
                    }),
                    DVBSubtitles = UserProfileSettings.UseSubTitles,
                    DolbyDigital = UserProfileSettings.UseAC3,
                    AllLanguages = UserProfileSettings.UseMP2,
                    Videotext = UserProfileSettings.UseTTX,
                    Name = guide.Name.MakeValid(),
                    Duration = duration,
                    FirstStart = start,
                });
            }

            // Consolidate exceptions
            schedule.CleanupExceptions();

            // Optionen ermitteln
            var streams    = schedule.Streams;
            var sourceName = ServerRuntime.VCRServer.GetUniqueName(schedule.Source);

            // Create
            return
                (new EditSchedule
            {
                Exceptions = schedule.Exceptions.Select(exception => PlanException.Create(exception, schedule)).ToArray(),
                LastDay = schedule.LastDay.GetValueOrDefault(VCRSchedule.MaxMovableDay),
                DolbyDigital = streams.GetUsesDolbyAudio(),
                DVBSubtitles = streams.GetUsesSubtitles(),
                AllLanguages = streams.GetUsesAllAudio(),
                Videotext = streams.GetUsesVideotext(),
                FirstStart = schedule.FirstStart,
                RepeatPattern = schedule.Days,
                Duration = schedule.Duration,
                Name = schedule.Name,
                Source = sourceName,
            });
        }
Beispiel #14
0
        static void Main1(string[] args)
        {
            // Attach to job manager
            VCRServer  server = new VCRServer(new DirectoryInfo(@"C:\temp\VCR.NET 3.9 Alpha\Jobs"));
            JobManager jobs   = server.JobManager;

            // Process all profiles
            foreach (Profile profile in VCRProfiles.Profiles)
            {
                // Report
                Console.WriteLine(profile.Name);

                // Start time
                DateTime start = DateTime.UtcNow;

                // Process a bit
                for (int i = 10; i-- > 0;)
                {
                    // Helper data
                    VCRRecordingInfo[] included;
                    bool inComplete;

                    // Find the recording
                    FullInfo         info  = jobs.FindNextRecording(start, profile, out inComplete, out included);
                    VCRRecordingInfo rec   = info.Recording;
                    VCRJob           job   = jobs[rec.JobUniqueID.Value];
                    VCRSchedule      sched = job[rec.ScheduleUniqueID.Value];

                    // Report
                    Console.WriteLine("\t{0} {1} {2} ({3}) {4} {5} {6} {7}", rec.StartsAt.Value.ToLocalTime(), rec.EndsAt.ToLocalTime().TimeOfDay, job.Name, sched.Name, inComplete, included.Length, rec.JobUniqueID, rec.ScheduleUniqueID);

                    // Report
                    foreach (VCRRecordingInfo include in included)
                    {
                        Console.WriteLine("\t\t{0} {1} {2} {3} {4}", include.Source.GetUniqueName(), include.StartsAt.Value.ToLocalTime(), include.EndsAt.ToLocalTime().TimeOfDay, include.JobUniqueID, include.ScheduleUniqueID);
                    }

                    // Report
                    foreach (StreamInfo stream in info.Streams)
                    {
                        foreach (ScheduleInfo schedule in stream.Schedules)
                        {
                            Console.WriteLine("\t\t{0} {1} {2} {3}", schedule.JobUniqueID, schedule.ScheduleUniqueID, schedule.StartsAt.ToLocalTime(), schedule.EndsAt.ToLocalTime().TimeOfDay);
                        }
                    }

                    // Advance
                    start = rec.EndsAt;
                }

                // Helper data
                VCRRecordingInfo[] incDummy;
                bool dummyFlag;

                // Start timer
                Stopwatch timer = Stopwatch.StartNew();

                // Measure
                for (int n = 0; ++n > 0;)
                {
                    // Find the recording
                    jobs.FindNextRecording(DateTime.UtcNow, profile, out dummyFlag, out incDummy);

                    // Get the time
                    TimeSpan delta = timer.Elapsed;
                    if (delta.TotalSeconds >= 5)
                    {
                        // Report
                        Console.WriteLine("{0}ms", delta.TotalMilliseconds / n);

                        // Done
                        break;
                    }
                }
            }

            // Get the profile
            Profile nexus = VCRProfiles.FindProfile("Nexus");

            // Find the next recording
            VCRRecordingInfo rec2 = jobs.FindNextJob(new DateTime(2009, 2, 19, 20, 0, 0), null, nexus);

            if (null != rec2)
            {
                if (rec2.StartsAt.HasValue)
                {
                    using (RecordingRequest recording = jobs.CreateRecording(rec2, rec2.StartsAt.Value, nexus))
                    {
                        // Get the information
                        FullInfo info0 = recording.CreateFullInformation();

#if EXEC
                        // Start it
                        recording.BeginExecute(false);

                        // Report
                        Console.WriteLine("Recording...");
                        Console.ReadLine();

                        // Get the information
                        FullInfo info1 = recording.CreateFullInformation();
#endif
                    }
                }
            }

            // Done
            Console.WriteLine("Done");
            Console.ReadLine();
        }