public void ConvertDefaults(List <DefaultAssignment> defaults) { ProductModel pm = ModelWorkspace.CreateFromFile(pmxFile).ProductModel; var pmProductModelStructure = pm.ProductModelStructure; foreach (var defaultAssignment in defaults) { //var characteristic = _parseUtils.FindSelectionCriteriaCharacteristic( defaultAssignment.HierarchyElement ); //var precondition = _parseUtils.GeneratePrecondition( characteristic, defaultAssignment.HierarchyElement ); var model = defaultAssignment.Model; var coutry = defaultAssignment.Country; var variant = defaultAssignment.Variant; var defaultModel = new LogicModel(); defaultModel.AddRule("", "", ExprBld.IfThen( (ExprBld.Variables["Model"] == model) .And(ExprBld.Variables["coutry"] == coutry) .And(ExprBld.Variables["variant"] == variant), ExprBld.Variables[defaultAssignment.Assignment.Characteristic]) == defaultAssignment.Assignment.Value); var compiler = new Core.Compile.Compilation.Compiler(defaultModel); var defaultSolveData = compiler.CompileNddSolve(); var scopedDefaultData = new ScopedDefaultData(new[] { "model", "country", "variant" }, defaultSolveData); var packagedModelSerializer = new PackagedModelSerializer(); var packagedModel = packagedModelSerializer.LoadAsync(cameronPackage).Result.CopyAndInclude(scopedDefaultData); packagedModelSerializer.SaveAsync(cameronPackage, new[] { packagedModel }).Wait(); } }
public List <ScopedDefaultData> CreateScopeDefaultData(List <DefaultAssignment> defaults, VariableCollection variables) { var scopedDefaultDatas = new List <ScopedDefaultData>(); foreach (var defaultAssignmentGroup in defaults.GroupBy(d => d.Assignment.Characteristic)) { var variableName = defaultAssignmentGroup.Key; Log.Info($"Adding default assignment for {variableName}"); string variableFullName = _variableLookup[variableName].FullyQualifiedName; var defaultModel = CreateDefaultModel(defaultAssignmentGroup, variableFullName, variables); //defaultModel. var compiler = new Core.Compile.Compilation.Compiler(defaultModel); var defaultSolveData = compiler.CompileNddSolve(); scopedDefaultDatas.Add(new ScopedDefaultData(new[] { MODEL_VARIABLE, COUNTRY_VARIABLE, VARIANT_VARIABLE }, defaultSolveData, null, new[] { variableFullName })); } return(scopedDefaultDatas); }