private BehaviorManager(BehaviorManager other)
 {
     this.BaseBehaviors    = new List <BatchClientBehavior>(other.BaseBehaviors);
     this.PerCallBehaviors = new List <BatchClientBehavior>(other.PerCallBehaviors);
 }
        private async Task WhenAllImplAsync(
            IEnumerable <CloudTask> tasksToMonitor,
            Common.TaskState desiredState,
            CancellationToken cancellationToken,
            ODATAMonitorControl controlParams,
            IEnumerable <BatchClientBehavior> additionalBehaviors)
        {
            if (null == tasksToMonitor)
            {
                throw new ArgumentNullException("tasksToMonitor");
            }

            // we only need the id and state for this monitor.  the filter clause will be updated by the monitor
            ODATADetailLevel odataSuperOptimalPredicates = new ODATADetailLevel()
            {
                SelectClause = "id,state"
            };

            // for validation and list calls we need the parent name values
            string jobId = null;

            // set up behaviors
            BehaviorManager bhMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors);

            // set up control params if needed
            if (null == controlParams)
            {
                controlParams = new ODATAMonitorControl(); // use defaults
            }

            tasksToMonitor = await UtilitiesInternal.EnumerateIfNeededAsync(tasksToMonitor, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);

            // validation: job schedule id and jobId
            foreach (CloudTask curTask in tasksToMonitor)
            {
                // can only monitor bound objects
                if (curTask.BindingState != BindingState.Bound)
                {
                    Exception ex = UtilitiesInternal.OperationForbiddenOnUnboundObjects;

                    throw ex;
                }

                // set or validate job Id
                if (null == jobId)
                {
                    jobId = curTask.ParentJobId;
                }
                else
                {
                    // all instances must have same parent
                    if (!jobId.Equals(curTask.ParentJobId, StringComparison.OrdinalIgnoreCase))
                    {
                        Exception ex = UtilitiesInternal.MonitorRequiresConsistentHierarchyChain;

                        throw ex;
                    }
                }
            }

            // start call
            Task asyncTask = ODATAMonitor.WhenAllAsync(
                tasksToMonitor,
                x =>
            {
                // return true if is desired state
                bool hasReachedDesiredState = x.State == desiredState;
                return(hasReachedDesiredState);
            },
                x => { return(x.Id); },                                                                                          // return the Id of the task
                () => _parentUtilities.ParentBatchClient.JobOperations.ListTasksImpl(jobId, bhMgr, odataSuperOptimalPredicates), // call this lambda to (re)fetch the list
                cancellationToken,
                odataSuperOptimalPredicates,
                controlParams);

            await asyncTask.ConfigureAwait(continueOnCapturedContext : false);
        }
 internal AsyncListPoolsEnumerator(PoolOperations parentPoolOperations, BehaviorManager behaviorMgr, DetailLevel detailLevel)
     : base(behaviorMgr, detailLevel)
 {
     _parentPoolOperations = parentPoolOperations;
 }
Exemplo n.º 4
0
 internal AsyncListNodeFilesByNodeEnumerator(PoolOperations parentPoolOperations, string poolId, string computeNodeId, bool?recursive, BehaviorManager behaviorMgr, DetailLevel detailLevel)
     : base(behaviorMgr, detailLevel)
 {
     _parentPoolOperations = parentPoolOperations;
     _poolId        = poolId;
     _computeNodeId = computeNodeId;
     _recursive     = recursive;
 }