private void ExecuteCommand(ScriptCommand programCommand) { string command = programCommand.Domain + "/" + programCommand.Target + "/" + programCommand.CommandString + "/" + System.Uri.EscapeDataString(programCommand.CommandArguments); var interfaceCommand = new MigInterfaceCommand(command); HomeGenie.InterfaceControl(interfaceCommand); }
public override MethodRunResult Run(string options) { var 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'); // foreach (var res in outputResult) { if (String.IsNullOrWhiteSpace(res)) continue; HomeGenie.RaiseEvent( Domains.HomeGenie_System, Domains.HomeAutomation_HomeGenie_Automation, ProgramBlock.Address.ToString(), "Arduino Sketch", "Arduino.UploadOutput", res ); Thread.Sleep(500); } // HomeGenie.RaiseEvent( Domains.HomeGenie_System, Domains.HomeAutomation_HomeGenie_Automation, ProgramBlock.Address.ToString(), "Arduino Sketch", "Arduino.UploadOutput", "Upload finished" ); return result; }
public void RouteModuleEvent(HomeGenie.Automation.ProgramManager.RoutedEvent eventData) { if (moduleUpdateHandler != null) { var module = new ModuleHelper(homegenie, eventData.Module); var parameter = eventData.Parameter; var callback = new WaitCallback((state) => { try { homegenie.MigService.RaiseEvent( this, Domains.HomeAutomation_HomeGenie, SourceModule.Scheduler, "Scheduler Routed Event", Properties.SchedulerModuleUpdateStart, schedulerItem.Name); moduleUpdateHandler(module, parameter); homegenie.MigService.RaiseEvent( this, Domains.HomeAutomation_HomeGenie, SourceModule.Scheduler, "Scheduler Routed Event", Properties.SchedulerModuleUpdateEnd, schedulerItem.Name); } catch (Exception e) { homegenie.MigService.RaiseEvent( this, Domains.HomeAutomation_HomeGenie, SourceModule.Scheduler, e.Message.Replace('\n', ' ').Replace('\r', ' '), Properties.SchedulerError, schedulerItem.Name); } }); ThreadPool.QueueUserWorkItem(callback); } }
internal void SetHomeGenieHost(HomeGenie.Service.HomeGenieService hg) { homegenie = hg; }
private void ExecuteScript(IReadOnlyList <ScriptCommand> commands) { int repeatStartLine = 0; int repeatCount = 0; if (script.ConditionType == ConditionType.Once) { // execute only once ProgramBlock.IsEnabled = false; } for (int x = 0; x < commands.Count; x++) { if (commands[x].Domain == Domains.HomeAutomation_HomeGenie && commands[x].Target == SourceModule.Automation) { string cs = commands[x].CommandString; switch (cs) { case "Program.Pause": Thread.Sleep((int)(double.Parse(commands[x].CommandArguments, CultureInfo.InvariantCulture) * 1000)); break; case "Program.Repeat": // TODO: implement check for contiguous repeat statements if (repeatCount <= 0) { repeatCount = (int)(double.Parse(commands[x].CommandArguments, CultureInfo.InvariantCulture)); } if (--repeatCount == 0) { repeatStartLine = x + 1; } else { x = repeatStartLine - 1; } break; case "Program.Run": string programId = commands[x].CommandArguments; var programToRun = HomeGenie.ProgramManager.Programs .Find(p => p.Address.ToString() == programId || p.Name == programId); if (programToRun != null && /*&& programToRun.Address != program.Address*/ !programToRun.IsRunning) { programToRun.Engine.StartProgram(); } break; case "Program.WaitFor": hgScriptingHost.Program.WaitFor(commands[x].CommandArguments); break; case "Program.Play": hgScriptingHost.Program.Play(commands[x].CommandArguments); break; case "Program.Say": var language = "en-US"; var sentence = commands[x].CommandArguments; int lidx = sentence.LastIndexOf("/"); if (lidx > 0) { language = sentence.Substring(lidx + 1); sentence = sentence.Substring(0, lidx); } hgScriptingHost.Program.Say(sentence, language); break; default: var programCommand = commands[x]; string wrequest = programCommand.Domain + "/" + programCommand.Target + "/" + programCommand.CommandString + "/" + programCommand.CommandArguments; HomeGenie.ExecuteAutomationRequest(new MigInterfaceCommand(wrequest)); break; } } else { ExecuteCommand(commands[x]); } // Thread.Sleep(10); } }