/// <summary>
 /// Create a new job or updates an existing job in the specified subscription.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='storageAccountName'>
 /// The name of the storage account where data will be imported to or exported
 /// from.
 /// </param>
 /// <param name='jobName'>
 /// The name of the import/export job.
 /// </param>
 /// <param name='putJobParameters'>
 /// </param>
 /// <param name='ifModifiedSince'>
 /// A DateTime value. Specify this header to perform the operation only if the
 /// resource has been modified since the specified time
 /// </param>
 /// <param name='ifUnmodifiedSince'>
 /// A DateTime value. Specify this header to perform the operation only if the
 /// resource has not been modified since the specified date/time.
 /// </param>
 /// <param name='ifMatch'>
 /// An ETag value. Specify this header to perform the operation only if the
 /// resource's ETag matches the value specified.
 /// </param>
 /// <param name='ifNoneMatch'>
 /// An ETag value, or the wildcard character (*). Specify this header to
 /// perform the operation only if the resource's ETag does not match the
 /// value specified.
 /// </param>
 public static int?PutJob(this IStorageImportExportLib operations, string storageAccountName, string jobName, PutJobParameters putJobParameters, string ifModifiedSince = default(string), string ifUnmodifiedSince = default(string), string ifMatch = default(string), string ifNoneMatch = default(string))
 {
     return(Task.Factory.StartNew(s => ((IStorageImportExportLib)s).PutJobAsync(storageAccountName, jobName, putJobParameters, ifModifiedSince, ifUnmodifiedSince, ifMatch, ifNoneMatch), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
 /// <summary>
 /// Create a new job or updates an existing job in the specified subscription.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='storageAccountName'>
 /// The name of the storage account where data will be imported to or exported
 /// from.
 /// </param>
 /// <param name='jobName'>
 /// The name of the import/export job.
 /// </param>
 /// <param name='putJobParameters'>
 /// </param>
 /// <param name='ifModifiedSince'>
 /// A DateTime value. Specify this header to perform the operation only if the
 /// resource has been modified since the specified time
 /// </param>
 /// <param name='ifUnmodifiedSince'>
 /// A DateTime value. Specify this header to perform the operation only if the
 /// resource has not been modified since the specified date/time.
 /// </param>
 /// <param name='ifMatch'>
 /// An ETag value. Specify this header to perform the operation only if the
 /// resource's ETag matches the value specified.
 /// </param>
 /// <param name='ifNoneMatch'>
 /// An ETag value, or the wildcard character (*). Specify this header to
 /// perform the operation only if the resource's ETag does not match the
 /// value specified.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <int?> PutJobAsync(this IStorageImportExportLib operations, string storageAccountName, string jobName, PutJobParameters putJobParameters, string ifModifiedSince = default(string), string ifUnmodifiedSince = default(string), string ifMatch = default(string), string ifNoneMatch = default(string), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.PutJobWithHttpMessagesAsync(storageAccountName, jobName, putJobParameters, ifModifiedSince, ifUnmodifiedSince, ifMatch, ifNoneMatch, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
        /// <summary>
        /// Create a new job in the Windows Azure Import/Export service.
        /// </summary>
        /// <param name="jobName">Name of the job.</param>
        /// <param name="configFilePath"></param>
        public void CreateJob(string jobName, string configFilePath)
        {
            var XConf = XDocument.Load(configFilePath);

            // ReturnAddress: Specifies the return address information for the job.
            var XReturnAddress = XConf.Descendants("ReturnAddress").First();
            var returnAddress  = new ReturnAddress(
                XReturnAddress.Element("Name").Value,
                XReturnAddress.Element("Address").Value,
                XReturnAddress.Element("Phone").Value,
                XReturnAddress.Element("Email").Value
                );

            // ReturnShipping: Specifies the return carrier and customer’s account with the carrier
            var XReturnShipping = XConf.Descendants("ReturnShipping").First();
            var returnShipping  = new ReturnShipping(
                XReturnShipping.Element("CarrierName").Value,
                XReturnShipping.Element("CarrierAccountNumber").Value
                );

            // Properties: The list of properties for the job.
            // refer to https://msdn.microsoft.com/en-us/library/azure/dn529110.aspx for more details
            var XJobProperty     = XConf.Descendants("JobProperty").First();
            var putJobProperties = new PutJobProperties(
                backupDriveManifest: bool.Parse(XJobProperty.Element("BackupDriveManifest").Value),
                description: XJobProperty.Element("Description").Value,
                enableVerboseLog: bool.Parse(XJobProperty.Element("EnableVerboseLog").Value),
                friendlyName: XJobProperty.Element("FriendlyName").Value,
                type: (XJobProperty.Element("JobType").Value.Equals("Import", StringComparison.InvariantCultureIgnoreCase)? JobType.Import: JobType.Export),
                location: XJobProperty.Element("Location").Value,
                storageAccountKey: XJobProperty.Element("StorageAccountKey").Value,
                storageAccountName: XJobProperty.Element("StorageAccountName").Value,
                importExportStatesPath: XJobProperty.Element("ImportExportStatesPath").Value,
                returnAddress: returnAddress,
                returnShipping: returnShipping
                );

            // must include either StorageAccountKey or ContainerSas in the request
            if (string.IsNullOrEmpty(XJobProperty.Element("StorageAccountKey").Value))
            {
                putJobProperties.StorageAccountKey = null;
                putJobProperties.ContainerSas      = XJobProperty.Element("ContainerSas").Value;
            }

            var putJobParameters = new PutJobParameters(jobName, putJobProperties);

            if (putJobProperties.Type == JobType.Export)
            {
                // BlobList: contain information about the blobs to be exported for an export job.
                var XBlobList = XConf.Descendants("BlobList").First().Elements();
                var blobList  = new BlobList(new List <string>(), new List <string>());
                foreach (var XBlob in XBlobList)
                {
                    if (!String.IsNullOrWhiteSpace(XBlob.Attribute("BlobPaths").Value))
                    {
                        blobList.BlobPath.Add(XBlob.Attribute("BlobPaths").Value);
                    }
                    if (!String.IsNullOrWhiteSpace(XBlob.Attribute("BlobPathPrefixes").Value))
                    {
                        blobList.BlobPathPrefix.Add(XBlob.Attribute("BlobPathPrefixes").Value);
                    }
                }
                putJobParameters.Export = new Export(blobList: blobList);
            }
            else
            {
                // DriveList: List of up to ten drives that comprise the job.
                var XDriveList = XConf.Descendants("DriveList").First().Elements();
                var driveList  = new List <Drive>();
                foreach (var XDrive in XDriveList)
                {
                    driveList.Add(new Drive(
                                      driveId: XDrive.Element("DriveId").Value,
                                      bitLockerKey: XDrive.Element("BitLockerKey").Value,
                                      manifestFile: XDrive.Element("ManifestFile").Value,
                                      manifestHash: XDrive.Element("ManifestHash").Value
                                      ));
                }
                putJobParameters.DriveList = driveList;
            }

            client.PutJob(XJobProperty.Element("StorageAccountName").Value, jobName, putJobParameters);
        }