Exemplo n.º 1
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";
            }
        }
Exemplo n.º 2
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);
            }
        }