示例#1
0
        private JobModelProxy GetDraftJobDetails(RunbookModelProxy runbook)
        {
            var job = _client.TestJobs.Get(_connectionData.AzureRMGroupName, _connectionData.AzureAutomationAccount, runbook.RunbookName);

            if (job.StatusCode != System.Net.HttpStatusCode.OK)
                return null;

            var jobModel = new JobModelProxy(new Vendor.Azure.Job
            {
                JobID = Guid.NewGuid(),
                Id = string.Empty,
                WarningCount = 0,
                ErrorCount = 0,
                JobException = job.TestJob.Exception,
                CreationTime = job.TestJob.CreationTime.DateTime,
                EndTime = (job.TestJob.EndTime != null ? job.TestJob.EndTime.DateTime : default(DateTime?)),
                JobStatus = job.TestJob.Status,
                JobStatusDeteails = job.TestJob.StatusDetails,
                LastModifiedTime = job.TestJob.LastModifiedTime.DateTime,
                StartTime = (job.TestJob.StartTime != null ? job.TestJob.StartTime.DateTime : default(DateTime?))
            }, Context);

            var jobStreamParameters = new JobStreamListParameters();
            jobStreamParameters.StreamType = "Any";

            var streams = default(JobStreamListResponse);
            do
            {
                if (streams != null)
                    streams = _client.JobStreams.ListNext(streams.NextLink);
                else
                    streams = _client.JobStreams.ListTestJobStreams(_connectionData.AzureRMGroupName, _connectionData.AzureAutomationAccount, runbook.RunbookName, jobStreamParameters);

                if (streams.StatusCode != System.Net.HttpStatusCode.OK)
                    return jobModel;

                var output = streams.JobStreams.Select(s => new JobOutput
                {
                    JobID = jobModel.JobID,
                    RunbookVersionID = runbook.DraftRunbookVersionID.Value,
                    StreamText = s.Properties.Summary,
                    StreamTime = s.Properties.Time.DateTime,
                    StreamTypeName = s.Properties.StreamType
                }).ToList();

                foreach (var o in output)
                    jobModel.Result.Add(o);
            }
            while (streams.NextLink != null);

            return jobModel;
        }
示例#2
0
        private JobModelProxy ParseJobStreams(JobModelProxy jobModelProxy, string output)
        {
            dynamic jsonOutput = JObject.Parse(output);

            if (jsonOutput != null && jsonOutput.value != null)
            {
                foreach (var outputRow in jsonOutput.value)
                {
                    if (outputRow.properties.time > jobModelProxy.LastDownloadTime)
                    {
                        jobModelProxy.Result.Add(new JobOutput()
                        {
                            JobID = jobModelProxy.JobID,
                            RunbookVersionID = Guid.Empty,
                            StreamTypeName = outputRow.properties.streamType,
                            StreamTime = outputRow.properties.time,
                            StreamText = outputRow.properties.summary,
                            TenantID = Guid.Empty
                        });
                    }
                }
            }

            return jobModelProxy;
        }
示例#3
0
        private JobModelProxy GetDraftJobDetails(RunbookModelProxy runbook)
        {
            var result = SendRequest("runbooks/" + runbook.RunbookName.ToUrlSafeString() + "/draft/testJob", HttpMethod.Get);

            if (result.Length < 1)
                return null;

            dynamic jsonJob = JObject.Parse(result);

            var job = new Job();
            job.JobID = Guid.NewGuid();
            job.CreationTime = (DateTime)jsonJob.creationTime;
            job.LastModifiedTime = (DateTime)jsonJob.lastModifiedTime;
            job.JobStatus = jsonJob.status;
            job.StartTime = jsonJob.startTime != null ? (DateTime?)jsonJob.startTime : null;
            job.EndTime = jsonJob.endTime != null ? (DateTime?)jsonJob.endTime : null;
            job.JobException = jsonJob.exception;

            var jobModelProxy = new JobModelProxy(job, Context);

            foreach (var param in jsonJob.parameters)
            {
                //jobModelProxy.Parameters.Add(param)
            }

            var output = string.Empty;

            try
            {
                output = SendRequest("runbooks/" + runbook.RunbookName.ToUrlSafeString() + "/draft/testJob/streams", HttpMethod.Get);
                jobModelProxy = ParseJobStreams(jobModelProxy, output);
            }
            catch (WebException)
            {
                // The job haven't been started yet, ignore this.
            }

            return jobModelProxy;
        }
示例#4
0
        private JobModelProxy GetPublishedJobDetails(Guid jobId)
        {
            var result = SendRequest("jobs/" + jobId, HttpMethod.Get);

            if (result.Length == 0) // maybe return null instead?
                return null;

            dynamic jsonJob = JObject.Parse(result);

            var job = new Job();
            job.JobID = jobId;
            job.CreationTime = (DateTime)jsonJob.properties.creationTime;
            job.LastModifiedTime = (DateTime)jsonJob.properties.lastModifiedTime;
            job.JobStatus = jsonJob.properties.status;
            job.StartTime = jsonJob.properties.startTime != null ? (DateTime?)jsonJob.properties.startTime : null;
            job.EndTime = jsonJob.properties.endTime != null ? (DateTime?)jsonJob.properties.endTime : null;

            var jobModelProxy = new JobModelProxy(job, Context);

            foreach (var param in jsonJob.properties.parameters)
            {
                //jobModelProxy.Parameters.Add(param)
            }

            var output = SendRequest("jobs/" + jobId + "/streams", HttpMethod.Get);
            jobModelProxy = ParseJobStreams(jobModelProxy, output);

            if (jsonJob.properties.exception != null)
            {
                jobModelProxy.Result.Add(new JobOutput()
                {
                    JobID = jobId,
                    RunbookVersionID = Guid.Empty,
                    StreamTypeName = "Error",
                    StreamTime = DateTime.Now,
                    StreamText = jsonJob.properties.exception,
                    TenantID = Guid.Empty
                });
            }

            return jobModelProxy;
        }
示例#5
0
        public async Task<JobModelProxy> GetJobInformationAsync(Guid jobId)
        {
            var result = await SendRequestAsync("jobs/" + jobId, HttpMethod.Get);
            dynamic jobRaw = JObject.Parse(result);

            var model = new JobModelProxy(new Job(), Context);
            model.Result.Add(new JobOutput
            {
                StreamText = jobRaw.properties.exception,
                StreamTime = DateTime.Now,
                StreamTypeName = jobRaw.properties.exception != null ? "Error" : "Information"
            });

            return model;
        }