Exemple #1
0
        private async Task CommandReceived(CommandEventArgs commandArgs)
        {
            try
            {
                _LastAccess = DateTime.UtcNow; //Refreshing time for Access Point
                switch (commandArgs.InputCommand.BaseCommand)
                {
                case CommandsEnum.GetAvailableNetworks:
                    await ProcessCommand(commandArgs, async() => {
                        return(await _WifiService.GetAvailableNetworkListHandler());
                    });

                    break;

                case CommandsEnum.ConnectToNetwork:
                    await ProcessCommand(commandArgs, async (RequestCommandConnectToNetwork request) => {
                        return(await _WifiService.ConnectToNetworkHandler(request));
                    });

                    break;

                case CommandsEnum.DisconnectFromNetwork:
                    await ProcessCommand(commandArgs, async (RequestCommandDisconnectFromNetwork request) => {
                        return(await _WifiService.DisconnectFromNetworkHandler(request));
                    });

                    break;

                case CommandsEnum.GetDeviceId:
                    ProcessCommand(commandArgs, () => { return(_ProvisioningService.GetDeviceId()); });
                    break;

                case CommandsEnum.ProvisionDevice:
                    await ProcessCommand(commandArgs, async (RequestCommandProvisionDevice request) => {
                        return(await _ProvisioningService.ProvisionDevice(request, SecretManager.CertificatePasskey));
                    });

                    break;

                case CommandsEnum.GetGeneratedCSR:
                    ProcessCommand(commandArgs, () => { return(_ProvisioningService.GenerateCSR()); });
                    break;

                case CommandsEnum.GetFirmwares:
                    await ProcessCommand(commandArgs, async() => { return(await _PortalService.GetFirmwares()); });

                    break;

                case CommandsEnum.SetDeviceType:
                    await ProcessCommand(commandArgs, async (RequestCommandSetDeviceType request) => {
                        return(await _PortalService.SetDeviceType(request));
                    });

                    break;

                case CommandsEnum.SetDeviceName:
                    await ProcessCommand(commandArgs, async (RequestCommandSetDeviceName request) => {
                        return(await _PortalService.SetDeviceName(request));
                    });

                    break;

                case CommandsEnum.GetAccessPointSettings:
                    await ProcessCommand(commandArgs, async() => { return(await _PortalService.GetAccessPointSettings()); });

                    break;

                case CommandsEnum.SetDeviceSecretKeys:
                    await ProcessCommand(commandArgs, async (RequestCommandSetDeviceSecretKeys request) => {
                        return(await _PortalService.SetDeviceSecretKeys(request));
                    });

                    break;

                case CommandsEnum.DisableAccessPointTimeout:
                    ProcessCommand(commandArgs, () => { return(SetAPTimeoutValue(false)); });
                    break;

                case CommandsEnum.EnableAccessPointTimeout:
                    ProcessCommand(commandArgs, () => { return(SetAPTimeoutValue(true)); });
                    break;

                case CommandsEnum.EnableEncryption:
                    ProcessCommand(commandArgs, () => { return(SetEncryptionState(true)); });
                    break;

                case CommandsEnum.DisableEncryption:
                    ProcessCommand(commandArgs, () => { return(SetEncryptionState(false)); });
                    break;

                case CommandsEnum.GetEncryptionState:
                    ProcessCommand(commandArgs, () => { return(GetEncryptionStatus()); });
                    break;

                case CommandsEnum.Unknown:
                    throw new Exception($"Command ${commandArgs.InputCommand.BaseCommand} not found.");
                }
            }
            catch (Exception e)
            {
                DebugHelper.LogCritical(e.Message);
                DebugHelper.LogCritical(e.StackTrace);
                ProcessCommand(commandArgs, () => { return(ProcessError(e)); });
            }
        }