/// <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 einen neuen Eintrag. /// </summary> /// <param name="planItem">Die zugehörige Beschreibung der geplanten Aktivität.</param> /// <param name="context">Die Abbildung auf die Aufträge.</param> /// <returns>Die angeforderte Repräsentation.</returns> public static VCRRecordingInfo Create(IScheduleInformation planItem, PlanContext context) { // Validate if (planItem == null) { throw new ArgumentNullException(nameof(planItem)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } // Check type var definition = planItem.Definition as IScheduleDefinition <VCRSchedule>; if (definition == null) { // Check for program guide collector var guideCollection = planItem.Definition as ProgramGuideTask; if (guideCollection != null) { return new VCRRecordingInfo { Source = new SourceSelection { ProfileName = planItem.Resource.Name, DisplayName = VCRJob.ProgramGuideName }, FileName = Path.Combine(guideCollection.CollectorDirectory.FullName, Guid.NewGuid().ToString("N") + ".epg"), ScheduleUniqueID = guideCollection.UniqueIdentifier, IsHidden = planItem.Resource == null, StartsLate = planItem.StartsLate, StartsAt = planItem.Time.Start, Name = guideCollection.Name, EndsAt = planItem.Time.End, } } ; // Check for source list update var sourceUpdater = planItem.Definition as SourceListTask; if (sourceUpdater != null) { return new VCRRecordingInfo { Source = new SourceSelection { ProfileName = planItem.Resource.Name, DisplayName = VCRJob.SourceScanName }, FileName = Path.Combine(sourceUpdater.CollectorDirectory.FullName, Guid.NewGuid().ToString("N") + ".psi"), ScheduleUniqueID = sourceUpdater.UniqueIdentifier, IsHidden = planItem.Resource == null, StartsLate = planItem.StartsLate, StartsAt = planItem.Time.Start, EndsAt = planItem.Time.End, Name = sourceUpdater.Name, } } ; // None return(null); } // Attach to the schedule and its job - using the context and the map is the easiest way although there may be better alternatives var job = context.TryFindJob(definition.UniqueIdentifier); var schedule = definition.Context; // Find the source var source = schedule.Source ?? job.Source; if (source != null) { // Create a clone source = new SourceSelection { DisplayName = source.DisplayName, SelectionKey = source.SelectionKey }; // Update the name of the profile var resource = planItem.Resource; if (resource != null) { source.ProfileName = resource.Name; } } // Create the description of this recording var recording = new VCRRecordingInfo { Streams = (schedule.Source == null) ? job.Streams : schedule.Streams, ScheduleUniqueID = schedule.UniqueID, IsHidden = planItem.Resource == null, StartsLate = planItem.StartsLate, StartsAt = planItem.Time.Start, EndsAt = planItem.Time.End, JobUniqueID = job.UniqueID, RelatedSchedule = schedule, FileName = job.Directory, Name = definition.Name, RelatedJob = job, Source = source, }; // May want to adjust start time if job is active var runningInfo = context.GetRunState(definition.UniqueIdentifier); if (runningInfo != null) { if (runningInfo.Schedule.Time.End == recording.EndsAt) { // Assume we never start late - we are running recording.StartsLate = false; // If we started prior to this plan report the time we really started if (planItem.Time.Start > runningInfo.Schedule.Time.Start) { recording.StartsAt = runningInfo.Schedule.Time.Start; } } } // Finish recording.LoadDefaults(); // Report return(recording); }