Exemplo n.º 1
0
        public async void RegisterAsync()
        {
            StartActivityIndication(TextConstants.ActivityRegistration);

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

            KeyVendorAnswer answer = await SendApplication(5000, 100);

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

            _user.IsInfoUpdated = false;
            StopActivityIndication();
            ShowMessage(TextConstants.SuccessApplicationSent, TextConstants.ButtonClose);
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
0
        public async void ConnectAsync()
        {
            if (!_bluetooth.IsBluetoothAvailable)
            {
                ShowMessage(TextConstants.BluetoothUnavailable, TextConstants.ButtonClose);
                return;
            }

            StartActivityIndication(TextConstants.ActivityConnection);
            await Task.Delay(50);

            if (!await _bluetooth.TurnOnBluetoothAsync(2000, 25))
            {
                StopActivityIndication();
                ShowMessage(TextConstants.BluetoothTurnOnFail, TextConstants.ButtonClose);
                return;
            }

            if (_user.SavedAddress == "")
            {
                var device = await _bluetooth.FindBluetoothDeviceByNameAsync(TextConstants.DefaultDeviceName, 25);

                if (device == null)
                {
                    StopActivityIndication();
                    ShowMessage(TextConstants.BluetoothDeviceSearchFail, TextConstants.ButtonClose);
                    return;
                }
                else
                {
                    _user.SavedAddress = device.Address;
                }
            }
            else
            {
                var device = await _bluetooth.FindBluetoothDeviceByAddressAsync(_user.SavedAddress, 25);

                if (device == null)
                {
                    StopActivityIndication();
                    ShowMessage(TextConstants.BluetoothDeviceSearchFail, TextConstants.ButtonClose);
                    return;
                }
            }

            if (!await _bluetooth.BondWithBluetoothDeviceAsync(_user.SavedAddress, 25000, 50))
            {
                StopActivityIndication();
                ShowMessage(TextConstants.BluetoothBondFail, TextConstants.ButtonClose);
                return;
            }
            if (!await _bluetooth.CreateConnectionAsync(5000, 50))
            {
                StopActivityIndication();
                ShowMessage(TextConstants.BluetoothConnectionFail, TextConstants.ButtonClose);
                return;
            }

            KeyVendorAnswer loginAnswer = await LogIn(3000, 50);

            if (!loginAnswer.IsCorrect || loginAnswer.AnswerType == KeyVendorAnswerType.InvalidCommand)
            {
                StopActivityIndication();
                ShowMessage(TextConstants.ErrorTryAgain, TextConstants.ButtonClose);
                return;
            }
            else if (loginAnswer.AnswerType == KeyVendorAnswerType.AccessDenied)
            {
                StopActivityIndication();
                ShowMessage(TextConstants.ErrorUserBlocked, TextConstants.ButtonClose);
                return;
            }
            else if (loginAnswer.AnswerType == KeyVendorAnswerType.Failure)
            {
                StopActivityIndication();
                IsRegistrationOverlayVisible = true;
                return;
            }

            if (_user.IsInfoUpdated)
            {
                KeyVendorAnswer updateUserInfoAnswer = await UpdateUserInfo(8000, 50);

                if (updateUserInfoAnswer.IsCorrect && updateUserInfoAnswer.AnswerType == KeyVendorAnswerType.Success)
                {
                    _user.IsInfoUpdated = false;
                }
            }

            KeyVendorAnswer checkForAdminRightsAnswer = await CheckForAdminRights(3000, 50);

            _user.HasAdminRights = checkForAdminRightsAnswer.AnswerType == KeyVendorAnswerType.Success;

            StopActivityIndication();
            OnOpenVendingPage(this, new VendingPageViewModel(_user, _bluetooth));
        }