/// <summary> /// Lists the jobs matching the specified filter options. /// </summary> /// <param name="options">The options to use when querying for jobs.</param> /// <returns>The jobs matching the specified filter options.</returns> public IEnumerable <PSCloudJob> ListJobs(ListJobOptions options) { if (options == null) { throw new ArgumentNullException("options"); } // Get the single job matching the specified id if (!string.IsNullOrEmpty(options.JobId)) { WriteVerbose(string.Format(Resources.GetJobById, options.JobId)); JobOperations jobOperations = options.Context.BatchOMClient.JobOperations; ODATADetailLevel getDetailLevel = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand); CloudJob job = jobOperations.GetJob(options.JobId, detailLevel: getDetailLevel, additionalBehaviors: options.AdditionalBehaviors); PSCloudJob psJob = new PSCloudJob(job); return(new PSCloudJob[] { psJob }); } // List jobs using the specified filter else { string jobScheduleId = options.JobSchedule == null ? options.JobScheduleId : options.JobSchedule.Id; bool filterByJobSchedule = !string.IsNullOrEmpty(jobScheduleId); ODATADetailLevel listDetailLevel = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand); string verboseLogString = null; if (!string.IsNullOrEmpty(options.Filter)) { verboseLogString = filterByJobSchedule ? Resources.GetJobByOData : string.Format(Resources.GetJobByODataAndJobSChedule, jobScheduleId); listDetailLevel.FilterClause = options.Filter; } else { verboseLogString = filterByJobSchedule ? Resources.GetJobNoFilter : string.Format(Resources.GetJobByJobScheduleNoFilter, jobScheduleId); } WriteVerbose(verboseLogString); IPagedEnumerable <CloudJob> jobs = null; if (filterByJobSchedule) { JobScheduleOperations jobScheduleOperations = options.Context.BatchOMClient.JobScheduleOperations; jobs = jobScheduleOperations.ListJobs(jobScheduleId, listDetailLevel, options.AdditionalBehaviors); } else { JobOperations jobOperations = options.Context.BatchOMClient.JobOperations; jobs = jobOperations.ListJobs(listDetailLevel, options.AdditionalBehaviors); } Func <CloudJob, PSCloudJob> mappingFunction = j => { return(new PSCloudJob(j)); }; return(PSPagedEnumerable <PSCloudJob, CloudJob> .CreateWithMaxCount( jobs, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount)))); } }
/// <summary> /// Lists the jobs matching the specified filter options. /// </summary> /// <param name="options">The options to use when querying for jobs.</param> /// <returns>The jobs matching the specified filter options.</returns> public IEnumerable<PSCloudJob> ListJobs(ListJobOptions options) { if (options == null) { throw new ArgumentNullException("options"); } // Get the single job matching the specified id if (!string.IsNullOrEmpty(options.JobId)) { WriteVerbose(string.Format(Resources.GetJobById, options.JobId)); JobOperations jobOperations = options.Context.BatchOMClient.JobOperations; ODATADetailLevel getDetailLevel = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand); CloudJob job = jobOperations.GetJob(options.JobId, detailLevel: getDetailLevel, additionalBehaviors: options.AdditionalBehaviors); PSCloudJob psJob = new PSCloudJob(job); return new PSCloudJob[] { psJob }; } // List jobs using the specified filter else { string jobScheduleId = options.JobSchedule == null ? options.JobScheduleId : options.JobSchedule.Id; bool filterByJobSchedule = !string.IsNullOrEmpty(jobScheduleId); ODATADetailLevel listDetailLevel = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand); string verboseLogString = null; if (!string.IsNullOrEmpty(options.Filter)) { verboseLogString = filterByJobSchedule ? Resources.GetJobByOData : string.Format(Resources.GetJobByODataAndJobSChedule, jobScheduleId); listDetailLevel.FilterClause = options.Filter; } else { verboseLogString = filterByJobSchedule ? Resources.GetJobNoFilter : string.Format(Resources.GetJobByJobScheduleNoFilter, jobScheduleId); } WriteVerbose(verboseLogString); IPagedEnumerable<CloudJob> jobs = null; if (filterByJobSchedule) { JobScheduleOperations jobScheduleOperations = options.Context.BatchOMClient.JobScheduleOperations; jobs = jobScheduleOperations.ListJobs(jobScheduleId, listDetailLevel, options.AdditionalBehaviors); } else { JobOperations jobOperations = options.Context.BatchOMClient.JobOperations; jobs = jobOperations.ListJobs(listDetailLevel, options.AdditionalBehaviors); } Func<CloudJob, PSCloudJob> mappingFunction = j => { return new PSCloudJob(j); }; return PSPagedEnumerable<PSCloudJob, CloudJob>.CreateWithMaxCount( jobs, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount))); } }
/// <summary> /// Lists the Jobs matching the specified filter options /// </summary> /// <param name="options">The options to use when querying for Jobs</param> /// <returns>The Jobs matching the specified filter options</returns> public IEnumerable <PSCloudJob> ListJobs(ListJobOptions options) { if (options == null) { throw new ArgumentNullException("options"); } if (string.IsNullOrEmpty(options.WorkItemName) && options.WorkItem == null) { throw new ArgumentNullException(Resources.GBJ_NoWorkItem); } string wiName = options.WorkItem == null ? options.WorkItemName : options.WorkItem.Name; // Get the single Job matching the specified name if (!string.IsNullOrEmpty(options.JobName)) { WriteVerbose(string.Format(Resources.GBJ_GetByName, options.JobName, wiName)); using (IWorkItemManager wiManager = options.Context.BatchOMClient.OpenWorkItemManager()) { ICloudJob job = wiManager.GetJob(wiName, options.JobName, additionalBehaviors: options.AdditionalBehaviors); PSCloudJob psJob = new PSCloudJob(job); return(new PSCloudJob[] { psJob }); } } // List Jobs using the specified filter else { if (options.MaxCount <= 0) { options.MaxCount = Int32.MaxValue; } ODATADetailLevel odata = null; if (!string.IsNullOrEmpty(options.Filter)) { WriteVerbose(string.Format(Resources.GBJ_GetByOData, wiName, options.MaxCount)); odata = new ODATADetailLevel(filterClause: options.Filter); } else { WriteVerbose(string.Format(Resources.GBJ_GetNoFilter, wiName, options.MaxCount)); } using (IWorkItemManager wiManager = options.Context.BatchOMClient.OpenWorkItemManager()) { IEnumerableAsyncExtended <ICloudJob> jobs = wiManager.ListJobs(wiName, odata, options.AdditionalBehaviors); Func <ICloudJob, PSCloudJob> mappingFunction = j => { return(new PSCloudJob(j)); }; return(new PSAsyncEnumerable <PSCloudJob, ICloudJob>(jobs, mappingFunction).Take(options.MaxCount)); } } }
public override void ExecuteCmdlet() { ListJobOptions options = new ListJobOptions(this.BatchContext, this.WorkItemName, this.WorkItem, this.AdditionalBehaviors) { JobName = this.Name, Filter = this.Filter, MaxCount = this.MaxCount }; // The enumerator will internally query the service in chunks. Using WriteObject with the enumerate flag will enumerate // the entire collection first and then write the items out one by one in a single group. Using foreach, we can take // advantage of the enumerator's behavior and write output to the pipeline in bursts. foreach (PSCloudJob job in BatchClient.ListJobs(options)) { WriteObject(job); } }
/// <summary> /// Lists the jobs matching the specified filter options /// </summary> /// <param name="options">The options to use when querying for jobs</param> /// <returns>The jobs matching the specified filter options</returns> public IEnumerable<PSCloudJob> ListJobs(ListJobOptions options) { if (options == null) { throw new ArgumentNullException("options"); } string wiName = options.WorkItem == null ? options.WorkItemName : options.WorkItem.Name; // Get the single job matching the specified name if (!string.IsNullOrEmpty(options.JobName)) { WriteVerbose(string.Format(Resources.GBJ_GetByName, options.JobName, wiName)); using (IWorkItemManager wiManager = options.Context.BatchOMClient.OpenWorkItemManager()) { ICloudJob job = wiManager.GetJob(wiName, options.JobName, additionalBehaviors: options.AdditionalBehaviors); PSCloudJob psJob = new PSCloudJob(job); return new PSCloudJob[] { psJob }; } } // List jobs using the specified filter else { ODATADetailLevel odata = null; string verboseLogString = null; if (!string.IsNullOrEmpty(options.Filter)) { verboseLogString = string.Format(Resources.GBJ_GetByOData, wiName); odata = new ODATADetailLevel(filterClause: options.Filter); } else { verboseLogString = string.Format(Resources.GBJ_GetNoFilter, wiName); } WriteVerbose(verboseLogString); using (IWorkItemManager wiManager = options.Context.BatchOMClient.OpenWorkItemManager()) { IEnumerableAsyncExtended<ICloudJob> jobs = wiManager.ListJobs(wiName, odata, options.AdditionalBehaviors); Func<ICloudJob, PSCloudJob> mappingFunction = j => { return new PSCloudJob(j); }; return PSAsyncEnumerable<PSCloudJob, ICloudJob>.CreateWithMaxCount( jobs, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount))); } } }
protected override void ProcessRecord() { ListJobOptions options = new ListJobOptions(this.BatchContext, this.AdditionalBehaviors) { JobId = this.Id, JobScheduleId = this.JobScheduleId, JobSchedule = this.JobSchedule, Filter = this.Filter, Select = this.Select, Expand = this.Expand, MaxCount = this.MaxCount }; // The enumerator will internally query the service in chunks. Using WriteObject with the enumerate flag will enumerate // the entire collection first and then write the items out one by one in a single group. Using foreach, we can take // advantage of the enumerator's behavior and write output to the pipeline in bursts. foreach (PSCloudJob job in BatchClient.ListJobs(options)) { WriteObject(job); } }