Exemplo n.º 1
0
        public bool?WriteSourceScan(string scan, [FromBody] SourceScanSettings settings)
        {
            // Check mode
            if (settings.Interval.GetValueOrDefault(0) == 0)
            {
                // Create settings
                var disable = VCRConfiguration.Current.BeginUpdate(SettingNames.ScanInterval);

                // Store
                disable[SettingNames.ScanInterval].NewValue = "0";

                // Process
                return(ServerRuntime.Update(disable.Values));
            }

            // Check mode
            if (settings.Interval < 0)
            {
                // Create settings
                var manual = VCRConfiguration.Current.BeginUpdate(SettingNames.ScanDuration, SettingNames.MergeScanResult, SettingNames.ScanInterval);

                // Store
                manual[SettingNames.MergeScanResult].NewValue = settings.MergeLists.ToString();
                manual[SettingNames.ScanDuration].NewValue    = settings.Duration.ToString();
                manual[SettingNames.ScanInterval].NewValue    = "-1";

                // Process
                return(ServerRuntime.Update(manual.Values));
            }

            // Prepare to update
            var update = VCRConfiguration.Current.BeginUpdate(SettingNames.ScanDuration, SettingNames.MergeScanResult, SettingNames.ScanInterval, SettingNames.ScanHours, SettingNames.ScanJoinThreshold);

            // Fill it
            update[SettingNames.ScanHours].NewValue         = string.Join(", ", settings.Hours.Select(hour => hour.ToString()));
            update[SettingNames.ScanJoinThreshold].NewValue = settings.Threshold.ToString();
            update[SettingNames.MergeScanResult].NewValue   = settings.MergeLists.ToString();
            update[SettingNames.ScanInterval].NewValue      = settings.Interval.ToString();
            update[SettingNames.ScanDuration].NewValue      = settings.Duration.ToString();

            // Process
            return(ServerRuntime.Update(update.Values));
        }
Exemplo n.º 2
0
        public void UpdateRecording(string detail, [FromBody] JobScheduleData data)
        {
            // Parameter analysieren
            VCRJob job;
            var    schedule = ServerRuntime.ParseUniqueWebId(detail, out job);

            // Validate
            if (schedule == null)
            {
                throw new ArgumentException("Job or Schedule not found");
            }

            // Take the new job data
            var newJob      = data.Job.CreateJob(job.UniqueID.Value);
            var newSchedule = data.Schedule.CreateSchedule(schedule.UniqueID.Value, newJob);

            // All exceptions still active
            var activeExceptions     = data.Schedule.Exceptions ?? Enumerable.Empty <PlanException>();
            var activeExceptionDates = new HashSet <DateTime>(activeExceptions.Select(exception => exception.ExceptionDate));

            // Copy over all exceptions
            newSchedule.Exceptions.AddRange(schedule.Exceptions.Where(exception => activeExceptionDates.Contains(exception.When)));

            // See if we can use it
            if (!newSchedule.IsActive)
            {
                throw new ArgumentException(Properties.Resources.ScheduleInPast);
            }

            // Copy all schedules expect the one wie founr
            newJob.Schedules.AddRange(job.Schedules.Where(oldSchedule => !ReferenceEquals(oldSchedule, schedule)));

            // Add the updated variant
            newJob.Schedules.Add(newSchedule);

            // Send to persistence
            ServerRuntime.VCRServer.UpdateJob(newJob, newSchedule.UniqueID.Value);

            // Update recently used channels
            UserProfileSettings.AddRecentChannel(data.Job.Source);
            UserProfileSettings.AddRecentChannel(data.Schedule.Source);
        }
Exemplo n.º 3
0
        public SourceScanSettings ReadSoureScan(string scan)
        {
            // Validate
            ServerRuntime.TestAdminAccess();

            // Load
            var interval = VCRConfiguration.Current.SourceListUpdateInterval;
            var join     = VCRConfiguration.Current.SourceListJoinThreshold;

            // Report
            return
                (new SourceScanSettings
            {
                Hours = VCRConfiguration.Current.SourceListUpdateHoursAsArray.OrderBy(hour => hour).ToArray(),
                Threshold = join.HasValue ? (int)join.Value.TotalDays : default(int?),
                MergeLists = VCRConfiguration.Current.MergeSourceListUpdateResult,
                Duration = VCRConfiguration.Current.SourceListUpdateDuration,
                Interval = (interval != 0) ? interval : default(int?),
            });
        }
Exemplo n.º 4
0
        public bool?WriteOther(string other, [FromBody] OtherSettings settings)
        {
            // Prepare to update
            var update =
                VCRConfiguration.Current.BeginUpdate
                (
                    SettingNames.SuppressDelayAfterForcedHibernation,
                    SettingNames.DisablePCRFromMPEG2Generation,
                    SettingNames.DisablePCRFromH264Generation,
                    SettingNames.DelayAfterForcedHibernation,
                    SettingNames.UseStandByForHibernation,
                    SettingNames.MayHibernateSystem,
                    SettingNames.HibernationDelay,
                    SettingNames.ArchiveLifeTime,
                    SettingNames.LoggingLevel,
                    SettingNames.LogLifeTime,
                    SettingNames.AllowBasic,
                    SettingNames.TCPPort,
                    SettingNames.SSLPort,
                    SettingNames.UseSSL
                );

            // Change
            update[SettingNames.SuppressDelayAfterForcedHibernation].NewValue = settings.SuppressDelayAfterForcedHibernation.ToString();
            update[SettingNames.DelayAfterForcedHibernation].NewValue         = settings.DelayAfterForcedHibernation.ToString();
            update[SettingNames.DisablePCRFromMPEG2Generation].NewValue       = settings.DisablePCRFromMPEG2.ToString();
            update[SettingNames.DisablePCRFromH264Generation].NewValue        = settings.DisablePCRFromH264.ToString();
            update[SettingNames.UseStandByForHibernation].NewValue            = settings.UseStandBy.ToString();
            update[SettingNames.HibernationDelay].NewValue   = settings.HibernationDelay.ToString();
            update[SettingNames.MayHibernateSystem].NewValue = settings.AllowHibernate.ToString();
            update[SettingNames.ArchiveLifeTime].NewValue    = settings.ArchiveTime.ToString();
            update[SettingNames.LogLifeTime].NewValue        = settings.ProtocolTime.ToString();
            update[SettingNames.AllowBasic].NewValue         = settings.AllowBasic.ToString();
            update[SettingNames.LoggingLevel].NewValue       = settings.Logging.ToString();
            update[SettingNames.SSLPort].NewValue            = settings.SSLPort.ToString();
            update[SettingNames.TCPPort].NewValue            = settings.WebPort.ToString();
            update[SettingNames.UseSSL].NewValue             = settings.UseSSL.ToString();

            // Process
            return(ServerRuntime.Update(update.Values));
        }
Exemplo n.º 5
0
        public GuideSettings ReadGuide(string guide)
        {
            // Validate
            ServerRuntime.TestAdminAccess();

            // Load
            var interval = VCRConfiguration.Current.ProgramGuideUpdateInterval;
            var join     = VCRConfiguration.Current.ProgramGuideJoinThreshold;

            // Report
            return
                (new GuideSettings
            {
                Sources = VCRConfiguration.Current.ProgramGuideSourcesAsArray.OrderBy(name => name, StringComparer.InvariantCultureIgnoreCase).ToArray(),
                Hours = VCRConfiguration.Current.ProgramGuideUpdateHoursAsArray.OrderBy(hour => hour).ToArray(),
                Interval = interval.HasValue ? (int)interval.Value.TotalHours : default(int?),
                Threshold = join.HasValue ? (int)join.Value.TotalHours : default(int?),
                Duration = VCRConfiguration.Current.ProgramGuideUpdateDuration,
                WithUKGuide = VCRConfiguration.Current.EnableFreeSat,
            });
        }
Exemplo n.º 6
0
        /// <summary>
        /// Erstellt eine Beschreibung zu einer einzelnen Aufzeichnung auf einem Gerät.
        /// </summary>
        /// <param name="active">Beschreibt die gesamte Aufzeichnung.</param>
        /// <param name="stream">Die zu verwendende Teilaufzeichnung.</param>
        /// <param name="streamIndex">Die laufende Nummer dieses Datenstroms.</param>
        /// <param name="server">Der zugehörige Dienst.</param>
        /// <returns>Die gewünschte Beschreibung.</returns>
        private static IEnumerable <PlanCurrent> Create(FullInfo active, StreamInfo stream, int streamIndex, VCRServer server)
        {
            // Static data
            var recording   = active.Recording;
            var profileName = recording.Source.ProfileName;
            var sizeHint    = GetSizeHint(recording.TotalSize) + " (Gerät)";

            // Process all - beginning with VCR.NET 4.1 there is only one schedule per stream
            foreach (var scheduleInfo in stream.Schedules)
            {
                // Try to locate the context
                var job      = string.IsNullOrEmpty(scheduleInfo.JobUniqueID) ? null : server.JobManager[new Guid(scheduleInfo.JobUniqueID)];
                var schedule = ((job == null) || string.IsNullOrEmpty(scheduleInfo.ScheduleUniqueID)) ? null : job[new Guid(scheduleInfo.ScheduleUniqueID)];

                // Create
                var start   = RoundToSecond(scheduleInfo.StartsAt);
                var end     = RoundToSecond(scheduleInfo.EndsAt);
                var current =
                    new PlanCurrent
                {
                    Identifier     = (schedule == null) ? null : ServerRuntime.GetUniqueWebId(job, schedule),
                    PlanIdentifier = scheduleInfo.ScheduleUniqueID,
                    Files          = scheduleInfo.Files ?? _NoFiles,
                    StreamTarget   = stream.StreamsTo,
                    m_source       = scheduleInfo.Source,
                    ProfileName    = profileName,
                    Name           = scheduleInfo.Name,
                    Duration       = end - start,
                    Index          = streamIndex,
                    SizeHint       = sizeHint,
                    StartTime      = start,
                };

                // Finish
                current.Complete(server);

                // Report
                yield return(current);
            }
        }
Exemplo n.º 7
0
        public string CreateNewRecording(string detail, [FromBody] JobScheduleData data)
        {
            // Parameter analysieren
            VCRJob job;

            ServerRuntime.ParseUniqueWebId(detail + Guid.NewGuid().ToString("N"), out job);

            // Validate
            if (job == null)
            {
                throw new ArgumentException("Job not found");
            }

            // Take the new job data
            var newJob      = data.Job.CreateJob(job.UniqueID.Value);
            var newSchedule = data.Schedule.CreateSchedule(newJob);

            // See if we can use it
            if (!newSchedule.IsActive)
            {
                throw new ArgumentException(Properties.Resources.ScheduleInPast);
            }

            // Add all existing
            newJob.Schedules.AddRange(job.Schedules);

            // Add the new one
            newJob.Schedules.Add(newSchedule);

            // Send to persistence
            ServerRuntime.VCRServer.UpdateJob(newJob, newSchedule.UniqueID.Value);

            // Update recently used channels
            UserProfileSettings.AddRecentChannel(data.Job.Source);
            UserProfileSettings.AddRecentChannel(data.Schedule.Source);

            // Report
            return(ServerRuntime.GetUniqueWebId(newJob, newSchedule));
        }
Exemplo n.º 8
0
 public void Dispose()
 {
     if (_Host != null)
     {
         _Host.Dispose();
         _Host = null;
     }
     if (_NodeBuilder != null)
     {
         _NodeBuilder.Dispose();
         _NodeBuilder = null;
     }
     if (ClientRuntime != null)
     {
         ClientRuntime.Dispose();
         ClientRuntime = null;
     }
     if (ServerRuntime != null)
     {
         ServerRuntime.Dispose();
         ServerRuntime = null;
     }
 }
Exemplo n.º 9
0
        public void DeleteRecording(string detail)
        {
            // Parameter analysieren
            var schedule = ServerRuntime.ParseUniqueWebId(detail, out VCRJob job);

            // Validate
            if (schedule == null)
            {
                throw new ArgumentException("Job or Schedule not found");
            }

            // Remove schedule from job - since we are living in a separate application domain we only have a copy of it
            job.Schedules.Remove(schedule);

            // Send to persistence
            if (job.Schedules.Count < 1)
            {
                ServerRuntime.VCRServer.DeleteJob(job);
            }
            else
            {
                ServerRuntime.VCRServer.UpdateJob(job, null);
            }
        }
Exemplo n.º 10
0
        public long SendPartOfFile(string path, long offset, int length, string target, ushort port)
        {
            // Make sure that user is allowed to access the server
            ServerRuntime.TestWebAccess();

            // Validate path
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }
            if (!path.ToLower().EndsWith(".ts"))
            {
                throw new ArgumentException(path, "path");
            }

            // Check against VCR.NET recording directories
            if (!VCRConfiguration.Current.IsValidTarget(path))
            {
                throw new ArgumentException(path, "path");
            }

            // Validate the slice
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            if ((length < 0) || (length > 100000000))
            {
                throw new ArgumentOutOfRangeException("length");
            }

            // Validate the IP
            if (string.IsNullOrEmpty(target))
            {
                throw new ArgumentException("target");
            }

            // We do not support multi-cast
            if (target.StartsWith("*"))
            {
                throw new ArgumentException("target");
            }

            // Find the first IP4 address
            var host     = Dns.GetHostEntry(target);
            var hostIP   = host.AddressList.FirstOrDefault(testIP => testIP.AddressFamily == AddressFamily.InterNetwork);
            var endPoint = new IPEndPoint(hostIP, port);

            // Create socket
            using (var socket = new Socket(endPoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp)
            {
                Blocking = true
            })
            {
                // Last size of stream
                long streamSize;

                // Collection ends in 0,5 Seconds
                var endCollect = DateTime.UtcNow.AddMilliseconds(500);

                // As long as necessary
                for (; ;)
                {
                    using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 10000000))
                    {
                        // Get the size
                        streamSize = stream.Length;

                        // And the maximum number of bytes left
                        var rest = streamSize - offset;
                        if (rest < 0)
                        {
                            throw new ArgumentOutOfRangeException("offset");
                        }

                        // None left
                        if (rest == 0)
                        {
                            // Check for retry
                            if (length < 1)
                            {
                                break;
                            }
                            if (DateTime.UtcNow >= endCollect)
                            {
                                break;
                            }

                            // Wait for new data
                            Thread.Sleep(100);

                            // Try again
                            continue;
                        }

                        // Correct
                        if (rest < length)
                        {
                            length = (int)rest;
                        }

                        // Create buffer
                        var buffer = new byte[length];

                        // Move to position
                        stream.Position = offset;

                        // Read data
                        if (stream.Read(buffer, 0, buffer.Length) != buffer.Length)
                        {
                            throw new IOException(path);
                        }

                        // When we started
                        var start = DateTime.UtcNow;

                        // Process all
                        for (var i = 0; i < buffer.Length;)
                        {
                            // Overall time
                            var delta = DateTime.UtcNow - start;

                            // Did something - at least
                            var run = delta.TotalSeconds;
                            if (run > 0)
                            {
                                // Check against our maximum
                                var rate = i * 8 / run;
                                if (rate >= 80000000)
                                {
                                    // Must delay
                                    Thread.Sleep(1);

                                    // Next try
                                    continue;
                                }
                            }

                            // Get the size
                            var n = Math.Min(buffer.Length - i, UDPStreaming.BufferSize);

                            // Send to endpoint
                            socket.SendTo(buffer, i, n, SocketFlags.None, endPoint);

                            // Adjust
                            i += n;
                        }

                        // Adjust counters
                        offset += buffer.Length;
                        length -= buffer.Length;

                        // Finished
                        if (length < 1)
                        {
                            break;
                        }
                        if (DateTime.UtcNow >= endCollect)
                        {
                            break;
                        }
                    }
                }

                // Close
                socket.Close(10);

                // Report size
                return(streamSize);
            }
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
 public bool?WriteSchedulerRules(string rules, [FromBody] SchedulerRules settings)
 {
     // Process
     return(ServerRuntime.UpdateSchedulerRules(settings.RuleFileContents));
 }
Exemplo n.º 13
0
 public bool?WriteSchedulerRules(string rules, [FromBody] SchedulerRules settings) => ServerRuntime.UpdateSchedulerRules(settings.RuleFileContents);