Example #1
0
 public DeviceConfig(RPCController rpc, long peerId, long channel, RPCParameterSetType type, Dictionary <string, ConfigParameter> deviceConfig) : base(deviceConfig)
 {
     _rpc     = rpc;
     _peerId  = peerId;
     _channel = channel;
     _type    = type;
 }
Example #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));
        }
        public RPCControllerTest()
        {
            this.testNetwork = KnownNetworks.TestNet;
            this.fullNode    = new Mock <IFullNode>();
            this.fullNode.Setup(f => f.Network)
            .Returns(this.testNetwork);
            this.rpcHost = new Mock <IWebHost>();
            var nodeSettings = new NodeSettings(this.testNetwork, args: new string[] { "-server=1" });

            this.rpcSettings      = new RpcSettings(nodeSettings);
            this.serviceProvider  = new Mock <IServiceProvider>();
            this.rpcClientFactory = new Mock <IRPCClientFactory>();
            this.actionDescriptorCollectionProvider = new Mock <IActionDescriptorCollectionProvider>();

            this.rpcClient = new Mock <IRPCClient>();
            this.rpcSettings.Bind.Add(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 0));
            this.rpcClientFactory.Setup(r => r.Create(It.IsAny <RpcSettings>(), It.Is <Uri>(u => u.ToString() == "http://127.0.0.1:0/"), It.IsAny <Network>()))
            .Returns(this.rpcClient.Object);

            this.fullNode.Setup(f => f.RPCHost)
            .Returns(this.rpcHost.Object);
            this.rpcHost.Setup(c => c.Services)
            .Returns(this.serviceProvider.Object);
            this.serviceProvider.Setup(s => s.GetService(typeof(IActionDescriptorCollectionProvider)))
            .Returns(this.actionDescriptorCollectionProvider.Object);

            this.descriptors = new List <ActionDescriptor>();
            this.actionDescriptorCollectionProvider.Setup(a => a.ActionDescriptors)
            .Returns(() =>
            {
                return(new ActionDescriptorCollection(this.descriptors, 0));
            });

            this.controller = new RPCController(this.fullNode.Object, this.LoggerFactory.Object, this.rpcSettings, this.rpcClientFactory.Object);
        }
Example #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);
        }
Example #5
0
 internal Variables(RPCController rpc, long peerId, long channel) : base()
 {
     _rpc     = rpc;
     _peerId  = peerId;
     _channel = channel;
     Reload();
 }
Example #6
0
        private void _rpc_OnUpdateEvent(RPCController sender, string id, EventType type, long peerId, long channelIndex, string variable)
        {
            if (type == EventType.Timed)
            {
                if (!TimedEvents.ContainsKey(id))
                {
                    return;
                }

                Event currentEvent = TimedEvents[id];
                _rpc.GetEvent(currentEvent);
                EventUpdated?.Invoke(this, currentEvent);
            }
            else
            {
                if (!Devices.ContainsKey(peerId))
                {
                    return;
                }

                Device device = Devices[peerId];
                if (!device.Events.ContainsKey(id))
                {
                    return;
                }

                Event currentEvent = device.Events[id];
                _rpc.GetEvent(currentEvent);
                EventUpdated?.Invoke(this, currentEvent);
            }
        }
Example #7
0
 public Variable(RPCController rpc, Int32 peerID, Int32 channel, String name)
 {
     _rpc     = rpc;
     _peerID  = peerID;
     _channel = channel;
     _name    = name;
 }
Example #8
0
 public DeviceConfig(RPCController rpc, Int32 peerID, Int32 channel, RPCParameterSetType type, Dictionary <String, ConfigParameter> deviceConfig) : base(deviceConfig)
 {
     _rpc     = rpc;
     _peerID  = peerID;
     _channel = channel;
     _type    = type;
 }
Example #9
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();
        }
Example #10
0
 public Variable(RPCController rpc, long peerId, long channel, string name)
 {
     _rpc     = rpc;
     _peerId  = peerId;
     _channel = channel;
     _name    = name;
 }
Example #11
0
        /// <summary>
        /// Creates and initializes the Homegear object. Upon instantiation, the object tries to connect to Homegear. And it tries to keep the connection up, no matter what. To orderly destroy the object again and to orderly disconnect from Homegear, call "Dispose".
        /// </summary>
        /// <param name="rpc">An initialized RPC controller object</param>
        /// <param name="events">When set to "true" the library starts an event server to receive events from Homegear.</param>
        public Homegear(RPCController rpc, bool events)
        {
            if (rpc == null)
            {
                throw new NullReferenceException("RPC object is null.");
            }

            _rpc                        = rpc;
            _events                     = events;
            _families                   = new Families(_rpc, new Dictionary <long, Family>());
            _devices                    = new Devices(_rpc, new Dictionary <long, Device>());
            _systemVariables            = new SystemVariables(_rpc, new Dictionary <string, SystemVariable>());
            _rpc.Disconnected          += _rpc_Disconnected;
            _rpc.InitCompleted         += _rpc_InitCompleted;
            _rpc.HomegearError         += _rpc_HomegearError;
            _rpc.DeviceVariableUpdated += _rpc_OnDeviceVariableUpdated;
            _rpc.SystemVariableUpdated += _rpc_OnSystemVariableUpdated;
            _rpc.Pong                  += _rpc_Pong;
            _rpc.SystemVariableDeleted += _rpc_OnSystemVariableDeleted;
            _rpc.MetadataUpdated       += _rpc_OnMetadataUpdated;
            _rpc.MetadataDeleted       += _rpc_OnMetadataDeleted;
            _rpc.NewDevices            += _rpc_OnNewDevices;
            _rpc.DevicesDeleted        += _rpc_OnDevicesDeleted;
            _rpc.UpdateDevice          += _rpc_OnUpdateDevice;
            _rpc.NewEvent              += _rpc_OnNewEvent;
            _rpc.EventDeleted          += _rpc_OnEventDeleted;
            _rpc.UpdateEvent           += _rpc_OnUpdateEvent;
            _stopConnectThread          = false;
            _connectThread              = new Thread(Connect);
            _connectThread.Start();
            while (!_connectThread.IsAlive)
            {
                ;
            }
        }
Example #12
0
 internal SystemVariable(RPCController rpc, String name, RPCVariable variable)
 {
     _rpc  = rpc;
     _name = name;
     Type  = variable.Type;
     SetValue(variable);
 }
Example #13
0
 void _rpc_HomegearError(RPCController sender, int level, string message)
 {
     if (HomegearError != null)
     {
         HomegearError(this, level, message);
     }
 }
Example #14
0
        private void _rpc_OnMetadataUpdated(RPCController sender, Int32 peerID, MetadataVariable value)
        {
            if (_disposing)
            {
                return;
            }
            if (!Devices.ContainsKey(peerID))
            {
                if (ReloadRequired != null)
                {
                    ReloadRequired(this, ReloadType.Full);
                }
                return;
            }
            Device device = Devices[peerID];

            if (!device.Metadata.ContainsKey(value.Name))
            {
                if (DeviceReloadRequired != null)
                {
                    DeviceReloadRequired(this, device, null, DeviceReloadType.Metadata);
                }
                return;
            }
            MetadataVariable variable = device.Metadata[value.Name];

            variable.SetValue(value);
            if (MetadataUpdated != null)
            {
                MetadataUpdated(this, device, variable);
            }
        }
Example #15
0
        private void _rpc_OnEventDeleted(RPCController sender, string id, EventType type, long peerId, long channelIndex, string variable)
        {
            if (type == EventType.Timed)
            {
                if (ReloadRequired != null)
                {
                    ReloadRequired(this, ReloadType.Events);
                }
            }
            else
            {
                if (!Devices.ContainsKey(peerId))
                {
                    return;
                }

                Device device = Devices[peerId];
                if (!device.Channels.ContainsKey(channelIndex))
                {
                    return;
                }

                Channel channel = device.Channels[channelIndex];
                DeviceReloadRequired?.Invoke(this, device, channel, DeviceReloadType.Events);
            }
        }
Example #16
0
 private void _rpc_OnDevicesDeleted(RPCController sender)
 {
     if (ReloadRequired != null)
     {
         ReloadRequired(this, ReloadType.Full);
     }
 }
Example #17
0
        private void _rpc_OnDeviceVariableUpdated(RPCController sender, Variable value)
        {
            if (_disposing)
            {
                return;
            }
            if (value.PeerID == 0)
            {
                return;                   //System variable
            }
            if (!Devices.ContainsKey(value.PeerID))
            {
                return;
            }
            Device device = Devices[value.PeerID];

            if (!device.Channels.ContainsKey(value.Channel))
            {
                return;
            }
            Channel deviceChannel = device.Channels[value.Channel];

            if (!deviceChannel.Variables.ContainsKey(value.Name))
            {
                return;
            }
            Variable variable = deviceChannel.Variables[value.Name];

            variable.SetValue(value);
            if (DeviceVariableUpdated != null)
            {
                DeviceVariableUpdated(this, device, deviceChannel, variable);
            }
        }
Example #18
0
 private void _rpc_OnUpdateEvent(RPCController sender, String id, EventType type, Int32 peerID, Int32 channelIndex, String variable)
 {
     if (type == EventType.Timed)
     {
         if (!TimedEvents.ContainsKey(id))
         {
             return;
         }
         Event currentEvent = TimedEvents[id];
         _rpc.GetEvent(currentEvent);
         if (EventUpdated != null)
         {
             EventUpdated(this, currentEvent);
         }
     }
     else
     {
         if (!Devices.ContainsKey(peerID))
         {
             return;
         }
         Device device = Devices[peerID];
         if (!device.Events.ContainsKey(id))
         {
             return;
         }
         Event currentEvent = device.Events[id];
         _rpc.GetEvent(currentEvent);
         if (EventUpdated != null)
         {
             EventUpdated(this, currentEvent);
         }
     }
 }
Example #19
0
 private void _rpc_OnNewEvent(RPCController sender, String id, EventType type, Int32 peerID, Int32 channelIndex, String variable)
 {
     if (type == EventType.Timed)
     {
         if (ReloadRequired != null)
         {
             ReloadRequired(this, ReloadType.Events);
         }
     }
     else
     {
         if (!Devices.ContainsKey(peerID))
         {
             return;
         }
         Device device = Devices[peerID];
         if (!device.Channels.ContainsKey(channelIndex))
         {
             return;
         }
         Channel channel = device.Channels[channelIndex];
         if (DeviceReloadRequired != null)
         {
             DeviceReloadRequired(this, device, channel, DeviceReloadType.Events);
         }
     }
 }
 public void Dispose()
 {
     _rpc = null;
     foreach (KeyValuePair <string, SystemVariable> systemVariable in _dictionary)
     {
         systemVariable.Value.Dispose();
     }
 }
Example #21
0
 public void Dispose()
 {
     _rpc = null;
     foreach (KeyValuePair <String, MetadataVariable> metadataVariable in _dictionary)
     {
         metadataVariable.Value.Dispose();
     }
 }
Example #22
0
 public void Dispose()
 {
     _rpc = null;
     foreach (KeyValuePair <String, Event> element in _dictionary)
     {
         element.Value.Dispose();
     }
 }
 internal MetadataVariable(RPCController rpc, long peerId, string name, RPCVariable variable)
 {
     _rpc    = rpc;
     _peerId = peerId;
     _name   = name;
     Type    = variable.Type;
     SetValue(variable);
 }
Example #24
0
 internal MetadataVariable(RPCController rpc, Int32 peerID, String name, RPCVariable variable)
 {
     _rpc    = rpc;
     _peerID = peerID;
     _name   = name;
     Type    = variable.Type;
     SetValue(variable);
 }
Example #25
0
 public void Dispose()
 {
     _rpc = null;
     foreach(KeyValuePair<Int32, Channel> channel in _dictionary)
     {
         channel.Value.Dispose();
     }
 }
Example #26
0
 public void Dispose()
 {
     _rpc = null;
     foreach (KeyValuePair <String, Variable> variable in _dictionary)
     {
         variable.Value.Dispose();
     }
 }
Example #27
0
 public void Dispose()
 {
     _rpc = null;
     foreach (KeyValuePair <Int32, Device> device in _dictionary)
     {
         device.Value.Dispose();
     }
 }
Example #28
0
 public void Dispose()
 {
     _rpc = null;
     foreach (KeyValuePair <long, Family> family in _dictionary)
     {
         family.Value.Dispose();
     }
 }
Example #29
0
 public void Dispose()
 {
     _rpc = null;
     foreach (KeyValuePair <string, Interface> physicalInterface in _dictionary)
     {
         physicalInterface.Value.Dispose();
     }
 }
Example #30
0
        private void _rpc_Pong(RPCController sender, string id)
        {
            if (_disposing)
            {
                return;
            }

            Pong?.Invoke(this, id);
        }
Example #31
0
 // Use this for initialization
 void Start()
 {
     instance = this;
     if(Network.isServer) {
         severScript = GameObject.Find("Server").GetComponent<ServerScript>();
     }
 }