コード例 #1
0
        static void StartPublish(string name)
        {
            //if we had an old publish, kill it.
            if (curPublish != null)
            {
                curPublish.Stop();
                curPublish.Dispose();
            }

            try
            {
                curPublish = Publish.Load(name, pubRoot);
            }
            catch (Exception ex)
            {
                comm.SendMessage <StartStopPublishMessageReply>(new StartStopPublishMessageReply(WatchdogComm.GetMachineName(), name, false, "Exception Loading Publish" + ex.Message));
                return;
            }
            PublishRunStatus status = new PublishRunStatus("Unknown Publish Error", false);

            try
            {
                status = curPublish.Start(pubRoot);
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Exception Starting! " + ex.Message);
                comm.SendMessage <StartStopPublishMessageReply>(new StartStopPublishMessageReply(WatchdogComm.GetMachineName(), name, false, "Exception Loading Publish" + ex.Message));
                return;
            }
            Trace.WriteLine("Pub Status: " + status.text);
            curPublish.WatchdogReset += new EventHandler(curPublish_WatchdogReset);
            comm.SendMessage <StartStopPublishMessageReply>(new StartStopPublishMessageReply(WatchdogComm.GetMachineName(), curPublish.name, status.ok, status.text));
        }
コード例 #2
0
 static Publish AutodetectActivePublish()
 {
     try
     {
         foreach (string s in Publish.GetAllPublishNames(pubRoot))
         {
             Publish p = Publish.Load(s, pubRoot);
             if (p.IsCommandRunning())
             {
                 return(p);
             }
         }
     }
     catch
     { }
     return(null);
 }
コード例 #3
0
        public static void MainLoop()
        {
            comm.GotStartPublishMessage      += new EventHandler <WatchdogMessageEventArgs <StartPublishMessage> >(comm_GotStartPublishMessage);
            comm.GotStopPublishMessage       += new EventHandler <WatchdogMessageEventArgs <StopPublishMessage> >(comm_GotStopPublishMessage);
            comm.GotWatchdogTerminateMessage += new EventHandler <WatchdogMessageEventArgs <WatchdogTerminateMessage> >(comm_GotWatchdogTerminateMessage);
            comm.GotCommandMessage           += new EventHandler <WatchdogMessageEventArgs <CommandMessage> >(comm_GotCommandMessage);

            Thread t = new Thread(new ThreadStart(StatusThread));

            t.Name = "Watchdog Status Thread";
            t.Start();
            Publish autoP = AutodetectActivePublish();

            if (autoP != null)
            {
                StartPublish(autoP.name);
            }
#if !SERVICE
            while (running)
            {
                string s = Console.ReadLine();
                if (s == null)
                {
                    continue;
                }
                if (s.StartsWith("load") && s.Split(" ".ToCharArray(), StringSplitOptions.None).Length > 1)                 //load a publish
                {
                    Trace.WriteLine("Loading " + s.Substring(s.IndexOf(" ") + 1));
                    curPublish = Publish.Load(s.Substring(s.IndexOf(" ") + 1), pubRoot);
                }
                if (s.StartsWith("show all"))
                {
                    foreach (string p in Publish.GetAllPublishNames(pubRoot))
                    {
                        Trace.WriteLine(p);
                    }
                }
                if (s.StartsWith("curpub"))
                {
                    if (curPublish == null)
                    {
                        Trace.WriteLine("No Publish Loaded.");
                    }
                    else
                    {
                        curPublish.PrintDebug();
                        Trace.WriteLine("Running: " + curPublish.IsCommandRunning());
                    }
                }
                if (s.StartsWith("start"))
                {
                    if (curPublish == null)
                    {
                        Trace.WriteLine("No publish loaded.");
                    }
                    else
                    {
                        curPublish.Start(pubRoot);
                    }
                }

                if (s.StartsWith("wdon"))
                {
                    if (curPublish == null)
                    {
                        Trace.WriteLine("No publish loaded.");
                    }
                    else
                    {
                        Trace.WriteLine("Enabling Watchdog...");
                        curPublish.watchdogAutoRestart = true;
                    }
                }

                if (s.StartsWith("wdoff"))
                {
                    if (curPublish == null)
                    {
                        Trace.WriteLine("No publish loaded.");
                    }
                    else
                    {
                        Trace.WriteLine("Disabling Watchdog...");
                        curPublish.watchdogAutoRestart = false;
                    }
                }
                if (s.StartsWith("list"))
                {
                    Process[]      parr             = Process.GetProcesses();
                    List <Process> runningProcesses = new List <Process>(parr);
                    foreach (Process filename in runningProcesses)
                    {
                        Trace.WriteLine(filename.ProcessName);
                    }
                }
            }
            t.Abort();
            traceText.Flush();
#endif
        }