Ejemplo n.º 1
0
        public bool ForegroundProgram(
            string name)
        {
            try
            {
                bool result;
                logger.Info("ForegroundProgram {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(false);
                }

                result = process.Foreground();
                logger.Info("\tForeground {0} {1}", name, result ? "OK" : "Fail");
                return(result);
            }
            catch (System.Exception ex)
            {
                logger.Error(ex);
                return(false);
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructor
        /// </summary>
        public DesktopController()
        {
            Trace.WriteLine(String.Format("New DesktopController"));

            //  The definition of the process that we can launch is in the AvidConfig.xml file.
            //  Each defines the path and arguments for a named process
            XDocument doc = XDocument.Load(@"C:\Avid.Net\AvidConfig.xml");

            if (processes == null)
            {
                processes = new Dictionary <string, DesktopProcess>();
                foreach (var program in doc.Root.Element("Programs").Elements("Program"))
                {
                    string name = program.Attribute("name").Value;
                    string path = program.Attribute("path").Value;
                    string args = program.Attribute("args") == null ? "" : program.Attribute("args").Value;
                    string mode = program.Attribute("mode") == null ? null : program.Attribute("mode").Value;
                    processes[name] = new DesktopProcess(name, path, args, mode);
                    Trace.WriteLine(String.Format("Service '{0}': {1}", name, System.IO.File.Exists(path) ? "OK" : "Not Found"));
                }
            }
        }
Ejemplo n.º 4
0
        public bool LaunchNewProgram(
            string name,
            string args)
        {
            try
            {
                logger.Info("LaunchNewProgram {0} '{1}'", name, args);

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

                DesktopProcess process = processes[name];

                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.FileName    = process.Path;
                startInfo.Arguments   = args;
                startInfo.WindowStyle = ProcessWindowStyle.Maximized;

                Process p = Process.Start(startInfo);
                if (p != null)
                {
                    p.WaitForInputIdle();
                }

                logger.Info("\tStart {0} {1}", name, p != null ? "OK" : "Fail");
                return(p != null);
            }
            catch (System.Exception ex)
            {
                logger.Error(ex);
                return(false);
            }
        }
Ejemplo n.º 5
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);
            }
        }