예제 #1
0
        public void ExecuteCommand(ILightSwitchCommand command)
        {
            switch (command)
            {
            case SetOverrideCommand setOverride:

                var(mode, interval) = setOverride;

                ToggleInterval = interval;
                SetOverrideMode(mode);

                break;
            }
        }
예제 #2
0
        public void OnMessage(UdpReceiveResult msg)
        {
            var kind = (CommandKind)msg.Buffer[0];

            ILightSwitchCommand command = null;

            switch (kind)
            {
            case CommandKind.SetOverrideMode:
                command = SetOverrideCommand.FromBuffer(msg.Buffer);
                break;
            }

            if (command != null)
            {
                OnCommand?.Invoke(command);
            }
        }
예제 #3
0
        public async Task SendCommand(ILightSwitchCommand command)
        {
            var bytes        = command.ToBuffer();
            var destinations = GetDestinations(Broadcast);

            foreach (var(name, destination) in destinations)
            {
                try
                {
                    Debug.WriteLine($"Sending {command} to {name} / {destination}");

                    await Client.SendAsync(bytes, bytes.Length, destination);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"An error occurred when sending {command} to {name}/{destination}: {ex}");
                }
            }
        }