Example #1
0
        private async void ButtonPublishRunbook_Click(object sender, RoutedEventArgs e)
        {
            AutomationRunbook selectedRunbook = (AutomationRunbook)RunbooksListView.SelectedItem;

            if (selectedRunbook == null)
            {
                MessageBox.Show("No runbook selected.");
                return;
            }
            try
            {
                /* Update UI */
                ButtonPublishRunbook.IsEnabled  = false;
                ButtonDownloadRunbook.IsEnabled = false;
                ButtonUploadRunbook.IsEnabled   = false;
                ButtonPublishRunbook.Content    = "Publishing...";
                /* Do the uploading */
                await AutomationRunbookManager.PublishRunbook(selectedRunbook, iseClient.automationManagementClient,
                                                              iseClient.accountResourceGroups[iseClient.currAccount].Name, iseClient.currAccount.Name);
            }
            catch (Exception ex)
            {
                MessageBox.Show("The runbook could not be published.\r\nDetails: " + ex.Message, "Error");
            }
            finally
            {
                /* Update UI */
                RunbooksListView.Items.Refresh();
                ButtonPublishRunbook.IsEnabled  = true;
                ButtonDownloadRunbook.IsEnabled = true;
                ButtonUploadRunbook.IsEnabled   = true;
                ButtonPublishRunbook.Content    = "Publish Draft";
            }
        }
        private async Task <TestJobCreateResponse> createTestJob()
        {
            RunbookDraft draft = await AutomationRunbookManager.GetRunbookDraft(runbookName, iseClient.automationManagementClient,
                                                                                iseClient.accountResourceGroups[iseClient.currAccount].Name, iseClient.currAccount.Name);

            if (draft.InEdit == false)
            {
                throw new Exception("This runbook has no draft to test because it is in a 'Published' state.");
            }

            HybridRunbookWorkerGroupsListResponse hybridGroupResponse = await iseClient.automationManagementClient.HybridRunbookWorkerGroups.ListAsync(
                iseClient.accountResourceGroups[iseClient.currAccount].Name, iseClient.currAccount.Name,
                new CancellationToken());

            TestJobCreateParameters jobCreationParams = new TestJobCreateParameters();

            jobCreationParams.RunbookName = runbookName;
            if (draft.Parameters.Count > 0 || hybridGroupResponse.HybridRunbookWorkerGroups.Count > 0)
            {
                /* User needs to specify some things */
                var existingParams = await GetLastTestJobParams();

                RunbookParamDialog paramDialog = new RunbookParamDialog(draft.Parameters, existingParams, hybridGroupResponse.HybridRunbookWorkerGroups);
                if (paramDialog.ShowDialog() == true)
                {
                    if (draft.Parameters.Count > 0)
                    {
                        jobCreationParams.Parameters = paramDialog.paramValues;
                    }
                    if (!String.IsNullOrEmpty(paramDialog.runOnSelection) && !paramDialog.runOnSelection.Equals("Azure"))
                    {
                        jobCreationParams.RunOn = paramDialog.runOnSelection;
                    }
                }
                else
                {
                    return(null);
                }
            }
            /* start the test job */
            CancellationTokenSource cts = new CancellationTokenSource();

            cts.CancelAfter(TIMEOUT_MS);
            TestJobCreateResponse jobResponse = await iseClient.automationManagementClient.TestJobs.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 test job could not be created: received HTTP status code " + jobResponse.StatusCode);
            }
            return(jobResponse);
        }
Example #3
0
        private async void ButtonRefreshRunbookList_Click(object sender, RoutedEventArgs e)
        {
            ButtonRefreshRunbookList.IsEnabled = false;
            ButtonRefreshRunbookList.Content   = "Refreshing...";
            try
            {
                ISet <AutomationRunbook> runbooks = await AutomationRunbookManager.GetAllRunbookMetadata(iseClient.automationManagementClient,
                                                                                                         iseClient.currWorkspace, iseClient.accountResourceGroups[iseClient.currAccount].Name, iseClient.currAccount.Name);

                IDictionary <String, AutomationRunbook> runbookWithName = new Dictionary <String, AutomationRunbook>(runbooks.Count);
                foreach (AutomationRunbook runbook in runbooks)
                {
                    runbookWithName.Add(runbook.Name, runbook);
                }
                foreach (AutomationRunbook curr in runbookListViewModel)
                {
                    curr.AuthoringState = runbookWithName[curr.Name].AuthoringState;
                    Debug.WriteLine(runbookWithName[curr.Name].AuthoringState);
                    curr.Parameters        = runbookWithName[curr.Name].Parameters;
                    curr.Description       = runbookWithName[curr.Name].Description;
                    curr.LastModifiedCloud = runbookWithName[curr.Name].LastModifiedCloud;
                    curr.LastModifiedLocal = runbookWithName[curr.Name].LastModifiedLocal;
                    curr.UpdateSyncStatus();
                    runbookWithName.Remove(curr.Name);
                }
                foreach (String name in runbookWithName.Keys)
                {
                    runbookListViewModel.Add(runbookWithName[name]);
                    Debug.WriteLine(name);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("The runbook list could not be refreshed.\r\nError details: " + ex.Message, "Error");
            }
            finally
            {
                ButtonRefreshRunbookList.IsEnabled = true;
                ButtonRefreshRunbookList.Content   = "Refresh";
            }
        }
Example #4
0
        private async Task <TestJobCreateResponse> createTestJob()
        {
            RunbookDraft draft = await AutomationRunbookManager.GetRunbookDraft(runbookName, iseClient.automationManagementClient,
                                                                                iseClient.accountResourceGroups[iseClient.currAccount].Name, iseClient.currAccount.Name);

            if (draft.InEdit == false)
            {
                throw new Exception("This runbook has no draft to test because it is in a 'Published' state.");
            }
            TestJobCreateParameters jobCreationParams = new TestJobCreateParameters();

            jobCreationParams.RunbookName = runbookName;
            if (draft.Parameters.Count > 0)
            {
                /* User needs to specify values for them */
                var existingParams = await GetTestJobParams();

                RunbookParamDialog paramDialog = new RunbookParamDialog(draft.Parameters, existingParams);
                if (paramDialog.ShowDialog() == true)
                {
                    jobCreationParams.Parameters = paramDialog.paramValues;
                }
                else
                {
                    return(null);
                }
            }
            /* start the test job */
            TestJobCreateResponse jobResponse = await iseClient.automationManagementClient.TestJobs.CreateAsync(
                iseClient.accountResourceGroups[iseClient.currAccount].Name,
                iseClient.currAccount.Name, jobCreationParams, new System.Threading.CancellationToken());

            if (jobResponse == null || jobResponse.StatusCode != System.Net.HttpStatusCode.Created)
            {
                throw new Exception("The test job could not be created: received HTTP status code " + jobResponse.StatusCode);
            }
            return(jobResponse);
        }
Example #5
0
 private async Task processJobsFromQueue(IProgress <RunbookTransferProgress> progress)
 {
     while (true)
     {
         RunbookTransferJob      job             = fileTransferQueue.Take(); //blocks until there is something to take
         RunbookTransferProgress currentProgress = new RunbookTransferProgress(job);
         progress.Report(currentProgress);
         if (job.Operation == RunbookTransferJob.TransferOperation.Download)
         {
             try
             {
                 await AutomationRunbookManager.DownloadRunbook(job.Runbook, iseClient.automationManagementClient,
                                                                iseClient.currWorkspace, iseClient.accountResourceGroups[iseClient.currAccount].Name, iseClient.currAccount);
             }
             catch (Exception ex)
             {
                 MessageBox.Show("The runbook " + job.Runbook.Name + " could not be downloaded.\r\nError details: " + ex.Message);
             }
         }
         else
         {
             try
             {
                 await AutomationRunbookManager.UploadRunbookAsDraft(job.Runbook, iseClient.automationManagementClient,
                                                                     iseClient.accountResourceGroups[iseClient.currAccount].Name, iseClient.currAccount);
             }
             catch (Exception ex)
             {
                 MessageBox.Show("The runbook " + job.Runbook.Name + " could not be uploaded.\r\nError details: " + ex.Message);
             }
         }
         //await Task.Delay(5000); //simulate work taking longer, for testing
         currentProgress.Status = RunbookTransferProgress.TransferStatus.Completed;
         progress.Report(currentProgress);
     }
 }
Example #6
0
        private async void accountsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                AutomationAccount account = (AutomationAccount)accountsComboBox.SelectedValue;
                iseClient.currAccount = account;
                refreshTimer.Stop();
                if (account != null)
                {
                    /* Update Status */
                    UpdateStatusBox(configurationStatusTextBox, "Selected automation account: " + account.Name);
                    if (iseClient.AccountWorkspaceExists())
                    {
                        accountPathTextBox.Text = iseClient.currWorkspace;
                    }
                    /* Update Runbooks */
                    UpdateStatusBox(configurationStatusTextBox, "Getting runbook data...");
                    if (runbookListViewModel != null)
                    {
                        runbookListViewModel.Clear();
                    }
                    runbookListViewModel = new ObservableCollection <AutomationRunbook>(await AutomationRunbookManager.GetAllRunbookMetadata(iseClient.automationManagementClient,
                                                                                                                                             iseClient.currWorkspace, iseClient.accountResourceGroups[iseClient.currAccount].Name, iseClient.currAccount.Name));
                    UpdateStatusBox(configurationStatusTextBox, "Done getting runbook data");
                    /* Update Assets */
                    //TODO: this is not quite checking what we need it to check
                    if (!iseClient.AccountWorkspaceExists())
                    {
                        UpdateStatusBox(configurationStatusTextBox, "Downloading assets...");
                        await downloadAllAssets();

                        UpdateStatusBox(configurationStatusTextBox, "Assets downloaded");
                    }
                    /* Update PowerShell Module */
                    try
                    {
                        PSModuleConfiguration.UpdateModuleConfiguration(iseClient.currWorkspace);
                    }
                    catch
                    {
                        string message = "Could not configure the " + PSModuleConfiguration.ModuleData.ModuleName + " module.\r\n";
                        message += "This module is required for your runbooks to run locally.\r\n";
                        message += "Make sure it exists in your module path (env:PSModulePath).";
                        MessageBox.Show(message);
                    }
                    /* Update UI */
                    RunbooksListView.ItemsSource = runbookListViewModel;
                    setRunbookSelectionButtonState(false);
                    setRunbookAndAssetNonSelectionButtonState(true);
                    assetsComboBox.SelectedValue     = AutomationISE.Model.Constants.assetVariable;
                    ButtonRefreshAssetList.IsEnabled = true;
                    /* Enable source control sync in Azure Automation if it is set up for this automation account */
                    bool isSourceControlEnabled = await AutomationSourceControl.isSourceControlEnabled(iseClient.automationManagementClient,
                                                                                                       iseClient.accountResourceGroups[iseClient.currAccount].Name, iseClient.currAccount.Name);

                    if (isSourceControlEnabled)
                    {
                        ButtonSourceControlRunbook.Visibility = Visibility.Visible;
                        ButtonSourceControlRunbook.IsEnabled  = true;
                    }
                    else
                    {
                        ButtonSourceControlRunbook.Visibility = Visibility.Collapsed;
                    }
                    /* Change current directory to new workspace location */
                    accountPathTextBox.Text = iseClient.currWorkspace;
                    HostObject.CurrentPowerShellTab.Invoke("cd '" + iseClient.currWorkspace + "'");

                    refreshTimer.Start();
                }
            }
            catch (Exception exception)
            {
                var detailsDialog = MessageBox.Show(exception.Message);
            }
        }