예제 #1
0
        private bool AttemptExecution(IResourceRequest request)
        {
            double proposedNewAmountAvailable = m_material.Mass - request.QuantityDesired;

            if (proposedNewAmountAvailable < (-PermissibleOverbook) || proposedNewAmountAvailable > m_capacity)
            {
                return(false);
            }
            request.QuantityObtained = request.QuantityDesired;
            request.ResourceObtained = this;
            Substance material = m_material as Substance;

            if (material != null)
            {
                material.Remove(request.QuantityDesired);
            }
            else if (m_material is Mixture)
            {
                ((Mixture)m_material).RemoveMaterial(request.QuantityDesired);
            }
            else
            {
                Debug.Assert(false, "Unknown IMaterial type : " + m_material.GetType().Name);
            }
            request.ResourceObtainedFrom = this;
            return(true);
        }
예제 #2
0
        public void TestMaterialSpecifications()
        {
            Model model = new Model("Test Model", Guid.NewGuid());
            BasicReactionSupporter brs = new BasicReactionSupporter();

            InitializeForTesting(brs);

            Guid         city      = Guid.NewGuid();
            Guid         dist      = Guid.NewGuid();
            Guid         perr      = Guid.NewGuid();
            MaterialType waterType = (MaterialType)brs.MyMaterialCatalog["Water"];

            Substance w1 = (Substance)waterType.CreateMass(100, 37);

            w1.SetMaterialSpec(city, 100);
            Debug.WriteLine("\r\nCreating 100 kg of City Water (" + city + ").");
            DumpMaterialSpecs(w1);

            Substance w2 = (Substance)waterType.CreateMass(40, 37);

            w2.SetMaterialSpec(dist, 40);
            Debug.WriteLine("\r\nCreating 40 kg of Distilled Water (" + dist + ").");
            DumpMaterialSpecs(w2);

            Debug.WriteLine("\r\nAdding city water to distilled water.");
            w1.Add(w2);
            DumpMaterialSpecs(w1);

            Debug.WriteLine("\r\nRemoving 60 kg of the blended water.");
            Substance w3 = w1.Remove(60);

            DumpMaterialSpecs(w1);
            DumpMaterialSpecs(w3);

            Debug.WriteLine("\r\nCloning the blended water.");
            Substance w4 = (Substance)w3.Clone();

            DumpMaterialSpecs(w4);

            Debug.WriteLine("\r\nPurifying the cloned blended water.");
            w4.ConvertMaterialSpec(dist, city);
            Debug.WriteLine("Purified clone:");
            DumpMaterialSpecs(w4);
            Debug.WriteLine("...and original water:");
            DumpMaterialSpecs(w3);

            double amtDistilled = w1.GetMaterialSpec(dist);

            Debug.WriteLine("\r\nThere are " + amtDistilled + " kg of distilled water.");

            w1.ConvertMaterialSpec(dist, city);
            Debug.WriteLine("\r\nConverting distilled water to city water.");
            DumpMaterialSpecs(w1);
        }