private void PostLoad(ConfigFile parent, string file, string[] macros, IEnumerable <KeyValue> variables) { FilePath = file; Parent = parent; Variables.Add(new KeyValue("THIS_CONFIG_PATH", Path.GetDirectoryName(AbsoluteFilePath))); Variables.AddRange(variables); // Load all dependencies foreach (var dependFile in Files) { var dependFilePath = ExpandString(dependFile, false); if (!Path.IsPathRooted(dependFilePath)) { dependFilePath = Path.Combine(Path.GetDirectoryName(AbsoluteFilePath), dependFilePath); } var subMapping = Load(this, dependFilePath, macros, variables); if (subMapping != null) { subMapping.FilePath = dependFile; References.Add(subMapping); } } // Clear all depends file Files.Clear(); // Add this mapping file GetRoot().MapIdToFile.Add(Id, this); }
/// <summary> /// Get the model collection : /// SubModel are transformed as Module /// InlineModel are transformed as Group /// </summary> /// <param name="parentModel"></param> /// <returns></returns> //TODO change name SubModel into Module - InlineModel into Group public virtual ModelCollection GetModelCollection(Model parentModel) { var models = new ModelCollection(); foreach (var subModel in SubModels) { var modelCollection = subModel.GetModelCollection(null); Variables.AddRange(modelCollection.GetVariables()); Groups.AddRange(modelCollection.GetGroups()); // Add module Module.CreateInstance(this, subModel.Name); models.AddRange(modelCollection); } foreach (var subModel in InlineModels) { var modelCollection = subModel.GetModelCollection(this); var variables = modelCollection.GetVariables(); Variables.AddRange(variables); // Add group for each inline model // InlineModel.Name are the same as their parentModel, therefore we use the className var group = new Group(subModel.GetType().Name, Name, variables.Names); Groups.Add(group); } models[0] = this; return(models); }
/// <summary> /// Add another model artefacts to the actual model /// </summary> /// <param name="model"></param> public void Add(XMileModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } Variables.AddRange(model.Variables); Groups.AddRange(model.Groups); }
public DataContext AddVariables(IEnumerable <VariableSymbol> variables) { if (variables == null) { throw new ArgumentNullException(nameof(variables)); } var newVariables = Variables.AddRange(variables); return(WithVariables(newVariables)); }
public Phase(string symbol, ThermodynamicSystem system) { Name = symbol; _system = system; Temperature = _system.VariableFactory.CreateVariable("T" + symbol, "Temperature", PhysicalDimension.Temperature); Pressure = _system.VariableFactory.CreateVariable("p" + symbol, "Pressure", PhysicalDimension.Pressure); SpecificEnthalpy = _system.VariableFactory.CreateVariable("h" + symbol, "Molar specific enthalpy", PhysicalDimension.SpecificMolarEnthalpy); TotalEnthalpy = _system.VariableFactory.CreateVariable("H" + symbol, "Total enthalpy", PhysicalDimension.Enthalpy); TotalVolumeflow = _system.VariableFactory.CreateVariable("V" + symbol, "Volume flow", PhysicalDimension.VolumeFlow); TotalMolarflow = _system.VariableFactory.CreateVariable("n" + symbol, "Total molar flow", PhysicalDimension.MolarFlow); TotalMassflow = _system.VariableFactory.CreateVariable("m" + symbol, "Total mass flow", PhysicalDimension.MassFlow); Density = _system.VariableFactory.CreateVariable("rho" + symbol, "Density", PhysicalDimension.MassDensity); DensityMolar = _system.VariableFactory.CreateVariable("rhom" + symbol, "Density", PhysicalDimension.MolarDensity); TotalMolarVolume = _system.VariableFactory.CreateVariable("v" + symbol, "Total molar volume", PhysicalDimension.MolarVolume); Variables.Add(Temperature); Variables.Add(Pressure); Variables.Add(SpecificEnthalpy); Variables.Add(Density); Variables.Add(DensityMolar); Variables.Add(TotalEnthalpy); Variables.Add(TotalVolumeflow); Variables.Add(TotalMolarflow); Variables.Add(TotalMassflow); foreach (var comp in system.Components) { ComponentMolarFraction.Add(_system.VariableFactory.CreateVariable("x" + symbol, comp.ID, "Molar Fraction of component " + comp.ID, PhysicalDimension.MolarFraction)); ComponentMassFraction.Add(_system.VariableFactory.CreateVariable("w" + symbol, comp.ID, "Molar Fraction of component " + comp.ID, PhysicalDimension.MassFraction)); ComponentMolarflow.Add(_system.VariableFactory.CreateVariable("n" + symbol, comp.ID, "Molar flow of component " + comp.ID, PhysicalDimension.MolarFlow)); ComponentMassflow.Add(_system.VariableFactory.CreateVariable("m" + symbol, comp.ID, "Mass flow of component " + comp.ID, PhysicalDimension.MassFlow)); ComponentMolarVolume.Add(_system.VariableFactory.CreateVariable("v" + symbol, comp.ID, "Molar volume of component " + comp.ID, PhysicalDimension.MolarVolume)); ComponentEnthalpy.Add(_system.VariableFactory.CreateVariable("h" + symbol, comp.ID, "Specific Molar Enthalpy of component " + comp.ID, PhysicalDimension.SpecificMolarEnthalpy)); } Variables.AddRange(ComponentMolarFraction); Variables.AddRange(ComponentMassFraction); Variables.AddRange(ComponentMolarflow); Variables.AddRange(ComponentMassflow); Variables.AddRange(ComponentMolarVolume); Variables.AddRange(ComponentEnthalpy); }
public Bonus(TextSpan value) { AddPropertyDefinitions(() => new[] { IsEquipment?CommonProperties.ConditionForEquipment: CommonProperties.Conditions, }); if (!value.TryRemoveInfix("|", out var category, out value)) { throw new ParseFailedException(value, "Unable to parse bonus."); } if (!value.TryRemoveInfix("|", out var variableSpan, out value)) { throw new ParseFailedException(value, "Unable to parse bonus."); } Category = category.Value; foreach (var part in value.Split('|')) { // This is fine, Provided that the only inheritor is EquipmentBonus // and it only overrides the IsEquipment property // ReSharper disable once VirtualMemberCallInConstructor AddField(part); } Formula ??= "%CHOICEVALUE"; switch (Category) { case "ITEMCOST": Variables.Add("Cost"); if (!variableSpan.TryRemovePrefix("TYPE.", out var types)) { throw new ParseFailedException(value, "Unable to parse bonus."); } var allTypes = types.Value.Split('.').Select(t => $"item.IsType(\"{t}\")").ToList(); Properties.GetList <Condition>("Conditions") .Add(new EquipmentTypeCondition(false, allTypes.Count, allTypes)); break; default: Variables.AddRange(variableSpan.Value.Split(',')); break; } }
protected EditVariablesBaseViewModel(ResinApiClient client, IEnumerable <GenericEnvironmentVariable> variables) { Client = client ?? throw new ArgumentNullException(nameof(client)); Variables.AddRange(variables.Select(v => new EnvironmentVariableViewModel(v))); InitializeCommands(); }
private void FromCurrentFormat(byte[] bytes, int offset = 0) { Signature = bytes.GetString(0, 2); Version = bytes.ToByte(2); Length = bytes.Length; offset += 3; int parts = 1; this.parentClass?.PassMessage(parts, $"PRG Header 1 - Offset {offset}"); //Get all inputs Inputs.AddRange(GetArray(bytes, InputPoint.GetCount(FileVersion), InputPoint.GetSize(FileVersion), ref offset) .Select(i => new InputPoint(i, 0, FileVersion))); parts += Inputs.Count; this.parentClass?.PassMessage(parts, $"InputPoints {Inputs.Count} - Offset {offset}"); //Get all outputs Outputs.AddRange(GetArray(bytes, OutputPoint.GetCount(FileVersion), OutputPoint.GetSize(FileVersion), ref offset) .Select(i => new OutputPoint(i, 0, FileVersion))); parts += Outputs.Count; this.parentClass?.PassMessage(parts, $"OutputPoints {Outputs.Count} - Offset {offset}"); //Get all variables Variables.AddRange(GetArray(bytes, VariablePoint.GetCount(FileVersion), VariablePoint.GetSize(FileVersion), ref offset) .Select(i => new VariablePoint(i, 0, FileVersion))); parts += Variables.Count; this.parentClass?.PassMessage(parts, $"VariablePoints {Variables.Count} - Offset {offset}"); //Get all programs Programs.AddRange(GetArray(bytes, ProgramPoint.GetCount(FileVersion), ProgramPoint.GetSize(FileVersion), ref offset) .Select(i => new ProgramPoint(i, 0, FileVersion))); parts += Programs.Count; this.parentClass?.PassMessage(parts, $"ProgramPoints {Programs.Count} - Offset {offset}"); //Get all controllers Controllers.AddRange(GetArray(bytes, ControllerPoint.GetCount(FileVersion), ControllerPoint.GetSize(FileVersion), ref offset) .Select(i => new ControllerPoint(i, 0, FileVersion))); parts += Controllers.Count; this.parentClass?.PassMessage(parts, $"ControllerPoints {Controllers.Count} - Offset {offset}"); //Get all screens Screens.AddRange(GetArray(bytes, ScreenPoint.GetCount(FileVersion), ScreenPoint.GetSize(FileVersion), ref offset) .Select(i => new ScreenPoint(i, 0, FileVersion))); parts += Screens.Count; this.parentClass?.PassMessage(parts, $"ScreenPoints {Screens.Count} - Offset {offset}"); //Get all graphics //TODO: NOT MINE: Constants to object static Size(FileVersion) Count(FileVersion) Graphics.AddRange(GetArray(bytes, GraphicPoint.GetCount(FileVersion), GraphicPoint.GetSize(FileVersion), ref offset) .Select(i => new GraphicPoint(i, 0, FileVersion))); parts += Graphics.Count; this.parentClass?.PassMessage(parts, $"GraphicPoints {Graphics.Count} - Offset {offset}"); Users.AddRange(GetArray(bytes, UserPoint.GetCount(FileVersion), UserPoint.GetSize(FileVersion), ref offset) .Select(i => new UserPoint(i, 0, FileVersion))); parts += Users.Count; this.parentClass?.PassMessage(parts, $"UserPoints {Users.Count} - Offset {offset}"); CustomUnits.Digital.AddRange(GetArray(bytes, CustomDigitalUnitsPoint.GetCount(FileVersion), CustomDigitalUnitsPoint.GetSize(FileVersion), ref offset) .Select(i => new CustomDigitalUnitsPoint(i, 0, FileVersion))); parts += CustomUnits.Digital.Count; this.parentClass?.PassMessage(parts, $"CustomUnits.DigitalPoints {CustomUnits.Digital.Count} - Offset {offset}"); Tables.AddRange(GetArray(bytes, TablePoint.GetCount(FileVersion), TablePoint.GetSize(FileVersion), ref offset) .Select(i => new TablePoint(i, 0, FileVersion))); parts += Tables.Count; this.parentClass?.PassMessage(parts, $"TablePoints {Tables.Count} - Offset {offset}"); Settings = new Settings( GetObject(bytes, Settings.GetSize(FileVersion), ref offset), 0, FileVersion); parts += 1; this.parentClass?.PassMessage(parts, $"Settings 1 - Offset {offset}"); Schedules.AddRange(GetArray(bytes, SchedulePoint.GetCount(FileVersion), SchedulePoint.GetSize(FileVersion), ref offset) .Select(i => new SchedulePoint(i, 0, FileVersion))); parts += Schedules.Count; this.parentClass?.PassMessage(parts, $"SchedulePoints {Schedules.Count} - Offset {offset}"); Holidays.AddRange(GetArray(bytes, HolidayPoint.GetCount(FileVersion), HolidayPoint.GetSize(FileVersion), ref offset) .Select(i => new HolidayPoint(i, 0, FileVersion))); parts += Holidays.Count; this.parentClass?.PassMessage(parts, $"HolidayPoints {Holidays.Count} - Offset {offset}"); Monitors.AddRange(GetArray(bytes, MonitorPoint.GetCount(FileVersion), MonitorPoint.GetSize(FileVersion), ref offset) .Select(i => new MonitorPoint(i, 0, FileVersion))); parts += Monitors.Count; this.parentClass?.PassMessage(parts, $"MonitorPoints {Monitors.Count} - Offset {offset}"); ScheduleCodes.AddRange(GetArray(bytes, ScheduleCode.GetCount(FileVersion), ScheduleCode.GetSize(FileVersion), ref offset) .Select(i => new ScheduleCode(i, 0, FileVersion))); parts += ScheduleCodes.Count; this.parentClass?.PassMessage(parts, $"ScheduleCodes {ScheduleCodes.Count} - Offset {offset}"); HolidayCodes.AddRange(GetArray(bytes, HolidayCode.GetCount(FileVersion), HolidayCode.GetSize(FileVersion), ref offset) .Select(i => new HolidayCode(i, 0, FileVersion))); parts += HolidayCodes.Count; this.parentClass?.PassMessage(parts, $"HolidayCodes {HolidayCodes.Count} - Offset {offset}"); int pcode_offset = offset; var ProgramCodeBytes = bytes.ToBytes(offset, ProgramCode.GetSize(FileVersion)); ProgramCodes.AddRange(GetArray(bytes, ProgramCode.GetCount(FileVersion), ProgramCode.GetSize(FileVersion), ref offset) //.Select(i => new ProgramCode(i, this, 0, FileVersion))); .Select(i => new ProgramCode())); ProgramCodes[0] = new ProgramCode(ProgramCodeBytes, this, 0, FileVersion); parts += 1; this.parentClass?.PassMessage(parts, $"ProgramCodes 1 - Offset {pcode_offset+2000}"); for (int i = 1; i < ProgramCode.GetCount(FileVersion); i++) { pcode_offset += ProgramCode.GetSize(FileVersion); ProgramCodeBytes = bytes.ToBytes(pcode_offset, ProgramCode.GetSize(FileVersion)); ProgramCodes[i] = new ProgramCode(ProgramCodeBytes, this, 0, FileVersion); parts += 1; this.parentClass?.PassMessage(parts, $"ProgramCodes {i+1} - Offset {pcode_offset+2000}"); //Debug.WriteLine($"Leído ProgramCode[{i}]"); } CustomUnits.Analog.AddRange(GetArray(bytes, CustomAnalogUnitsPoint.GetCount(FileVersion), CustomAnalogUnitsPoint.GetSize(FileVersion), ref offset) .Select(i => new CustomAnalogUnitsPoint(i, 0, FileVersion))); parts += CustomUnits.Analog.Count; this.parentClass?.PassMessage(parts, $"CustomUnits.AnalogPoints {CustomUnits.Analog.Count} - Offset {offset}"); CheckOffset(offset, Length); UpdateCustomUnits(); }
private void FromCurrentFormat(byte[] bytes, int offset = 0) { Signature = bytes.GetString(0, 2); Version = bytes.ToByte(2); Length = bytes.Length; offset += 3; //Get all inputs Inputs.AddRange(GetArray(bytes, InputPoint.GetCount(FileVersion), InputPoint.GetSize(FileVersion), ref offset) .Select(i => new InputPoint(i, 0, FileVersion))); //Get all outputs Outputs.AddRange(GetArray(bytes, OutputPoint.GetCount(FileVersion), OutputPoint.GetSize(FileVersion), ref offset) .Select(i => new OutputPoint(i, 0, FileVersion))); //Get all variables Variables.AddRange(GetArray(bytes, VariablePoint.GetCount(FileVersion), VariablePoint.GetSize(FileVersion), ref offset) .Select(i => new VariablePoint(i, 0, FileVersion))); //Get all programs Programs.AddRange(GetArray(bytes, ProgramPoint.GetCount(FileVersion), ProgramPoint.GetSize(FileVersion), ref offset) .Select(i => new ProgramPoint(i, 0, FileVersion))); //Get all controllers Controllers.AddRange(GetArray(bytes, ControllerPoint.GetCount(FileVersion), ControllerPoint.GetSize(FileVersion), ref offset) .Select(i => new ControllerPoint(i, 0, FileVersion))); //Get all screens Screens.AddRange(GetArray(bytes, ScreenPoint.GetCount(FileVersion), ScreenPoint.GetSize(FileVersion), ref offset) .Select(i => new ScreenPoint(i, 0, FileVersion))); //Get all graphics //TODO: Constants to object static Size(FileVersion) Count(FileVersion) Graphics.AddRange(GetArray(bytes, GraphicPoint.GetCount(FileVersion), GraphicPoint.GetSize(FileVersion), ref offset) .Select(i => new GraphicPoint(i, 0, FileVersion))); Users.AddRange(GetArray(bytes, UserPoint.GetCount(FileVersion), UserPoint.GetSize(FileVersion), ref offset) .Select(i => new UserPoint(i, 0, FileVersion))); CustomUnits.Digital.AddRange(GetArray(bytes, CustomDigitalUnitsPoint.GetCount(FileVersion), CustomDigitalUnitsPoint.GetSize(FileVersion), ref offset) .Select(i => new CustomDigitalUnitsPoint(i, 0, FileVersion))); Tables.AddRange(GetArray(bytes, TablePoint.GetCount(FileVersion), TablePoint.GetSize(FileVersion), ref offset) .Select(i => new TablePoint(i, 0, FileVersion))); Settings = new Settings( GetObject(bytes, Settings.GetSize(FileVersion), ref offset), 0, FileVersion); Schedules.AddRange(GetArray(bytes, SchedulePoint.GetCount(FileVersion), SchedulePoint.GetSize(FileVersion), ref offset) .Select(i => new SchedulePoint(i, 0, FileVersion))); Holidays.AddRange(GetArray(bytes, HolidayPoint.GetCount(FileVersion), HolidayPoint.GetSize(FileVersion), ref offset) .Select(i => new HolidayPoint(i, 0, FileVersion))); Monitors.AddRange(GetArray(bytes, MonitorPoint.GetCount(FileVersion), MonitorPoint.GetSize(FileVersion), ref offset) .Select(i => new MonitorPoint(i, 0, FileVersion))); ScheduleCodes.AddRange(GetArray(bytes, ScheduleCode.GetCount(FileVersion), ScheduleCode.GetSize(FileVersion), ref offset) .Select(i => new ScheduleCode(i, 0, FileVersion))); HolidayCodes.AddRange(GetArray(bytes, HolidayCode.GetCount(FileVersion), HolidayCode.GetSize(FileVersion), ref offset) .Select(i => new HolidayCode(i, 0, FileVersion))); int pcode_offset = offset; var ProgramCodeBytes = bytes.ToBytes(offset, ProgramCode.GetSize(FileVersion)); ProgramCodes.AddRange(GetArray(bytes, ProgramCode.GetCount(FileVersion), ProgramCode.GetSize(FileVersion), ref offset) //.Select(i => new ProgramCode(i, this, 0, FileVersion))); .Select(i => new ProgramCode())); ProgramCodes[0] = new ProgramCode(ProgramCodeBytes, this, 0, FileVersion); for (int i = 1; i < ProgramCode.GetCount(FileVersion); i++) { pcode_offset += ProgramCode.GetSize(FileVersion); ProgramCodeBytes = bytes.ToBytes(pcode_offset, ProgramCode.GetSize(FileVersion)); ProgramCodes[i] = new ProgramCode(ProgramCodeBytes, this, 0, FileVersion); Debug.WriteLine($"Leído ProgramCode[{i}]"); } CustomUnits.Analog.AddRange(GetArray(bytes, CustomAnalogUnitsPoint.GetCount(FileVersion), CustomAnalogUnitsPoint.GetSize(FileVersion), ref offset) .Select(i => new CustomAnalogUnitsPoint(i, 0, FileVersion))); CheckOffset(offset, Length); UpdateCustomUnits(); }
public TupleExpression(params LocalVariable[] variables) { Variables.AddRange(variables); }
public MaterialStream(string name, ThermodynamicSystem system) : base(name, system) { Class = "MaterialStream"; if (system.EquilibriumMethod.AllowedPhases == AllowedPhases.VLE) { Mixed = new Phase("", system); Liquid = new Phase("L", system); Vapor = new Phase("V", system); Vfmolar = system.VariableFactory.CreateVariable("VF", "Mole-based vapor fraction", PhysicalDimension.MolarFraction); Vfmolar.Group = "Equilibrium"; Beta = new Variable("d", 0.5, -100, 100, SI.nil, "Phase equilibrium defect"); Beta.Group = "Equilibrium"; MinVfBeta = new Variable("d2", 0.1, -100, 100, SI.nil, "min(Vapor fraction,Beta)"); MinVfBeta.Group = "Equilibrium"; MaxVfBeta = new Variable("d3", 0.1, -100, 100, SI.nil, "max(Vapor fraction, beta)"); MaxVfBeta.Group = "Equilibrium"; // AddVariable(MinVfBeta); // AddVariable(MaxVfBeta); MW = system.VariableFactory.CreateVariable("MW", "Average molar weight (bulk)", PhysicalDimension.MolarWeight); Gamma = new Variable[System.Components.Count]; KValues = new Variable[System.Components.Count]; for (int i = 0; i < System.Components.Count; i++) { KValues[i] = system.VariableFactory.CreateVariable("K", "Equilibrium distribution coefficient", PhysicalDimension.Dimensionless); KValues[i].Subscript = System.Components[i].ID; KValues[i].Group = "Equilibrium"; KValues[i].ValueInSI = 1.4; KValues[i].LowerBound = 1e-8; KValues[i].UpperBound = 1e6; System.EquationFactory.EquilibriumCoefficient(System, KValues[i], Mixed.Temperature, Mixed.Pressure, Liquid.ComponentMolarFraction, Vapor.ComponentMolarFraction, i); Gamma[i] = system.VariableFactory.CreateVariable("gamma", "Activity coefficient", PhysicalDimension.Dimensionless); Gamma[i].Subscript = System.Components[i].ID; Gamma[i].Group = "Equilibrium"; Gamma[i].ValueInSI = 1.4; System.EquationFactory.ActivityCoefficient(System, Gamma[i], Mixed.Temperature, Liquid.ComponentMolarFraction, i); } AddVariable(MW); AddVariable(Vfmolar); AddVariable(Beta); foreach (var vari in Mixed.Variables) { vari.Group = "Mixed"; } foreach (var vari in Liquid.Variables) { vari.Group = "Liquid"; } foreach (var vari in Vapor.Variables) { vari.Group = "Vapor"; } Variables.AddRange(Mixed.Variables); Variables.AddRange(Liquid.Variables); Variables.AddRange(Vapor.Variables); Variables.AddRange(KValues); Variables.AddRange(Gamma); Variables.Remove(Liquid.Temperature); Variables.Remove(Vapor.Temperature); Variables.Remove(Liquid.Pressure); Variables.Remove(Vapor.Pressure); for (int i = 0; i < System.Components.Count; i++) { Variables.Remove(Mixed.ComponentMolarVolume[i]); Variables.Remove(Vapor.ComponentMolarVolume[i]); Variables.Remove(Mixed.ComponentEnthalpy[i]); } } else { throw new NotSupportedException("Only VLE supported"); } }