Beispiel #1
0
        private static bool WriteMxf()
        {
            // add dummy lineup with dummy channel
            var service = SdMxf.GetService("DUMMY");

            service.CallSign = "DUMMY";
            service.Name     = "DUMMY Station";

            SdMxf.With.Lineups.Add(new MxfLineup
            {
                Index    = SdMxf.With.Lineups.Count + 1,
                LineupId = "ZZZ-DUMMY-EPG123",
                Name     = "ZZZ123 Dummy Lineup",
                channels = new List <MxfChannel>()
            });

            var lineupIndex = SdMxf.With.Lineups.Count - 1;

            SdMxf.With.Lineups[lineupIndex].channels.Add(new MxfChannel
            {
                mxfService = service,
                mxfLineup  = SdMxf.With.Lineups[lineupIndex],
            });

            // make sure background worker to download station logos is complete
            processedObjects = 0; totalObjects = 1;
            ++processStage; ReportProgress();
            var waits = 0;

            while (!StationLogosDownloadComplete)
            {
                ++waits;
                System.Threading.Thread.Sleep(100);
            }
            if (waits > 0)
            {
                Logger.WriteInformation($"Waited {waits * 0.1} seconds for the background worker to complete station logo downloads prior to saving files.");
            }

            // reset counters
            processedObjects = 0; totalObjects = 1 + (config.CreateXmltv ? 1 : 0) + (config.ModernMediaUiPlusSupport ? 1 : 0);
            ++processStage; ReportProgress();

            AddBrandLogoToMxf();
            SdMxf.Providers[0].Status = Logger.EventId.ToString();
            try
            {
                using (var stream = new StreamWriter(Helper.Epg123MxfPath, false, Encoding.UTF8))
                {
                    using (var writer = XmlWriter.Create(stream, new XmlWriterSettings {
                        Indent = true
                    }))
                    {
                        var serializer = new XmlSerializer(typeof(Mxf));
                        var ns         = new XmlSerializerNamespaces();
                        ns.Add("", "");
                        serializer.Serialize(writer, SdMxf, ns);
                    }
                }

                Logger.WriteInformation($"Completed save of the MXF file to \"{Helper.Epg123MxfPath}\".");
                ++processedObjects; ReportProgress();
                return(true);
            }
            catch (Exception ex)
            {
                Logger.WriteError($"Failed to save the MXF file to \"{Helper.Epg123MxfPath}\". Message: {ex.Message}");
            }
            return(false);
        }