private bool IsRuleApplicable(RichIdentity sourceUserIdentity, DisplayNameMapping rule, bool leftToRight) { string fromDispName = (leftToRight ? rule.Left : rule.Right); if (string.IsNullOrEmpty(fromDispName)) { return(false); } bool mappingRuleIsKnown = false; switch (rule.MappingRule) { case MappingRules.SimpleReplacement: case MappingRules.Ignore: case MappingRules.FormatStringComposition: case MappingRules.FormatStringDecomposition: mappingRuleIsKnown = true; break; default: TraceManager.TraceError("Unknown DisplayNameMapping.MappingRule type"); mappingRuleIsKnown = false; break; } if (!mappingRuleIsKnown) { return(false); } return(fromDispName.Equals(UserIdentityMappingConfigSymbols.ANY, StringComparison.OrdinalIgnoreCase) || fromDispName.Equals(sourceUserIdentity.DisplayName ?? string.Empty, StringComparison.OrdinalIgnoreCase)); }
private bool TryApplyMappingRule( RichIdentity sourceUserIdentity, bool leftToRight, RichIdentity mappingOutput, DisplayNameMapping rule) { if (IsRuleApplicable(sourceUserIdentity, rule, leftToRight)) { return(ApplyRule(sourceUserIdentity, leftToRight, mappingOutput, rule)); } else { return(false); } }
public void MyTestInitialize() { var mappingsCollection = new DisplayNameMappings(); mappingsCollection.DirectionOfMapping = MappingDirectionEnum.LeftToRight; foreach (var mapping in m_leftToRigthMappings) { DisplayNameMapping mappingRule = new DisplayNameMapping(); mappingRule.Left = mapping.Left; mappingRule.Right = mapping.Right; mappingRule.MappingRule = MappingRules.SimpleReplacement; mappingsCollection.DisplayNameMapping.Add(mappingRule); } m_mappings.Add(mappingsCollection); mappingsCollection = new DisplayNameMappings(); mappingsCollection.DirectionOfMapping = MappingDirectionEnum.RightToLeft; foreach (var mapping in m_rightToLeftMappings) { DisplayNameMapping mappingRule = new DisplayNameMapping(); mappingRule.Left = mapping.Left; mappingRule.Right = mapping.Right; mappingRule.MappingRule = MappingRules.SimpleReplacement; mappingsCollection.DisplayNameMapping.Add(mappingRule); } m_mappings.Add(mappingsCollection); mappingsCollection = new DisplayNameMappings(); mappingsCollection.DirectionOfMapping = MappingDirectionEnum.TwoWay; foreach (var mapping in m_twoWayMappings) { DisplayNameMapping mappingRule = new DisplayNameMapping(); mappingRule.Left = mapping.Left; mappingRule.Right = mapping.Right; mappingRule.MappingRule = MappingRules.SimpleReplacement; mappingsCollection.DisplayNameMapping.Add(mappingRule); } m_mappings.Add(mappingsCollection); }
private bool MapUser( RichIdentity sourceUserIdentity, bool leftToRight, RichIdentity mappedUserIdentity) { m_mappingRuleComparer.MapFromLeftToRight = leftToRight; NotifyingCollection <DisplayNameMapping> unidirectionalRules; if (leftToRight) { if (!m_perDirectionMappings.ContainsKey(MappingDirectionEnum.LeftToRight)) { return(false); } unidirectionalRules = m_perDirectionMappings[MappingDirectionEnum.LeftToRight]; } else { if (!m_perDirectionMappings.ContainsKey(MappingDirectionEnum.RightToLeft)) { return(false); } unidirectionalRules = m_perDirectionMappings[MappingDirectionEnum.RightToLeft]; } bool mapped = false; DisplayNameMapping appliedUnidirectionalRule = null; RichIdentity unidirectionalMappingOutput = null; foreach (DisplayNameMapping rule in unidirectionalRules) { RichIdentity mappingOutput = new RichIdentity(); if (TryApplyMappingRule(sourceUserIdentity, leftToRight, mappingOutput, rule)) { if (appliedUnidirectionalRule == null || m_mappingRuleComparer.Compare(rule, appliedUnidirectionalRule) < 0) { appliedUnidirectionalRule = rule; unidirectionalMappingOutput = mappingOutput; } mapped = true; } } if (mapped) { mappedUserIdentity.DisplayName = unidirectionalMappingOutput.DisplayName; return(true); } DisplayNameMapping appliedBidirectionalRule = null; RichIdentity bidirectionalMappingOutput = null; if (m_perDirectionMappings.ContainsKey(MappingDirectionEnum.TwoWay)) { foreach (DisplayNameMapping rule in m_perDirectionMappings[MappingDirectionEnum.TwoWay]) { RichIdentity mappingOutput = new RichIdentity(); if (TryApplyMappingRule(sourceUserIdentity, leftToRight, mappingOutput, rule)) { if (appliedBidirectionalRule == null || m_mappingRuleComparer.Compare(rule, appliedBidirectionalRule) < 0) { appliedBidirectionalRule = rule; bidirectionalMappingOutput = mappingOutput; } mapped = true; } } } if (mapped) { mappedUserIdentity.DisplayName = bidirectionalMappingOutput.DisplayName; } return(mapped); }
private bool ApplyRule(RichIdentity sourceUserIdentity, bool leftToRight, RichIdentity mappingOutput, DisplayNameMapping rule) { string toDisplayName = (leftToRight ? rule.Right : rule.Left); IStringManipulationRule stringManipulationRule = StringManipulationRuleFactory.GetInstance(rule.MappingRule); if (stringManipulationRule != null) { mappingOutput.DisplayName = stringManipulationRule.Apply(sourceUserIdentity.DisplayName, toDisplayName); return(true); } else { return(false); } }