Пример #1
0
        private async void GetLogAsync(int indexer)
        {
            StartActivityIndication(TextConstants.ActivityGettingLog);
            LogList.Clear();

            await Task.Run(async() =>
            {
                if (!await _bluetooth.TurnOnBluetoothAsync(1000, 25))
                {
                    ShowMessage(TextConstants.BluetoothTurnOnFail, TextConstants.ButtonClose);
                    return;
                }
                if (!await _bluetooth.CreateConnectionAsync(5000, 50))
                {
                    ShowMessage(TextConstants.BluetoothConnectionFail, TextConstants.ButtonClose);
                    return;
                }

                KeyVendorCommand getLogCommand = new KeyVendorCommand
                {
                    UserUUID    = _user.UUID,
                    Time        = DateTime.Now,
                    CommandType = KeyVendorCommandType.GetLog,
                    Data        = indexer.ToString()
                };
                KeyVendorTerminal terminal = new KeyVendorTerminal(_bluetooth);
                KeyVendorAnswer answer     = await terminal.ExecuteCommandAsync(getLogCommand, 15000, 100);

                if (!answer.IsCorrect || answer.AnswerType != KeyVendorAnswerType.Success)
                {
                    ShowMessage(TextConstants.ErrorGetLogFail, TextConstants.ButtonClose);
                    return;
                }

                string answerData  = answer.Data;
                string[] dataArray = answerData.Split('@');

                for (int i = 0; i < dataArray.Length; i += 6)
                {
                    LogInfo logInfo = new LogInfo
                    {
                        UUID     = dataArray[i],
                        Time     = dataArray[i + 1],
                        Command  = ((KeyVendorCommandType)(int.Parse(dataArray[i + 2]))).ToString(),
                        Answer   = ((KeyVendorAnswerType)(int.Parse(dataArray[i + 3]))).ToString(),
                        Data     = dataArray[i + 4],
                        UserName = dataArray[i + 5]
                    };

                    LogList.Add(logInfo);
                }
            });

            UpdateCommands();
            StopActivityIndication();
        }
Пример #2
0
        private async Task <KeyVendorAnswer> CheckForAdminRights(uint timeout, uint delay)
        {
            KeyVendorCommand adminCheckCommand = new KeyVendorCommand
            {
                UserUUID    = _user.UUID,
                Time        = DateTime.Now,
                CommandType = KeyVendorCommandType.AdminCheck
            };
            KeyVendorTerminal terminal = new KeyVendorTerminal(_bluetooth);

            return(await terminal.ExecuteCommandAsync(adminCheckCommand, timeout, delay));
        }
Пример #3
0
        private async Task <KeyVendorAnswer> LogIn(uint timeout, uint delay)
        {
            KeyVendorCommand loginCommand = new KeyVendorCommand
            {
                UserUUID    = _user.UUID,
                Time        = DateTime.Now,
                CommandType = KeyVendorCommandType.UserLogin
            };
            KeyVendorTerminal terminal = new KeyVendorTerminal(_bluetooth);

            return(await terminal.ExecuteCommandAsync(loginCommand, timeout, delay));
        }
Пример #4
0
        private async Task <KeyVendorAnswer> UpdateUserInfo(uint timeout, uint delay)
        {
            KeyVendorCommand updateUserInfoCommand = new KeyVendorCommand
            {
                UserUUID    = _user.UUID,
                Time        = DateTime.Now,
                CommandType = KeyVendorCommandType.UpdateInfo,
                Data        = (_user.Name + "@" + _user.Description).Replace(Environment.NewLine, "")
            };
            KeyVendorTerminal terminal = new KeyVendorTerminal(_bluetooth);

            return(await terminal.ExecuteCommandAsync(updateUserInfoCommand, timeout, delay));
        }
Пример #5
0
        private async Task <KeyVendorAnswer> SendApplication(uint timeout, uint delay)
        {
            KeyVendorCommand registerCommand = new KeyVendorCommand
            {
                UserUUID    = _user.UUID,
                Time        = DateTime.Now,
                CommandType = KeyVendorCommandType.UserRegister,
                Data        = _user.Name + "@" + _user.Description
            };
            KeyVendorTerminal terminal = new KeyVendorTerminal(_bluetooth);

            return(await terminal.ExecuteCommandAsync(registerCommand, timeout, delay));
        }
Пример #6
0
        private async void GetKeyListAsync()
        {
            StartActivityIndication();

            await Task.Run(async() =>
            {
                KeyList.Clear();

                if (!await _bluetooth.TurnOnBluetoothAsync(1000, 25))
                {
                    ShowMessage(TextConstants.BluetoothTurnOnFail, TextConstants.ButtonClose);
                    return;
                }
                if (!await _bluetooth.CreateConnectionAsync(5000, 50))
                {
                    ShowMessage(TextConstants.BluetoothConnectionFail, TextConstants.ButtonClose);
                    return;
                }

                KeyVendorCommand getKeyListCommand = new KeyVendorCommand
                {
                    UserUUID    = _user.UUID,
                    Time        = DateTime.Now,
                    CommandType = KeyVendorCommandType.GetKeyList,
                    Data        = ""
                };
                KeyVendorTerminal terminal = new KeyVendorTerminal(_bluetooth);
                KeyVendorAnswer answer     = await terminal.ExecuteCommandAsync(getKeyListCommand, 5000, 100);

                if (!answer.IsCorrect || answer.AnswerType != KeyVendorAnswerType.Success)
                {
                    ShowMessage(TextConstants.ErrorGetKeyListFail, TextConstants.ButtonClose);
                    return;
                }

                string answerData  = answer.Data;
                string[] dataArray = answerData.Split('@');

                foreach (var item in dataArray)
                {
                    KeyList.Add(item);
                }
            });

            StopActivityIndication();
        }
        public async void SetKeyList()
        {
            StartActivityIndication(TextConstants.ActivitySettingKeyList);

            await Task.Run(async() =>
            {
                if (!await _bluetooth.TurnOnBluetoothAsync(1000, 25))
                {
                    ShowMessage(TextConstants.BluetoothTurnOnFail, TextConstants.ButtonClose);
                    return;
                }
                if (!await _bluetooth.CreateConnectionAsync(5000, 50))
                {
                    ShowMessage(TextConstants.BluetoothConnectionFail, TextConstants.ButtonClose);
                    return;
                }

                var splittedData = KeyList.Split('\n').Where(key =>
                                                             key != "" && key != "\n" && !String.IsNullOrWhiteSpace(key));
                string data = String.Join("@", splittedData);

                KeyVendorCommand setKeyListCommand = new KeyVendorCommand
                {
                    UserUUID    = _user.UUID,
                    Time        = DateTime.Now,
                    CommandType = KeyVendorCommandType.SetKeyList,
                    Data        = data
                };
                KeyVendorTerminal terminal = new KeyVendorTerminal(_bluetooth);
                KeyVendorAnswer answer     = await terminal.ExecuteCommandAsync(setKeyListCommand, 10000, 100);

                if (!answer.IsCorrect || answer.AnswerType != KeyVendorAnswerType.Success)
                {
                    ShowMessage(TextConstants.ErrorSetKeyListFail, TextConstants.ButtonClose);
                }
                else
                {
                    ShowMessage(TextConstants.SuccessKeyListSet, TextConstants.ButtonClose);
                }
            });

            StopActivityIndication();
        }
Пример #8
0
        private async void ClearLogAsync()
        {
            StartActivityIndication(TextConstants.ActivityClearingLog);

            await Task.Run(async() =>
            {
                if (!await _bluetooth.TurnOnBluetoothAsync(1000, 25))
                {
                    ShowMessage(TextConstants.BluetoothTurnOnFail, TextConstants.ButtonClose);
                    return;
                }
                if (!await _bluetooth.CreateConnectionAsync(5000, 50))
                {
                    ShowMessage(TextConstants.BluetoothConnectionFail, TextConstants.ButtonClose);
                    return;
                }

                KeyVendorCommand clearLogCommand = new KeyVendorCommand
                {
                    UserUUID    = _user.UUID,
                    Time        = DateTime.Now,
                    CommandType = KeyVendorCommandType.ClearLog
                };
                KeyVendorTerminal terminal = new KeyVendorTerminal(_bluetooth);
                KeyVendorAnswer answer     = await terminal.ExecuteCommandAsync(clearLogCommand, 15000, 100);

                if (!answer.IsCorrect || answer.AnswerType != KeyVendorAnswerType.Success)
                {
                    ShowMessage(TextConstants.ErrorClearLogFail, TextConstants.ButtonClose);
                    return;
                }

                LogList.Clear();
                Indexer = 0;
                ShowMessage(TextConstants.SuccessLogCleared, TextConstants.ButtonClose);
            });

            UpdateCommands();
            StopActivityIndication();
        }
Пример #9
0
        private async void GetKeyAsync()
        {
            GettingKey = true;

            await Task.Run(async() =>
            {
                if (!await _bluetooth.TurnOnBluetoothAsync(1000, 25))
                {
                    GettingKey = false;
                    ShowMessage(TextConstants.BluetoothTurnOnFail, TextConstants.ButtonClose);
                    return;
                }
                if (!await _bluetooth.CreateConnectionAsync(5000, 50))
                {
                    GettingKey = false;
                    ShowMessage(TextConstants.BluetoothConnectionFail, TextConstants.ButtonClose);
                    return;
                }

                KeyVendorCommand getKeyCommand = new KeyVendorCommand
                {
                    UserUUID    = _user.UUID,
                    Time        = DateTime.Now,
                    CommandType = KeyVendorCommandType.GetKey,
                    Data        = SelectedKey
                };
                KeyVendorTerminal terminal = new KeyVendorTerminal(_bluetooth);
                KeyVendorAnswer answer     = await terminal.ExecuteCommandAsync(getKeyCommand, 3000, 100);

                if (!answer.IsCorrect || answer.AnswerType != KeyVendorAnswerType.Success)
                {
                    ShowMessage(TextConstants.ErrorGetKeyFail, TextConstants.ButtonClose);
                }
            });

            GettingKey = false;
        }