private string getEventCategory(string title, string description, EventInformationTableEntry eventEntry)
        {
            if (RunParameters.Instance.Options.Contains("CUSTOMCATEGORYOVERRIDE"))
            {
                string customCategory = getCustomCategory(title, description);
                if (customCategory != null)
                {
                    return(customCategory);
                }
            }

            string category = AtscPsipProgramCategory.GetCategories(eventEntry);

            if (category != null)
            {
                return(category);
            }

            if (RunParameters.Instance.Options.Contains("CUSTOMCATEGORYOVERRIDE"))
            {
                return(null);
            }

            return(getCustomCategory(title, description));
        }
        /// <summary>
        /// Parse the section.
        /// </summary>
        /// <param name="byteData">The MPEG2 section containing the section.</param>
        /// <param name="mpeg2Header">The MPEG2 header that preceedes the section.</param>
        public void Process(byte[] byteData, Mpeg2ExtendedHeader mpeg2Header)
        {
            lastIndex         = mpeg2Header.Index;
            sourceID          = mpeg2Header.TableIDExtension;
            lastSectionNumber = mpeg2Header.LastSectionNumber;

            protocolVersion = (int)byteData[lastIndex];
            lastIndex++;

            int entryCount = (int)byteData[lastIndex];

            lastIndex++;

            if (entryCount != 0)
            {
                events = new Collection <EventInformationTableEntry>();

                while (entryCount != 0)
                {
                    EventInformationTableEntry eventEntry = new EventInformationTableEntry();
                    eventEntry.Process(byteData, lastIndex);

                    events.Add(eventEntry);

                    lastIndex += eventEntry.TotalLength;
                    entryCount--;
                }
            }

            Validate();
        }
        /// <summary>
        /// Get a list of the categories for an event.
        /// </summary>
        /// <param name="eventEntry">The event to be processed.</param>
        /// <returns>A list of comma separated categories or null if none exist.</returns>
        public static string GetCategories(EventInformationTableEntry eventEntry)
        {
            if (eventEntry.Descriptors == null)
            {
                return(null);
            }

            StringBuilder categoryString = new StringBuilder();

            foreach (DescriptorBase descriptorBase in eventEntry.Descriptors)
            {
                GenreDescriptor genreDescriptor = descriptorBase as GenreDescriptor;
                if (genreDescriptor != null)
                {
                    if (genreDescriptor.Attributes != null)
                    {
                        foreach (GenreAttribute genreAttribute in genreDescriptor.Attributes)
                        {
                            AtscPsipProgramCategory category = FindCategory(genreAttribute.Attribute);
                            if (category != null)
                            {
                                if (categoryString.Length != 0)
                                {
                                    categoryString.Append(",");
                                }
                                categoryString.Append(category.Description);

                                if (category.SampleEvent == null)
                                {
                                    category.SampleEvent = eventEntry.EventName.ToString();
                                }
                                category.UsedCount++;
                            }
                            else
                            {
                                AtscPsipProgramCategory.AddUndefinedCategory(genreAttribute.Attribute, eventEntry.EventName.ToString());
                            }
                        }
                    }
                }
            }

            if (categoryString.Length != 0)
            {
                return(categoryString.ToString());
            }
            else
            {
                return(null);
            }
        }
        private void processEvent(int frequency, int sourceID, EventInformationTableEntry eventEntry)
        {
            VirtualChannel channel = VirtualChannelTable.FindChannel(frequency, sourceID);

            if (channel == null)
            {
                return;
            }

            EPGEntry epgEntry = new EPGEntry();

            epgEntry.EventID = eventEntry.EventID;

            if (eventEntry.EventName != null)
            {
                epgEntry.EventName = eventEntry.EventName.ToString().Replace("\0", "");
            }
            else
            {
                epgEntry.EventName = "No Event Name";
            }

            if (eventEntry.ETMLocation == 1 || eventEntry.ETMLocation == 2)
            {
                ExtendedTextTableEntry textEntry = ExtendedTextTable.FindEntry(sourceID, eventEntry.EventID);
                if (textEntry != null)
                {
                    epgEntry.ShortDescription = textEntry.Text.ToString().Replace("\0", "");
                }
            }

            epgEntry.StartTime            = Utils.RoundTime(TimeOffsetEntry.GetAdjustedTime(eventEntry.StartTime));
            epgEntry.Duration             = Utils.RoundTime(eventEntry.Duration);
            epgEntry.EventCategory        = getEventCategory(epgEntry.EventName, epgEntry.ShortDescription, eventEntry);
            epgEntry.ParentalRating       = eventEntry.ParentalRating;
            epgEntry.ParentalRatingSystem = "VCHIP";
            epgEntry.AudioQuality         = eventEntry.AudioQuality;
            epgEntry.EPGSource            = EPGSource.PSIP;

            channel.AddEPGEntry(epgEntry);
        }
        private void processEvent(int frequency, int sourceID, EventInformationTableEntry eventEntry)
        {
            VirtualChannel channel = VirtualChannelTable.FindChannel(frequency, sourceID);
            if (channel == null)
                return;

            EPGEntry epgEntry = new EPGEntry();

            epgEntry.EventID = eventEntry.EventID;

            if (eventEntry.EventName != null)
                epgEntry.EventName = eventEntry.EventName.ToString().Replace("\0", "");
            else
                epgEntry.EventName = "No Event Name";

            if (eventEntry.ETMLocation == 1 || eventEntry.ETMLocation == 2)
            {
                ExtendedTextTableEntry textEntry = ExtendedTextTable.FindEntry(sourceID, eventEntry.EventID);
                if (textEntry != null)
                    epgEntry.ShortDescription = textEntry.Text.ToString().Replace("\0", "");
            }

            epgEntry.StartTime = Utils.RoundTime(TimeOffsetEntry.GetAdjustedTime(eventEntry.StartTime));
            epgEntry.Duration = Utils.RoundTime(eventEntry.Duration);
            epgEntry.EventCategory = getEventCategory(epgEntry.EventName, epgEntry.ShortDescription, eventEntry);
            epgEntry.ParentalRating = eventEntry.ParentalRating;
            epgEntry.ParentalRatingSystem = "VCHIP";
            epgEntry.AudioQuality = eventEntry.AudioQuality;
            epgEntry.EPGSource = EPGSource.PSIP;

            channel.AddEPGEntry(epgEntry);
        }
        private string getEventCategory(string title, string description, EventInformationTableEntry eventEntry)
        {
            if (RunParameters.Instance.Options.Contains("CUSTOMCATEGORYOVERRIDE"))
            {
                string customCategory = getCustomCategory(title, description);
                if (customCategory != null)
                    return (customCategory);
            }

            string category = AtscPsipProgramCategory.GetCategories(eventEntry);
            if (category != null)
                return (category);

            if (RunParameters.Instance.Options.Contains("CUSTOMCATEGORYOVERRIDE"))
                return (null);

            return (getCustomCategory(title, description));
        }
        /// <summary>
        /// Parse the section.
        /// </summary>
        /// <param name="byteData">The MPEG2 section containing the section.</param>
        /// <param name="mpeg2Header">The MPEG2 header that preceedes the section.</param>
        public void Process(byte[] byteData, Mpeg2ExtendedHeader mpeg2Header)
        {
            lastIndex = mpeg2Header.Index;
            sourceID = mpeg2Header.TableIDExtension;
            lastSectionNumber = mpeg2Header.LastSectionNumber;

            protocolVersion = (int)byteData[lastIndex];
            lastIndex++;

            int entryCount = (int)byteData[lastIndex];
            lastIndex++;

            if (entryCount != 0)
            {
                events = new Collection<EventInformationTableEntry>();

                while (entryCount != 0)
                {
                    EventInformationTableEntry eventEntry = new EventInformationTableEntry();
                    eventEntry.Process(byteData, lastIndex);

                    events.Add(eventEntry);

                    lastIndex += eventEntry.TotalLength;
                    entryCount--;
                }
            }

            Validate();
        }
        /// <summary>
        /// Get a list of the categories for an event.
        /// </summary>
        /// <param name="eventEntry">The event to be processed.</param>
        /// <returns>A list of comma separated categories or null if none exist.</returns>
        public static string GetCategories(EventInformationTableEntry eventEntry)
        {
            if (eventEntry.Descriptors == null)
                return(null);

            StringBuilder categoryString = new StringBuilder();

            foreach (DescriptorBase descriptorBase in eventEntry.Descriptors)
            {
                GenreDescriptor genreDescriptor = descriptorBase as GenreDescriptor;
                if (genreDescriptor != null)
                {
                    if (genreDescriptor.Attributes != null)
                    {
                        foreach (GenreAttribute genreAttribute in genreDescriptor.Attributes)
                        {
                            AtscPsipProgramCategory category = FindCategory(genreAttribute.Attribute);
                            if (category != null)
                            {
                                if (categoryString.Length != 0)
                                    categoryString.Append(",");
                                categoryString.Append(category.Description);

                                if (category.SampleEvent == null)
                                    category.SampleEvent = eventEntry.EventName.ToString();
                                category.UsedCount++;
                            }
                            else
                                AtscPsipProgramCategory.AddUndefinedCategory(genreAttribute.Attribute, eventEntry.EventName.ToString());
                        }
                    }
                }
            }

            if (categoryString.Length != 0)
                return(categoryString.ToString());
            else
                return(null);
        }