Example #1
0
        private void TransferOut(MaterialResourceRequest mrr, IResourceManager secondary, double quantity)
        {
            //_Debug.WriteLine("Gotta transfer " + quantity + " kg out.");
            IResourceRequest newMrr = new MaterialResourceRequest(mrr.MaterialType, quantity, MaterialResourceRequest.Direction.Deplete);

            if (secondary.Acquire(newMrr, false))
            {
                //_Debug.WriteLine("Successfully transferred.");
            }
        }
Example #2
0
        public ISuiteResult Run(IIntent intent, ISuiteProvider provider)
        {
            if (provider.Ignored)
            {
                return(_resultFactory.CreateIgnoredSuiteResult(provider));
            }

            using (_resourceManager.Acquire(provider.Resources))
            {
                var suitePairs = Pair(intent.Intents, provider.SuiteProviders);
                var testPairs  = Pair(intent.Intents, provider.TestProviders);

                return(RunWithResourcesAcquired(intent, provider, suitePairs, testPairs));
            }
        }
Example #3
0
        /// <summary>
        /// Acquires a resource from the specified resource manager, or the provided default manager,
        /// if none is provided in this call. If the request has already successfully reserved a resource,
        /// then the reservation is revoked and the acquisition is honored in one atomic operation.
        /// </summary>
        /// <param name="resourceManager">The resource manager from which the resource is desired. Can be null, if a default manager has been provided.</param>
        /// <param name="blockAwaitingAcquisition">If true, this call blocks until the resource is available.</param>
        /// <returns>true if the acquisition was successful, false otherwise.</returns>
        /// <exception cref="ApplicationException">Acquire API on resource request was called with neither an explicit nor a default resource manager.</exception>
        public bool Acquire(IResourceManager resourceManager, bool blockAwaitingAcquisition)
        {
            if (resourceManager == null && DefaultResourceManager == null)
            {
                throw new ApplicationException("Acquire API on resource request was called with neither an explicit nor a default resource manager.");
            }

            if (resourceManager == null)
            {
                resourceManager = DefaultResourceManager;
            }

            if (resourceManager.Acquire(this, blockAwaitingAcquisition))
            {
                ResourceObtainedFrom = resourceManager;
                return(true);
            }
            return(false);
        }
Example #4
0
 public bool Acquire(IResourceManager resourceManager, bool blockAwaitingAcquisition)
 {
     return(resourceManager.Acquire(this, blockAwaitingAcquisition));
 }