Example #1
0
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;

            using (var client = new PlanContext())
            {
                client.Database.EnsureCreated();

                try
                {
                    Rodzaj_uzytkownika rodzaj_Uzytkownika = new Rodzaj_uzytkownika();
                    rodzaj_Uzytkownika.rodzajuzytkownikaId = 1;
                    rodzaj_Uzytkownika.rodzajuzytkownika   = "Admin";
                    client.Rodzaj_uzytkownika.Add(rodzaj_Uzytkownika);
                    client.SaveChanges();

                    Uzytkownik uzytkownik = new Uzytkownik();
                    uzytkownik.rodzajuzytkownikaId = 1;
                    uzytkownik.login = "******";
                    uzytkownik.haslo = "1234";
                    uzytkownik.rodzajuzytkownikaId = 1;
                    client.Uzytkownik.Add(uzytkownik);
                    client.SaveChanges();
                }
                catch (Exception) { }
            }
        }
Example #2
0
        /// <summary>
        /// Erstellt eine neue Beschreibung aus dem Aufzeichnungsplan.
        /// </summary>
        /// <param name="plan">Die Planung der Aufzeichnung.</param>
        /// <param name="context">Die aktuelle Analyseumgebung.</param>
        /// <param name="server">Der zugehörige Dienst.</param>
        /// <returns>Die gewünschte Beschreibung.</returns>
        public static PlanCurrent Create(IScheduleInformation plan, PlanContext context, VCRServer server)
        {
            // Attach to the definition
            var definition = (IScheduleDefinition <VCRSchedule>)plan.Definition;
            var job        = context.TryFindJob(definition.UniqueIdentifier);
            var schedule   = (job == null) ? null : job[definition.UniqueIdentifier];
            var source     = (schedule == null) ? null : (schedule.Source ?? job.Source);

            // Create
            var planned =
                new PlanCurrent
            {
                Identifier  = (schedule == null) ? null : ServerRuntime.GetUniqueWebId(job, schedule),
                ProfileName = plan.Resource.Name,
                Duration    = plan.Time.Duration,
                StartTime   = plan.Time.Start,
                IsLate      = plan.StartsLate,
                SizeHint    = string.Empty,
                Name        = definition.Name,
                m_source    = source,
                Files       = _NoFiles,
                Index       = -1,
            };

            // Finish
            planned.Complete(server);

            // Report
            return(planned);
        }
Example #3
0
        /// <summary>
        /// Fordert zum Starten einer Aufzeichnung oder Aufgabe auf.
        /// </summary>
        /// <param name="item">Die Beschreibung der Aufgabe.</param>
        /// <param name="planner">Die zugehörige Aufzeichnungsplanung.</param>
        /// <param name="context">Zusatzinformationen zur Aufzeichnungsplanung.</param>
        public void Start(IScheduleInformation item, RecordingPlanner planner, PlanContext context)
        {
            // Report
            Debug.WriteLine(string.Format("{0} start{3} on {1}: {2}", m_planTime.ToLocalTime(), item.Resource, item.Definition.Name, item.StartsLate ? " late" : string.Empty));

            // Forward
            planner.Start(item);
        }
Example #4
0
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;

            using (var client = new PlanContext())
            {
                client.Database.EnsureCreated();
            }
        }
Example #5
0
        public ServiceCore()
        {
            PlanContext db = new PlanContext();

            _timer = new Timer(30000)
            {
                AutoReset = true
            };
            _timer.Elapsed += (sender, eventArgs) => PlanyATH_Server.Program.RunnAllFunction();//wasza funkcja



            Console.WriteLine("Database write successes !!!");
            Console.ReadKey();
        }
Example #6
0
        public void BeforeTest()
        {
            var builder = new DbContextOptionsBuilder <PlanContext>();

            builder.EnableSensitiveDataLogging();
            builder.UseInMemoryDatabase("testplan");

            var context    = new PlanContext(builder.Options);
            var repository = new PlanRepository(context);

            this.controller = new(
                Mock.Of <ILogger <PlansController> >(),
                repository);
            Assert.IsNotNull(this.controller);
        }
Example #7
0
        public static IEnumerable <DataModelView> GetDataModelList()
        {
            using (var db = new PlanContext())
            {
                var list = new List <DataModelView>();


                var result = db.PlanModel.ToList();

                foreach (var item in result)
                {
                    var plan = new DataModelView()
                    {
                        FileName = item.FileName,
                        Name     = item.Name
                    };
                    list.Add(plan);
                }
                return(list);
            }
        }
Example #8
0
 public ClientRepository(PlanContext context)
 {
     _context = context;
 }
Example #9
0
 public AdminController(IUniversalRepositoryTypeOf UNI, PlanContext _DB)
 {
     uni = UNI;
     Db  = _DB;
 }
Example #10
0
 public BCPPlansController(PlanContext context)
 {
     _context = context;
 }
Example #11
0
 public HomeController(PlanContext db, IUniversalRepositoryTypeOf UNI)
 {
     _db = db;
     uni = UNI;
 }
Example #12
0
 public HomeController(PlanContext context) // For HomeController to be able to use PlanContext
 {
     _context = context;                    // Needed to Query stuff
 }
        /// <summary>
        /// Fordert zum Starten einer Aufzeichnung oder Aufgabe auf.
        /// </summary>
        /// <param name="item">Die Beschreibung der Aufgabe.</param>
        /// <param name="planner">Die zugehörige Aufzeichnungsplanung.</param>
        /// <param name="context">Zusatzinformationen zur Aufzeichnungsplanung.</param>
        public void Start( IScheduleInformation item, RecordingPlanner planner, PlanContext context )
        {
            // Report
            Debug.WriteLine( string.Format( "{0} start{3} on {1}: {2}", m_planTime.ToLocalTime(), item.Resource, item.Definition.Name, item.StartsLate ? " late" : string.Empty ) );

            // Forward
            planner.Start( item );
        }
Example #14
0
 public PlanificationRepository(PlanContext context)
 {
     _context = context;
 }
        public PlanViewModels(PlanType type, List <DateTime> dates)
        {
            if (dates == null)
            {
                return;
            }
            this.type  = type;
            this.dates = dates;
            db         = new PlanContext();
            switch (type)
            {
            case PlanType.ГГПЗ:
                db.PlanGGPZ.Load();
                {
                    List <PlanGGPZ> planDatas = db.PlanGGPZ.Local.ToBindingList().Where(x => Between(DateTime.Parse(x.Date), dates.First(), dates.Last())).ToList();
                    foreach (DateTime dateTime in dates)
                    {
                        if (!planDatas.Any(x => DateTime.Parse(x.Date) == dateTime))
                        {
                            db.PlanGGPZ.Add(new PlanGGPZ()
                            {
                                Date = dateTime.ToLongDateString()
                            });
                        }
                    }
                }
                db.SaveChanges();
                PlanGGPZ = db.PlanGGPZ.Local.ToBindingList().Where(x => Between(DateTime.Parse(x.Date), dates.First(), dates.Last())).ToList();
                break;

            case PlanType.НГП:
                db.PlanNGP.Load();
                {
                    List <PlanNGP> planDatas = db.PlanNGP.Local.ToBindingList().Where(x => Between(DateTime.Parse(x.Date), dates.First(), dates.Last())).ToList();
                    foreach (DateTime dateTime in dates)
                    {
                        if (!planDatas.Any(x => DateTime.Parse(x.Date) == dateTime))
                        {
                            db.PlanNGP.Add(new PlanNGP()
                            {
                                Date = dateTime.ToLongDateString()
                            });
                        }
                    }
                }
                db.SaveChanges();
                PlanNGP = db.PlanNGP.Local.ToBindingList().Where(x => Between(DateTime.Parse(x.Date), dates.First(), dates.Last())).ToList();
                break;

            case PlanType.ЮПГПЗ:
                db.PlanYPGPZ.Load();
                {
                    List <PlanYPGPZ> planDatas = db.PlanYPGPZ.Local.ToBindingList().Where(x => Between(DateTime.Parse(x.Date), dates.First(), dates.Last())).ToList();
                    foreach (DateTime dateTime in dates)
                    {
                        if (!planDatas.Any(x => DateTime.Parse(x.Date) == dateTime))
                        {
                            db.PlanYPGPZ.Add(new PlanYPGPZ()
                            {
                                Date = dateTime.ToLongDateString()
                            });
                        }
                    }
                }
                db.SaveChanges();
                PlanYPGPZ = db.PlanYPGPZ.Local.ToBindingList().Where(x => Between(DateTime.Parse(x.Date), dates.First(), dates.Last())).ToList();
                break;

            case PlanType.ЮБГПЗ:
                db.PlanYBGPZ.Load();
                {
                    List <PlanYBGPZ> planDatas = db.PlanYBGPZ.Local.ToBindingList().Where(x => Between(DateTime.Parse(x.Date), dates.First(), dates.Last())).ToList();
                    foreach (DateTime dateTime in dates)
                    {
                        if (!planDatas.Any(x => DateTime.Parse(x.Date) == dateTime))
                        {
                            db.PlanYBGPZ.Add(new PlanYBGPZ()
                            {
                                Date = dateTime.ToLongDateString()
                            });
                        }
                    }
                }
                db.SaveChanges();
                PlanYBGPZ = db.PlanYBGPZ.Local.ToBindingList().Where(x => Between(DateTime.Parse(x.Date), dates.First(), dates.Last())).ToList();
                break;

            case PlanType.МГПЗ:
                db.PlanMGPZ.Load();
                {
                    List <PlanMGPZ> planDatas = db.PlanMGPZ.Local.ToBindingList().Where(x => Between(DateTime.Parse(x.Date), dates.First(), dates.Last())).ToList();
                    foreach (DateTime dateTime in dates)
                    {
                        if (!planDatas.Any(x => DateTime.Parse(x.Date) == dateTime))
                        {
                            db.PlanMGPZ.Add(new PlanMGPZ()
                            {
                                Date = dateTime.ToLongDateString()
                            });
                        }
                    }
                }
                db.SaveChanges();
                PlanMGPZ = db.PlanMGPZ.Local.ToBindingList().Where(x => Between(DateTime.Parse(x.Date), dates.First(), dates.Last())).ToList();
                break;

            case PlanType.ВГПЗ:
                db.PlanVGPZ.Load();
                {
                    List <PlanVGPZ> planDatas = db.PlanVGPZ.Local.ToBindingList().Where(x => Between(DateTime.Parse(x.Date), dates.First(), dates.Last())).ToList();
                    foreach (DateTime dateTime in dates)
                    {
                        if (!planDatas.Any(x => DateTime.Parse(x.Date) == dateTime))
                        {
                            db.PlanVGPZ.Add(new PlanVGPZ()
                            {
                                Date = dateTime.ToLongDateString()
                            });
                        }
                    }
                }
                db.SaveChanges();
                PlanVGPZ = db.PlanVGPZ.Local.ToBindingList().Where(x => Between(DateTime.Parse(x.Date), dates.First(), dates.Last())).ToList();
                break;

            case PlanType.НВГПК:
                db.PlanNVGPK.Load();
                {
                    List <PlanNVGPK> planDatas = db.PlanNVGPK.Local.ToBindingList().Where(x => Between(DateTime.Parse(x.Date), dates.First(), dates.Last())).ToList();
                    foreach (DateTime dateTime in dates)
                    {
                        if (!planDatas.Any(x => DateTime.Parse(x.Date) == dateTime))
                        {
                            db.PlanNVGPK.Add(new PlanNVGPK()
                            {
                                Date = dateTime.ToLongDateString()
                            });
                        }
                    }
                }
                db.SaveChanges();
                PlanNVGPK = db.PlanNVGPK.Local.ToBindingList().Where(x => Between(DateTime.Parse(x.Date), dates.First(), dates.Last())).ToList();
                break;

            case PlanType.БГПК:
                db.PlanBGPK.Load();
                {
                    List <PlanBGPK> planDatas = db.PlanBGPK.Local.ToBindingList().Where(x => Between(DateTime.Parse(x.Date), dates.First(), dates.Last())).ToList();
                    foreach (DateTime dateTime in dates)
                    {
                        if (!planDatas.Any(x => DateTime.Parse(x.Date) == dateTime))
                        {
                            db.PlanBGPK.Add(new PlanBGPK()
                            {
                                Date = dateTime.ToLongDateString()
                            });
                        }
                    }
                }
                db.SaveChanges();
                PlanBGPK = db.PlanBGPK.Local.ToBindingList().Where(x => Between(DateTime.Parse(x.Date), dates.First(), dates.Last())).ToList();
                break;
            }
        }
Example #16
0
        /// <summary>
        /// Registriert diese Aufzeichnung in einer Planungsinstanz.
        /// </summary>
        /// <param name="scheduler">Die zu verwendende Planungsinstanz.</param>
        /// <param name="job">Der zugehörige Auftrag.</param>
        /// <param name="devices">Die Liste der Geräte, auf denen die Aufzeichnung ausgeführt werden darf.</param>
        /// <param name="findSource">Dient zum Prüfen einer Quelle.</param>
        /// <param name="disabled">Alle deaktivierten Aufträge.</param>
        /// <param name="context">Die aktuelle Planungsumgebung.</param>
        /// <exception cref="ArgumentNullException">Es wurden nicht alle Parameter angegeben.</exception>
        public void AddToScheduler( RecordingScheduler scheduler, VCRJob job, IScheduleResource[] devices, Func<SourceSelection, SourceSelection> findSource, Func<Guid, bool> disabled, PlanContext context )
        {
            // Validate
            if (scheduler == null)
                throw new ArgumentNullException( nameof( scheduler ) );
            if (job == null)
                throw new ArgumentNullException( nameof( job ) );
            if (findSource == null)
                throw new ArgumentNullException( nameof( findSource ) );

            // Let VCR.NET choose a profile to do the work
            if (job.AutomaticResourceSelection)
                devices = null;

            // Create the source selection
            var persistedSource = Source ?? job.Source;
            var selection = findSource( persistedSource );

            // Station no longer available
            if (selection == null)
                if (persistedSource != null)
                    selection =
                        new SourceSelection
                        {
                            DisplayName = persistedSource.DisplayName,
                            ProfileName = persistedSource.ProfileName,
                            Location = persistedSource.Location,
                            Group = persistedSource.Group,
                            Source =
                                new Station
                                {
                                    TransportStream = persistedSource.Source?.TransportStream ?? 0,
                                    Network = persistedSource.Source?.Network ?? 0,
                                    Service = persistedSource.Source?.Service ?? 0,
                                    Name = persistedSource.DisplayName,
                                },
                        };

            // See if we are allowed to process
            var identifier = UniqueID.Value;
            if (disabled != null)
                if (disabled( identifier ))
                    return;

            // Load all
            var name = string.IsNullOrEmpty( Name ) ? job.Name : $"{job.Name} ({Name})";
            var source = ProfileScheduleResource.CreateSource( selection );
            var duration = TimeSpan.FromMinutes( Duration );
            var noStartBefore = NoStartBefore;
            var start = FirstStart;

            // Check repetition
            var repeat = CreateRepeatPattern();
            if (repeat == null)
            {
                // Only if not being recorded
                if (!noStartBefore.HasValue)
                    scheduler.Add( RecordingDefinition.Create( this, name, identifier, devices, source, start, duration ) );
            }
            else
            {
                // See if we have to adjust the start day
                if (noStartBefore.HasValue)
                {
                    // Attach to the limit - actually we shift it a bit further assuming that we did have no large exception towards the past and the duration is moderate
                    var startAfter = noStartBefore.Value.AddHours( 12 );
                    var startAfterDay = startAfter.ToLocalTime().Date;

                    // Localize the start time
                    var startTime = start.ToLocalTime().TimeOfDay;

                    // First adjust
                    start = (startAfterDay + startTime).ToUniversalTime();

                    // One more day
                    if (start < startAfter)
                        start = (startAfterDay.AddDays( 1 ) + startTime).ToUniversalTime();
                }

                // Read the rest
                var exceptions = Exceptions.Select( e => e.ToPlanException( duration ) ).ToArray();
                var endDay = LastDay.GetValueOrDefault( MaxMovableDay );

                // A bit more complex
                if (start.Date <= endDay.Date)
                    scheduler.Add( RecordingDefinition.Create( this, name, identifier, devices, source, start, duration, endDay, repeat ), exceptions );
            }
        }
        /// <summary>
        /// Ermittelt den aktuellen Aufzeichnungsplan.
        /// </summary>
        /// <param name="scheduler">Die zu verwendende Zeitplanungsinstanz.</param>
        /// <param name="referenceTime">Der Bezugspunkt für die Planung.</param>
        /// <param name="disabled">Alle deaktivierte Aufträge und Aufgaben.</param>
        /// <param name="limit">Die Anzahl der zu berücksichtigenden Planungselemente.</param>
        /// <returns>Die Liste der nächsten Aufzeichnungen.</returns>
        private PlanContext GetPlan( RecordingScheduler scheduler, DateTime referenceTime, Func<Guid, bool> disabled, int limit )
        {
            // Create a new plan context
            var context = new PlanContext( m_started.Values );

            // Configure it
            m_site.AddRegularJobs( scheduler, disabled, this, context );

            // Enable all
            if (disabled == null)
                disabled = identifier => false;

            // Do the sort
            context.LoadPlan( scheduler.GetSchedules( referenceTime, m_tasks.Where( task => !disabled( task.UniqueIdentifier ) ).ToArray() ).Take( limit ) );

            // Report
            return context;
        }
Example #18
0
 public CropTypeRepository(PlanContext context)
 {
     _context = context;
 }
Example #19
0
        /// <summary>
        /// Erstellt eine neue Beschreibung aus dem Aufzeichnungsplan.
        /// </summary>
        /// <param name="plan">Die Planung der Aufzeichnung.</param>
        /// <param name="context">Die aktuelle Analyseumgebung.</param>
        /// <param name="server">Der zugehörige Dienst.</param>
        /// <returns>Die gewünschte Beschreibung.</returns>
        public static PlanCurrent Create( IScheduleInformation plan, PlanContext context, VCRServer server )
        {
            // Attach to the definition
            var definition = (IScheduleDefinition<VCRSchedule>) plan.Definition;
            var job = context.TryFindJob( definition.UniqueIdentifier );
            var schedule = (job == null) ? null : job[definition.UniqueIdentifier];
            var source = (schedule == null) ? null : (schedule.Source ?? job.Source);

            // Create
            var planned =
                new PlanCurrent
                {
                    Identifier = (schedule == null) ? null : ServerRuntime.GetUniqueWebId( job, schedule ),
                    ProfileName = plan.Resource.Name,
                    Duration = plan.Time.Duration,
                    StartTime = plan.Time.Start,
                    IsLate = plan.StartsLate,
                    SizeHint = string.Empty,
                    Name = definition.Name,
                    m_source = source,
                    Files = _NoFiles,
                    Index = -1,
                };

            // Finish
            planned.Complete( server );

            // Report
            return planned;
        }
 public HomeController(PlanContext context)
 {
     _context = context;
 }
        /// <summary>
        /// Ergänzt alle bekannten Aufzeichnungen zu einer Planungsinstzanz.
        /// </summary>
        /// <param name="scheduler">Die Verwaltung der Aufzeichnungen.</param>
        /// <param name="disabled">Alle nicht zu verwendenden Aufzeichnungen.</param>
        /// <param name="planner">Die Gesamtplanung.</param>
        /// <param name="context">Zusätzliche Informationen zur aktuellen Planung.</param>
        void IRecordingPlannerSite.AddRegularJobs(RecordingScheduler scheduler, Func <Guid, bool> disabled, RecordingPlanner planner, PlanContext context)
        {
            // Retrieve all jobs related to this profile
            foreach (var job in Server.JobManager.GetActiveJobs())
            {
                foreach (var schedule in job.Schedules)
                {
                    // No longer in use
                    if (!schedule.IsActive)
                    {
                        continue;
                    }

                    // Resolve source
                    var source = schedule.Source ?? job.Source;
                    if (source == null)
                    {
                        continue;
                    }

                    // Resolve profile
                    var resource = planner.GetResourceForProfile(source.ProfileName);
                    if (resource == null)
                    {
                        continue;
                    }

                    // Register single item
                    schedule.AddToScheduler(scheduler, job, new[] { resource }, VCRProfiles.FindSource, disabled, context);

                    // Remember - even if we skipped it
                    context.RegisterSchedule(schedule, job);
                }
            }
        }
        /// <summary>
        /// Meldet, dass eine Aufzeichnung nun beginnen sollte.
        /// </summary>
        /// <param name="item">Die zu startende Aufzeichnung.</param>
        /// <param name="planner">Die Planungsinstanz.</param>
        /// <param name="context">Zusatzinformationen zur Aufzeichnungsplanung.</param>
        void IRecordingPlannerSite.Start(IScheduleInformation item, RecordingPlanner planner, PlanContext context)
        {
            // We are no longer active - simulate start and do nothing
            if (!m_plannerActive)
            {
                // Make planner believe we did it
                planner.Start(item);

                // Make sure that we wake up after the grace period
                if (PowerManager.IsSuspended && VCRConfiguration.Current.SuppressDelayAfterForcedHibernation)
                {
                    Tools.ExtendedLogging("Hibernation Delay is disabled and can not be enforced");
                }
                else
                {
                    m_timer.SecondsToWait = VCRConfiguration.Current.DelayAfterForcedHibernation.TotalSeconds;
                }

                // Done
                return;
            }

            // Report
            VCRServer.Log(LoggingLevel.Schedules, "Start recording '{0}'", item.Definition.Name);

            // Locate the profile - if we don't find it we are in big trouble!
            ProfileState profile;

            if (!m_profiles.TryGetValue(item.Resource.Name, out profile))
            {
                return;
            }

            // Mark as pending
            m_pendingSchedule = item;
            m_pendingStart    = true;

            // Create the recording
            var recording = VCRRecordingInfo.Create(item, context);

            // Check for EPG
            var guideUpdate = item.Definition as ProgramGuideTask;

            if (guideUpdate != null)
            {
                // Start a new guide collector
                m_pendingActions += ProgramGuideProxy.Create(profile, recording).Start;
            }
            else
            {
                // Check for PSI
                var sourceUpdate = item.Definition as SourceListTask;
                if (sourceUpdate != null)
                {
                    // Start a new update
                    m_pendingActions += SourceScanProxy.Create(profile, recording).Start;
                }
                else
                {
                    // Start a regular recording - profile will decide if to join an existing recording
                    m_pendingActions += () => profile.StartRecording(recording);
                }
            }
        }
Example #23
0
        /// <summary>
        /// Überträgt alle Aufträge in einen Ablaufplanung.
        /// </summary>
        /// <param name="scheduler">Die zu befüllende Ablaufplanung.</param>
        /// <param name="disabled">Alle deaktivierten Aufträge.</param>
        /// <param name="planner">Die zugehörige Aufzeichnungsplanung.</param>
        /// <param name="context">Detailinformationen zur Planung.</param>
        public void AddRegularJobs(RecordingScheduler scheduler, Func <Guid, bool> disabled, RecordingPlanner planner, PlanContext context)
        {
            // Retrieve all jobs related to this profile
            foreach (var job in m_jobs.Values)
            {
                foreach (var schedule in job.Schedules)
                {
                    // No longer in use
                    if (!schedule.IsActive)
                    {
                        continue;
                    }

                    // Resolve source
                    var source = schedule.Source ?? job.Source;
                    if (source == null)
                    {
                        continue;
                    }

                    // Resolve profile
                    var resource = planner.GetResourceForProfile(source.ProfileName);
                    if (resource == null)
                    {
                        continue;
                    }

                    // Register
                    schedule.AddToScheduler(scheduler, job, new[] { resource }, FindSource, disabled, context);

                    // Connect
                    context.RegisterSchedule(schedule, job);
                }
            }
        }
Example #24
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>
        /// Überträgt alle Aufträge in einen Ablaufplanung.
        /// </summary>
        /// <param name="scheduler">Die zu befüllende Ablaufplanung.</param>
        /// <param name="disabled">Alle deaktivierten Aufträge.</param>
        /// <param name="planner">Die zugehörige Aufzeichnungsplanung.</param>
        /// <param name="context">Detailinformationen zur Planung.</param>
        public void AddRegularJobs( RecordingScheduler scheduler, Func<Guid, bool> disabled, RecordingPlanner planner, PlanContext context )
        {
            // Retrieve all jobs related to this profile
            foreach (var job in m_jobs.Values)
                foreach (var schedule in job.Schedules)
                {
                    // No longer in use
                    if (!schedule.IsActive)
                        continue;

                    // Resolve source
                    var source = schedule.Source ?? job.Source;
                    if (source == null)
                        continue;

                    // Resolve profile
                    var resource = planner.GetResourceForProfile( source.ProfileName );
                    if (resource == null)
                        continue;

                    // Register
                    schedule.AddToScheduler( scheduler, job, new[] { resource }, FindSource, disabled, context );

                    // Connect
                    context.RegisterSchedule( schedule, job );
                }
        }
Example #26
0
        /// <summary>
        /// Registriert diese Aufzeichnung in einer Planungsinstanz.
        /// </summary>
        /// <param name="scheduler">Die zu verwendende Planungsinstanz.</param>
        /// <param name="job">Der zugehörige Auftrag.</param>
        /// <param name="devices">Die Liste der Geräte, auf denen die Aufzeichnung ausgeführt werden darf.</param>
        /// <param name="findSource">Dient zum Prüfen einer Quelle.</param>
        /// <param name="disabled">Alle deaktivierten Aufträge.</param>
        /// <param name="context">Die aktuelle Planungsumgebung.</param>
        /// <exception cref="ArgumentNullException">Es wurden nicht alle Parameter angegeben.</exception>
        public void AddToScheduler(RecordingScheduler scheduler, VCRJob job, IScheduleResource[] devices, Func <SourceSelection, SourceSelection> findSource, Func <Guid, bool> disabled, PlanContext context)
        {
            // Validate
            if (scheduler == null)
            {
                throw new ArgumentNullException(nameof(scheduler));
            }
            if (job == null)
            {
                throw new ArgumentNullException(nameof(job));
            }
            if (findSource == null)
            {
                throw new ArgumentNullException(nameof(findSource));
            }

            // Let VCR.NET choose a profile to do the work
            if (job.AutomaticResourceSelection)
            {
                devices = null;
            }

            // Create the source selection
            var persistedSource = Source ?? job.Source;
            var selection       = findSource(persistedSource);

            // Station no longer available
            if (selection == null)
            {
                if (persistedSource != null)
                {
                    selection =
                        new SourceSelection
                    {
                        DisplayName = persistedSource.DisplayName,
                        ProfileName = persistedSource.ProfileName,
                        Location    = persistedSource.Location,
                        Group       = persistedSource.Group,
                        Source      =
                            new Station
                        {
                            TransportStream = persistedSource.Source?.TransportStream ?? 0,
                            Network         = persistedSource.Source?.Network ?? 0,
                            Service         = persistedSource.Source?.Service ?? 0,
                            Name            = persistedSource.DisplayName,
                        },
                    }
                }
            }
            ;

            // See if we are allowed to process
            var identifier = UniqueID.Value;

            if (disabled != null)
            {
                if (disabled(identifier))
                {
                    return;
                }
            }

            // Load all
            var name          = string.IsNullOrEmpty(Name) ? job.Name : $"{job.Name} ({Name})";
            var source        = ProfileScheduleResource.CreateSource(selection);
            var duration      = TimeSpan.FromMinutes(Duration);
            var noStartBefore = NoStartBefore;
            var start         = FirstStart;

            // Check repetition
            var repeat = CreateRepeatPattern();

            if (repeat == null)
            {
                // Only if not being recorded
                if (!noStartBefore.HasValue)
                {
                    scheduler.Add(RecordingDefinition.Create(this, name, identifier, devices, source, start, duration));
                }
            }
            else
            {
                // See if we have to adjust the start day
                if (noStartBefore.HasValue)
                {
                    // Attach to the limit - actually we shift it a bit further assuming that we did have no large exception towards the past and the duration is moderate
                    var startAfter    = noStartBefore.Value.AddHours(12);
                    var startAfterDay = startAfter.ToLocalTime().Date;

                    // Localize the start time
                    var startTime = start.ToLocalTime().TimeOfDay;

                    // First adjust
                    start = (startAfterDay + startTime).ToUniversalTime();

                    // One more day
                    if (start < startAfter)
                    {
                        start = (startAfterDay.AddDays(1) + startTime).ToUniversalTime();
                    }
                }

                // Read the rest
                var exceptions = Exceptions.Select(e => e.ToPlanException(duration)).ToArray();
                var endDay     = LastDay.GetValueOrDefault(MaxMovableDay);

                // A bit more complex
                if (start.Date <= endDay.Date)
                {
                    scheduler.Add(RecordingDefinition.Create(this, name, identifier, devices, source, start, duration, endDay, repeat), exceptions);
                }
            }
        }
Example #27
0
 public PlanSchedule()
 {
     _ctx = new PlanContext();
 }
Example #28
0
 public UniversalRepositoryTypeOf(PlanContext planContext)
 {
     db = planContext;
 }
Example #29
0
        /// <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);
        }