/// <summary> /// Creates a new resource manager. /// </summary> /// <param name="model">The model to which this resource manager belongs. It can be null.</param> /// <param name="name">The name of this resource manager.</param> /// <param name="guid">The guid by which this resource manager will be known.</param> /// <param name="priorityEnabled">If true, this resource manager will handle prioritized resource requests.</param> public ResourceManager(IModel model, string name, Guid guid, bool priorityEnabled = false) { InitializeIdentity(model, name, null, guid); SupportsPrioritizedRequests = priorityEnabled; m_onResourceRequestAborting = OnResourceRequestAborting; m_waiters = new RscWaiterList(SupportsPrioritizedRequests); m_resources = new ArrayList(); IMOHelper.RegisterWithModel(this); }
/// <summary> /// Initializes a new instance of the <see cref="MaterialResourceItem"/> class. /// </summary> /// <param name="model">The model in which the MaterialResourceItem runs.</param> /// <param name="name">The name under which the MaterialResourceItem will be known.</param> /// <param name="guid">The unique identifier of the MaterialResourceItem.</param> /// <param name="mt">The MaterialType of the substance managed in this MaterialResourceItem.</param> /// <param name="initialQuantity">The initial quantity of the substance.</param> /// <param name="initialTemp">The initial temperature of the substance.</param> /// <param name="initialCapacity">The initial capacity of the MaterialResourceItem to hold the substance.</param> /// <param name="materialSpecGuids">The material specification guids. See Material Specifications tech note.</param> /// <exception cref="System.ApplicationException">A MaterialResourceItem cannot contain a spec with the same Guid as that of its own core material type.</exception> public MaterialResourceItem(IModel model, string name, Guid guid, MaterialType mt, double initialQuantity, double initialTemp, double initialCapacity, ICollection materialSpecGuids) { if (materialSpecGuids == null) { materialSpecGuids = s_empty_List; } m_guid = guid; m_name = name; m_model = model; m_initialCapacity = initialCapacity; m_initialQuantity = initialQuantity; m_initialTemperature = initialTemp; MaterialType = mt; MaterialSpecificationGuids = materialSpecGuids; m_waiters = new ArrayList(); Initialize(); if (s_diagnostics) { m_material.MaterialChanged += m_material_MaterialChanged; } m_onResourceRequestAborting = OnResourceRequestAborting; // Ensure that no specifications contain the same Guid as the MRI's core material type. foreach (object obj in MaterialSpecificationGuids) { Guid msGuid; if (obj is Guid) { msGuid = (Guid)obj; } else { msGuid = (Guid)((DictionaryEntry)obj).Key; } if (msGuid == MaterialType.Guid) { throw new ApplicationException("A MRI cannot contain a spec with the same Guid as that of its own core material type."); } } if (m_model != null) { if (model is IModelWithResources) { ((IModelWithResources)m_model).OnNewResourceCreated(this); } m_model.ModelObjects.Add(guid, this); } }