/// <summary> /// return a list of resource group cpmponents available /// </summary> /// <returns>A list of names of components</returns> public IEnumerable <string> GetResourceGroupsAvailable() { List <string> results = new List <string>(); Zone zone = this.FindAncestor <Zone>(); if (!(zone is null)) { ResourcesHolder resources = zone.FindChild <ResourcesHolder>(); if (!(resources is null)) { foreach (var model in resources.FindAllChildren <ResourceBaseWithTransactions>()) { results.Add(model.Name); } } } return(results.AsEnumerable()); }
/// <summary> /// Gets the names of all the items for each ResourceGroup whose items you want to put into a dropdown list. /// eg. "AnimalFoodStore,HumanFoodStore,ProductStore" /// Will create a dropdown list with all the items from the AnimalFoodStore, HumanFoodStore and ProductStore. /// /// To help uniquely identify items in the dropdown list will need to add the ResourceGroup name to the item name. /// eg. The names in the drop down list will become AnimalFoodStore.Wheat, HumanFoodStore.Wheat, ProductStore.Wheat, etc. /// </summary> /// <returns>Will create a string array with all the items from the AnimalFoodStore, HumanFoodStore and ProductStore. /// to help uniquely identify items in the dropdown list will need to add the ResourceGroup name to the item name. /// eg. The names in the drop down list will become AnimalFoodStore.Wheat, HumanFoodStore.Wheat, ProductStore.Wheat, etc. </returns> private string[] GetCLEMResourceNames(Type[] resourceNameResourceGroups) { List <string> result = new List <string>(); IModel zoneCLEM = model.FindAncestor <Zone>(); ResourcesHolder resHolder = zoneCLEM.FindChild <ResourcesHolder>(); if (resourceNameResourceGroups != null) { // resource groups specified (use them) foreach (Type resGroupType in resourceNameResourceGroups) { IModel resGroup = resHolder.Children.Find(c => resGroupType.IsAssignableFrom(c.GetType())); if (resGroup != null) //see if this group type is included in this particular simulation. { foreach (IModel item in resGroup.Children.Where(a => a.Enabled)) { if (item.GetType() != typeof(Memo)) { result.Add(resGroup.Name + "." + item.Name); } } } } } else { // no resource groups specified so use all avaliable resources foreach (IModel resGroup in resHolder.FindAllChildren <IModel>()) { foreach (IModel item in resGroup.Children) { if (item.GetType() != typeof(Memo)) { result.Add(resGroup.Name + "." + item.Name); } } } } return(result.ToArray()); }