Example #1
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 #2
0
 /// <summary>
 /// Disposes all subobjects and initiates a full reload.
 /// </summary>
 public void Reload()
 {
     if (_disposing)
     {
         return;
     }
     _version = "";
     _rpc.Clear();
     if (_families != null)
     {
         _families.Dispose();
     }
     _families = new Families(_rpc, _rpc.Families);
     if (_devices != null)
     {
         _devices.Dispose();
     }
     _devices = new Devices(_rpc, _rpc.Devices);
     foreach (KeyValuePair <Int32, Device> device in _devices)
     {
         device.Value.VariableReloadRequiredEvent += OnDevice_VariableReloadRequired;
     }
     if (_interfaces != null)
     {
         _interfaces.Dispose();
     }
     _interfaces = null;
     if (_systemVariables != null)
     {
         _systemVariables.Dispose();
     }
     _systemVariables = new SystemVariables(_rpc, _rpc.SystemVariables);
     if (Reloaded != null)
     {
         Reloaded(this);
     }
 }
Example #3
0
        /// <summary>
        /// Disposes all subobjects and initiates a full reload.
        /// </summary>
        public void Reload()
        {
            if (_disposing)
            {
                return;
            }

            _version = "";
            _rpc.Clear();
            _families?.Dispose();
            _families = new Families(_rpc, _rpc.Families);
            _devices?.Dispose();
            _devices = new Devices(_rpc, _rpc.Devices);
            foreach (KeyValuePair <long, Device> device in _devices)
            {
                device.Value.VariableReloadRequiredEvent += OnDevice_VariableReloadRequired;
            }

            _interfaces?.Dispose();
            _interfaces = null;
            _systemVariables?.Dispose();
            _systemVariables = new SystemVariables(_rpc, _rpc.SystemVariables);
            Reloaded?.Invoke(this);
        }