/// <summary> /// Returns a list of WorkItems /// </summary> /// <returns></returns> public IEnumerable <ICloudWorkItem> ListWorkItems(DetailLevel detailLevel = null) { using (IWorkItemManager wiManager = this.Client.OpenWorkItemManager()) { return(wiManager.ListWorkItems(detailLevel)); } }
private static void ListWorkItems(IBatchClient client) { // All Workitem, Job, and Task related operation start from WorkItemManager using (IWorkItemManager wm = client.OpenWorkItemManager()) { Console.WriteLine("Listing Workitems\n================="); IEnumerable <ICloudWorkItem> wis = wm.ListWorkItems(); foreach (var w in wis) { Console.WriteLine("Workitem: " + w.Name + " State:" + w.State); } Console.WriteLine(); } }
/// <summary> /// Lists the workitems matching the specified filter options /// </summary> /// <param name="options">The options to use when querying for workitems</param> /// <returns>The workitems matching the specified filter options</returns> public IEnumerable <PSCloudWorkItem> ListWorkItems(ListWorkItemOptions options) { if (options == null) { throw new ArgumentNullException("options"); } // Get the single WorkItem matching the specified name if (!string.IsNullOrWhiteSpace(options.WorkItemName)) { WriteVerbose(string.Format(Resources.GBWI_GetByName, options.WorkItemName)); using (IWorkItemManager wiManager = options.Context.BatchOMClient.OpenWorkItemManager()) { ICloudWorkItem workItem = wiManager.GetWorkItem(options.WorkItemName, additionalBehaviors: options.AdditionalBehaviors); PSCloudWorkItem psWorkItem = new PSCloudWorkItem(workItem); return(new PSCloudWorkItem[] { psWorkItem }); } } // List WorkItems using the specified filter else { ODATADetailLevel odata = null; string verboseLogString = null; if (!string.IsNullOrEmpty(options.Filter)) { verboseLogString = Resources.GBWI_GetByOData; odata = new ODATADetailLevel(filterClause: options.Filter); } else { verboseLogString = Resources.GBWI_NoFilter; } WriteVerbose(verboseLogString); using (IWorkItemManager wiManager = options.Context.BatchOMClient.OpenWorkItemManager()) { IEnumerableAsyncExtended <ICloudWorkItem> workItems = wiManager.ListWorkItems(odata, options.AdditionalBehaviors); Func <ICloudWorkItem, PSCloudWorkItem> mappingFunction = w => { return(new PSCloudWorkItem(w)); }; return(PSAsyncEnumerable <PSCloudWorkItem, ICloudWorkItem> .CreateWithMaxCount( workItems, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount)))); } } }