} // GetLastUserSelectedProvider private bool LoadServiceProviderList(bool fromCache) { try { ProviderDiscoveryRoot discovery; var baseIpAddress = AppUiConfiguration.Current.ContentProvider.Bootstrap.MulticastAddress; // can load from cache? discovery = null; if (fromCache) { discovery = AppUiConfiguration.Current.Cache.LoadXml <ProviderDiscoveryRoot>("ProviderDiscovery", baseIpAddress); if (discovery == null) { return(false); } // if } // if if (discovery == null) { var basePort = AppUiConfiguration.Current.ContentProvider.Bootstrap.MulticastPort; var downloader = new UiDvbStpSimpleDownloader() { Request = new UiDvbStpSimpleDownloadRequest() { PayloadId = 0x01, SegmentId = null, // accept any segment MulticastAddress = IPAddress.Parse(baseIpAddress), MulticastPort = basePort, Description = Properties.DiscoveryTexts.SPObtainingList, DescriptionParsing = Properties.DiscoveryTexts.SPParsingList, PayloadDataType = typeof(ProviderDiscoveryRoot), AllowXmlExtraWhitespace = false, XmlNamespaceReplacer = NamespaceUnification.Replacer, }, TextUserCancelled = Properties.DiscoveryTexts.UserCancelListRefresh, TextDownloadException = Properties.DiscoveryTexts.SPListUnableRefresh, }; downloader.Download(this); if (!downloader.IsOk) { return(false); } discovery = downloader.Response.DeserializedPayloadData as ProviderDiscoveryRoot; AppUiConfiguration.Current.Cache.SaveXml("ProviderDiscovery", baseIpAddress, downloader.Response.Version, discovery); } // if ProvidersDiscovery = new UiProviderDiscovery(discovery); FillServiceProviderList(); return(true); } catch (Exception ex) { HandleException(new ExceptionEventData(Properties.DiscoveryTexts.SPListUnableRefresh, ex)); return(false); } // try-catch } // LoadServiceProviderList
} // constructor private void buttonDownload_Click(object sender, EventArgs e) { string context = null; string input; textBoxResult.Text = null; try { context = "IP Address"; input = textIpAddress.Text.Trim(); var ipAddress = IPAddress.Parse(input); context = "Port"; var port = Program.ParseNumber(textPort.Text); context = "PayloadID"; var payloadId = (byte)Program.ParseNumber(textPayloadId.Text); context = "SegmentID"; var segmentId = (short?)Program.ParseNullableNumber(textSegmentId.Text); context = "Start downloader"; var downloader = new UiDvbStpSimpleDownloader(); downloader.Request = new UiDvbStpSimpleDownloadRequest() { MulticastAddress = ipAddress, MulticastPort = port, PayloadId = payloadId, SegmentId = segmentId, NoDataTimeout = 120000, }; downloader.Download(this); context = "After download"; if (downloader.IsOk) { if (radioFormatBinary.Checked) { textBoxResult.ScrollBars = ScrollBars.Vertical; textBoxResult.WordWrap = true; } else { textBoxResult.ScrollBars = ScrollBars.Both; textBoxResult.WordWrap = false; } // if-else textBoxResult.Text = GetPayloadText(downloader.Response.PayloadData); } // if } catch (Exception ex) { MyApplication.HandleException(this, context, ex); } // try-catch } // buttonDownload_Click
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