Exemple #1
0
        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();
            }
        }
        public bool LaunchProgram(
            string name,
            string args)
        {
            try
            {
                bool result;
                logger.Info("LaunchProgram {0} '{1}'", name, args == null ? "" : args);

                if (!processes.ContainsKey(name))
                {
                    logger.Info("\tUnknown {0}", name);
                    return(false);
                }

                DesktopProcess process = processes[name];

                //  If the process is already running and no new arguments are specified, simply bring it to the foreground
                //  Otherwise if it is already running with different arguments, exit the existing process instance
                if (process.Running)
                {
                    if (!String.IsNullOrEmpty(args))
                    {
                        result = process.Exit();
                        logger.Info("\tExit {0} {1}", name, result ? "OK" : "Fail");
                    }
                    else
                    {
                        result = process.Foreground();
                        logger.Info("\tForeground {0} {1}", name, result ? "OK" : "Fail");
                        return(result);
                    }
                }

                //  Stop all other desktop applications - only one will run at at a time
                foreach (var otherProcess in processes.Values)
                {
                    if (otherProcess.Name != name && otherProcess.Running)
                    {
                        DvbViewerMonitor.NothingToMonitor();
                        result = otherProcess.Exit();
                        logger.Info("\tExit {0} {1}", otherProcess.Name, result ? "OK" : "Fail");
                    }
                }

                result = process.Start(args);
                logger.Info("\tStart {0} {1}", name, result ? "OK" : "Fail");

                if (name == "TV")
                {
                    DvbViewerMonitor.StartMonitoring();
                }

                return(result);
            }
            catch (System.Exception ex)
            {
                logger.Error(ex);
                return(false);
            }
        }