/// <summary>
        /// Asynchronous method that delays execution until the specified pool reaches the specified state.
        /// </summary>
        /// <param name="client">A fully intitialized <see cref="BatchClient"/>.</param>
        /// <param name="poolId">The ID of the pool to monitor for the specified <see cref="AllocationState"/>.</param>
        /// <param name="targetAllocationState">The allocation state to monitor.</param>
        /// <param name="timeout">The maximum time to wait for the pool to reach the specified state.</param>
        /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns>
        public static async Task WaitForPoolToReachStateAsync(BatchClient client, string poolId, AllocationState targetAllocationState, TimeSpan timeout)
        {
            Console.WriteLine("Waiting for pool {0} to reach allocation state {1}", poolId, targetAllocationState);

            DateTime startTime = DateTime.UtcNow;
            DateTime timeoutAfterThisTimeUtc = startTime.Add(timeout);

            ODATADetailLevel detail = new ODATADetailLevel(selectClause: "id,allocationState");
            CloudPool pool = await client.PoolOperations.GetPoolAsync(poolId, detail);

            while (pool.AllocationState != targetAllocationState)
            {
                Console.Write(".");

                await Task.Delay(TimeSpan.FromSeconds(10));
                await pool.RefreshAsync(detail);

                if (DateTime.UtcNow > timeoutAfterThisTimeUtc)
                {
                    Console.WriteLine();
                    Console.WriteLine("Timed out waiting for pool {0} to reach state {1}", poolId, targetAllocationState);

                    return;
                }
            }

            Console.WriteLine();
        }
示例#2
0
        public System.Collections.IEnumerator Pool(System.Action <T> oninstantiated = default(System.Action <T>), System.Action <ObjectAllocation <T> > onallocated = default(System.Action <ObjectAllocation <T> >), CoroutinePriority priority = DEFAULT_COROUTINE_PRIORITY)
        {
            if (State == AllocationState.ALLOCATED)
            {
                throw new UnityEngine.UnityException("Is already allocated");
            }

            if (State == AllocationState.ALLOCATING)
            {
                throw new UnityEngine.UnityException("Is allocating");
            }

            State = AllocationState.ALLOCATING;

            for (int i = 0; i < allocation.Length; i++)
            {
                allocation[i] = UnityEngine.Object.Instantiate(original) as T;

                if (oninstantiated != default(System.Action <T>))
                {
                    oninstantiated(allocation[i]);
                }

                yield return(GetYieldInstruction(priority));
            }

            State = AllocationState.ALLOCATED;

            if (onallocated != default(System.Action <ObjectAllocation <T> >))
            {
                onallocated(this);
            }
        }
示例#3
0
        public void TestProcessNull()
        {
            int?expResult = null;
            var array     = new Single[] { 1.5F, 2.5F, 3.5F, 4.5F, 5.5F };
            var rndValue  = .3F;

            var itemSelectorMock = new Mock <IItemSelector>();

            itemSelectorMock.Setup(x => x.SelectItem(array, rndValue)).Returns(expResult);
            var itemSelector = itemSelectorMock.Object;

            var allState = new AllocationState(10, 15, array, itemSelector);

            allState.Reset();

            allState.Process(rndValue);

            Assert.That(allState.Processed, Is.True);
            Assert.That(allState.Forced, Is.False);
            Assert.That(allState.ChosenItem, Is.Null);
            itemSelectorMock.Verify(x => x.SelectItem(array, rndValue), Times.Once);
        }