Esempio n. 1
0
        /// <summary>
        /// This method validates the customer shipping address and provide alternate addresses
        /// if any.
        /// </summary>
        private static void ValidateShippingAddress()
        {
            AddressType addressType     = AddressType.None;
            string      companyName     = "<company-name>";
            string      streetAddress1  = "<street-address-1>";
            string      streetAddress2  = "<street-address-2>";
            string      streetAddress3  = "<street-address-3>";
            string      postalCode      = "<postal-code>";
            string      city            = "<city>";
            string      stateOrProvince = "<state-or-province>";
            CountryCode countryCode     = CountryCode.US;

            ShippingAddress shippingAddress = new ShippingAddress()
            {
                AddressType     = addressType,
                CompanyName     = companyName,
                StreetAddress1  = streetAddress1,
                StreetAddress2  = streetAddress2,
                StreetAddress3  = streetAddress3,
                City            = city,
                StateOrProvince = stateOrProvince,
                PostalCode      = postalCode,
                Country         = countryCode.ToString(),
            };

            // Set location of the resource
            string location = "<location>";

            // Initializes a new instance of the DataBoxManagementClient class
            DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient();

            dataBoxManagementClient.Location = location;

            ValidateAddress         validateAddress         = new ValidateAddress(shippingAddress, DeviceType.Pod);
            AddressValidationOutput addressValidationOutput = ServiceOperationsExtensions.ValidateAddressMethod(dataBoxManagementClient.Service, validateAddress);

            // Verify shipping address validation status
            CheckShippingAddressValidationResult(addressValidationOutput);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new job with the specified parameters.
        /// </summary>
        private static void CreateJob()
        {
            AddressType addressType     = AddressType.None;
            string      streetAddress1  = "<street-address-1>";
            string      streetAddress2  = "<street-address-2>";
            string      streetAddress3  = "<street-address-3>";
            string      postalCode      = "<postal-code>";
            string      city            = "<city>";
            string      stateOrProvince = "<state-or-province>";
            CountryCode countryCode     = CountryCode.US;

            ShippingAddress shippingAddress = new ShippingAddress()
            {
                StreetAddress1  = streetAddress1,
                StreetAddress2  = streetAddress2,
                StreetAddress3  = streetAddress3,
                AddressType     = addressType,
                Country         = countryCode.ToString(),
                PostalCode      = postalCode,
                City            = city,
                StateOrProvince = stateOrProvince,
            };

            string emailIds = "<email-ids>";
            // Input a semicolon (;) separated string of email ids, eg. "[email protected];[email protected]"
            string phoneNumber = "<phone-number>";
            string contactName = "<contact-name>";

            List <string> emailIdList = new List <string>();

            emailIdList = emailIds.Split(new char[';'], StringSplitOptions.RemoveEmptyEntries).ToList();

            ContactDetails contactDetails = new ContactDetails()
            {
                Phone       = phoneNumber,
                EmailList   = emailIdList,
                ContactName = contactName
            };

            string      storageAccProviderType      = "Microsoft.Storage"; // Input the storage account provider type; Valid types: Microsoft.Storage / Microsoft.ClassicStorage
            string      storageAccResourceGroupName = "<storage-account-resource-group-name>";
            string      storageAccName = "<storage-account-name>";
            AccountType accountType    = "<account-type>"; // Choose account type from Storage AccountType list. eg. AccountType.GeneralPurposeStorage

            List <DestinationAccountDetails> destinationAccountDetails = new List <DestinationAccountDetails>();

            destinationAccountDetails.Add(
                new DestinationAccountDetails(
                    string.Concat("/subscriptions/", subscriptionId, "/resourceGroups/", storageAccResourceGroupName,
                                  "/providers/", storageAccProviderType, "/storageAccounts/", storageAccName.ToLower()), accountType));


            // Note.
            // For multiple destination storage accounts, follow above steps to add more than one account.
            // The storage accounts should be in the same Azure DataBox order's subscription and location (region).

            PodJobDetails jobDetails = new PodJobDetails(contactDetails, shippingAddress);

            string resourceGroupName = "<resource-group-name>";
            string location          = "<location>";
            string jobName           = "<job-or-order-name>";

            JobResource newJobResource = new JobResource(location, destinationAccountDetails, jobDetails);

            newJobResource.DeviceType = DeviceType.Pod;

            // Initializes a new instance of the DataBoxManagementClient class.
            DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient();

            dataBoxManagementClient.Location = location;

            // Validate shipping address
            AddressValidationOutput addressValidateResult =
                ServiceOperationsExtensions.ValidateAddressMethod(
                    dataBoxManagementClient.Service,
                    new ValidateAddress(
                        shippingAddress,
                        newJobResource.DeviceType));

            // Verify shipping address validation status
            CheckShippingAddressValidationResult(addressValidateResult);

            // Creates a new job.
            if (addressValidateResult.ValidationStatus == AddressValidationStatus.Valid)
            {
                JobResource jobResource = JobsOperationsExtensions.Create(
                    dataBoxManagementClient.Jobs,
                    resourceGroupName,
                    jobName, newJobResource);
            }
        }
        public override void ExecuteCmdlet()
        {
            if (DataBoxType == "DataBoxDisk" && ExpectedDataSizeInTeraBytes.Equals(0))
            {
                throw new PSArgumentNullException("ExpectedDataSizeInTeraBytes");
            }

            ShippingAddress shippingAddress = new ShippingAddress()
            {
                AddressType     = this.AddressType,
                CompanyName     = this.CompanyName,
                StreetAddress1  = this.StreetAddress1,
                StreetAddress2  = this.StreetAddress2,
                StreetAddress3  = this.StreetAddress3,
                City            = this.City,
                StateOrProvince = this.StateOrProvinceCode,
                Country         = this.CountryCode,
                PostalCode      = this.PostalCode
            };

            ContactDetails contactDetails = new ContactDetails()
            {
                Phone       = this.PhoneNumber,
                EmailList   = EmailId,
                ContactName = this.ContactName
            };

            List <DestinationAccountDetails> destinationAccountDetails = new List <DestinationAccountDetails>();

            foreach (var storageAccount in StorageAccountResourceId)
            {
                destinationAccountDetails.Add(
                    new DestinationAccountDetails(storageAccount));
            }

            DataBoxDiskJobDetails  diskDetails;
            DataBoxJobDetails      databoxDetails;
            DataBoxHeavyJobDetails heavyDetails;

            JobResource newJobResource = new JobResource();

            Sku sku = new Sku();

            switch (DataBoxType)
            {
            case "DataBoxDisk":
                diskDetails    = new DataBoxDiskJobDetails(contactDetails, shippingAddress, destinationAccountDetails, expectedDataSizeInTeraBytes: ExpectedDataSizeInTeraBytes);
                sku.Name       = SkuName.DataBoxDisk;
                newJobResource = new JobResource(Location, sku, details: diskDetails);
                break;

            case "DataBox":
                databoxDetails = new DataBoxJobDetails(contactDetails, shippingAddress, destinationAccountDetails);
                sku.Name       = SkuName.DataBox;
                newJobResource = new JobResource(Location, sku, details: databoxDetails);
                break;

            case "DataBoxHeavy":
                heavyDetails   = new DataBoxHeavyJobDetails(contactDetails, shippingAddress, destinationAccountDetails);
                sku.Name       = SkuName.DataBoxHeavy;
                newJobResource = new JobResource(Location, sku, details: heavyDetails);
                break;

            default: break;
            }

            AddressValidationOutput addressValidationResult = ServiceOperationsExtensions.ValidateAddressMethod(
                DataBoxManagementClient.Service, Location, shippingAddress, newJobResource.Sku.Name);

            if (addressValidationResult.ValidationStatus != AddressValidationStatus.Valid)
            {
                WriteVerbose(Resource.AddressValidationStatus + addressValidationResult.ValidationStatus + "\n");

                //print alternate address
                if (addressValidationResult.ValidationStatus == AddressValidationStatus.Ambiguous)
                {
                    WriteVerbose(Resource.SupportAddresses + "\n\n");
                    foreach (ShippingAddress address in addressValidationResult.AlternateAddresses)
                    {
                        WriteVerbose(Resource.AddressType + address.AddressType + "\n");
                        if (!(string.IsNullOrEmpty(address.CompanyName)))
                        {
                            WriteVerbose(Resource.CompanyName + address.CompanyName);
                        }
                        if (!(string.IsNullOrEmpty(address.StreetAddress1)))
                        {
                            WriteVerbose(Resource.StreetAddress1 + address.StreetAddress1);
                        }
                        if (!(string.IsNullOrEmpty(address.StreetAddress2)))
                        {
                            WriteVerbose(Resource.StreetAddress2 + address.StreetAddress2);
                        }
                        if (!(string.IsNullOrEmpty(address.StreetAddress3)))
                        {
                            WriteVerbose(Resource.StreetAddress3 + address.StreetAddress3);
                        }
                        if (!(string.IsNullOrEmpty(address.City)))
                        {
                            WriteVerbose(Resource.City + address.City);
                        }
                        if (!(string.IsNullOrEmpty(address.StateOrProvince)))
                        {
                            WriteVerbose(Resource.StateOrProvince + address.StateOrProvince);
                        }
                        if (!(string.IsNullOrEmpty(address.Country)))
                        {
                            WriteVerbose(Resource.Country + address.Country);
                        }
                        if (!(string.IsNullOrEmpty(address.PostalCode)))
                        {
                            WriteVerbose(Resource.PostalCode + address.PostalCode);
                        }
                        if (!(string.IsNullOrEmpty(address.ZipExtendedCode)))
                        {
                            WriteVerbose(Resource.ZipExtendedCode + address.ZipExtendedCode);
                        }
                        WriteVerbose("\n\n");
                    }
                    throw new PSNotSupportedException(Resource.AmbiguousAddressMessage);
                }
                throw new PSNotSupportedException(Resource.InvalidAddressMessage);
            }

            if (ShouldProcess(this.Name, string.Format(Resource.CreatingDataboxJob + this.Name + Resource.InResourceGroup + this.ResourceGroupName)))
            {
                JobResource finalJobResource = JobsOperationsExtensions.Create(
                    DataBoxManagementClient.Jobs,
                    ResourceGroupName,
                    Name,
                    newJobResource);

                WriteObject(new PSDataBoxJob(finalJobResource));
            }
        }