예제 #1
0
        private void _rpc_OnDeviceVariableUpdated(RPCController sender, Variable value, string eventSource)
        {
            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);
            DeviceVariableUpdated?.Invoke(this, device, deviceChannel, variable, eventSource);
        }
예제 #2
0
        private void _rpc_InitCompleted(RPCController sender)
        {
            if (_disposing)
            {
                return;
            }

            if (Devices.Count == 0)
            {
                Reload();
            }
            else
            {
                bool            devicesDeleted   = false;
                bool            newDevices       = false;
                List <Variable> updatedVariables = Devices.UpdateVariables(_rpc.GetAllValues(), out devicesDeleted, out newDevices);
                foreach (Variable variable in updatedVariables)
                {
                    if (!Devices.ContainsKey(variable.PeerID))
                    {
                        continue;
                    }

                    Device device = Devices[variable.PeerID];
                    if (!device.Channels.ContainsKey(variable.Channel))
                    {
                        continue;
                    }

                    DeviceVariableUpdated?.Invoke(this, device, device.Channels[variable.Channel], variable, "HomegearLib.NET");
                }
                bool systemVariablesAdded   = false;
                bool systemVariablesDeleted = false;
                List <SystemVariable> updatedSystemVariables = SystemVariables.Update(out systemVariablesDeleted, out systemVariablesAdded);
                foreach (SystemVariable variable in updatedSystemVariables)
                {
                    SystemVariableUpdated?.Invoke(this, variable);
                }
                if ((devicesDeleted || newDevices) && ReloadRequired != null)
                {
                    ReloadRequired(this, ReloadType.Full);
                }
                else
                {
                    if ((systemVariablesAdded || systemVariablesDeleted) && ReloadRequired != null)
                    {
                        System.Diagnostics.Debug.Write("Position 3");
                        ReloadRequired(this, ReloadType.SystemVariables);
                    }
                    foreach (KeyValuePair <long, Device> devicePair in Devices)
                    {
                        if (devicePair.Value.MetadataRequested)
                        {
                            bool variablesAdded   = false;
                            bool variablesDeleted = false;
                            List <MetadataVariable> updatedMetadata = devicePair.Value.Metadata.Update(out variablesDeleted, out variablesAdded);
                            foreach (MetadataVariable variable in updatedMetadata)
                            {
                                MetadataUpdated?.Invoke(this, devicePair.Value, variable);
                            }
                            if (variablesAdded || variablesDeleted)
                            {
                                DeviceReloadRequired?.Invoke(this, devicePair.Value, null, DeviceReloadType.Metadata);
                            }
                        }
                    }
                }
            }
        }