Esempio n. 1
0
 private void runScript(string message)
 {
     if (_isFaulted)
         return;
     var originalMessage = message;
     message = "{event} {global-profile} {local-profile}";
     Logger.Write("Running: " + _file + " " + message);
     ThreadPool.QueueUserWorkItem((task) => {
         try
         {
             var process = new Process();
             var responseDispatcher = new ResponseDispatcher(
                 _keyPath,
                 _dispatchErrors,
                 "rscript-" + Name + " ",
                 _outputDispatcher,
                 internalDispatch,
                 (response) => process.Write(response)
             );
             process.SetLogger((logMsg) => Logger.Write(logMsg));
             var msg = task.ToString();
             process.Query(
                 _file,
                 msg,
                 false,
                 _keyPath,
                 (error, m) => {
                     if (m == null)
                         return;
                     Logger.Write("request doing " + m);
                     if (error) {
                         Logger.Write("rscript-" + Name + " produced an error:");
                         Logger.Write("rscript-" + Name + "-" + m);
                     }
                     responseDispatcher.Handle(error, m);
                 },
                 new[] {
                     new KeyValuePair<string,string>("{event}", "\"" + originalMessage + "\""),
                     new KeyValuePair<string,string>("{global-profile}", "\"" + _globalProfileName + "\""),
                     new KeyValuePair<string,string>("{local-profile}", "\"" + _localProfileName + "\"")
                 });
             Logger.Write("RScript completed");
         }
         catch (Exception ex)
         {
             internalDispatch("rscript-" + Name + " " + ex.ToString());
             Logger.Write(ex.ToString());
         }
     }, message);
 }
Esempio n. 2
0
 private void startService()
 {
     _service = new Process();
     try
     {
         var responseDispatcher = new ResponseDispatcher(
             _keyPath,
             _dispatchErrors,
             "rscript-" + Name + " ",
             _outputDispatcher,
             internalDispatch,
             (response) => _service.Write(response)
         );
         _service.SetLogger((logMsg) => Logger.Write(logMsg));
         _service.Query(
             _file,
             "{global-profile} {local-profile}",
             false,
             _keyPath,
             (error, m) => {
                 if (m == null)
                     return;
                 Logger.Write("request doing " + m);
                 if (error) {
                     Logger.Write("rscript-" + Name + " produced an error:");
                     Logger.Write("rscript-" + Name + "-" + m);
                 }
                 responseDispatcher.Handle(error, m);
             },
             new[] {
                 new KeyValuePair<string,string>("{global-profile}", "\"" + _globalProfileName + "\""),
                 new KeyValuePair<string,string>("{local-profile}", "\"" + _localProfileName + "\"")
             });
         Logger.Write("Exiting service script");
     }
     catch (Exception ex)
     {
         internalDispatch("rscript-" + Name + " " + ex.ToString());
         Logger.Write(ex.ToString());
     }
 }
Esempio n. 3
0
 public void Run(string message)
 {
     if (Environment.OSVersion.Platform != PlatformID.Unix &&
         Environment.OSVersion.Platform != PlatformID.MacOSX)
     {
         message = message
                     .Replace(" ", "^ ")
                     .Replace("|", "^|")
                     .Replace("%", "^&")
                     .Replace("&", "^&")
                     .Replace("<", "^<")
                     .Replace(">", "^>");
     }
     var originalMessage = message;
     message = "{event} {global-profile} {local-profile}";
     Logger.Write("Running: " + _file + " " + message);
     ThreadPool.QueueUserWorkItem((task) => {
         try
         {
             var process = new Process();
             process.SetLogger((logMsg) => Logger.Write(logMsg));
             var msg = task.ToString();
             process.Query(
                 _file,
                 msg,
                 false,
                 _keyPath,
                 (error, m) => {
                     if (m == null)
                         return;
                     var cmdText = "command|";
                     var eventText = "event|";
                     if (error) {
                         Logger.Write("rscript-" + Name + " produced an error:");
                         Logger.Write("rscript-" + Name + "-" + m);
                     } else {
                         if (m.StartsWith(cmdText))
                             _dispatch(m.Substring(cmdText.Length, m.Length - cmdText.Length));
                         else if (m.StartsWith(eventText))
                             _dispatch(m.Substring(eventText.Length, m.Length - eventText.Length));
                         else
                             _dispatch("rscript-" + Name + " " + m);
                     }
                 },
                 new[] {
                     new KeyValuePair<string,string>("{event}", "\"" + originalMessage + "\""),
                     new KeyValuePair<string,string>("{global-profile}", "\"" + _globalProfileName + "\""),
                     new KeyValuePair<string,string>("{local-profile}", "\"" + _localProfileName + "\"")
                 });
         }
         catch (Exception ex)
         {
             Logger.Write(ex.ToString());
         }
     }, message);
 }