private static void UnhandledExceptionTrapper(object sender, UnhandledExceptionEventArgs e) { var logEntry = new HomeGenie.Data.LogEntry() { Domain = Domains.HomeAutomation_HomeGenie, Source = "Trapper", Description = "Unhandled Exception", Property = "Error.Exception", Value = e.ExceptionObject.ToString() }; try { // try broadcast first _homegenie.LogBroadcastEvent( logEntry.Domain, logEntry.Source, logEntry.Description, logEntry.Property, logEntry.Value ); } catch { HomeGenieService.LogEvent(logEntry); } }
public void ProcessRequest(MIGClientRequest request, MIGInterfaceCommand migcmd) { switch (migcmd.command) { case "Events.Push": //TODO: implemet security and trust mechanism string objstream = new StreamReader(request.InputStream).ReadToEnd(); ModuleEvent mev = JsonConvert.DeserializeObject <ModuleEvent>(objstream); // Module mod = _hg.Modules.Find(delegate(Module o) { return(o.Domain == mev.Module.Domain && o.Address == mev.Module.Address); }); if (mod == null) { mod = mev.Module; _hg.Modules.Add(mod); } else { Utility.ModuleParameterSet(mod, mev.Parameter.Name, mev.Parameter.Value); } // "<ip>:<port>" remote endpoint port is passed as the first argument from the remote point itself mod.RoutingNode = request.RequestOrigin + (migcmd.GetOption(0) != "" ? ":" + migcmd.GetOption(0) : ""); // _hg.LogBroadcastEvent(mev.Module.Domain, mev.Module.Address, request.RequestOrigin, mev.Parameter.Name, mev.Parameter.Value); _hg.RouteParameterChangedEvent(request.RequestOrigin, mod, mev.Parameter); break; } }
/// <summary> /// Display UI notification message from current program. /// </summary> /// <param name="title">Title.</param> /// <param name="message">Message.</param> /// <remarks /> /// <example> /// Example: /// <code> /// Program.Notify("Test Program", "Hello world!"); /// </code> /// </example> public ProgramHelper Notify(string title, string message) { homegenie.LogBroadcastEvent( Domains.HomeAutomation_HomeGenie_Automation, myProgramId.ToString(), "Automation Program", title, message ); return(this); }
public void ProcessRequest(MIGClientRequest request, MIGInterfaceCommand migCommand) { switch (migCommand.Command) { case "Events.Push": //TODO: implemet security and trust mechanism var stream = new StreamReader(request.InputStream).ReadToEnd(); var moduleEvent = JsonConvert.DeserializeObject <ModuleEvent>( stream, new JsonSerializerSettings() { Culture = System.Globalization.CultureInfo.InvariantCulture } ); // // prefix remote event domain with HGIC:<remote_node_address>.<domain> moduleEvent.Module.Domain = "HGIC:" + request.RequestOrigin.Replace(".", "_") + "." + moduleEvent.Module.Domain; // var module = homegenie.Modules.Find(delegate(Module o) { return(o.Domain == moduleEvent.Module.Domain && o.Address == moduleEvent.Module.Address); }); if (module == null) { module = moduleEvent.Module; homegenie.Modules.Add(module); } else { Utility.ModuleParameterSet(module, moduleEvent.Parameter.Name, moduleEvent.Parameter.Value); } // "<ip>:<port>" remote endpoint port is passed as the first argument from the remote point itself module.RoutingNode = request.RequestOrigin + (migCommand.GetOption(0) != "" ? ":" + migCommand.GetOption(0) : ""); // homegenie.LogBroadcastEvent( moduleEvent.Module.Domain, moduleEvent.Module.Address, request.RequestOrigin, moduleEvent.Parameter.Name, moduleEvent.Parameter.Value ); HomeGenie.Service.HomeGenieService.RoutedEvent eventData = new HomeGenie.Service.HomeGenieService.RoutedEvent() { Sender = request.RequestOrigin, Module = module, Parameter = moduleEvent.Parameter }; ThreadPool.QueueUserWorkItem(new WaitCallback(homegenie.RouteParameterChangedEvent), eventData); break; } }
/// <summary> /// Display UI notification message from current program. /// </summary> /// <param name="title">Title.</param> /// <param name="message">Message.</param> /// <remarks /> /// <example> /// Example: /// <code> /// Program.Notify("Test Program", "Hello world!"); /// </code> /// </example> public ProgramHelper Notify(string title, string message) { dynamic notification = new ExpandoObject(); notification.Title = title; notification.Message = message; string serializedMessage = JsonConvert.SerializeObject(notification); homegenie.LogBroadcastEvent( Domains.HomeAutomation_HomeGenie_Automation, myProgramId.ToString(), "Automation Program", Properties.PROGRAM_NOTIFICATION, serializedMessage ); return(this); }
public ProgramHelper Notify(string title, string message) { _homegenie.LogBroadcastEvent("HomeGenie.Automation", _myprogramid.ToString(), "Automation Program", title, message); return(this); }
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); }