Exemple #1
0
        /// <summary>
        /// Erstellt die interne Repräsentation eines Filters.
        /// </summary>
        /// <param name="filter">Die externe Darstellung des Filters.</param>
        /// <returns>Die gewünschte Repräsentation.</returns>
        public static GuideEntryFilter Translate(GuideFilter filter)
        {
            // None
            if (filter == null)
            {
                return(null);
            }

            // Lookup source by unique name
            var source = (filter.Source == null) ? null : VCRProfiles.FindSource(filter.ProfileName, filter.Source);

            // Process
            return
                (new GuideEntryFilter
            {
                Source = (source == null) ? null : source.Source,
                SourceEncryption = filter.SourceEncryption,
                ContentPattern = filter.ContentPattern,
                TitlePattern = filter.TitlePattern,
                ProfileName = filter.ProfileName,
                SourceType = filter.SourceType,
                PageIndex = filter.PageIndex,
                PageSize = filter.PageSize,
                Start = filter.Start,
            });
        }
        /// <summary>
        /// Erstellt einen neuen Eintrag für die Programmzeitschrift.
        /// </summary>
        /// <param name="entry">Der originale Eintrag aus der Verwaltung.</param>
        /// <param name="profileName">Der Name des zugehörigen Geräteprofils.</param>
        /// <returns>Die gewünschte Beschreibung.</returns>
        public static GuideItem Create(ProgramGuideEntry entry, string profileName)
        {
            // Validate
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            // Default name of the station
            var source = VCRProfiles.FindSource(profileName, entry.Source);

            // Create
            return
                (new GuideItem
            {
                Identifier = string.Format("{0}:{1}:{2}", entry.StartTime.Ticks, profileName, SourceIdentifier.ToString(entry.Source).Replace(" ", "")),
                Station = (source == null) ? entry.StationName : source.GetUniqueName(),
                Duration = TimeSpan.FromSeconds(entry.Duration),
                Categories = entry.Categories.ToArray(),
                Ratings = entry.Ratings.ToArray(),
                Summary = entry.ShortDescription,
                Description = entry.Description,
                StartTime = entry.StartTime,
                Language = entry.Language,
                Name = entry.Name,
            });
        }
Exemple #3
0
        /// <summary>
        /// Erstellt eine neue Beschreibung.
        /// </summary>
        /// <param name="guide">Die zugehörige Programmzeitschrift.</param>
        /// <returns>Die gewünschte Beschreibung.</returns>
        public static GuideInfo Create(ProgramGuideManager guide)
        {
            // Collectors
            var sources  = new HashSet <SourceIdentifier>();
            var stations = new HashSet <string>();
            var first    = default(DateTime? );
            var last     = default(DateTime? );

            // Process
            foreach (var entry in guide.LeafEntries.Events)
            {
                // Start time
                var start = entry.StartTime;
                if (!first.HasValue)
                {
                    first = start;
                }
                else if (start < first.Value)
                {
                    first = start;
                }
                if (!last.HasValue)
                {
                    last = start;
                }
                else if (start > last.Value)
                {
                    last = start;
                }

                // Add the source name
                var source     = entry.Source;
                var sourceInfo = VCRProfiles.FindSource(guide.ProfileName, source);
                if (sourceInfo != null)
                {
                    if (sources.Add(source))
                    {
                        stations.Add(sourceInfo.GetUniqueName());
                    }
                }
            }

            // Report
            return
                (new GuideInfo
            {
                SourceNames = stations.OrderBy(name => name).ToArray(),
                FirstStart = first,
                LastStart = last,
            });
        }
        static void Main6(string[] args)
        {
            // Attach to job manager
            VCRServer  server = new VCRServer(new DirectoryInfo(@"C:\temp\VCR.NET 3.9 Alpha\Jobs"));
            JobManager jobs   = server.JobManager;

            // Create EPG collection
            using (ZappingRequest request = ZappingRequest.CreateDefault("Nexus Scan", jobs))
                if (null != request)
                {
                    // Get the information
                    FullInfo info0 = request.CreateFullInformation();

                    // Report
                    Console.WriteLine(info0.Recording.JobType);

                    // Start it
                    request.BeginExecute(false);

                    // Go to ZDF
                    LiveModeStatus stat1 = request.SetSource(VCRProfiles.FindSource("Nexus Scan", "ZDF [ZDFvision]"), "localhost:5555");

                    // Report
                    Console.WriteLine("ZDF on");
                    Console.ReadLine();

                    // Get status
                    LiveModeStatus stat2 = request.CreateStatus();

                    // Go to PREMIERE
                    LiveModeStatus stat3 = request.SetSource(VCRProfiles.FindSource("Nexus Scan", "PREMIERE DIREKT [PREMIERE]"), "localhost:5555");

                    // Report
                    Console.WriteLine("PREMIERE on");
                    Console.ReadLine();

                    // Get status
                    LiveModeStatus stat4 = request.CreateStatus();

                    // Stop it
                    request.Stop();

                    // Get the information
                    FullInfo info1 = request.CreateFullInformation();
                }

            // Done
            Console.WriteLine("Done");
            Console.ReadLine();
        }
        /// <summary>
        /// Aktiviert eine neue Quelle.
        /// </summary>
        /// <typeparam name="TStatus">Die Art der Zustandsinformation.</typeparam>
        /// <param name="source">Die gewünschte Quelle.</param>
        /// <param name="factory">Methode zum Erzeugen einer neuen Zustandsinformation.</param>
        /// <returns>Der neue Zustand der Übertragung.</returns>
        public TStatus SetSource <TStatus>(SourceIdentifier source, Func <string, ServerInformation, TStatus> factory)
        {
            // Update end time
            Stamp();

            // Remap to real source
            var selection = VCRProfiles.FindSource(ProfileName, source);

            if (selection == null)
            {
                throw new ArgumentNullException("source");
            }

            // Report
            Tools.ExtendedLogging("Will now zap to Source {0}", selection.Source);

            // Process and remember
            m_lastState = EnqueueActionAndWait(() => ServerImplementation.EndRequest(Server.BeginSetZappingSource(selection.SelectionKey, m_target)));

            // Report
            return(CreateStatus(factory));
        }
Exemple #6
0
 /// <summary>
 /// Prüft, ob eine Quelle gültig ist.
 /// </summary>
 /// <param name="source">Die Auswahl der Quelle oder <i>null</i>.</param>
 /// <returns>Gesetzt, wenn die Auswahl gültig ist.</returns>
 public static bool Validate(this SourceSelection source) => (VCRProfiles.FindSource(source) != null);
        /// <summary>
        /// Wendet die Fiterbedingung an.
        /// </summary>
        /// <param name="entries">Eine Liste von Einträgen.</param>
        /// <returns>Die gefilterte Liste.</returns>
        public IEnumerable <ProgramGuideEntry> Filter(IEnumerable <ProgramGuideEntry> entries)
        {
            // Only use sources available to the target profile
            var entrySet = entries
                           .Select(entry => new { e = entry, s = VCRProfiles.FindSource(ProfileName, entry.Source) })
                           .Where(entry => entry.s != null)
                           .Select(entry => new { e = entry.e, s = (Station)entry.s.Source });

            // Name of the station - best filter first
            if (Source != null)
            {
                // One source - no more filters
                entrySet = entrySet.Where(entry => Source.Equals(entry.e.Source));
            }
            else
            {
                // Apply source type filter
                if (SourceType == GuideSourceFilter.Television)
                {
                    entrySet = entrySet.Where(entry => entry.s.SourceType == SourceTypes.TV);
                }
                else if (SourceType == GuideSourceFilter.Radio)
                {
                    entrySet = entrySet.Where(entry => entry.s.SourceType == SourceTypes.Radio);
                }

                // Apply encryption filter
                if (SourceEncryption == GuideEncryptionFilter.Free)
                {
                    entrySet = entrySet.Where(entry => !entry.s.IsEncrypted);
                }
                else if (SourceEncryption == GuideEncryptionFilter.Encrypted)
                {
                    entrySet = entrySet.Where(entry => entry.s.IsEncrypted);
                }
            }

            // Start time
            if (Start.HasValue)
            {
                // Later
                entrySet = entrySet.Where(entry => entry.e.StartTime >= Start.Value);
            }
            else
            {
                // Current
                var now = DateTime.UtcNow;

                // Still active
                entrySet = entrySet.Where(entry => entry.e.EndTime > now);
            }

            // Matcher on content
            Func <ProgramGuideEntry, bool> matchTitle   = null;
            Func <ProgramGuideEntry, bool> matchContent = null;

            // Title
            if (!string.IsNullOrEmpty(TitlePattern))
            {
                var title = TitlePattern.Substring(1);
                switch (TitlePattern[0])
                {
                case '=': matchTitle = entry => (entry.Name ?? string.Empty).Equals(title, StringComparison.InvariantCultureIgnoreCase); break;

                case '*': matchTitle = entry => (entry.Name ?? string.Empty).IndexOf(title, StringComparison.InvariantCultureIgnoreCase) >= 0; break;
                }
            }

            // Both descriptions
            if (!string.IsNullOrEmpty(ContentPattern))
            {
                var content = ContentPattern.Substring(1);
                switch (ContentPattern[0])
                {
                case '=': matchContent = entry => (entry.Description ?? string.Empty).Equals(content, StringComparison.InvariantCultureIgnoreCase) || (entry.ShortDescription ?? string.Empty).Equals(content, StringComparison.InvariantCultureIgnoreCase); break;

                case '*': matchContent = entry => ((entry.Description ?? string.Empty).IndexOf(content, StringComparison.InvariantCultureIgnoreCase) >= 0) || ((entry.ShortDescription ?? string.Empty).IndexOf(content, StringComparison.InvariantCultureIgnoreCase) >= 0); break;
                }
            }

            // Apply content filter
            if (matchTitle != null)
            {
                if (matchContent != null)
                {
                    entrySet = entrySet.Where(entry => matchTitle(entry.e) || matchContent(entry.e));
                }
                else
                {
                    entrySet = entrySet.Where(entry => matchTitle(entry.e));
                }
            }
            else if (matchContent != null)
            {
                entrySet = entrySet.Where(entry => matchContent(entry.e));
            }

            // Back mapping
            entries = entrySet.Select(entry => entry.e);

            // Caller will get it all
            if (PageSize < 1)
            {
                return(entries);
            }

            // Copy local
            var matches = entries.ToList();

            // Sort in list to improve overall performance
            matches.Sort(Comparer);

            // Adjust extract - report one more if possible to indicate that there is more available
            return(matches.Skip(PageIndex * PageSize).Take(PageSize + 1));
        }
        /// <summary>
        /// Beendet die Sammlung endgültig.
        /// </summary>
        protected override void OnStop()
        {
            // At least we tried
            ProfileState.ProgramGuide.LastUpdateTime = DateTime.UtcNow;

            // Report
            Tools.ExtendedLogging("Converting Program Guide Entries from Card Server to VCR.NET Format");

            // Create result
            var result = new ProgramGuideEntries();

            // Fill it
            foreach (var item in Server.BeginEndEPGCollection().Result)
            {
                // Create event
                var epg =
                    new ProgramGuideEntry
                {
                    TransportIdentifier = item.Source.TransportStream,
                    ShortDescription    = item.ShortDescription,
                    NetworkIdentifier   = item.Source.Network,
                    ServiceIdentifier   = item.Source.Service,
                    Description         = item.Description,
                    Duration            = item.Duration,
                    Language            = item.Language,
                    StartTime           = item.Start,
                    Name = item.Name
                };

                // Finish
                if (item.Content != null)
                {
                    epg.Categories.AddRange(item.Content.Select(c => c.ToString()));
                }
                if (item.Ratings != null)
                {
                    epg.Ratings.AddRange(item.Ratings);
                }

                // Resolve
                var source = VCRProfiles.FindSource(ProfileName, item.Source);
                if (source == null)
                {
                    // Load default
                    epg.StationName = item.Source.ToString();
                }
                else
                {
                    // Attach to the station
                    var station = (Station)source.Source;

                    // Load names
                    epg.StationName = station.Name;
                }

                // Add it
                result.Add(epg);
            }

            // Report
            ProfileState.ProgramGuide.UpdateGuide(result);
        }