/// <summary> /// Computes the virtual map after the execution of this operator /// Increments any existing virtual maps (if given) /// </summary> /// <param name="ExistingVirtualMap"></param> /// <returns></returns> public override VirtualMap ComputeVirtualMap(VirtualMap ExistingVirtualMap = null) { // Adds the prefix 'data_Entity' to attributes VirtualRule TargetVRule = new VirtualRule(TargetEntity.Element, TargetEntity.Alias); // Fetch original map for target entity MapRule TargetRule = ModelMap.Rules.First(Rule => Rule.Source.Name == TargetEntity.Element.Name && Rule.IsMain); foreach (DataAttribute Attribute in TargetEntity.Element.Attributes) { string AttributeRule = TargetRule.Rules.First(Rule => Rule.Key == Attribute.Name).Value; TargetVRule.AddRule(Attribute.Name, $"data_{TargetEntity.Element.Name}.{AttributeRule}"); } // Also process source entity rule VirtualRule SourceVRule = new VirtualRule(SourceEntity.Element, SourceEntity.Alias); // Fetch original map for source entity MapRule SourceRule = ModelMap.Rules.First(Rule => Rule.Source.Name == SourceEntity.Element.Name && Rule.IsMain); foreach (DataAttribute Attribute in SourceEntity.Element.Attributes) { string AttributeRule = SourceRule.Rules.First(Rule => Rule.Key == Attribute.Name).Value; SourceVRule.AddRule(Attribute.Name, AttributeRule); } VirtualMap VMap = new VirtualMap(new List <VirtualRule>()); VMap.Rules.AddRange(new VirtualRule[] { SourceVRule, TargetVRule }); if (ExistingVirtualMap != null) { // Check if source rule already exist if (ExistingVirtualMap.Rules.Exists(Rule => Rule.SourceERElement.Name == SourceEntity.Element.Name && Rule.Alias == SourceEntity.Alias)) { VMap.Rules.Remove(SourceVRule); } // Check if the new rules already exists if (ExistingVirtualMap.Rules.Exists(Rule => Rule.SourceERElement.Name == TargetEntity.Element.Name && Rule.Alias == TargetEntity.Alias)) { VMap.Rules.Remove(TargetVRule); } VMap.Rules.AddRange(ExistingVirtualMap.Rules); } return(VMap); }
/// <summary> /// Generates a virtual map for this operator /// </summary> /// <param name="ExistingVirtualMap"></param> /// <returns></returns> public override VirtualMap ComputeVirtualMap(VirtualMap ExistingVirtualMap = null) { // If the virtual map is not set we will use the IModelObject object if (ExistingVirtualMap == null && Map is ModelMapping) { ExistingVirtualMap = VirtualMap.FromModelMap((ModelMapping)Map); } else if (ExistingVirtualMap == null && Map is VirtualMap) { ExistingVirtualMap = Map as VirtualMap; } // Store new rules List <VirtualRule> NewRules = new List <VirtualRule>(); // Iterate arguments and keep rules that are either a BooleanExpr(true) or define a value to an attribute foreach (ProjectArgument Argument in Arguments.Where(Arg => Arg.Expression.IsAddingOrForcingAFieldVisible)) { // Check if rule already exists and update it VirtualRule ElementRule = NewRules.Find(R => R.SourceERElement.Name == Argument.ParentEntity.GetName() && R.Alias == Argument.ParentEntity.Alias); string RuleValue = ExistingVirtualMap.GetRuleValue(Argument.ParentEntity.GetAliasOrName(), Argument.Attribute.Name); if (ElementRule == null) { // Create new entry VirtualRule ArgRule = new VirtualRule(Argument.ParentEntity.Element, Argument.ParentEntity.Alias); ArgRule.Rules.Add(Argument.Attribute.Name, RuleValue); NewRules.Add(ArgRule); } else { ElementRule.Rules.Add(Argument.Attribute.Name, RuleValue); } } return(new VirtualMap(NewRules)); }