コード例 #1
0
        public async Task <RunbookJob> GetAutomationJobAsync(string accessToken, string subscriptionId, string resourceGroupName, string automationAccountName, string jobId, bool configureAwait = false)
        {
            var credentials = new TokenCredentials(subscriptionId, accessToken);

            using (var automationClient = new AutomationManagementClient(credentials))
            {
                var automationJobResult = configureAwait ? await automationClient.Jobs.GetAsync(resourceGroupName, automationAccountName, new Guid(jobId)).ConfigureAwait(false) :
                                          await automationClient.Jobs.GetAsync(resourceGroupName, automationAccountName, new Guid(jobId));

                var automationJob = new RunbookJob
                {
                    JobId                 = automationJobResult.Job.Properties.JobId.ToString(),
                    Status                = automationJobResult.Job.Properties.Status,
                    RunbookName           = automationJobResult.Job.Properties.Runbook?.Name ?? "_(Unknown)_",
                    ResourceGroupName     = resourceGroupName,
                    AutomationAccountName = automationAccountName,
                    StartDateTime         = automationJobResult.Job.Properties.StartTime,
                    EndDateTime           = automationJobResult.Job.Properties.EndTime
                };

                return(automationJob);
            }
        }
コード例 #2
0
        private static async Task CheckLongRunningOperationStatus <T>(IDialogContext context, RunbookJob automationJob, string accessToken,
                                                                      Func <string, string, string, string, string, bool, Task <T> > getOperationStatusAsync, Func <T, bool> completionCondition,
                                                                      Func <T, T, RunbookJob, string> getOperationStatusMessage, int delayBetweenPoolingInSeconds = 2)
        {
            var lastOperationStatus = default(T);

            do
            {
                var subscriptionId = context.GetSubscriptionId();

                var newOperationStatus = await getOperationStatusAsync(accessToken, subscriptionId, automationJob.ResourceGroupName, automationJob.AutomationAccountName, automationJob.JobId, true).ConfigureAwait(false);

                var message = getOperationStatusMessage(lastOperationStatus, newOperationStatus, automationJob);
                await context.NotifyUser(message);

                await Task.Delay(TimeSpan.FromSeconds(delayBetweenPoolingInSeconds)).ConfigureAwait(false);

                lastOperationStatus = newOperationStatus;
            }while (!completionCondition(lastOperationStatus));
        }
コード例 #3
0
        public async Task<RunbookJob> GetAutomationJobAsync(string accessToken, string subscriptionId, string resourceGroupName, string automationAccountName, string jobId, bool configureAwait = false)
        {
            var credentials = new TokenCredentials(subscriptionId, accessToken);

            using (var automationClient = new AutomationManagementClient(credentials))
            {
                var automationJobResult = configureAwait ? await automationClient.Jobs.GetAsync(resourceGroupName, automationAccountName, new Guid(jobId)).ConfigureAwait(false) :
                    await automationClient.Jobs.GetAsync(resourceGroupName, automationAccountName, new Guid(jobId));

                var automationJob = new RunbookJob
                {
                    JobId = automationJobResult.Job.Properties.JobId.ToString(),
                    Status = automationJobResult.Job.Properties.Status,
                    RunbookName = automationJobResult.Job.Properties.Runbook?.Name ?? "_(Unknown)_",
                    ResourceGroupName = resourceGroupName,
                    AutomationAccountName = automationAccountName,
                    StartDateTime = automationJobResult.Job.Properties.StartTime,
                    EndDateTime = automationJobResult.Job.Properties.EndTime
                };

                return automationJob;
            }
        }