/// <summary> /// /// </summary> /// <param name="element"></param> /// <param name="rawInputModels"></param> /// <returns></returns> public static List <InputModel> GenerateSimInputModels(XElement element, List <InputModel> rawInputModels) { List <InputModel> simInputModels = new List <InputModel>(); foreach (XElement xe in element.Elements()) { //Firstly find the target InputModel rawInputModel = rawInputModels.Where(x => x.FileName == xe.Attribute("href").Value.ToString()).FirstOrDefault(); //Then clone the raw model InputModel simInputModel = Cloner.Clone(rawInputModel); simInputModels.Add(simInputModel); //Then apply any overrides foreach (XElement child in xe.Elements()) { if (child.Elements().Count() == 0) { if (child.Value != null) { simInputModel.Overrides.Add(child.Name.ToString(), child.Value); } else { //Should have an index simInputModel.Overrides.Add(child.Name.ToString(), child.Attribute("index").Value); } } else { //Should be override parameters //Check----- if (child.Attribute("Active").Value == "true") { simInputModel.Overrides.Add(child.Name.ToString(), child.Element("Value").Value); } } } //Apply any overrides simInputModel.ApplyOverrides(); } return(null); }
public static Simulation GenerateSimulationXML(Project Project, XElement simElement, List <InputModel> allModels) { List <InputModel> simModels = new List <InputModel>(); int startYear = 0; int endYear = 0; //Get the models from the filenames of the simualtion pointers foreach (XElement element in simElement.Elements()) { if (element.Name.ToString() == "StartYear") { startYear = element.Value.ToString() == "default" ? 0 : int.Parse(element.Value.ToString()); } else if (element.Name.ToString() == "EndYear") { endYear = element.Value.ToString() == "default" ? 0 : int.Parse(element.Value.ToString()); } else { try { string fileName = element.Attribute("href").Value.ToString().Replace("\\", "/"); if (fileName.Contains("./")) { fileName = Path.GetDirectoryName(Project.FileName).Replace("\\", "/") + "/" + fileName; } InputModel model = allModels.Where(im => im.FileName == fileName).FirstOrDefault(); InputModel model2 = Cloner.DeepClone <InputModel>(model); string modelDescription = model.GetType().Name; modelDescription += (":" + model.Name); //Check for child nodes foreach (XElement childElement in element.Elements()) { if (childElement.Name == "OverrideParameter") { if (childElement.Attribute("Keyword").Value.ToString() == "" && childElement.Attribute("Active").Value.ToString() != "false") { //Add the override to the model model2.Overrides.Add(childElement.Attribute("Keyword").Value, childElement.Element("Value").Value); modelDescription += (";" + childElement.Attribute("Keyword").Value + "=" + childElement.Element("Value").Value); } } else { //Probably a climate file override if (element.Name == "ptrStation") { if (childElement.Attribute("index") != null) { model2.Overrides.Add(childElement.Name.ToString(), childElement.Attribute("index").Value); modelDescription += (";" + childElement.Name.ToString() + "=" + childElement.Attribute("index").Value); } else { model2.Overrides.Add(childElement.Name.ToString(), childElement.Value); modelDescription += (";" + childElement.Name.ToString() + "=" + childElement.Value); } } } } if (element.Name == "ptrStation") { //Map the data to the original model ClimateInputModel cimNew = (ClimateInputModel)model2; ClimateInputModel cimOrig = (ClimateInputModel)model; cimNew.Rain = cimOrig.Rain; cimNew.MaxT = cimOrig.MaxT; cimNew.MinT = cimOrig.MinT; cimNew.PanEvap = cimOrig.PanEvap; cimNew.Radiation = cimOrig.Radiation; cimNew.VP = cimOrig.VP; //cimNew.StartDate = cimOrig.StartDate; //cimNew.EndDate = cimOrig.EndDate; } model2.ApplyOverrides(); model2.LongName = modelDescription; simModels.Add(model2); } catch (Exception e) { } } } return(new Simulation(Project, simModels, startYear, endYear)); }