/// <summary>
 /// Creates the Dsc compilation job of the configuration.  (see
 /// http://aka.ms/azureautomationsdk/dscconfigurationcompilejoboperations
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Automation.IDscCompilationJobOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group
 /// </param>
 /// <param name='automationAccount'>
 /// Required. The automation account name.
 /// </param>
 /// <param name='parameters'>
 /// Required. The parameters supplied to the create compilation job
 /// operation.
 /// </param>
 /// <returns>
 /// The response model for the create Dsc Compilation job operation.
 /// </returns>
 public static Task <DscCompilationJobCreateResponse> CreateAsync(this IDscCompilationJobOperations operations, string resourceGroupName, string automationAccount, DscCompilationJobCreateParameters parameters)
 {
     return(operations.CreateAsync(resourceGroupName, automationAccount, parameters, CancellationToken.None));
 }
 /// <summary>
 /// Creates the Dsc compilation job of the configuration.  (see
 /// http://aka.ms/azureautomationsdk/dscconfigurationcompilejoboperations
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Automation.IDscCompilationJobOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group
 /// </param>
 /// <param name='automationAccount'>
 /// Required. The automation account name.
 /// </param>
 /// <param name='parameters'>
 /// Required. The parameters supplied to the create compilation job
 /// operation.
 /// </param>
 /// <returns>
 /// The response model for the create Dsc Compilation job operation.
 /// </returns>
 public static DscCompilationJobCreateResponse Create(this IDscCompilationJobOperations operations, string resourceGroupName, string automationAccount, DscCompilationJobCreateParameters parameters)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IDscCompilationJobOperations)s).CreateAsync(resourceGroupName, automationAccount, parameters);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
 /// <summary>
 /// Creates the Dsc compilation job of the configuration.
 /// <see href="http://aka.ms/azureautomationsdk/dscconfigurationcompilejoboperations" />
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Name of an Azure Resource group.
 /// </param>
 /// <param name='automationAccountName'>
 /// The name of the automation account.
 /// </param>
 /// <param name='compilationJobName'>
 /// The the DSC configuration Id.
 /// </param>
 /// <param name='parameters'>
 /// The parameters supplied to the create compilation job operation.
 /// </param>
 public static DscCompilationJob Create(this IDscCompilationJobOperations operations, string resourceGroupName, string automationAccountName, string compilationJobName, DscCompilationJobCreateParameters parameters)
 {
     return(operations.CreateAsync(resourceGroupName, automationAccountName, compilationJobName, parameters).GetAwaiter().GetResult());
 }
 /// <summary>
 /// Creates the Dsc compilation job of the configuration.
 /// <see href="http://aka.ms/azureautomationsdk/dscconfigurationcompilejoboperations" />
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Name of an Azure Resource group.
 /// </param>
 /// <param name='automationAccountName'>
 /// The name of the automation account.
 /// </param>
 /// <param name='compilationJobName'>
 /// The the DSC configuration Id.
 /// </param>
 /// <param name='parameters'>
 /// The parameters supplied to the create compilation job operation.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <DscCompilationJob> CreateAsync(this IDscCompilationJobOperations operations, string resourceGroupName, string automationAccountName, string compilationJobName, DscCompilationJobCreateParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CreateWithHttpMessagesAsync(resourceGroupName, automationAccountName, compilationJobName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
        private async Task <DscCompilationJobCreateResponse> createDSCJob()
        {
            DscConfiguration draft = await AutomationDSCManager.GetConfigurationDraft(configurationName, iseClient.automationManagementClient,
                                                                                      iseClient.accountResourceGroups[iseClient.currAccount].Name, iseClient.currAccount.Name);

            Dictionary <string, string> filePathForRunbook = new Dictionary <string, string>();

            if (Directory.Exists(iseClient.currWorkspace))
            {
                foreach (string path in localRunbookFilePaths)
                {
                    if (path.EndsWith(Constants.nodeConfigurationIdentifier + ".ps1"))
                    {
                        filePathForRunbook.Add(System.IO.Path.GetFileNameWithoutExtension(path), path);
                    }
                }
            }


            var jobCreationParams = new DscCompilationJobCreateParameters()
            {
                Properties = new DscCompilationJobCreateProperties()
                {
                    Configuration = new DscConfigurationAssociationProperty()
                    {
                        Name = configurationName
                    },
                    Parameters = null
                }
            };

            jobCreationParams.Name = configurationName;
            if ((draft.Properties.Parameters.Count > 0) || filePathForRunbook.Count > 0)
            {
                /* User needs to specify some things */
                var existingParams = await GetLastCompilationJobParams();

                DSCConfigurationParamDialog paramDialog = new DSCConfigurationParamDialog(draft.Properties.Parameters, existingParams, filePathForRunbook);
                string configData = null;

                if (paramDialog.ShowDialog() == true)
                {
                    if (!String.IsNullOrEmpty(paramDialog.configDataSelection) && !paramDialog.configDataSelection.Equals("None"))
                    {
                        configData = getConfigurationData(paramDialog.configDataSelection);
                    }
                    jobCreationParams.Properties.Parameters = GetDSCParameters(paramDialog.paramValues, configData);
                }
                else
                {
                    return(null);
                }
            }
            /* start the compilation job */
            CancellationTokenSource cts = new CancellationTokenSource();

            cts.CancelAfter(TIMEOUT_MS);
            DscCompilationJobCreateResponse jobResponse = await iseClient.automationManagementClient.CompilationJobs.CreateAsync(
                iseClient.accountResourceGroups[iseClient.currAccount].Name,
                iseClient.currAccount.Name, jobCreationParams, cts.Token);

            if (jobResponse == null || jobResponse.StatusCode != System.Net.HttpStatusCode.Created)
            {
                throw new Exception("The DSC compilation job could not be created: received HTTP status code " + jobResponse.StatusCode);
            }
            lastJobID = jobResponse.DscCompilationJob.Properties.JobId;
            return(jobResponse);
        }