private void SetModel(XMileModel model) { cbGroups.Items.Clear(); cbVariables.Items.Clear(); var groups = model == null?_stateMachine.Models.GetGroups() : model.Groups; if (groups.Any()) { cbGroups.Items.Add(All); cbGroups.Items.AddRange(groups.OrderBy(x => x.Name).ToArray()); foreach (var group in groups) { cbVariables.Items.AddRange(group.Entities.ToArray()); } cbGroups.Enabled = true; } else { cbGroups.Enabled = false; if (model == null) { cbVariables.Items.AddRange(_stateMachine.Models.GetVariables().ToArray()); } else { cbVariables.Items.AddRange(model.Variables.ToArray()); } } btnSubModelProcess.Enabled = model != null; }
public async Task ParseStocks(XContainer variables, XMileModel model) { if (variables == null) { throw new ArgumentNullException(nameof(variables)); } if (model == null) { throw new ArgumentNullException(nameof(model)); } foreach (var stock in variables.Descendants(_ns + "stock")) { await Stock.CreateInstance(stock.FirstAttribute.Value, model, ParseEquation(stock), ParseInflows(stock), ParseOutflows(stock), ParseGraphicalFunction(stock), ParseRange(stock, "range"), ParseRange(stock, "scale"), ParseNonNegative(stock), ParseAccess(stock)); } }
public void ParseModules(XContainer variables, XMileModel model) { if (variables == null) { throw new ArgumentNullException(nameof(variables)); } if (model == null) { throw new ArgumentNullException(nameof(model)); } foreach (var module in variables.Descendants(_ns + "module")) { Module.CreateInstance(model, module.FirstAttribute.Value, ParseConnects(module)); } }
public async Task ParseAuxiliaries(XContainer variables, XMileModel model) { if (variables == null) { throw new ArgumentNullException(nameof(variables)); } if (model == null) { throw new ArgumentNullException(nameof(model)); } foreach (var auxiliary in variables.Descendants(_ns + "aux")) { await Auxiliary.CreateInstance(auxiliary.FirstAttribute.Value, model, ParseEquation(auxiliary), ParseGraphicalFunction(auxiliary), ParseRange(auxiliary, "range"), ParseRange(auxiliary, "scale"), ParseNonNegative(auxiliary), ParseAccess(auxiliary)); } }
public async Task <XMileModel> ParseModel(XElement xModel) { if (xModel == null) { throw new NullReferenceException(nameof(_xDoc.Root)); } var variables = xModel.Descendants(_ns + "variables"); var model = new XMileModel(xModel.FirstAttribute?.Value); foreach (var variable in variables) { await ParseStocks(variable, model); await ParseFlows(variable, model); await ParseAuxiliaries(variable, model); ParseGroups(variable, model); ParseModules(variable, model); } return(model); }
/// <summary> /// Add a model /// </summary> /// <param name="model"></param> public void Add(XMileModel model) { Models.Add(model); }