/// <summary>
        /// Create the EPG entries from the stored title and summary data.
        /// </summary>
        /// <param name="station">The station that the EPG records are for.</param>
        /// <param name="titleLogger">A Logger instance for the program titles.</param>
        /// <param name="descriptionLogger">A Logger instance for the program descriptions.</param>
        /// <param name="collectionType">The type of collection, MHW1 or MHW2.</param>
        public void ProcessChannelForEPG(TVStation station, Logger titleLogger, Logger descriptionLogger, CollectionType collectionType)
        {
            bool     first             = true;
            DateTime expectedStartTime = new DateTime();

            foreach (MediaHighwayTitle title in Titles)
            {
                EPGEntry epgEntry = new EPGEntry();
                epgEntry.OriginalNetworkID = OriginalNetworkID;
                epgEntry.TransportStreamID = TransportStreamID;
                epgEntry.ServiceID         = ServiceID;
                epgEntry.EventID           = title.EventID;

                processEventName(epgEntry, title.EventName);

                MediaHighwaySummary summary = null;

                if (title.SummaryAvailable)
                {
                    summary = findSummary(title.EventID);
                    if (summary != null)
                    {
                        processShortDescription(epgEntry, summary.ShortDescription);
                    }
                    else
                    {
                        if (RunParameters.Instance.DebugIDs.Contains("MHW2SUMMARYMISSING"))
                        {
                            Logger.Instance.Write("Summary missing for event ID " + title.EventID);
                        }
                    }
                }
                if (summary == null)
                {
                    epgEntry.ShortDescription = "No Synopsis Available";
                }

                if (collectionType == CollectionType.MediaHighway1)
                {
                    epgEntry.StartTime = Utils.RoundTime(TimeOffsetEntry.GetOffsetTime(title.StartTime));
                }
                else
                {
                    epgEntry.StartTime = Utils.RoundTime(TimeOffsetEntry.GetAdjustedTime(title.StartTime));
                }
                epgEntry.Duration = Utils.RoundTime(title.Duration);

                epgEntry.EventCategory = getEventCategory(epgEntry.EventName, epgEntry.ShortDescription, title.CategoryID);

                if (collectionType == CollectionType.MediaHighway1)
                {
                    epgEntry.EPGSource = EPGSource.MediaHighway1;
                }
                else
                {
                    epgEntry.EPGSource = EPGSource.MediaHighway2;
                }

                epgEntry.VideoQuality = getVideoQuality(epgEntry.EventName);

                epgEntry.PreviousPlayDate = title.PreviousPlayDate;

                station.AddEPGEntry(epgEntry);

                if (first)
                {
                    expectedStartTime = new DateTime();
                    first             = false;
                }
                else
                {
                    if (epgEntry.StartTime < expectedStartTime)
                    {
                        if (titleLogger != null)
                        {
                            titleLogger.Write(" ** Overlap In Schedule **");
                        }
                    }
                    else
                    {
                        if (RunParameters.Instance.Options.Contains("ACCEPTBREAKS"))
                        {
                            if (epgEntry.StartTime > expectedStartTime + new TimeSpan(0, 5, 0))
                            {
                                if (titleLogger != null)
                                {
                                    titleLogger.Write(" ** Gap In Schedule **");
                                }
                            }
                        }
                        else
                        {
                            if (epgEntry.StartTime > expectedStartTime)
                            {
                                if (titleLogger != null)
                                {
                                    titleLogger.Write(" ** Gap In Schedule **");
                                }
                            }
                        }
                    }
                }

                expectedStartTime = epgEntry.StartTime + epgEntry.Duration;

                if (titleLogger != null)
                {
                    if (collectionType == CollectionType.MediaHighway1)
                    {
                        titleLogger.Write(epgEntry.OriginalNetworkID + ":" + epgEntry.TransportStreamID + ":" + epgEntry.ServiceID + " " +
                                          " Evt ID " + title.EventID +
                                          " Cat ID " + title.CategoryID.ToString("00") +
                                          " Summary " + title.SummaryAvailable + ":" + (summary != null) + " " +
                                          " Orig Day " + title.LogDay +
                                          " Orig Hours " + title.LogHours +
                                          " YDay " + title.LogYesterday +
                                          " Day " + title.Day +
                                          " Hours " + title.Hours +
                                          " Mins " + title.Minutes + " " +
                                          epgEntry.StartTime.ToShortDateString() + " " +
                                          epgEntry.StartTime.ToString("HH:mm") + " - " +
                                          epgEntry.StartTime.Add(epgEntry.Duration).ToString("HH:mm") + " " +
                                          title.EventName);
                    }
                    else
                    {
                        titleLogger.Write(epgEntry.OriginalNetworkID + ":" + epgEntry.TransportStreamID + ":" + epgEntry.ServiceID + " " +
                                          " Evt ID " + title.EventID +
                                          " Cat ID " + title.CategoryID.ToString("000") +
                                          " Main cat " + title.MainCategory +
                                          " Sub cat " + title.SubCategory +
                                          " Summary " + title.SummaryAvailable + ":" + (summary != null) +
                                          " Unknown " + Utils.ConvertToHex(title.Unknown) + " " +
                                          epgEntry.StartTime.ToShortDateString() + " " +
                                          epgEntry.StartTime.ToString("HH:mm") + " - " +
                                          epgEntry.StartTime.Add(epgEntry.Duration).ToString("HH:mm") + " " +
                                          title.EventName);
                    }
                }

                if (descriptionLogger != null && summary != null)
                {
                    if (collectionType == CollectionType.MediaHighway1)
                    {
                        descriptionLogger.Write(epgEntry.OriginalNetworkID + ":" + epgEntry.TransportStreamID + ":" + epgEntry.ServiceID + " " +
                                                " Evt ID " + title.EventID +
                                                " Rpts: " + summary.ReplayCount + " " +
                                                epgEntry.StartTime.ToShortDateString() + " " +
                                                epgEntry.StartTime.ToString("HH:mm") + " - " +
                                                epgEntry.StartTime.Add(epgEntry.Duration).ToString("HH:mm") + " " +
                                                summary.ShortDescription);
                    }
                    else
                    {
                        descriptionLogger.Write(epgEntry.OriginalNetworkID + ":" + epgEntry.TransportStreamID + ":" + epgEntry.ServiceID + " " +
                                                " Evt ID " + title.EventID + " " +
                                                " Unknown " + Utils.ConvertToHex(summary.Unknown) + " " +
                                                epgEntry.StartTime.ToShortDateString() + " " +
                                                epgEntry.StartTime.ToString("HH:mm") + " - " +
                                                epgEntry.StartTime.Add(epgEntry.Duration).ToString("HH:mm") + " " +
                                                summary.ShortDescription);
                    }
                }

                if (!RunParameters.Instance.Options.Contains("ACCEPTBREAKS"))
                {
                    if (epgEntry.StartTime.Second != 0)
                    {
                        if (titleLogger != null)
                        {
                            titleLogger.Write("** Suspect Start Time **");
                        }
                    }
                }
            }
        }
        /// <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;
            serviceID = mpeg2Header.TableIDExtension;

            try
            {
                transportStreamID = Utils.Convert2BytesToInt(byteData, lastIndex);
                lastIndex        += 2;

                originalNetworkID = Utils.Convert2BytesToInt(byteData, lastIndex);
                lastIndex        += 2;

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

                lastTableID = (int)byteData[lastIndex];
                lastIndex++;
            }
            catch (IndexOutOfRangeException)
            {
                throw (new ArgumentOutOfRangeException("The FreeSat EIT section is short"));
            }

            TVStation tvStation = TVStation.FindStation(originalNetworkID, transportStreamID, serviceID);

            if (tvStation == null)
            {
                return;
            }

            bool newSection = tvStation.AddMapEntry(mpeg2Header.TableID, mpeg2Header.SectionNumber, lastTableID, mpeg2Header.LastSectionNumber, segmentLastSectionNumber);

            if (!newSection)
            {
                return;
            }

            while (lastIndex < byteData.Length - 4)
            {
                FreeSatEntry freeSatEntry = new FreeSatEntry();
                freeSatEntry.Process(byteData, lastIndex);

                EPGEntry epgEntry = new EPGEntry();
                epgEntry.OriginalNetworkID = tvStation.OriginalNetworkID;
                epgEntry.TransportStreamID = tvStation.TransportStreamID;
                epgEntry.ServiceID         = tvStation.ServiceID;
                epgEntry.EPGSource         = EPGSource.FreeSat;

                switch (freeSatEntry.ComponentTypeAudio)
                {
                case 3:
                    epgEntry.AudioQuality = "stereo";
                    break;

                case 5:
                    epgEntry.AudioQuality = "dolby digital";
                    break;

                default:
                    break;
                }

                if (freeSatEntry.ComponentTypeVideo > 9)
                {
                    epgEntry.VideoQuality = "HDTV";
                }

                epgEntry.Duration  = Utils.RoundTime(freeSatEntry.Duration);
                epgEntry.EventID   = freeSatEntry.EventID;
                epgEntry.EventName = freeSatEntry.EventName;

                if (freeSatEntry.ParentalRating > 11)
                {
                    epgEntry.ParentalRating = "AO";
                }
                else
                {
                    if (freeSatEntry.ParentalRating > 8)
                    {
                        epgEntry.ParentalRating = "PGR";
                    }
                    else
                    {
                        epgEntry.ParentalRating = "G";
                    }
                }

                setSeriesEpisode(epgEntry, freeSatEntry);

                epgEntry.RunningStatus    = freeSatEntry.RunningStatus;
                epgEntry.Scrambled        = freeSatEntry.Scrambled;
                epgEntry.ShortDescription = freeSatEntry.ShortDescription;
                epgEntry.StartTime        = Utils.RoundTime(TimeOffsetEntry.GetOffsetTime(freeSatEntry.StartTime));

                epgEntry.EventCategory = getEventCategory(epgEntry.EventName, epgEntry.ShortDescription, freeSatEntry.ContentType, freeSatEntry.ContentSubType);

                tvStation.AddEPGEntry(epgEntry);

                if (titleLogger != null)
                {
                    logTitle(freeSatEntry.EventName, epgEntry, titleLogger);
                }
                if (descriptionLogger != null)
                {
                    logDescription(freeSatEntry.ShortDescription, epgEntry, descriptionLogger);
                }

                lastIndex = freeSatEntry.Index;
            }
        }