示例#1
0
        /// <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))));
            }
        }
        /// <summary>
        /// Lists the Tasks matching the specified filter options
        /// </summary>
        /// <param name="options">The options to use when querying for Tasks</param>
        /// <returns>The Tasks matching the specified filter options</returns>
        public IEnumerable <PSCloudTask> ListTasks(ListTaskOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            if ((string.IsNullOrWhiteSpace(options.WorkItemName) || string.IsNullOrWhiteSpace(options.JobName)) && options.Job == null)
            {
                throw new ArgumentNullException(Resources.GBT_NoJob);
            }

            // Get the single Task matching the specified name
            if (!string.IsNullOrEmpty(options.TaskName))
            {
                WriteVerbose(string.Format(Resources.GBT_GetByName, options.TaskName, options.JobName, options.WorkItemName));
                using (IWorkItemManager wiManager = options.Context.BatchOMClient.OpenWorkItemManager())
                {
                    ICloudTask  task   = wiManager.GetTask(options.WorkItemName, options.JobName, options.TaskName, additionalBehaviors: options.AdditionalBehaviors);
                    PSCloudTask psTask = new PSCloudTask(task);
                    return(new PSCloudTask[] { psTask });
                }
            }
            // List Tasks using the specified filter
            else
            {
                string           jName = options.Job == null ? options.JobName : options.Job.Name;
                ODATADetailLevel odata = null;
                if (!string.IsNullOrEmpty(options.Filter))
                {
                    WriteVerbose(string.Format(Resources.GBT_GetByOData, jName));
                    odata = new ODATADetailLevel(filterClause: options.Filter);
                }
                else
                {
                    WriteVerbose(string.Format(Resources.GBT_GetNoFilter, jName));
                }

                IEnumerableAsyncExtended <ICloudTask> tasks = null;
                if (options.Job != null)
                {
                    tasks = options.Job.omObject.ListTasks(odata, options.AdditionalBehaviors);
                }
                else
                {
                    using (IWorkItemManager wiManager = options.Context.BatchOMClient.OpenWorkItemManager())
                    {
                        tasks = wiManager.ListTasks(options.WorkItemName, options.JobName, odata, options.AdditionalBehaviors);
                    }
                }
                Func <ICloudTask, PSCloudTask> mappingFunction = t => { return(new PSCloudTask(t)); };
                return(PSAsyncEnumerable <PSCloudTask, ICloudTask> .CreateWithMaxCount(
                           tasks, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount))));
            }
        }
        /// <summary>
        /// Lists the vm files matching the specified filter options
        /// </summary>
        /// <param name="options">The options to use when querying for vm files</param>
        /// <returns>The vm files matching the specified filter options</returns>
        public IEnumerable <PSVMFile> ListVMFiles(ListVMFileOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            // Get the single vm file matching the specified name
            if (!string.IsNullOrEmpty(options.VMFileName))
            {
                WriteVerbose(string.Format(Resources.GBVMF_GetByName, options.VMFileName, options.VMName));
                using (IPoolManager poolManager = options.Context.BatchOMClient.OpenPoolManager())
                {
                    ITaskFile vmFile   = poolManager.GetVMFile(options.PoolName, options.VMName, options.VMFileName, options.AdditionalBehaviors);
                    PSVMFile  psVMFile = new PSVMFile(vmFile);
                    return(new PSVMFile[] { psVMFile });
                }
            }
            // List vm files using the specified filter
            else
            {
                string           vmName           = options.VM == null ? options.VMName : options.VM.Name;
                ODATADetailLevel odata            = null;
                string           verboseLogString = null;
                if (!string.IsNullOrEmpty(options.Filter))
                {
                    verboseLogString = string.Format(Resources.GBVMF_GetByOData, vmName);
                    odata            = new ODATADetailLevel(filterClause: options.Filter);
                }
                else
                {
                    verboseLogString = string.Format(Resources.GBVMF_NoFilter, vmName);
                }
                WriteVerbose(verboseLogString);

                IEnumerableAsyncExtended <ITaskFile> vmFiles = null;
                if (options.VM != null)
                {
                    vmFiles = options.VM.omObject.ListVMFiles(options.Recursive, odata, options.AdditionalBehaviors);
                }
                else
                {
                    using (IPoolManager poolManager = options.Context.BatchOMClient.OpenPoolManager())
                    {
                        vmFiles = poolManager.ListVMFiles(options.PoolName, options.VMName, options.Recursive, odata, options.AdditionalBehaviors);
                    }
                }
                Func <ITaskFile, PSVMFile> mappingFunction = f => { return(new PSVMFile(f)); };
                return(PSAsyncEnumerable <PSVMFile, ITaskFile> .CreateWithMaxCount(
                           vmFiles, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount))));
            }
        }
示例#4
0
        /// <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.IsNullOrWhiteSpace(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
            {
                ODATADetailLevel odata = null;
                if (!string.IsNullOrEmpty(options.Filter))
                {
                    WriteVerbose(string.Format(Resources.GBJ_GetByOData, wiName));
                    odata = new ODATADetailLevel(filterClause: options.Filter);
                }
                else
                {
                    WriteVerbose(string.Format(Resources.GBJ_GetNoFilter, wiName));
                }

                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))));
                }
            }
        }
        /// <summary>
        /// Lists the vms matching the specified filter options
        /// </summary>
        /// <param name="options">The options to use when querying for vms</param>
        /// <returns>The vms matching the specified filter options</returns>
        public IEnumerable <PSVM> ListVMs(ListVMOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            string poolName = options.Pool == null ? options.PoolName : options.Pool.Name;

            // Get the single vm matching the specified name
            if (!string.IsNullOrEmpty(options.VMName))
            {
                WriteVerbose(string.Format(Resources.GBVM_GetByName, options.VMName, poolName));
                using (IPoolManager poolManager = options.Context.BatchOMClient.OpenPoolManager())
                {
                    IVM  vm   = poolManager.GetVM(poolName, options.VMName, additionalBehaviors: options.AdditionalBehaviors);
                    PSVM psVM = new PSVM(vm);
                    return(new PSVM[] { psVM });
                }
            }
            // List vms using the specified filter
            else
            {
                ODATADetailLevel odata            = null;
                string           verboseLogString = null;
                if (!string.IsNullOrEmpty(options.Filter))
                {
                    verboseLogString = string.Format(Resources.GBVM_GetByOData, poolName);
                    odata            = new ODATADetailLevel(filterClause: options.Filter);
                }
                else
                {
                    verboseLogString = string.Format(Resources.GBVM_NoFilter, poolName);
                }
                WriteVerbose(verboseLogString);

                using (IPoolManager poolManager = options.Context.BatchOMClient.OpenPoolManager())
                {
                    IEnumerableAsyncExtended <IVM> vms = poolManager.ListVMs(poolName, odata, options.AdditionalBehaviors);
                    Func <IVM, PSVM> mappingFunction   = v => { return(new PSVM(v)); };
                    return(PSAsyncEnumerable <PSVM, IVM> .CreateWithMaxCount(
                               vms, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount))));
                }
            }
        }
示例#6
0
        internal static IEnumerable <T1> CreateWithMaxCount(
            IEnumerableAsyncExtended <T2> omAsyncEnumerable, Func <T2, T1> mappingFunction, int maxCount, Action logMaxCount = null)
        {
            PSAsyncEnumerable <T1, T2> asyncEnumerable = new PSAsyncEnumerable <T1, T2>(omAsyncEnumerable, mappingFunction);

            if (maxCount <= 0)
            {
                return(asyncEnumerable);
            }
            else
            {
                if (logMaxCount != null)
                {
                    logMaxCount();
                }
                return(asyncEnumerable.Take(maxCount));
            }
        }
        /// <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))));
                }
            }
        }
        /// <summary>
        /// Lists the pools matching the specified filter options
        /// </summary>
        /// <param name="options">The options to use when querying for pools</param>
        /// <returns>The pools matching the specified filter options</returns>
        public IEnumerable <PSCloudPool> ListPools(ListPoolOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            // Get the single pool matching the specified name
            if (!string.IsNullOrWhiteSpace(options.PoolName))
            {
                WriteVerbose(string.Format(Resources.GBP_GetByName, options.PoolName));
                using (IPoolManager poolManager = options.Context.BatchOMClient.OpenPoolManager())
                {
                    ICloudPool  pool   = poolManager.GetPool(options.PoolName, additionalBehaviors: options.AdditionalBehaviors);
                    PSCloudPool psPool = new PSCloudPool(pool);
                    return(new PSCloudPool[] { psPool });
                }
            }
            // List pools using the specified filter
            else
            {
                ODATADetailLevel odata            = null;
                string           verboseLogString = null;
                if (!string.IsNullOrEmpty(options.Filter))
                {
                    verboseLogString = Resources.GBP_GetByOData;
                    odata            = new ODATADetailLevel(filterClause: options.Filter);
                }
                else
                {
                    verboseLogString = Resources.GBP_NoFilter;
                }
                WriteVerbose(verboseLogString);

                using (IPoolManager poolManager = options.Context.BatchOMClient.OpenPoolManager())
                {
                    IEnumerableAsyncExtended <ICloudPool> pools           = poolManager.ListPools(odata, options.AdditionalBehaviors);
                    Func <ICloudPool, PSCloudPool>        mappingFunction = p => { return(new PSCloudPool(p)); };
                    return(PSAsyncEnumerable <PSCloudPool, ICloudPool> .CreateWithMaxCount(
                               pools, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount))));
                }
            }
        }