/// <summary> /// Discover a Sky STB on the local LAN and populate a registry key with string values for the services it reports /// </summary> /// <param name="localIpAddress"></param> /// <param name="logger"></param> /// <returns></returns> public static Dictionary <string, string> GetSkyServices( string localIpAddress, Logger logger) { // Instantiate a SkyLocator and use it to determine the available Sky STB device service locations // We expect to find two of these SkyLocator locator = new SkyLocator(); IEnumerable <string> locations = locator.GetSkyLocations(localIpAddress); // A dictionary keyed by Sky service types for the service URLs // We expect to find two of these Dictionary <string, string> services = new Dictionary <string, string>(); // For each Sky STB service location we find, request (synchronously) for the services its provides foreach (string location in locations) { int lastSlash = location.LastIndexOf("/"); string host = location.Substring(0, lastSlash); // Query synchronously the discovered service location URLs HttpWebRequest request = WebRequest.Create(location) as HttpWebRequest; request.UserAgent = "SKY_skyplus"; request.Accept = "text/xml"; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { using (Stream responseStream = response.GetResponseStream()) { // The response will be a service description XML var doc = XDocument.Load(responseStream); var nsRoot = doc.Root.GetDefaultNamespace(); // The <service> elements are the ones we want. // For each of these, add a Directory mapping of <serviceType> to <controlURL> foreach (var service in doc.Descendants(nsRoot + "service")) { services[service.Element(nsRoot + "serviceType").Value] = host + service.Element(nsRoot + "controlURL").Value; } } } } // For all discovered services, add them to the registry to be used in another process context which is unable // to run this service discovery using (RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)) { using (RegistryKey key = baseKey.CreateSubKey(@"Software\Avid\Sky")) { foreach (string serviceType in services.Keys) { key.SetValue(serviceType, services[serviceType]); if (logger != null) { logger.Info("Sky Service '{0}' = '{1}'", serviceType, services[serviceType]); } } } } return(services); }
static void Main() { Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory; logger.Info("Avid Desktop Started"); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); try { #if USE_SKY_STB // The Desktop tray app is also responsible for discovering the Sky STB service locations and recording them in the registry // This is simply a convenient place to do this work with the necessary access rights logger.Info("SkyLocator.GetSkyServices"); SkyLocator.GetSkyServices(ConfigurationManager.AppSettings["IpAddress"], logger); #endif // Run a background thread to monitor any DVBViewer player through its COM interface DvbViewerMonitor.StartMonitoring(); var config = new HttpSelfHostConfiguration("http://localhost:89"); config.Routes.MapHttpRoute( "API Default", "api/{controller}/{action}/{id}", new { id = RouteParameter.Optional }); // Create a timer with a one minute interval. securityPollTimer = new System.Timers.Timer(60000); // Hook up the Elapsed event for the timer. securityPollTimer.Elapsed += OnSecurityPollTimerEvent; securityPollTimer.Enabled = true; using (HttpSelfHostServer server = new HttpSelfHostServer(config)) { server.OpenAsync().Wait(); var applicationContext = new CustomApplicationContext(); Application.Run(applicationContext); logger.Info("Avid Desktop Exit"); DvbViewerMonitor.NothingToMonitor(); securityPollTimer.Stop(); } } catch (Exception ex) { logger.Fatal(ex); DvbViewerMonitor.NothingToMonitor(); } }