/// <summary>
 /// The Create VM Image operation creates a VM image that in your image
 /// repository.  (see
 /// http://msdn.microsoft.com/en-us/library/azure/dn775054.aspx for
 /// more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IVirtualMachineVMImageOperations.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the virtual machine VM image
 /// create operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static AzureOperationResponse BeginCreating(this IVirtualMachineVMImageOperations operations, VirtualMachineVMImageCreateParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IVirtualMachineVMImageOperations)s).BeginCreatingAsync(parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// The Create VM Image operation creates a VM image that in your image
 /// repository.  (see
 /// http://msdn.microsoft.com/en-us/library/azure/dn775054.aspx for
 /// more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IVirtualMachineVMImageOperations.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the virtual machine VM image
 /// create operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task<AzureOperationResponse> BeginCreatingAsync(this IVirtualMachineVMImageOperations operations, VirtualMachineVMImageCreateParameters parameters)
 {
     return operations.BeginCreatingAsync(parameters, CancellationToken.None);
 }
        protected PSArgument[] CreateVirtualMachineVMImageCreateParameters()
        {
            VirtualMachineVMImageCreateParameters parameters = new VirtualMachineVMImageCreateParameters();

            return ConvertFromObjectsToArguments(new string[] { "Parameters" }, new object[] { parameters });
        }
 /// <summary>
 /// The Create VM Image operation creates a VM image that in your image
 /// repository.  (see
 /// http://msdn.microsoft.com/en-us/library/azure/dn775054.aspx for
 /// more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IVirtualMachineVMImageOperations.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Create Virtual Machine Image
 /// operation.
 /// </param>
 /// <returns>
 /// The response body contains the status of the specified asynchronous
 /// operation, indicating whether it has succeeded, is inprogress, or
 /// has failed. Note that this status is distinct from the HTTP status
 /// code returned for the Get Operation Status operation itself. If
 /// the asynchronous operation succeeded, the response body includes
 /// the HTTP status code for the successful request. If the
 /// asynchronous operation failed, the response body includes the HTTP
 /// status code for the failed request and error information regarding
 /// the failure.
 /// </returns>
 public static Task<OperationStatusResponse> CreateAsync(this IVirtualMachineVMImageOperations operations, VirtualMachineVMImageCreateParameters parameters)
 {
     return operations.CreateAsync(parameters, CancellationToken.None);
 }
        protected override void OnProcessRecord()
        {
            ServiceManagementProfile.Initialize();

            if (string.Equals(ParameterSetName, VMImageParamSet, StringComparison.OrdinalIgnoreCase))
            {
                var osDiskConfig = DiskConfig == null ? null : DiskConfig.OSDiskConfiguration;
                var dataDiskConfigs = DiskConfig == null ? null : DiskConfig.DataDiskConfigurations.ToList();

                var parameters = new VirtualMachineVMImageCreateParameters
                {
                    Name = this.ImageName,
                    OSDiskConfiguration = osDiskConfig == null ? null : new OSDiskConfigurationCreateParameters
                    {
                        OS = osDiskConfig.OS,
                        OSState = osDiskConfig.OSState,
                        HostCaching = osDiskConfig.HostCaching,
                        MediaLink = osDiskConfig.MediaLink
                    },
                    DataDiskConfigurations = dataDiskConfigs == null ? null : dataDiskConfigs.Select(d => new DataDiskConfigurationCreateParameters
                    {
                        HostCaching = d.HostCaching,
                        LogicalUnitNumber = d.Lun,
                        MediaLink = d.MediaLink
                    }).ToList(),
                    Label = string.IsNullOrEmpty(this.Label) ? this.ImageName : this.Label,
                    Eula = this.Eula,
                    Description = this.Description,
                    ImageFamily = this.ImageFamily,
                    PublishedDate = this.PublishedDate,
                    PrivacyUri = this.PrivacyUri,
                    RecommendedVMSize = this.RecommendedVMSize,
                    IconUri = this.IconName,
                    SmallIconUri = this.SmallIconName,
                    ShowInGui = this.ShowInGui
                };

                this.ExecuteClientActionNewSM(
                    null,
                    this.CommandRuntime.ToString(),
                    () => this.ComputeClient.VirtualMachineVMImages.Create(parameters));
            }
            else
            {
                var parameters = new VirtualMachineOSImageCreateParameters
                {
                    Name = this.ImageName,
                    MediaLinkUri = new Uri(this.MediaLocation),
                    Label = string.IsNullOrEmpty(this.Label) ? this.ImageName : this.Label,
                    OperatingSystemType = this.OS,
                    Eula = this.Eula,
                    Description = this.Description,
                    ImageFamily = this.ImageFamily,
                    PublishedDate = this.PublishedDate,
                    PrivacyUri = this.PrivacyUri,
                    RecommendedVMSize = this.RecommendedVMSize,
                    IconUri = this.IconName,
                    SmallIconUri = this.SmallIconName,
                    ShowInGui = this.ShowInGui
                };

                this.ExecuteClientActionNewSM(
                    null,
                    this.CommandRuntime.ToString(),
                    () => this.ComputeClient.VirtualMachineOSImages.Create(parameters),
                    (s, response) => this.ContextFactory<VirtualMachineOSImageCreateResponse, OSImageContext>(response, s));
            }
        }