Пример #1
0
        public bool ExitProgram(
            string name)
        {
            try
            {
                bool result;
                logger.Info("ExitProgram {0}", name);

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

                DesktopProcess process = processes[name];

                if (!process.Running)
                {
                    logger.Info("\tStopped {0}", name);
                    return(true);
                }

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


                DvbViewerMonitor.NothingToMonitor();
                return(result);
            }
            catch (System.Exception ex)
            {
                logger.Error(ex);
                return(false);
            }
        }
Пример #2
0
        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);
            }
        }