Пример #1
0
        /// <summary>
        /// The update administrator account.
        /// </summary>
        /// <param name="account">
        /// The account.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task <Status> UpdateAdministratorAccount(AccountWithPhoneNumber account)
        {
            var parameters = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(account.password))
            {
                parameters["password"] = account.password;
            }
            if (!string.IsNullOrEmpty(account.emailAddress))
            {
                parameters["emailAddress"] = account.emailAddress;
            }
            if (!string.IsNullOrEmpty(account.fullName))
            {
                parameters["fullName"] = account.fullName;
            }
            if (!string.IsNullOrEmpty(account.firstName))
            {
                parameters["firstName"] = account.firstName;
            }
            if (!string.IsNullOrEmpty(account.lastName))
            {
                parameters["lastName"] = account.lastName;
            }
            if (!string.IsNullOrEmpty(account.department))
            {
                parameters["department"] = account.department;
            }
            if (!string.IsNullOrEmpty(account.customDefined1))
            {
                parameters["customDefined1"] = account.customDefined1;
            }
            if (!string.IsNullOrEmpty(account.customDefined2))
            {
                parameters["customDefined2"] = account.customDefined2;
            }
            if (!string.IsNullOrEmpty(account.phoneCountryCode))
            {
                parameters["phoneCountryCode"] = account.phoneCountryCode;
            }
            if (!string.IsNullOrEmpty(account.phoneNumber))
            {
                parameters["phoneNumber"] = account.phoneNumber;
            }

            string postBody = parameters.ToQueryString();

            if (account.MemberOfRoles.Any())
            {
                IEnumerable <string> roles = account.MemberOfRoles.Select(role => string.Format("role={0}", role.Name));
                string roleParameters      = string.Join("&", roles);

                postBody = string.Join("&", postBody, roleParameters);
            }

            return
                (await
                 _apiClient.PostAsync <Status>(ApiUris.UpdateAdministrator(_apiClient.OrganizationId, account.userName), postBody));
        }
 /// <summary>
 /// The add sub administrator account.
 /// </summary>
 /// <param name="account">
 /// The account.
 /// </param>
 /// <returns>
 /// The <see cref="Task"/>.
 /// </returns>
 public async Task <Status> AddSubAdministratorAccount(AccountWithPhoneNumber account)
 {
     return
         (await
          _apiClient.PostAsync <AccountWithPhoneNumber, Status>(
              ApiUris.AccountWithPhoneNumber(_apiClient.OrganizationId),
              account));
 }
        /// <summary>
        /// The get administrator account.
        /// </summary>
        /// <param name="username">
        /// The username.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task <AccountWithPhoneNumber> GetAdministratorAccount(string username)
        {
            AccountWithPhoneNumber account =
                await
                _apiClient.GetAsync <AccountWithPhoneNumber>(ApiUris.AccountWithPhoneNumber(_apiClient.OrganizationId, username));

            return(account);
        }
Пример #4
0
        /// <summary>
        /// Try to login into the account using the credentials.
        ///     If succeed, it will return the account details.
        /// </summary>
        /// <param name="connection">
        /// The connection.
        /// </param>
        /// <returns>
        /// The CaaS connection
        /// </returns>
        private async Task <Status> ResetPasswordTask(ComputeServiceConnection connection)
        {
            var account = new AccountWithPhoneNumber
            {
                userName = connection.User.UserName,
                password = NewPassword.ToPlainString()
            };

            return(await connection.ApiClient.Account.UpdateAdministratorAccount(account));
        }
        /// <summary>
        ///     The create account.
        /// </summary>
        /// <returns>
        ///     The <see cref="Status" />.
        /// </returns>
        private Status CreateAccount()
        {
            var roles = new List <Role>();

            if (Roles != null)
            {
                roles.AddRange(Roles);
            }

            var account = new AccountWithPhoneNumber
            {
                orgId            = Connection.User.OrganizationId.ToString(),
                userName         = Username,
                password         = Password.ToPlainString(),
                fullName         = FullName,
                firstName        = FirstName,
                lastName         = LastName,
                emailAddress     = EmailAddress,
                department       = Department,
                phoneCountryCode = PhoneCountryCode,
                phoneNumber      = PhoneNumber,
                customDefined1   = CustomDefined1,
                customDefined2   = CustomDefined2,
                MemberOfRoles    = roles
            };


            Status status = Connection.ApiClient.Account.AddSubAdministratorAccount(account).Result;

            if (status != null)
            {
                WriteDebug(
                    string.Format(
                        "{0} resulted in {1} ({2}): {3}",
                        status.operation,
                        status.result,
                        status.resultCode,
                        status.resultDetail));
            }

            return(status);
        }
        /// <summary>
        /// Process the record
        /// </summary>
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            try
            {
                var roles = new List <Role>();
                if (Roles != null)
                {
                    roles.AddRange(Roles);
                }

                var account = new AccountWithPhoneNumber
                {
                    userName         = Username,
                    fullName         = FullName,
                    firstName        = FirstName,
                    lastName         = LastName,
                    emailAddress     = EmailAddress,
                    department       = Department,
                    phoneCountryCode = PhoneCountryCode,
                    phoneNumber      = PhoneNumber,
                    customDefined1   = CustomDefined1,
                    customDefined2   = CustomDefined2,
                    MemberOfRoles    = roles
                };
                if (Password != null)
                {
                    account.password = Password.ToPlainString();
                }

                Status status = Connection.ApiClient.UpdateAdministratorAccount(account).Result;
                if (status != null)
                {
                    WriteDebug(
                        string.Format(
                            "{0} resulted in {1} ({2}): {3}",
                            status.operation,
                            status.result,
                            status.resultCode,
                            status.resultDetail));
                }
            }
            catch (AggregateException ae)
            {
                ae.Handle(
                    e =>
                {
                    if (e is ComputeApiException)
                    {
                        WriteError(new ErrorRecord(e, "-2", ErrorCategory.InvalidOperation, Connection));
                    }
                    else
                    {
// if (e is HttpRequestException)
                        ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.ConnectionError, Connection));
                    }

                    return(true);
                });
            }
        }