private void AssignProperties()
 {
     if (!(identity is null))
     {
         this.Created        = identity.Created;
         this.Updated        = identity.Updated.GetDateOrNullIfMinValue();
         this.LegalId        = identity.Id;
         this.State          = identity.State.ToString();
         this.From           = identity.From.GetDateOrNullIfMinValue();
         this.To             = identity.To.GetDateOrNullIfMinValue();
         this.FirstName      = identity[Constants.XmppProperties.FirstName];
         this.MiddleNames    = identity[Constants.XmppProperties.MiddleName];
         this.LastNames      = identity[Constants.XmppProperties.LastName];
         this.PersonalNumber = identity[Constants.XmppProperties.PersonalNumber];
         this.Address        = identity[Constants.XmppProperties.Address];
         this.Address2       = identity[Constants.XmppProperties.Address2];
         this.ZipCode        = identity[Constants.XmppProperties.ZipCode];
         this.Area           = identity[Constants.XmppProperties.Area];
         this.City           = identity[Constants.XmppProperties.City];
         this.Region         = identity[Constants.XmppProperties.Region];
         this.CountryCode    = identity[Constants.XmppProperties.Country];
         this.Country        = ISO_3166_1.ToName(this.CountryCode);
         this.IsApproved     = identity.State == IdentityState.Approved;
         this.BareJId        = identity.GetJId(Constants.NotAvailableValue);
     }
예제 #2
0
        private void AssignProperties()
        {
            if (!(this.tagProfile?.LegalIdentity is null))
            {
                string firstName = this.tagProfile.LegalIdentity[Constants.XmppProperties.FirstName];
                string lastNames = this.tagProfile.LegalIdentity[Constants.XmppProperties.LastName];

                if (!string.IsNullOrWhiteSpace(firstName) && !string.IsNullOrWhiteSpace(lastNames))
                {
                    this.FullName = $"{firstName} {lastNames}";
                }
                else if (!string.IsNullOrWhiteSpace(firstName) && string.IsNullOrWhiteSpace(lastNames))
                {
                    this.FullName = firstName;
                }
                else if (string.IsNullOrWhiteSpace(firstName) && !string.IsNullOrWhiteSpace(lastNames))
                {
                    this.FullName = lastNames;
                }
                else
                {
                    this.FullName = string.Empty;
                }

                this.City = this.tagProfile.LegalIdentity[Constants.XmppProperties.City];
                string countryCode = this.tagProfile.LegalIdentity[Constants.XmppProperties.Country];
                if (ISO_3166_1.TryGetCountry(countryCode, out string country))
                {
                    this.Country = country;
                }
                else
                {
                    this.Country = string.Empty;
                }
            }
        /// <summary>
        /// Copies values from the existing TAG Profile's Legal identity.
        /// </summary>
        public virtual void PopulateFromTagProfile()
        {
            LegalIdentity identity = this.TagProfile.LegalIdentity;

            if (!(identity is null))
            {
                this.FirstName      = identity[Constants.XmppProperties.FirstName];
                this.MiddleNames    = identity[Constants.XmppProperties.MiddleName];
                this.LastNames      = identity[Constants.XmppProperties.LastName];
                this.PersonalNumber = identity[Constants.XmppProperties.PersonalNumber];
                this.Address        = identity[Constants.XmppProperties.Address];
                this.Address2       = identity[Constants.XmppProperties.Address2];
                this.ZipCode        = identity[Constants.XmppProperties.ZipCode];
                this.Area           = identity[Constants.XmppProperties.Area];
                this.City           = identity[Constants.XmppProperties.City];
                this.Region         = identity[Constants.XmppProperties.Region];
                string countryCode = identity[Constants.XmppProperties.Country];
                if (!string.IsNullOrWhiteSpace(countryCode) && ISO_3166_1.TryGetCountry(countryCode, out string country))
                {
                    this.SelectedCountry = country;
                }

                Attachment firstAttachment = identity.Attachments?.GetFirstImageAttachment();
                if (!(firstAttachment is null))
                {
                    // Don't await this one, just let it run asynchronously.
                    this.photosLoader
                    .LoadOnePhoto(firstAttachment, SignWith.LatestApprovedIdOrCurrentKeys)
                    .ContinueWith(task =>
                    {
                        MemoryStream stream = task.Result;
                        if (!(stream is null))
                        {
                            if (!this.IsBound)     // Page no longer on screen when download is done?
                            {
                                stream.Dispose();
                                return;
                            }
                            this.UiDispatcher.BeginInvokeOnMainThread(async() =>
                            {
                                await this.AddPhoto(stream, true, false);
                            });
                        }
                    }, TaskContinuationOptions.NotOnFaulted | TaskContinuationOptions.NotOnCanceled);
                }
            }
        }
        /// <summary>
        /// Converts the <see cref="RegisterIdentityModel"/> to an array of <inheritdoc cref="Property"/>.
        /// </summary>
        /// <param name="neuronService">The Neuron service to use for accessing the Bare Jid.</param>
        /// <returns>The <see cref="RegisterIdentityModel"/> as a list of properties.</returns>
        public Property[] ToProperties(INeuronService neuronService)
        {
            List <Property> properties = new List <Property>();
            string          s;

            if (!string.IsNullOrWhiteSpace(s = this.FirstName?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.FirstName, s));
            }

            if (!string.IsNullOrWhiteSpace(s = this.MiddleNames?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.MiddleName, s));
            }

            if (!string.IsNullOrWhiteSpace(s = this.LastNames?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.LastName, s));
            }

            if (!string.IsNullOrWhiteSpace(s = this.PersonalNumber?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.PersonalNumber, s));
            }

            if (!string.IsNullOrWhiteSpace(s = this.Address?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.Address, s));
            }

            if (!string.IsNullOrWhiteSpace(s = this.Address2?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.Address2, s));
            }

            if (!string.IsNullOrWhiteSpace(s = this.ZipCode?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.ZipCode, s));
            }

            if (!string.IsNullOrWhiteSpace(s = this.Area?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.Area, s));
            }

            if (!string.IsNullOrWhiteSpace(s = this.City?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.City, s));
            }

            if (!string.IsNullOrWhiteSpace(s = this.Region?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.Region, s));
            }

            if (!string.IsNullOrWhiteSpace(s = this.Country?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.Country, ISO_3166_1.ToCode(s)));
            }

            if (!string.IsNullOrWhiteSpace(s = this.DeviceId?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.DeviceId, s));
            }

            properties.Add(new Property(Constants.XmppProperties.JId, neuronService.BareJId));

            return(properties.ToArray());
        }
        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);
            }
        }