示例#1
0
 public MethodRunResult Run(string options)
 {
     var result = new MethodRunResult();
     try
     {
         ExecuteScript(programBlock.Commands);
     }
     catch (Exception e)
     {
         result.Exception = e;
     }
     return result;
 }
示例#2
0
 public MethodRunResult EvaluateCondition()
 {
     MethodRunResult result = null;
     result = new MethodRunResult();
     try
     {
         result.ReturnValue = EvaluateCondition(programBlock.Conditions);
     }
     catch (Exception e)
     {
         result.Exception = e;
     }
     return result;
 }
示例#3
0
 public MethodRunResult EvaluateCondition()
 {
     MethodRunResult result = null;
     string pythonScript = programBlock.ScriptCondition;
     result = new MethodRunResult();
     try
     {
         var sh = (scriptScope as dynamic).hg as ScriptingHost;
         scriptEngine.Execute(pythonScript, scriptScope);
         result.ReturnValue = sh.executeProgramCode || programBlock.WillRun;
     }
     catch (Exception e)
     {
         result.Exception = e;
     }
     return result;
 }
示例#4
0
 public MethodRunResult EvaluateCondition()
 {
     MethodRunResult result = null;
     string jsScript = programBlock.ScriptCondition;
     result = new MethodRunResult();
     try
     {
         var sh = (scriptEngine.GetValue("hg").ToObject() as ScriptingHost);
         scriptEngine.Execute(jsScript);
         result.ReturnValue = sh.executeProgramCode || programBlock.WillRun;
     }
     catch (Exception e)
     {
         result.Exception = e;
     }
     return result;
 }
示例#5
0
 public MethodRunResult Run(string options)
 {
     var result = new MethodRunResult();
     result = new MethodRunResult();
     homegenie.RaiseEvent(
         Domains.HomeGenie_System,
         Domains.HomeAutomation_HomeGenie_Automation,
         programBlock.Address.ToString(),
         "Arduino Sketch Upload",
         "Arduino.UploadOutput",
         "Upload started"
     );
     string[] outputResult = ArduinoAppFactory.UploadSketch(Path.Combine(
         AppDomain.CurrentDomain.BaseDirectory,
         "programs",
         "arduino",
         programBlock.Address.ToString()
     )).Split('\n');
     //
     for (int x = 0; x < outputResult.Length; x++)
     {
         if (!String.IsNullOrWhiteSpace(outputResult[x]))
         {
             homegenie.RaiseEvent(
                 Domains.HomeGenie_System,
                 Domains.HomeAutomation_HomeGenie_Automation,
                 programBlock.Address.ToString(),
                 "Arduino Sketch",
                 "Arduino.UploadOutput",
                 outputResult[x]
             );
             Thread.Sleep(500);
         }
     }
     //
     homegenie.RaiseEvent(
         Domains.HomeGenie_System,
         Domains.HomeAutomation_HomeGenie_Automation,
         programBlock.Address.ToString(),
         "Arduino Sketch",
         "Arduino.UploadOutput",
         "Upload finished"
     );
     return result;
 }
示例#6
0
 internal MethodRunResult Run(string options)
 {
     MethodRunResult result = null;
     switch (codeType.ToLower())
     {
         case "python":
             string pythonScript = this.ScriptSource;
             ScriptEngine pythonEngine = (scriptEngine as ScriptEngine);
             result = new MethodRunResult();
             try
             {
                 pythonEngine.Execute(pythonScript, scriptScope);
             }
             catch (Exception e)
             {
                 result.Exception = e;
             }
             break;
         case "ruby":
             string rubyScript = this.ScriptSource;
             ScriptEngine rubyEngine = (scriptEngine as ScriptEngine);
             result = new MethodRunResult();
             try
             {
                 rubyEngine.Execute(rubyScript, scriptScope);
             }
             catch (Exception e)
             {
                 result.Exception = e;
             }
             break;
         case "javascript":
             string jsScript = this.ScriptSource;
             Jint.Engine engine = (scriptEngine as Jint.Engine);
             //engine.Options.AllowClr(false);
             result = new MethodRunResult();
             try
             {
                 engine.Execute(jsScript);
             }
             catch (Exception e)
             {
                 result.Exception = e;
             }
             break;
         case "csharp":
             if (appAssembly != null && CheckAppInstance())
             {
                 result = (MethodRunResult)methodRun.Invoke(assembly, new object[1] { options });
             }
             break;
     }
     //
     return result;
 }
示例#7
0
 internal MethodRunResult EvaluateCondition()
 {
     MethodRunResult result = null;
     switch (codeType.ToLower())
     {
         case "python":
             string pythonScript = this.ScriptCondition;
             ScriptEngine pythonEngine = (scriptEngine as ScriptEngine);
             result = new MethodRunResult();
             try
             {
                 pythonEngine.Execute(pythonScript, scriptScope);
                 result.ReturnValue = (scriptScope as dynamic).hg.executeCodeToRun;
             }
             catch (Exception e)
             {
                 result.Exception = e;
             }
             break;
         case "ruby":
             string rubyScript = this.ScriptCondition;
             ScriptEngine rubyEngine = (scriptEngine as ScriptEngine);
             result = new MethodRunResult();
             try
             {
                 rubyEngine.Execute(rubyScript, scriptScope);
                 result.ReturnValue = (scriptScope as dynamic).hg.executeCodeToRun;
             }
             catch (Exception e)
             {
                 result.Exception = e;
             }
             break;
         case "javascript":
             string jsScript = this.ScriptCondition;
             Jint.Engine engine = (scriptEngine as Jint.Engine);
             result = new MethodRunResult();
             try
             {
                 engine.Execute(jsScript);
                 result.ReturnValue = (engine.GetValue("hg").ToObject() as ScriptingHost).executeCodeToRun;
             }
             catch (Exception e)
             {
                 result.Exception = e;
             }
             break;
         case "csharp":
             if (appAssembly != null && CheckAppInstance())
             {
                 result = (MethodRunResult)methodEvaluateCondition.Invoke(assembly, null);
             }
             break;
     }
     //
     return result;
 }
示例#8
0
 public MethodRunResult EvaluateCondition()
 {
     MethodRunResult result = null;
     string jsScript = programBlock.ScriptCondition;
     result = new MethodRunResult();
     try
     {
         var sh = (scriptEngine.GetValue("hg").ToObject() as ScriptingHost);
         if (!jsScript.ToLower().Contains("hg.program.setup"))
         {
             sh.Program.Setup(()=>{
                 scriptEngine.Execute(jsScript);
             });
         }
         else
         {
             scriptEngine.Execute(jsScript);
         }
         result.ReturnValue = sh.executeProgramCode || programBlock.Autostart;
     }
     catch (Exception e)
     {
         result.Exception = e;
     }
     return result;
 }
示例#9
0
 public MethodRunResult Run(string options)
 {
     MethodRunResult result = null;
     string jsScript = programBlock.ScriptSource;
     //scriptEngine.Options.AllowClr(false);
     result = new MethodRunResult();
     try
     {
         scriptEngine.Execute(jsScript);
     }
     catch (Exception e)
     {
         result.Exception = e;
     }
     return result;
 }
示例#10
0
        public void StartProgram(string options)
        {
            if (programBlock.IsRunning)
                return;

            // TODO: since if !program.IsRunning also thread should be null
            // TODO: so this is probably useless here and could be removed?
            if (programThread != null)
                StopProgram();

            programBlock.IsRunning = true;
            homegenie.ProgramManager.RaiseProgramModuleEvent(programBlock, Properties.ProgramStatus, "Running");

            programBlock.TriggerTime = DateTime.UtcNow;

            programThread = new Thread(() =>
            {
                try
                {
                    MethodRunResult result = null;
                    try
                    {
                        result = programBlock.Run(options);
                    }
                    catch (Exception ex)
                    {
                        result = new MethodRunResult();
                        result.Exception = ex;
                    }
                    programThread = null;
                    programBlock.IsRunning = false;
                    if (result != null && result.Exception != null && !result.Exception.GetType().Equals(typeof(System.Reflection.TargetException)))
                    {
                        // runtime error occurred, script is being disabled
                        // so user can notice and fix it
                        List<ProgramError> error = new List<ProgramError>() { programBlock.GetFormattedError(result.Exception, false) };
                        programBlock.ScriptErrors = JsonConvert.SerializeObject(error);
                        programBlock.IsEnabled = false;
                        homegenie.ProgramManager.RaiseProgramModuleEvent(programBlock, Properties.RuntimeError, "CR: " + result.Exception.Message.Replace('\n', ' ').Replace('\r', ' '));
                    }
                    homegenie.ProgramManager.RaiseProgramModuleEvent(programBlock, Properties.ProgramStatus, programBlock.IsEnabled ? "Idle" : "Stopped");
                }
                catch (ThreadAbortException)
                {
                    programThread = null;
                    programBlock.IsRunning = false;
                    homegenie.ProgramManager.RaiseProgramModuleEvent(programBlock, Properties.ProgramStatus, "Interrupted");
                }
            });

            if (programBlock.ConditionType == ConditionType.Once)
            {
                programBlock.IsEnabled = false;
            }

            try
            {
                programThread.Start();
            }
            catch
            {
                StopProgram();
                homegenie.ProgramManager.RaiseProgramModuleEvent(programBlock, Properties.ProgramStatus, "Idle");
            }
        }
示例#11
0
 public MethodRunResult Run(string options)
 {
     MethodRunResult result = null;
     string pythonScript = programBlock.ScriptSource;
     result = new MethodRunResult();
     try
     {
         scriptEngine.Execute(pythonScript, scriptScope);
     }
     catch (Exception e)
     {
         result.Exception = e;
     }
     return result;
 }
示例#12
0
 internal MethodRunResult Run(string options)
 {
     MethodRunResult result = null;
     switch (codeType.ToLower())
     {
     case "python":
         string pythonScript = this.ScriptSource;
         ScriptEngine pythonEngine = (scriptEngine as ScriptEngine);
         result = new MethodRunResult();
         try
         {
             pythonEngine.Execute(pythonScript, scriptScope);
         }
         catch (Exception e)
         {
             result.Exception = e;
         }
         break;
     case "ruby":
         string rubyScript = this.ScriptSource;
         ScriptEngine rubyEngine = (scriptEngine as ScriptEngine);
         result = new MethodRunResult();
         try
         {
             rubyEngine.Execute(rubyScript, scriptScope);
         }
         catch (Exception e)
         {
             result.Exception = e;
         }
         break;
     case "javascript":
         string jsScript = this.ScriptSource;
         Jint.Engine engine = (scriptEngine as Jint.Engine);
             //engine.Options.AllowClr(false);
         result = new MethodRunResult();
         try
         {
             engine.Execute(jsScript);
         }
         catch (Exception e)
         {
             result.Exception = e;
         }
         break;
     case "csharp":
         if (appAssembly != null && CheckAppInstance())
         {
             result = (MethodRunResult)methodRun.Invoke(assembly, new object[1] { options });
         }
         break;
     case "arduino":
         result = new MethodRunResult();
         homegenie.LogBroadcastEvent(
             Domains.HomeAutomation_HomeGenie_Automation,
             this.Address.ToString(),
             "Arduino Sketch Upload",
             "Arduino.UploadOutput",
             "Upload started"
             );
         string[] outputResult = ArduinoAppFactory.UploadSketch(Path.Combine(
             AppDomain.CurrentDomain.BaseDirectory,
             "programs",
             "arduino",
             this.Address.ToString()
         )).Split('\n');
         //
         for (int x = 0; x < outputResult.Length; x++)
         {
             if (!String.IsNullOrWhiteSpace(outputResult[x]))
             {
                 homegenie.LogBroadcastEvent(
                     Domains.HomeAutomation_HomeGenie_Automation,
                     this.Address.ToString(),
                     "Arduino Sketch",
                     "Arduino.UploadOutput",
                     outputResult[x]
                 );
                 Thread.Sleep(500);
             }
         }
         //
         homegenie.LogBroadcastEvent(
             Domains.HomeAutomation_HomeGenie_Automation,
             this.Address.ToString(),
             "Arduino Sketch",
             "Arduino.UploadOutput",
             "Upload finished"
             );
         break;
     }
     //
     return result;
 }
示例#13
0
 internal MethodRunResult EvaluateCondition()
 {
     MethodRunResult result = null;
     switch (codeType.ToLower())
     {
     case "python":
         string pythonScript = this.ScriptCondition;
         ScriptEngine pythonEngine = (scriptEngine as ScriptEngine);
         result = new MethodRunResult();
         try
         {
             var sh = (scriptScope as dynamic).hg as ScriptingHost;
             if (!pythonScript.ToLower().Contains("hg.program.setup"))
             {
                 sh.Program.Setup(()=>{
                     pythonEngine.Execute(pythonScript, scriptScope);
                 });
             }
             else
             {
                 pythonEngine.Execute(pythonScript, scriptScope);
             }
             result.ReturnValue = sh.executeProgramCode || this.Autostart;
         }
         catch (Exception e)
         {
             result.Exception = e;
         }
         break;
     case "ruby":
         string rubyScript = this.ScriptCondition;
         ScriptEngine rubyEngine = (scriptEngine as ScriptEngine);
         result = new MethodRunResult();
         try
         {
             var sh = (scriptScope as dynamic).hg as ScriptingHost;
             if (!rubyScript.ToLower().Contains("hg.program.setup"))
             {
                 sh.Program.Setup(()=>{
                     rubyEngine.Execute(rubyScript, scriptScope);
                 });
             }
             else
             {
                 rubyEngine.Execute(rubyScript, scriptScope);
             }
             result.ReturnValue = sh.executeProgramCode || this.Autostart;
         }
         catch (Exception e)
         {
             result.Exception = e;
         }
         break;
     case "javascript":
         string jsScript = this.ScriptCondition;
         Jint.Engine engine = (scriptEngine as Jint.Engine);
         result = new MethodRunResult();
         try
         {
             var sh = (engine.GetValue("hg").ToObject() as ScriptingHost);
             if (!jsScript.ToLower().Contains("hg.program.setup"))
             {
                 sh.Program.Setup(()=>{
                     engine.Execute(jsScript);
                 });
             }
             else
             {
                 engine.Execute(jsScript);
             }
             result.ReturnValue = sh.executeProgramCode || this.Autostart;
         }
         catch (Exception e)
         {
             result.Exception = e;
         }
         break;
     case "csharp":
         if (appAssembly != null && CheckAppInstance())
         {
             result = (MethodRunResult)methodEvaluateCondition.Invoke(assembly, null);
             result.ReturnValue = (bool)result.ReturnValue || this.Autostart;
         }
         break;
     case "wizard":
         WizardEngine wizardEngine = (scriptEngine as WizardEngine);
         result = new MethodRunResult();
         try
         {
             result.ReturnValue = wizardEngine.EvaluateCondition(this.Conditions);
         }
         catch (Exception e)
         {
             result.Exception = e;
         }
         break;
     }
     //
     return result;
 }