Esempio n. 1
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;

            case "wizard":
                WizardEngine wizardEngine = (scriptEngine as WizardEngine);
                result = new MethodRunResult();
                try
                {
                    result.ReturnValue = wizardEngine.EvaluateTrigger(this.Conditions);
                }
                catch (Exception e)
                {
                    result.Exception = e;
                }
                break;
            }
            //
            return(result);
        }
Esempio n. 2
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 "wizard":
                WizardEngine wizardEngine = (scriptEngine as WizardEngine);
                result = new MethodRunResult();
                try
                {
                    wizardEngine.ExecuteScript(this.Commands);
                }
                catch (Exception e)
                {
                    result.Exception = e;
                }
                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);
        }