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)));
}
}