Esempio n. 1
0
            } // Dispose

            private void ProcessSegments()
            {
                byte[] payload;

                while ((payload = GetNextSegment()) != null)
                {
                    try
                    {
                        var item     = XmlSerialization.Deserialize <TvaMain>(payload, trimExtraWhitespace: true, namespaceReplacer: NamespaceUnification.Replacer) as ExtendedPurchaseItem;
                        var schedule = item?.ProgramDescription?.LocationTable?.Schedule;
                        if (schedule == null)
                        {
                            // TODO: log
                            continue;
                        } // if
                        var epgService = EpgService.FromSchedule(schedule);
                        Datastore.Add(epgService);
                    }
                    catch (Exception ex)
                    {
                        // TODO: log
                        Console.WriteLine("Unable to parse: {0}", ex.Message);
                        return;
                    } // try-catch
                }     // while

                ProcessSegmentsEnded.Set();
            } // ProcessSegments
Esempio n. 2
0
        }     // GetUtcProgram

        public static EpgService FromSchedule(TvAnytime.TvaSchedule schedule)
        {
            if (schedule == null)
            {
                return(null);
            }

            var result = new EpgService()
            {
                Version            = TryParseInt(schedule.Version, -1),
                ServiceIdReference = schedule.ServiceIdRef
            };

            if (schedule.Events == null)
            {
                return(result);
            } // if

            var programs = from item in schedule.Events
                           let program = EpgProgram.FromScheduleEvent(item)
                                         select program;

            result.Programs = new LinkedList <EpgProgram>(programs);

            return(result);
        } // FromSchedule
Esempio n. 3
0
            } // Dispose

            private void ProcessSegments()
            {
                byte[] payload;

                while ((payload = GetNextSegment()) != null)
                {
                    try
                    {
                        var item     = XmlSerialization.Deserialize <TvaMain>(payload, trimExtraWhitespace: true, namespaceReplacer: NamespaceUnification.Replacer);
                        var schedule = item?.ProgramDescription?.LocationTable?.Schedule;
                        if (schedule == null)
                        {
                            // TODO: log
                            continue;
                        } // if
                        var epgService = EpgService.FromSchedule(schedule);
                        ScheduleReceived?.Invoke(this, EventArgs.Empty);
                        _datastore.Add(epgService);
                    }
                    catch (Exception ex)
                    {
                        ParseError?.Invoke(this, EventArgs.Empty);
#if DEBUG
                        // TODO: log
                        Console.WriteLine("Unable to parse: {0}", ex.Message);
#endif
                        return;
                    } // try-catch
                }     // while

                _processSegmentsEnded.Set();
            } // ProcessSegments
Esempio n. 4
0
        } // Sort

        /// <summary>
        /// Fills-in the blanks
        /// </summary>
        /// <param name="epgService"></param>
        private void Fill(EpgService epgService)
        {
            if ((epgService.Programs == null) || (epgService.Programs.Count == 0))
            {
                return;
            }

            var current = epgService.Programs.First.Next;

            while (current != null)
            {
                var previous   = current.Previous.Value;
                var utcEndTime = previous.UtcStartTime + previous.Duration;
                if (utcEndTime < current.Value.UtcStartTime)
                {
                    var empty = new EpgProgram()
                    {
                        Title        = Properties.Texts.EpgBlankTitle,
                        IsBlank      = true,
                        UtcStartTime = utcEndTime,
                        Duration     = current.Value.UtcStartTime - utcEndTime
                    };
                    current.List.AddBefore(current, empty);
                } // if
                current = current.Next;
            }     // while
        }         // Fill
Esempio n. 5
0
        } // Merge

        private IEpgLinkedList GetLinkedList(EpgService service, DateTime?localTime)
        {
            LinkedListNode <EpgProgram> node;
            EpgProgram program;
            EpgProgram phantomProgram;

            if ((service.Programs == null) || (service.Programs.First == null))
            {
                return(null);
            }

            if (localTime == null)
            {
                localTime = DateTime.Now;
            }
            var utcTime          = localTime.Value.ToUniversalTime();
            var truncatedUtcTime = utcTime.TruncateToMinutes();

            program = service.Programs.First.Value;
            if (utcTime < program.UtcStartTime)
            {
                phantomProgram = new EpgProgram()
                {
                    Title        = Properties.Texts.EpgBlankTitle,
                    IsBlank      = true,
                    UtcStartTime = truncatedUtcTime,
                    Duration     = program.UtcStartTime - truncatedUtcTime - new TimeSpan(0, 15, 0)
                };

                return(new EpgLinkedListWrapper(service.ServiceIdReference, service.Programs, phantomProgram));
            } // if

            program = service.Programs.Last.Value;
            if (utcTime >= program.UtcEndTime)
            {
                phantomProgram = new EpgProgram()
                {
                    Title        = Properties.Texts.EpgBlankTitle,
                    IsBlank      = true,
                    UtcStartTime = program.UtcEndTime,
                    Duration     = (truncatedUtcTime - program.UtcEndTime) + new TimeSpan(0, 15, 0)
                };

                return(new EpgLinkedListWrapper(service.ServiceIdReference, service.Programs, phantomProgram, false));
            } // if

            node = service.Programs.First;
            while (node != null)
            {
                if (node.Value.IsCurrent(utcTime))
                {
                    break;
                } // if
                node = node.Next;
            }     // while

            return(new EpgLinkedListWrapper(service.ServiceIdReference, service.Programs, node));
        } // GetLinkedList
Esempio n. 6
0
        } // IsProgramDataUnsorted

        public void Add(EpgService epgService)
        {
            if (IsProgramDataUnsorted)
            {
                Sort(epgService);
            } // if

            Fill(epgService);

            AddEpgService(epgService);
        } // Add
Esempio n. 7
0
        } // GetAllPrograms

        protected override void AddEpgService(EpgService epgService)
        {
            // Console.WriteLine("Store.Add: {0} with {1} programs", epgService.ServiceIdReference, epgService.Programs?.Count ?? 0);
            if (epgService.Programs == null)
            {
                return;
            }

            switch (StorageMethod)
            {
            case EpgMemoryStorageMethod.Replace:
                _data[epgService.ServiceIdReference] = epgService;
                break;

            case EpgMemoryStorageMethod.Merge:
                _data.AddOrUpdate(epgService.ServiceIdReference, epgService, (k, v) => Merge(v, epgService));
                break;
            } // switch
        }     // AddEpgService
Esempio n. 8
0
        /// <summary>
        /// Sorts the list programs by start time
        /// </summary>
        /// <param name="epgService">Service to sort</param>
        private void Sort(EpgService epgService)
        {
            if ((epgService.Programs == null) || (epgService.Programs.Count == 0))
            {
                return;
            }

            var programs = new EpgProgram[epgService.Programs.Count];

            var index = 0;

            foreach (var program in epgService.Programs)
            {
                programs[index++] = program;
            } // foreach

            var sortedPrograms = from program in programs
                                 orderby program.UtcStartTime
                                 select program;

            epgService.Programs = new LinkedList <EpgProgram>(sortedPrograms);
        } // Sort
Esempio n. 9
0
        }     // AddEpgService

        private EpgService Merge(EpgService currentEpgService, EpgService newEpgService)
        {
            // TODO
            throw new NotImplementedException();
        } // Merge
Esempio n. 10
0
 protected abstract void AddEpgService(EpgService epgService);
Esempio n. 11
0
 protected override void AddEpgService(EpgService epgService)
 {
     // do nothing
 } // Add
Esempio n. 12
0
        } // constructor

        protected override void AddEpgService(EpgService epgService)
        {
            throw new InvalidOperationException();
        } // Add