Пример #1
0
        } // ProcessArguments

        private static void ForceUiCulture(string culture)
        {
            if (culture == null)
            {
                return;
            }
            culture = culture.Trim();
            if (culture == string.Empty)
            {
                return;
            }

            try
            {
                Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(culture);
            }
            catch (Exception ex)
            {
                MyApplication.HandleException(null, string.Format("Invalid argument value for /ForceUiCulture:{0}", culture), ex);
            } // try-catch
        }     // ForceUiCulture
Пример #2
0
        static int Main(string[] args)
        {
            try
            {
                var StartTime = DateTime.Now;

                // Set console icon
                using (var icon = Properties.Resources.ConsoleEpgLoader)
                {
                    UnsafeNativeMethods.SetConsoleIcon(icon.Handle);
                } // using icon

                Console.Title = "TV-Anytime EPG loader utility";

                if (!ProcessArguments(args))
                {
                    return(1);
                } // if

                DisplayLogo();

                var downloader = new UiDvbStpSimpleDownloader()
                {
                    Request = new UiDvbStpSimpleDownloadRequest()
                    {
                        NoDataTimeout           = 180000,
                        PayloadId               = 0x06,
                        SegmentId               = null, // accept any segment
                        MulticastAddress        = DiscoveryEndpoint.Address,
                        MulticastPort           = DiscoveryEndpoint.Port,
                        Description             = "Downloading list of EPG servers...",
                        DescriptionParsing      = "Processing list of EPG servers...",
                        PayloadDataType         = typeof(BroadcastContentGuideDiscoveryRoot),
                        AllowXmlExtraWhitespace = false,
                        XmlNamespaceReplacer    = NamespaceUnification.Replacer,
                    },
                };
                Console.Write("Downloading list of EPG servers...");
                downloader.Download(null);
                if (!downloader.IsOk)
                {
                    Console.WriteLine(" failed");
                    return(-1);
                } // if
                Console.WriteLine(" ok");

                var bcgDiscovery = downloader.Response.DeserializedPayloadData as BroadcastContentGuideDiscoveryRoot;

                if ((bcgDiscovery == null) || (bcgDiscovery.Offering == null) || (bcgDiscovery.Offering.Length < 1) || (bcgDiscovery.Offering[0].ContentGuides == null))
                {
                    throw new ApplicationException("List is EPG servers is empty!");
                } // if

                var serversList = new List <IPEndPoint>();
                foreach (var item in bcgDiscovery.Offering[0].ContentGuides)
                {
                    if ((item.Id == "p_f") || (item.TransportMode == null) || (item.TransportMode.Push == null))
                    {
                        continue;
                    }
                    foreach (var pushServer in item.TransportMode.Push)
                    {
                        serversList.Add(new IPEndPoint(IPAddress.Parse(pushServer.Address), pushServer.Port));
                    } // foreach
                }     // if
                if (serversList.Count == 0)
                {
                    throw new ApplicationException("List is push EPG servers is empty!");
                } // if

                PrepareDatabase();
                CompactDatabase();

                ProcessEpgSource(serversList);

                Log("Main thread {0} waiting for processing threads to end...", Thread.CurrentThread.ManagedThreadId);
                MainEvent = new AutoResetEvent(false);
                MainEvent.WaitOne();

                UpdateDbStatus(0);
                CompactDatabase();

                Console.WriteLine();
                Console.WriteLine("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
                Console.WriteLine("Ellapsed time: {0}", FormatString.TimeSpanTotalMinutes(DateTime.Now - StartTime, FormatString.Format.Extended));
                Console.WriteLine();

                return(0);
            }
            catch (Exception ex)
            {
                Exception = ex;
            } // try-catch

            if (Exception != null)
            {
                try
                {
                    UpdateDbStatus(-1);
                }
                catch
                {
                    // ignore
                } // try-catch

                Console.WriteLine();
                Console.WriteLine("UNEXPECTED EXCEPTION!");
                Console.WriteLine(Exception.GetType().FullName);
                Console.WriteLine(Exception.Message);
                Console.WriteLine();
                MyApplication.HandleException(null, Exception);

                return(-1);
            } // if

            return(0);
        } // Main