private void TagProfile_Changed(object sender, PropertyChangedEventArgs e)
 {
     UiDispatcher.BeginInvokeOnMainThread(() =>
     {
         IntroText = string.Format(AppResources.ToConnectToDomainYouNeedAnAccount, this.TagProfile.Domain);
     });
 }
 private void NeuronService_ConnectionStateChanged(object sender, ConnectionStateChangedEventArgs e)
 {
     UiDispatcher.BeginInvokeOnMainThread(() =>
     {
         AssignProperties(e.State);
     });
 }
 private void NeuronService_ConnectionStateChanged(object sender, ConnectionStateChangedEventArgs e)
 {
     UiDispatcher.BeginInvokeOnMainThread(() =>
     {
         SetConnectionStateAndText(e.State);
         RegisterCommand.ChangeCanExecute();
     });
 }
Esempio n. 4
0
        private async Task Connect()
        {
            if (!this.networkService.IsOnline)
            {
                await this.UiDispatcher.DisplayAlert(AppResources.ErrorTitle, AppResources.NetworkSeemsToBeMissing);

                return;
            }

            SetIsBusy(ConnectCommand);

            try
            {
                string domainName = GetOperator();
                (this.hostName, this.portNumber, this.isIpAddress) = await this.networkService.LookupXmppHostnameAndPort(domainName);

                (bool succeeded, string errorMessage) = await this.NeuronService.TryConnect(domainName, this.isIpAddress, hostName, portNumber, Constants.LanguageCodes.Default, typeof(App).Assembly, null);

                UiDispatcher.BeginInvokeOnMainThread(async() =>
                {
                    this.SetIsDone(ConnectCommand);

                    if (succeeded)
                    {
                        this.TagProfile.SetDomain(this.GetOperator());
                        this.OnStepCompleted(EventArgs.Empty);
                    }
                    else
                    {
                        this.LogService.LogException(new InvalidOperationException(), new KeyValuePair <string, string>("Connect", "Failed to connect"));
                        await this.UiDispatcher.DisplayAlert(AppResources.ErrorTitle, errorMessage, AppResources.Ok);
                    }
                });
            }
            catch (Exception ex)
            {
                this.LogService.LogException(ex);
                await this.UiDispatcher.DisplayAlert(AppResources.ErrorTitle, ex.Message, AppResources.Ok);
            }
            finally
            {
                this.BeginInvokeSetIsDone(ConnectCommand);
            }
        }
        private async Task PerformAction()
        {
            if (!this.networkService.IsOnline)
            {
                await this.UiDispatcher.DisplayAlert(AppResources.ErrorTitle, AppResources.NetworkSeemsToBeMissing);

                return;
            }

            SetIsBusy(PerformActionCommand, SwitchModeCommand);
            try
            {
                bool succeeded;
                if (CreateNew)
                {
                    succeeded = await CreateAccount();
                }
                else
                {
                    succeeded = await ConnectToAccount();
                }

                UiDispatcher.BeginInvokeOnMainThread(() =>
                {
                    SetIsDone(PerformActionCommand, SwitchModeCommand);

                    if (succeeded)
                    {
                        OnStepCompleted(EventArgs.Empty);
                    }
                });
            }
            catch (Exception ex)
            {
                this.LogService.LogException(ex);
                await this.UiDispatcher.DisplayAlert(ex);
            }
            finally
            {
                BeginInvokeSetIsDone(PerformActionCommand, SwitchModeCommand);
            }
        }
        private async Task Register()
        {
            if (!(await this.ValidateInput(true)))
            {
                return;
            }

            string countryCode           = ISO_3166_1.ToCode(this.SelectedCountry);
            string pnr                   = PersonalNumber.Trim();
            string pnrBeforeValidation   = pnr;
            bool?  personalNumberIsValid = PersonalNumberSchemes.IsValid(countryCode, ref pnr, out string personalNumberFormat);

            if (personalNumberIsValid.HasValue && !personalNumberIsValid.Value)
            {
                if (string.IsNullOrWhiteSpace(personalNumberFormat))
                {
                    await this.UiDispatcher.DisplayAlert(AppResources.ErrorTitle, AppResources.PersonalNumberDoesNotMatchCountry);
                }
                else
                {
                    await this.UiDispatcher.DisplayAlert(AppResources.ErrorTitle, AppResources.PersonalNumberDoesNotMatchCountry_ExpectedFormat + personalNumberFormat);
                }
                return;
            }
            if (pnr != pnrBeforeValidation)
            {
                this.PersonalNumber = pnr;
            }

            if (string.IsNullOrWhiteSpace(this.TagProfile.LegalJid))
            {
                await this.UiDispatcher.DisplayAlert(AppResources.ErrorTitle, AppResources.OperatorDoesNotSupportLegalIdentitiesAndSmartContracts);

                return;
            }

            if (string.IsNullOrWhiteSpace(this.TagProfile.RegistryJid))
            {
                await this.UiDispatcher.DisplayAlert(AppResources.ErrorTitle, AppResources.OperatorDoesNotSupportThingRegistries);

                return;
            }

            if (string.IsNullOrWhiteSpace(this.TagProfile.ProvisioningJid))
            {
                await this.UiDispatcher.DisplayAlert(AppResources.ErrorTitle, AppResources.OperatorDoesNotSupportProvisioningAndDecisionSupportForThings);

                return;
            }

            if (!this.NeuronService.IsOnline)
            {
                await this.UiDispatcher.DisplayAlert(AppResources.ErrorTitle, AppResources.NotConnectedToTheOperator);

                return;
            }

            SetIsBusy(RegisterCommand, TakePhotoCommand, PickPhotoCommand);

            try
            {
                RegisterIdentityModel     model  = CreateRegisterModel();
                LegalIdentityAttachment[] photos = { photo };
                (bool succeeded, LegalIdentity addedIdentity) = await this.networkService.TryRequest(() => this.NeuronService.Contracts.AddLegalIdentity(model, photos));

                if (succeeded)
                {
                    this.LegalIdentity = addedIdentity;
                    this.TagProfile.SetLegalIdentity(this.LegalIdentity);
                    UiDispatcher.BeginInvokeOnMainThread(() =>
                    {
                        SetIsDone(RegisterCommand, TakePhotoCommand, PickPhotoCommand);
                        OnStepCompleted(EventArgs.Empty);
                    });
                }
            }
            catch (Exception ex)
            {
                this.LogService.LogException(ex);
                await this.UiDispatcher.DisplayAlert(ex);
            }
            finally
            {
                BeginInvokeSetIsDone(RegisterCommand, TakePhotoCommand, PickPhotoCommand);
            }
        }
Esempio n. 7
0
 /// <summary>
 /// A helper method for asynchronously setting this registration step to Done, and also calling
 /// <see cref="Command.ChangeCanExecute"/> on the list of commands passed in.
 /// </summary>
 /// <param name="commands">The commands to re-evaluate.</param>
 protected void BeginInvokeSetIsDone(params ICommand[] commands)
 {
     UiDispatcher.BeginInvokeOnMainThread(() => SetIsDone(commands));
 }