/// <summary> /// Lists the node files matching the specified filter options. /// </summary> /// <param name="options">The options to use when querying for node files.</param> /// <returns>The node files matching the specified filter options.</returns> public IEnumerable <PSNodeFile> ListNodeFiles(ListNodeFileOptions options) { if (options == null) { throw new ArgumentNullException("options"); } switch (options.NodeFileType) { case PSNodeFileType.Task: { return(ListNodeFilesByTask(options)); } case PSNodeFileType.ComputeNode: { return(ListNodeFilesByComputeNode(options)); } default: { throw new ArgumentException(Resources.NoNodeFileParent); } } }
// Lists the node files under a task. private IEnumerable <PSNodeFile> ListNodeFilesByTask(ListNodeFileOptions options) { // Get the single node file matching the specified name if (!string.IsNullOrEmpty(options.NodeFileName)) { WriteVerbose(string.Format(Resources.GetNodeFileByTaskByName, options.NodeFileName, options.TaskId)); JobOperations jobOperations = options.Context.BatchOMClient.JobOperations; NodeFile nodeFile = jobOperations.GetNodeFile(options.JobId, options.TaskId, options.NodeFileName, options.AdditionalBehaviors); PSNodeFile psNodeFile = new PSNodeFile(nodeFile); return(new PSNodeFile[] { psNodeFile }); } // List node files using the specified filter else { string taskId = options.Task == null ? options.TaskId : options.Task.Id; ODATADetailLevel odata = null; string verboseLogString = null; if (!string.IsNullOrEmpty(options.Filter)) { verboseLogString = string.Format(Resources.GetNodeFileByTaskByOData, taskId); odata = new ODATADetailLevel(filterClause: options.Filter); } else { verboseLogString = string.Format(Resources.GetNodeFileByTaskNoFilter, taskId); } WriteVerbose(verboseLogString); IPagedEnumerable <NodeFile> nodeFiles = null; if (options.Task != null) { nodeFiles = options.Task.omObject.ListNodeFiles(options.Recursive, odata, options.AdditionalBehaviors); } else { JobOperations jobOperations = options.Context.BatchOMClient.JobOperations; nodeFiles = jobOperations.ListNodeFiles(options.JobId, options.TaskId, options.Recursive, odata, options.AdditionalBehaviors); } Func <NodeFile, PSNodeFile> mappingFunction = f => { return(new PSNodeFile(f)); }; return(PSPagedEnumerable <PSNodeFile, NodeFile> .CreateWithMaxCount( nodeFiles, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount)))); } }
// Lists the node files under a task. private IEnumerable<PSNodeFile> ListNodeFilesByTask(ListNodeFileOptions options) { // Get the single node file matching the specified name if (!string.IsNullOrEmpty(options.NodeFileName)) { WriteVerbose(string.Format(Resources.GBTF_GetByName, options.NodeFileName, options.TaskId)); JobOperations jobOperations = options.Context.BatchOMClient.JobOperations; NodeFile nodeFile = jobOperations.GetNodeFile(options.JobId, options.TaskId, options.NodeFileName, options.AdditionalBehaviors); PSNodeFile psNodeFile = new PSNodeFile(nodeFile); return new PSNodeFile[] { psNodeFile }; } // List node files using the specified filter else { string taskId = options.Task == null ? options.TaskId : options.Task.Id; ODATADetailLevel odata = null; string verboseLogString = null; if (!string.IsNullOrEmpty(options.Filter)) { verboseLogString = string.Format(Resources.GBTF_GetByOData, taskId); odata = new ODATADetailLevel(filterClause: options.Filter); } else { verboseLogString = string.Format(Resources.GBTF_NoFilter, taskId); } WriteVerbose(verboseLogString); IPagedEnumerable<NodeFile> nodeFiles = null; if (options.Task != null) { nodeFiles = options.Task.omObject.ListNodeFiles(options.Recursive, odata, options.AdditionalBehaviors); } else { JobOperations jobOperations = options.Context.BatchOMClient.JobOperations; nodeFiles = jobOperations.ListNodeFiles(options.JobId, options.TaskId, options.Recursive, odata, options.AdditionalBehaviors); } Func<NodeFile, PSNodeFile> mappingFunction = f => { return new PSNodeFile(f); }; return PSPagedEnumerable<PSNodeFile, NodeFile>.CreateWithMaxCount( nodeFiles, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount))); } }
/// <summary> /// Lists the node files matching the specified filter options. /// </summary> /// <param name="options">The options to use when querying for node files.</param> /// <returns>The node files matching the specified filter options.</returns> public IEnumerable<PSNodeFile> ListNodeFiles(ListNodeFileOptions options) { if (options == null) { throw new ArgumentNullException("options"); } switch (options.NodeFileType) { case PSNodeFileType.Task: { return ListNodeFilesByTask(options); } case PSNodeFileType.ComputeNode: { return ListNodeFilesByComputeNode(options); } default: { throw new ArgumentException(Resources.NoNodeFileParent); } } }
public override void ExecuteCmdlet() { ListNodeFileOptions options = new ListNodeFileOptions(this.BatchContext, this.JobId, this.TaskId, this.Task, this.PoolId, this.ComputeNodeId, this.ComputeNode, this.AdditionalBehaviors) { NodeFileName = this.Name, Filter = this.Filter, MaxCount = this.MaxCount, Recursive = this.Recursive.IsPresent }; // 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 (PSNodeFile nodeFile in BatchClient.ListNodeFiles(options)) { WriteObject(nodeFile); } }