Beispiel #1
0
 public object InterfaceControl(MigInterfaceCommand cmd)
 {
     object response = null;
     var target = systemModules.Find(m => m.Domain == cmd.Domain && m.Address == cmd.Address);
     bool isRemoteModule = (target != null && !String.IsNullOrWhiteSpace(target.RoutingNode));
     if (isRemoteModule)
     {
         try
         {
             string domain = cmd.Domain;
             if (domain.StartsWith("HGIC:"))
                 domain = domain.Substring(domain.IndexOf(".") + 1);
             string serviceUrl = "http://" + target.RoutingNode + "/api/" + domain + "/" + cmd.Address + "/" + cmd.Command + "/" + cmd.OptionsString;
             Automation.Scripting.NetHelper netHelper = new Automation.Scripting.NetHelper(this).WebService(serviceUrl);
             string username = webGateway.GetOption("Username").Value;
             string password = webGateway.GetOption("Password").Value;
             if (!String.IsNullOrWhiteSpace(username) && !String.IsNullOrWhiteSpace(password))
             {
                 netHelper.WithCredentials(username, password);
             }
             response = netHelper.GetData();
         }
         catch (Exception ex)
         {
             LogError(Domains.HomeAutomation_HomeGenie, "Interconnection:" + target.RoutingNode, ex.Message, "Exception.StackTrace", ex.StackTrace);
         }
     }
     else
     {
         var migInterface = migService.GetInterface(cmd.Domain);
         if (migInterface != null)
         {
             try
             {
                 response = migInterface.InterfaceControl(cmd);
             }
             catch (Exception ex)
             {
                 LogError(Domains.HomeAutomation_HomeGenie, "InterfaceControl", ex.Message, "Exception.StackTrace", ex.StackTrace);
             }
         }
         //
         // If the command was not already handled, let automation programs process it
         if (response == null || String.IsNullOrWhiteSpace(response.ToString()))
         {
             response = ProgramDynamicApi.TryApiCall(cmd);
         }
         //
         // Macro Recording
         //
         // TODO: find a better solution for this....
         // TODO: it was: migService_ServiceRequestPostProcess(this, new ProcessRequestEventArgs(cmd));
         // TODO: !IMPORTANT!
         if (masterControlProgram != null && masterControlProgram.MacroRecorder.IsRecordingEnabled && cmd != null && cmd.Command != null && (cmd.Command.StartsWith("Control.") || (cmd.Command.StartsWith("AvMedia.") && cmd.Command != "AvMedia.Browse" && cmd.Command != "AvMedia.GetUri")))
         {
             masterControlProgram.MacroRecorder.AddCommand(cmd);
         }
     }
     return response;
 }
Beispiel #2
0
 public object InterfaceControl(MIGInterfaceCommand cmd)
 {
     object response = null;
     var target = systemModules.Find(m => m.Domain == cmd.Domain && m.Address == cmd.NodeId);
     bool isRemoteModule = (target != null && !String.IsNullOrWhiteSpace(target.RoutingNode));
     if (isRemoteModule)
     {
         try
         {
             string domain = cmd.Domain;
             if (domain.StartsWith("HGIC:"))
                 domain = domain.Substring(domain.IndexOf(".") + 1);
             string serviceUrl = "http://" + target.RoutingNode + "/api/" + domain + "/" + cmd.NodeId + "/" + cmd.Command + "/" + cmd.OptionsString;
             Automation.Scripting.NetHelper netHelper = new Automation.Scripting.NetHelper(this).WebService(serviceUrl);
             if (!String.IsNullOrWhiteSpace(systemConfiguration.HomeGenie.UserLogin) && !String.IsNullOrWhiteSpace(systemConfiguration.HomeGenie.UserPassword))
             {
                 netHelper.WithCredentials(systemConfiguration.HomeGenie.UserLogin, systemConfiguration.HomeGenie.UserPassword);
             }
             response = netHelper.GetData();
         }
         catch (Exception ex)
         {
             HomeGenieService.LogEvent(Domains.HomeAutomation_HomeGenie, "Interconnection:" + target.RoutingNode, ex.Message, "Exception.StackTrace", ex.StackTrace);
         }
     }
     else
     {
         MIGInterface migInterface = GetInterface(cmd.Domain);
         if (migInterface != null)
         {
             try
             {
                 response = migInterface.InterfaceControl(cmd);
             }
             catch (Exception ex)
             {
                 HomeGenieService.LogEvent(Domains.HomeAutomation_HomeGenie, "InterfaceControl", ex.Message, "Exception.StackTrace", ex.StackTrace);
             }
         }
         //
         if (response == null || response.Equals(""))
         {
             response = migService.WebServiceDynamicApiCall(cmd);
         }
         // let HG post process the local command
         migService_ServiceRequestPostProcess(null, cmd);
     }
     return response;
 }