/// <summary> /// Lists the Task files matching the specified filter options /// </summary> /// <param name="options">The options to use when querying for Task files</param> /// <returns>The Task files matching the specified filter options</returns> public IEnumerable <PSTaskFile> ListTaskFiles(ListTaskFileOptions options) { if (options == null) { throw new ArgumentNullException("options"); } if ((string.IsNullOrWhiteSpace(options.WorkItemName) || string.IsNullOrWhiteSpace(options.JobName) || string.IsNullOrWhiteSpace(options.TaskName)) && options.Task == null) { throw new ArgumentNullException(Resources.GBTF_NoTaskSpecified); } // Get the single Task file matching the specified name if (!string.IsNullOrEmpty(options.TaskFileName)) { WriteVerbose(string.Format(Resources.GBTF_GetByName, options.TaskFileName, options.TaskName)); using (IWorkItemManager wiManager = options.Context.BatchOMClient.OpenWorkItemManager()) { ITaskFile taskFile = wiManager.GetTaskFile(options.WorkItemName, options.JobName, options.TaskName, options.TaskFileName, options.AdditionalBehaviors); PSTaskFile psTaskFile = new PSTaskFile(taskFile); return(new PSTaskFile[] { psTaskFile }); } } // List Task files using the specified filter else { string tName = options.Task == null ? options.TaskName : options.Task.Name; ODATADetailLevel odata = null; if (!string.IsNullOrEmpty(options.Filter)) { WriteVerbose(string.Format(Resources.GBTF_GetByOData, tName)); odata = new ODATADetailLevel(filterClause: options.Filter); } else { WriteVerbose(string.Format(Resources.GBTF_NoFilter, tName)); } IEnumerableAsyncExtended <ITaskFile> taskFiles = null; if (options.Task != null) { taskFiles = options.Task.omObject.ListTaskFiles(options.Recursive, odata, options.AdditionalBehaviors); } else { using (IWorkItemManager wiManager = options.Context.BatchOMClient.OpenWorkItemManager()) { taskFiles = wiManager.ListTaskFiles(options.WorkItemName, options.JobName, options.TaskName, options.Recursive, odata, options.AdditionalBehaviors); } } Func <ITaskFile, PSTaskFile> mappingFunction = f => { return(new PSTaskFile(f)); }; return(PSAsyncEnumerable <PSTaskFile, ITaskFile> .CreateWithMaxCount( taskFiles, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount)))); } }