Пример #1
0
        private async Task LoginAsync(bool asRegistered)
        {
            ControlsEnabled.Value = false;
            bool succeed = false;

            try
            {
                _environment.SetHighPriorityToApplication();
                _environment.StartObtainProcessorName();

                await StoreLoginData(asRegistered);

                if (asRegistered && (string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(Password)))
                {
                    throw new WrongUserNamePasswordException();
                }

                NetworkCredential credentials = asRegistered ? new NetworkCredential(UserName, Password) : null;

                _notificationService.SetProgress("Initializing...");

                _main.BeforeConnect();
                await _idService.WaitDeviceId();

                var response = await _connectionService.StartAsync(credentials);

                bool updateUrgent = ClientVersionHelper.IsBreakingChange(response.UpperVersions);
                if (!updateUrgent)
                {
                    await _main.StartAsync();

                    var readyToDisplay = Task.Delay(800);
                    Connected.Value = true;

                    await _main.DisplayAsync(readyToDisplay, response.UpperVersions, _connectionService.Claims.AppUpdatePath);

                    _notificationService.Clear(this);
                }
                else
                {
                    _notificationService.Clear(this);
                    _updateModel.Display(response);
                }
                succeed = true;
            }
            catch (WrongUserNamePasswordException)
            {
                _notificationService.SetError(this, "Wrong user name/password or your account is not active");
            }
            catch (ConnectionServiceException e)
            {
                _notificationService.SetError(this, e.Message, e);
            }
            catch (HubConnectionException e)
            {
                _notificationService.SetError(this, $"Something went wrong with app. Please contact service administrator ({e.Message})", e);
            }
            catch (Exception e)
            {
                _notificationService.SetError(this, $"Something went wrong with the app. Please contact service administrator ({e.Message})", e);
            }

            if (!succeed)
            {
                Connected.Value       = false;
                ControlsEnabled.Value = true;
                ControlsVisible.Value = true;
            }
        }