Ejemplo n.º 1
0
        void homegear_OnDeviceVariableUpdated(Homegear sender, Device device, Channel channel, Variable variable)
        {
            try
            {
                _logger.LogDebug("Update event received for variable {0} for device id {1} with value {2}.", variable.Name, device.TypeID, variable.BooleanValue);

                dynamic variableValue = "";
                if (variable.StringValue != null && variable.StringValue != "")
                {
                    variableValue = variable.StringValue;
                }
                else if (variable.DoubleValue != 0)
                {
                    variableValue = variable.DoubleValue;
                }
                else if (variable.IntegerValue != 0)
                {
                    variableValue = variable.IntegerValue;
                }

                _eventLoggerFactory.GetEventLoggerFor((HomegearDeviceTypes)device.TypeID, variable.Name).LogEvent(device.ID, variable.Name, variableValue);
            }
            catch (KeyNotFoundException exception)
            {
                _logger.LogDebug("No handler found for variable {0} with id {1}. Exception message: {1}", variable.Name, device.TypeID, exception.Message);
            }
        }
Ejemplo n.º 2
0
        public XMLRPCHomegearConnectionService(
            Homegear homegear,
            RPCController rpcController,
            ILightSwitchesPersistenceService lightSwitchesPersistence,
            IDoorWindowSensorPersistenceService doorWindowSensorActivityPersistence,
            IExternalWallSocketsPersistenceService externalWallSocketPersistenceService,
            ILogger <XMLRPCHomegearConnectionService> logger,
            IDevicesService <LightSwitchModel> lightSwitchesService)
        {
            _homegearController = rpcController;
            _homegear           = homegear;
            _logger             = logger;

            _homegearController.ServerConnected += rpc_serverConnected;

            //this.homegear.Reloaded += homegear_OnReloaded;
            //this.homegear.ConnectError += homegear_OnConnectError;
            _homegear.ReloadRequired        += homegear_OnReloadRequired;
            _homegear.DeviceReloadRequired  += homegear_OnDeviceReloadRequired;
            _homegear.DeviceVariableUpdated += homegear_OnDeviceVariableUpdated;

            _eventLoggerFactory = new EventHandlerFactory();

            _eventLoggerFactory.RegisterEventLogger(HomegearDeviceTypes.LightSwitch, LightSwitchVariables.STATE, new LightSwitchEventHandler(lightSwitchesPersistence));
            _eventLoggerFactory.RegisterEventLogger(HomegearDeviceTypes.DoorWindowMagneticSensor, DoorWindowSensorVariables.STATE, new DoorWindowSensorStateEventHandler(doorWindowSensorActivityPersistence, lightSwitchesService));
            _eventLoggerFactory.RegisterEventLogger(HomegearDeviceTypes.DoorWindowMagneticSensor, DoorWindowSensorVariables.LOWBAT, new DoorWindowSensorLowBatteryEventHandler(doorWindowSensorActivityPersistence));
            _eventLoggerFactory.RegisterEventLogger(HomegearDeviceTypes.ExternalWallSocket, ExternalWallSocketVariables.CURRENT, new ExternalWallSocketHandler(externalWallSocketPersistenceService));
            _eventLoggerFactory.RegisterEventLogger(HomegearDeviceTypes.ExternalWallSocket, ExternalWallSocketVariables.VOLTAGE, new ExternalWallSocketHandler(externalWallSocketPersistenceService));
            _eventLoggerFactory.RegisterEventLogger(HomegearDeviceTypes.ExternalWallSocket, ExternalWallSocketVariables.FREQUENCY, new ExternalWallSocketHandler(externalWallSocketPersistenceService));
            _eventLoggerFactory.RegisterEventLogger(HomegearDeviceTypes.ExternalWallSocket, ExternalWallSocketVariables.ENERGY_COUNTER, new ExternalWallSocketHandler(externalWallSocketPersistenceService));
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.Write("Please enter the hostname or IP address of your server running Homegear: ");
            string homegearHost = Console.ReadLine();

            #region Without SSL support
            RPCController rpc = new RPCController
                                (
                homegearHost,                      //Hostname of your server running Homegear
                2001                               //Port Homegear listens on
                                );
            #endregion

            #region With SSL support

            /*
             * SSLClientInfo sslClientInfo = new SSLClientInfo
             *                              (
             *                                  "MyComputer",   //Hostname of the computer your program runs on.
             *  //This hostname is used for certificate verification.
             *                                  "user",
             *                                  "secret",
             *                                  true            //Enable certificate verification
             *                              );
             *
             * RPCController rpc = new RPCController(homegearHost, 2003, sslClientInfo);
             */
            #endregion

            Homegear homegear = new Homegear(rpc, true);

            homegear.ConnectError                     += homegear_ConnectError;
            homegear.Reloaded                         += homegear_Reloaded;
            homegear.SystemVariableUpdated            += homegear_SystemVariableUpdated;
            homegear.DeviceVariableUpdated            += homegear_DeviceVariableUpdated;
            homegear.MetadataUpdated                  += homegear_MetadataUpdated;
            homegear.DeviceConfigParameterUpdated     += homegear_DeviceConfigParameterUpdated;
            homegear.DeviceLinkConfigParameterUpdated += homegear_DeviceLinkConfigParameterUpdated;

            Console.WriteLine("Connecting to Homegear...");
            _connectedEvent.WaitOne();

            if (!rpc.IsConnected)
            {
                Console.WriteLine("Exiting...");
                homegear.Dispose();
                Environment.Exit(1);
            }

            Console.WriteLine("Press 'q' to exit program.");
            Thread.Sleep(2000);

            ConsoleKeyInfo key;
            do
            {
                key = Console.ReadKey();
            } while (key.KeyChar != 'q');

            homegear.Dispose();
        }
Ejemplo n.º 4
0
        public XMLRPCDevicesServiceTest()
        {
            RPCController _rpc = new RPCController("localhost", 2001, "alvin", "0.0.0.0", 4002);

            _homegear       = new Homegear(_rpc, true);
            _devicesService = new XMLRPCDevicesService(_homegear);
        }
Ejemplo n.º 5
0
 void homegear_OnDeviceReloadRequired(Homegear sender, Device device, Channel channel, DeviceReloadType reloadType)
 {
     if (reloadType == DeviceReloadType.Full)
     {
         //WriteLog("Reloading device " + device.ID.ToString() + ".");
         //Finish all operations on the device and then call:
         device.Reload();
     }
     else if (reloadType == DeviceReloadType.Metadata)
     {
         //WriteLog("Reloading metadata of device " + device.ID.ToString() + ".");
         //Finish all operations on the device's metadata and then call:
         device.Metadata.Reload();
     }
     else if (reloadType == DeviceReloadType.Channel)
     {
         //WriteLog("Reloading channel " + channel.Index + " of device " + device.ID.ToString() + ".");
         //Finish all operations on the device's channel and then call:
         channel.Reload();
     }
     else if (reloadType == DeviceReloadType.Variables)
     {
         //WriteLog("Device variables were updated: Device type: \"" + device.TypeString + "\", ID: " + device.ID.ToString() + ", Channel: " + channel.Index.ToString());
         //WriteLog("Reloading variables of channel " + channel.Index + " and device " + device.ID.ToString() + ".");
         //Finish all operations on the channels's variables and then call:
         channel.Variables.Reload();
     }
     else if (reloadType == DeviceReloadType.Links)
     {
         //WriteLog("Device links were updated: Device type: \"" + device.TypeString + "\", ID: " + device.ID.ToString() + ", Channel: " + channel.Index.ToString());
         //WriteLog("Reloading links of channel " + channel.Index + " and device " + device.ID.ToString() + ".");
         //Finish all operations on the channels's links and then call:
         channel.Links.Reload();
     }
     else if (reloadType == DeviceReloadType.Team)
     {
         //WriteLog("Device team was updated: Device type: \"" + device.TypeString + "\", ID: " + device.ID.ToString() + ", Channel: " + channel.Index.ToString());
         //WriteLog("Reloading channel " + channel.Index + " of device " + device.ID.ToString() + ".");
         //Finish all operations on the device's channel and then call:
         channel.Reload();
     }
     else if (reloadType == DeviceReloadType.Events)
     {
         //WriteLog("Device events were updated: Device type: \"" + device.TypeString + "\", ID: " + device.ID.ToString() + ", Channel: " + channel.Index.ToString());
         //WriteLog("Reloading events of device " + device.ID.ToString() + ".");
         //Finish all operations on the device's events and then call:
         device.Events.Reload();
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Used at application startup in order to add the <see cref="Homegear"/> and <see cref="RPCController"/> services.
        /// These services will establish a connection to the Homegear server and will create a bidirectional communication channel to
        /// and from Homegear server that will be used in the other <see cref="HomegearXMLRPCService"/> services.
        /// </summary>
        /// <param name="services">The current services collection</param>
        /// <param name="connectionConfig">Provides the information to connect to the Homegear server</param>
        /// <returns></returns>
        public static IServiceCollection AddXMLRPCHomegear(this IServiceCollection services, IConfigurationSection connectionConfig)
        {
            RPCController homegearController = new RPCController(
                connectionConfig.GetValue <string>("IP"),
                connectionConfig.GetValue <int>("Port"),
                connectionConfig.GetValue <string>("EventListenerHostname"),
                connectionConfig.GetValue <string>("EventListenerIP"),
                connectionConfig.GetValue <int>("EventListenerPort"));

            Homegear homegear = new Homegear(homegearController, true);

            services.AddSingleton <RPCController>(homegearController);
            services.AddSingleton <Homegear>(homegear);

            return(services);
        }
Ejemplo n.º 7
0
        public frmCreateDevice(Homegear homegear, Int64 address = 0, Family family = null)
        {
            _homegear = homegear;
            InitializeComponent();
            foreach (KeyValuePair <Int64, Family> familyEntry in homegear.Families)
            {
                cbFamilies.Items.Add(familyEntry.Value);
            }
            if (family != null)
            {
                cbFamilies.SelectedItem = family;
            }

            if (address != 0)
            {
                txtAddress.Text = address.ToString("X");
            }
        }
Ejemplo n.º 8
0
        public frmSniffPackets(Homegear homegear)
        {
            _homegear = homegear;
            InitializeComponent();
            foreach (KeyValuePair <Int64, Family> family in homegear.Families)
            {
                cbFamilies.Items.Add(family.Value);
            }
            if (!System.Windows.Forms.SystemInformation.TerminalServerSession)
            {
                System.Reflection.PropertyInfo propertyInfo =
                    typeof(System.Windows.Forms.Control).GetProperty(
                        "DoubleBuffered",
                        System.Reflection.BindingFlags.NonPublic |
                        System.Reflection.BindingFlags.Instance);

                propertyInfo.SetValue(tvDevices, true, null);
            }
        }
Ejemplo n.º 9
0
        public frmSetTeam(Channel channel, Homegear homegear)
        {
            InitializeComponent();

            if (channel.TeamTag.Length == 0 || channel.TeamID == 0)
            {
                MessageBox.Show(this, "Channel does not support teams.", "Set Team", MessageBoxButtons.OK, MessageBoxIcon.Information);
                DialogResult     = System.Windows.Forms.DialogResult.Abort;
                bnRemove.Enabled = false;
                bnOK.Enabled     = false;
                lstTeams.Enabled = false;
                return;
            }

            try
            {
                foreach (KeyValuePair <Int64, Device> devicePair in homegear.Devices)
                {
                    if (devicePair.Key < 0x40000000)
                    {
                        continue;
                    }

                    foreach (KeyValuePair <Int64, Channel> channelPair in devicePair.Value.Channels)
                    {
                        if (channelPair.Value.TeamTag == channel.TeamTag)
                        {
                            TeamListEntry entry = new TeamListEntry();
                            entry.Description = "Team: 0x" + devicePair.Key.ToString("X2") + " Channel: " + channelPair.Value.Index.ToString();
                            entry.Channel     = channelPair.Value;
                            lstTeams.Items.Add(entry);
                        }
                    }
                }
            }
            catch (Exception)
            {
                DialogResult = System.Windows.Forms.DialogResult.Abort;
                Close();
            }
        }
Ejemplo n.º 10
0
 void homegear_OnReloadRequired(Homegear sender, ReloadType reloadType)
 {
     if (reloadType == ReloadType.Full)
     {
         //WriteLog("Received reload required event. Reloading.");
         //Finish all operations on the Homegear object and then call:
         _homegear.Reload();
     }
     else if (reloadType == ReloadType.SystemVariables)
     {
         //WriteLog("Reloading system variables.");
         //Finish all operations on the system variables and then call:
         _homegear.SystemVariables.Reload();
     }
     else if (reloadType == ReloadType.Events)
     {
         //WriteLog("Reloading timed events.");
         //Finish all operations on the timed events and then call:
         _homegear.TimedEvents.Reload();
     }
 }
Ejemplo n.º 11
0
 static void homegear_ConnectError(Homegear sender, string message, string stackTrace)
 {
     Console.WriteLine("Error connecting to Homegear: " + message);
     _connectedEvent.Set();
 }
Ejemplo n.º 12
0
 public XMLRPCDevicesService(Homegear homegear)
 {
     this._homegear = homegear;
 }
Ejemplo n.º 13
0
 static void homegear_SystemVariableUpdated(Homegear sender, SystemVariable variable)
 {
     Console.WriteLine("System variable updated: Value: " + variable.ToString());
 }
Ejemplo n.º 14
0
 static void homegear_DeviceVariableUpdated(Homegear sender, Device device, Channel channel, Variable variable)
 {
     Console.WriteLine("Variable updated: Device type: \"" + device.TypeString + "\", ID: " + device.ID.ToString() + ", Channel: " + channel.Index.ToString() + ", Variable Name: \"" + variable.Name + "\", Value: " + variable.ToString());
 }
Ejemplo n.º 15
0
 static void homegear_DeviceLinkConfigParameterUpdated(Homegear sender, Device device, Channel channel, Link link, ConfigParameter parameter)
 {
     Console.WriteLine("Link config parameter updated: Device type: \"" + device.TypeString + "\", ID: " + device.ID.ToString() + ", Channel: " + channel.Index.ToString() + ", Remote Peer: " + link.RemotePeerID.ToString() + ", Remote Channel: " + link.RemoteChannel.ToString() + ", Parameter Name: \"" + parameter.Name + "\", Value: " + parameter.ToString());
 }
Ejemplo n.º 16
0
 static void homegear_MetadataUpdated(Homegear sender, Device device, MetadataVariable variable)
 {
     Console.WriteLine("Metadata updated: Device: " + device.ID.ToString() + ", Value: " + variable.ToString());
 }
Ejemplo n.º 17
0
 static void homegear_Reloaded(Homegear sender)
 {
     Console.WriteLine("Connected. Got " + sender.Devices.Count.ToString() + " devices.");
     _connectedEvent.Set();
 }
Ejemplo n.º 18
0
        public frmAddLink(Channel channel, Homegear homegear)
        {
            _homegear = homegear;
            InitializeComponent();

            if (channel.LinkSourceRoles.Length == 0 && channel.LinkTargetRoles.Length == 0)
            {
                MessageBox.Show(this, "Channel does not support links.", "Add Link", MessageBoxButtons.OK, MessageBoxIcon.Information);
                DialogResult     = System.Windows.Forms.DialogResult.Abort;
                bnOK.Enabled     = false;
                tvLinkTo.Enabled = false;
                return;
            }

            try
            {
                foreach (KeyValuePair <Int32, Device> devicePair in _homegear.Devices)
                {
                    TreeNode deviceNode = new TreeNode("Device " + devicePair.Key + ((devicePair.Value.Name != "") ? " (" + devicePair.Value.Name + ")" : ""));
                    foreach (KeyValuePair <Int32, Channel> channelPair in devicePair.Value.Channels)
                    {
                        if (channel.LinkSourceRoles.Length > 0)
                        {
                            foreach (String role in channel.LinkSourceRoles)
                            {
                                if (role.Length == 0)
                                {
                                    continue;
                                }
                                if (channelPair.Value.LinkTargetRoles.Contains(role))
                                {
                                    TreeNode channelNode = new TreeNode("Channel " + channelPair.Key.ToString());
                                    channelNode.Tag = channelPair.Value;
                                    deviceNode.Nodes.Add(channelNode);
                                    break;
                                }
                            }
                        }
                        else if (channel.LinkTargetRoles.Length > 0)
                        {
                            foreach (String role in channel.LinkTargetRoles)
                            {
                                if (role.Length == 0)
                                {
                                    continue;
                                }
                                if (channelPair.Value.LinkSourceRoles.Contains(role))
                                {
                                    TreeNode channelNode = new TreeNode("Channel " + channelPair.Key.ToString());
                                    channelNode.Tag = channelPair.Value;
                                    deviceNode.Nodes.Add(channelNode);
                                    break;
                                }
                            }
                        }
                    }
                    if (deviceNode.Nodes.Count > 0)
                    {
                        tvLinkTo.Nodes.Add(deviceNode);
                    }
                }
            }
            catch (Exception)
            {
                DialogResult = System.Windows.Forms.DialogResult.Abort;
                Close();
            }
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            Console.Write("Please enter the hostname or IP address of your server running Homegear: ");
            string homegearHost = Console.ReadLine();

            #region Without SSL support
            RPCController rpc = new RPCController(
                homegearHost,      //Hostname of your server running Homegear
                2001               //Port Homegear listens on
                );
            #endregion

            #region With SSL support and no authentication

            /*
             * SslInfo sslInfo = new SslInfo();
             *
             * RPCController rpc = new RPCController("homegear", 2003, sslInfo);
             *
             * //With SSL support and username/password:
             * SslInfo sslInfo = new SslInfo(
             *                          new Tuple<string, string>("user", "secret"),
             *                          true			//Enable hostname verification
             *                  );
             *
             * RPCController rpc = new RPCController("homegear", 2003, sslInfo);
             */
            #endregion

            #region With SSL support and client certificate authentication

            /*
             * SslInfo sslInfo = new SslInfo(
             *                          "Path to PKCS #12 certificate file",
             *                          "secret",
             *                          true			//Enable hostname verification
             *                  );
             */
            #endregion

            Homegear homegear = new Homegear(rpc, false);

            homegear.ConnectError += homegear_ConnectError;
            homegear.Reloaded     += homegear_Reloaded;

            Console.WriteLine("Connecting to Homegear...");
            _connectedEvent.WaitOne();

            if (!rpc.IsConnected)
            {
                Console.WriteLine("Exiting...");
                homegear.Dispose();
                Environment.Exit(1);
            }

            ConsoleKeyInfo key;
            do
            {
                ShowMenu();
                key = Console.ReadKey();
                Console.WriteLine();

                switch (key.KeyChar)
                {
                case '1':
                {
                    Console.Write("Please enter peer ID: ");
                    string peerIdString = Console.ReadLine();
                    Console.Write("Please enter channel: ");
                    string channelString = Console.ReadLine();
                    Console.Write("Please enter variable name: ");
                    string variableName = Console.ReadLine();

                    // {{{ Convert Strings to numbers
                    Int32 peerId = 0;
                    if (!Int32.TryParse(peerIdString, out peerId))
                    {
                        Console.WriteLine("Peer ID was not a number.");
                        break;
                    }

                    Int32 channel = 0;
                    if (!Int32.TryParse(channelString, out channel))
                    {
                        Console.WriteLine("Channel was not a number.");
                        break;
                    }
                    // }}}

                    // {{{ Get and print value
                    Variable variable;
                    try
                    {
                        variable = homegear.Devices[peerId].Channels[channel].Variables[variableName];
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.GetType().ToString() + ": " + ex.Message);
                        break;
                    }
                    Console.WriteLine("Value is: " + variable.ToString() + " " + variable.Unit);
                    // }}}
                }
                break;

                case '2':
                {
                    Console.Write("Please enter peer ID: ");
                    string peerIdString = Console.ReadLine();
                    Console.Write("Please enter channel: ");
                    string channelString = Console.ReadLine();
                    Console.Write("Please enter variable name: ");
                    string variableName = Console.ReadLine();
                    Console.Write("Please enter value: ");
                    string value = Console.ReadLine();

                    // {{{ Convert Strings to numbers
                    Int32 peerId = 0;
                    if (!Int32.TryParse(peerIdString, out peerId))
                    {
                        Console.WriteLine("Peer ID was not a number.");
                        break;
                    }

                    Int32 channel = 0;
                    if (!Int32.TryParse(channelString, out channel))
                    {
                        Console.WriteLine("Channel was not a number.");
                        break;
                    }
                    // }}}

                    // {{{ Set value
                    Variable variable;
                    try
                    {
                        variable = homegear.Devices[peerId].Channels[channel].Variables[variableName];
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.GetType().ToString() + ": " + ex.Message);
                        break;
                    }

                    switch (variable.Type)
                    {
                    case VariableType.tAction:
                        Boolean actionValue = false;
                        if (Boolean.TryParse(value, out actionValue))
                        {
                            variable.BooleanValue = actionValue;
                        }

                        break;

                    case VariableType.tBoolean:
                        Boolean booleanValue = false;
                        if (Boolean.TryParse(value, out booleanValue))
                        {
                            variable.BooleanValue = booleanValue;
                        }

                        break;

                    case VariableType.tInteger:
                        Int32 integerValue = 0;
                        if (Int32.TryParse(value, out integerValue))
                        {
                            variable.IntegerValue = integerValue;
                        }

                        break;

                    case VariableType.tEnum:
                        Int32 enumValue = 0;
                        if (Int32.TryParse(value, out enumValue))
                        {
                            variable.IntegerValue = enumValue;
                        }

                        break;

                    case VariableType.tDouble:
                        Double doubleValue = 0;
                        if (Double.TryParse(value, out doubleValue))
                        {
                            variable.DoubleValue = doubleValue;
                        }

                        break;

                    case VariableType.tString:
                        variable.StringValue = value;
                        break;
                    }
                    // }}}
                }
                break;
                }
            } while (key.KeyChar != '0');

            homegear.Dispose();
        }
Ejemplo n.º 20
0
        static void Main(string[] args)
        {
            Console.Write("Please enter the hostname or IP address of your server running Homegear: ");
            string homegearHost = Console.ReadLine();

            #region Without SSL support
            RPCController rpc = new RPCController(
                homegearHost,      //Hostname of your server running Homegear
                2001               //Port Homegear listens on
                );
            #endregion

            #region With SSL support and no authentication

            /*
             * SslInfo sslInfo = new SslInfo();
             *
             * RPCController rpc = new RPCController("homegear", 2003, sslInfo);
             *
             * //With SSL support and username/password:
             * SslInfo sslInfo = new SslInfo(
             *                          new Tuple<string, string>("user", "secret"),
             *                          true			//Enable hostname verification
             *                  );
             *
             * RPCController rpc = new RPCController("homegear", 2003, sslInfo);
             */
            #endregion

            #region With SSL support and client certificate authentication

            /*
             * SslInfo sslInfo = new SslInfo(
             *                          "Path to PKCS #12 certificate file",
             *                          "secret",
             *                          true			//Enable hostname verification
             *                  );
             */
            #endregion

            Homegear homegear = new Homegear(rpc, true);

            homegear.ConnectError                     += homegear_ConnectError;
            homegear.Reloaded                         += homegear_Reloaded;
            homegear.SystemVariableUpdated            += homegear_SystemVariableUpdated;
            homegear.DeviceVariableUpdated            += homegear_DeviceVariableUpdated;
            homegear.MetadataUpdated                  += homegear_MetadataUpdated;
            homegear.DeviceConfigParameterUpdated     += homegear_DeviceConfigParameterUpdated;
            homegear.DeviceLinkConfigParameterUpdated += homegear_DeviceLinkConfigParameterUpdated;

            Console.WriteLine("Connecting to Homegear...");
            _connectedEvent.WaitOne();

            if (!rpc.IsConnected)
            {
                Console.WriteLine("Exiting...");
                homegear.Dispose();
                Environment.Exit(1);
            }

            Console.WriteLine("Press 'q' to exit program.");
            Thread.Sleep(2000);

            ConsoleKeyInfo key;
            do
            {
                key = Console.ReadKey();
            } while (key.KeyChar != 'q');

            homegear.Dispose();
        }
Ejemplo n.º 21
0
        static void Main(string[] args)
        {
            Console.Write("Please enter the hostname or IP address of your server running Homegear: ");
            string homegearHost = Console.ReadLine();

            #region Without SSL support
            RPCController rpc = new RPCController
                                (
                homegearHost,                       //Hostname of your server running Homegear
                2001                                //Port Homegear listens on
                                );
            #endregion

            #region With SSL support

            /*
             * SSLClientInfo sslClientInfo = new SSLClientInfo
             *                              (
             *                                  "MyComputer",   //Hostname of the computer your program runs on.
             *  //This hostname is used for certificate verification.
             *                                  "user",
             *                                  "secret",
             *                                  true            //Enable certificate verification
             *                              );
             * //You can create the certificate file with: openssl pkcs12 -export -inkey YourPrivateKey.key -in YourCA.pem -in YourPublicCert.pem -out MyCertificate.pfx
             * SSLServerInfo sslServerInfo = new SSLServerInfo
             *                              (
             *                                  "MyCertificate.pfx",    //Path to the certificate the callback server
             *  //will use.
             *                                  "secret",               //Certificate password
             *                                  "localUser",            //The username Homegear needs to use to connect
             *  //to our callback server
             *                                  "localSecret"           //The password Homegear needs to use to connect
             *  //to our callback server
             *                              );
             * RPCController rpc = new RPCController(homegearHost, 2003, "", "", -1, sslClientInfo, sslServerInfo);
             */
            #endregion

            Homegear homegear = new Homegear(rpc, false);

            homegear.ConnectError += homegear_ConnectError;
            homegear.Reloaded     += homegear_Reloaded;

            Console.WriteLine("Connecting to Homegear...");
            _connectedEvent.WaitOne();

            if (!rpc.IsConnected)
            {
                Console.WriteLine("Exiting...");
                homegear.Dispose();
                Environment.Exit(1);
            }

            ConsoleKeyInfo key;
            do
            {
                ShowMenu();
                key = Console.ReadKey();
                Console.WriteLine();

                switch (key.KeyChar)
                {
                case '1':
                {
                    Console.Write("Please enter peer ID: ");
                    string peerIdString = Console.ReadLine();
                    Console.Write("Please enter channel: ");
                    string channelString = Console.ReadLine();
                    Console.Write("Please enter variable name: ");
                    string variableName = Console.ReadLine();

                    // {{{ Convert Strings to numbers
                    Int32 peerId = 0;
                    if (!Int32.TryParse(peerIdString, out peerId))
                    {
                        Console.WriteLine("Peer ID was not a number.");
                        break;
                    }

                    Int32 channel = 0;
                    if (!Int32.TryParse(channelString, out channel))
                    {
                        Console.WriteLine("Channel was not a number.");
                        break;
                    }
                    // }}}

                    // {{{ Get and print value
                    Variable variable;
                    try
                    {
                        variable = homegear.Devices[peerId].Channels[channel].Variables[variableName];
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.GetType().ToString() + ": " + ex.Message);
                        break;
                    }
                    Console.WriteLine("Value is: " + variable.ToString() + " " + variable.Unit);
                    // }}}
                }
                break;

                case '2':
                {
                    Console.Write("Please enter peer ID: ");
                    string peerIdString = Console.ReadLine();
                    Console.Write("Please enter channel: ");
                    string channelString = Console.ReadLine();
                    Console.Write("Please enter variable name: ");
                    string variableName = Console.ReadLine();
                    Console.Write("Please enter value: ");
                    string value = Console.ReadLine();

                    // {{{ Convert Strings to numbers
                    Int32 peerId = 0;
                    if (!Int32.TryParse(peerIdString, out peerId))
                    {
                        Console.WriteLine("Peer ID was not a number.");
                        break;
                    }

                    Int32 channel = 0;
                    if (!Int32.TryParse(channelString, out channel))
                    {
                        Console.WriteLine("Channel was not a number.");
                        break;
                    }
                    // }}}

                    // {{{ Set value
                    Variable variable;
                    try
                    {
                        variable = homegear.Devices[peerId].Channels[channel].Variables[variableName];
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.GetType().ToString() + ": " + ex.Message);
                        break;
                    }

                    switch (variable.Type)
                    {
                    case VariableType.tAction:
                        Boolean actionValue = false;
                        if (Boolean.TryParse(value, out actionValue))
                        {
                            variable.BooleanValue = actionValue;
                        }

                        break;

                    case VariableType.tBoolean:
                        Boolean booleanValue = false;
                        if (Boolean.TryParse(value, out booleanValue))
                        {
                            variable.BooleanValue = booleanValue;
                        }

                        break;

                    case VariableType.tInteger:
                        Int32 integerValue = 0;
                        if (Int32.TryParse(value, out integerValue))
                        {
                            variable.IntegerValue = integerValue;
                        }

                        break;

                    case VariableType.tEnum:
                        Int32 enumValue = 0;
                        if (Int32.TryParse(value, out enumValue))
                        {
                            variable.IntegerValue = enumValue;
                        }

                        break;

                    case VariableType.tDouble:
                        Double doubleValue = 0;
                        if (Double.TryParse(value, out doubleValue))
                        {
                            variable.DoubleValue = doubleValue;
                        }

                        break;

                    case VariableType.tString:
                        variable.StringValue = value;
                        break;
                    }
                    // }}}
                }
                break;
                }
            } while (key.KeyChar != '0');

            homegear.Dispose();
        }
Ejemplo n.º 22
0
 public XMLRPCDimmersService(Homegear homegear)
 {
     _homegear = homegear;
 }
Ejemplo n.º 23
0
 public XMLRPCLightSwitchesService(Homegear homegear, ILightSwitchesPersistenceService lightSiwtchPersistence)
 {
     this._homegear = homegear;
 }