/// <summary> /// Gets the number of parameters that the system recognizes /// </summary> /// <param name="Constructor">Constructor to check</param> /// <param name="MappingManager">Mapping manager</param> /// <returns>The number of parameters that it has knoweledge of</returns> private static int GetParameterCount(ConstructorInfo Constructor, MappingManager MappingManager) { int Count = 0; ParameterInfo[] Parameters = Constructor.GetParameters(); foreach (ParameterInfo Parameter in Parameters) { bool Inject = true; object[] Attributes = Parameter.GetCustomAttributes(false); if (Attributes.Length > 0) { foreach (Attribute Attribute in Attributes) { if (MappingManager.GetMapping(Parameter.ParameterType, Attribute.GetType()) != null) { ++Count; Inject = false; break; } } } if (Inject) { if (MappingManager.GetMapping(Parameter.ParameterType) != null) { ++Count; } } } if (Count == Parameters.Length) { return(Count); } return(int.MinValue); }
/// <summary> /// Creates an object of the specified type associated with the attribute type /// </summary> /// <param name="ServiceType">Service type</param> /// <param name="AttributeType">Attribute type</param> /// <returns>An object of the specified type</returns> public object Get(Type ServiceType, Type AttributeType) { IMapping Mapping = MappingManager.GetMapping(ServiceType, AttributeType); if (Mapping.IsNull()) { throw new ArgumentException("ServiceType not found in mappings"); } return(Mapping.Implementation.Create()); }
public void LoadFromAssembly_Should_Load_Mappings() { var assembly = typeof(PersonMap).Assembly; var manager = new MappingManager(); manager.LoadFromAssembly(assembly); var map = manager.GetMapping(typeof(Person)); Assert.IsNotNull(map); }
// GET: DIM/Mapping public ActionResult Index(long sourceId = 1, long targetId = 0, LinkElementType type = LinkElementType.System) { MappingManager mappingManager = new MappingManager(); try { MappingMainModel model = new MappingMainModel(); // load from mds example model.Source = MappingHelper.LoadFromMetadataStructure(sourceId, LinkElementPostion.Source, mappingManager); switch (type) { case LinkElementType.System: { model.Target = MappingHelper.LoadfromSystem(LinkElementPostion.Target, mappingManager); model.SelectionList = MappingHelper.LoadSelectionList(); break; } case LinkElementType.MetadataStructure: { model.Target = MappingHelper.LoadFromMetadataStructure(targetId, LinkElementPostion.Target, mappingManager); model.SelectionList = MappingHelper.LoadSelectionList(); break; } } if (model.Source != null && model.Target != null) { //get linkelements LinkElement source = mappingManager.GetLinkElement(sourceId, LinkElementType.MetadataStructure); LinkElement target = mappingManager.GetLinkElement(targetId, type); if (source != null && target != null) { //get root mapping Mapping rootMapping = mappingManager.GetMapping(source, target); if (rootMapping != null) { //get complex mappings model.ParentMappings = MappingHelper.LoadMappings(rootMapping); } } } return(View(model)); } finally { mappingManager.Dispose(); } }
private object GetObject(Type Type, Type AttributeType) { IMapping Mapping = MappingManager.GetMapping(Type, AttributeType); return(Mapping == null ? null : Mapping.Implementation.Create()); }
private object GetObject(Type Type) { IMapping Mapping = MappingManager.GetMapping(Type); return(Mapping.IsNull() ? null : Mapping.Implementation.Create()); }
public ActionResult Mapping(long sourceId = 1, long targetId = 0, LinkElementType sourceType = LinkElementType.System, LinkElementType targetType = LinkElementType.System, LinkElementPostion position = LinkElementPostion.Target) { MappingManager mappingManager = new MappingManager(); try { MappingMainModel model = new MappingMainModel(); // load from mds example //model.Source = MappingHelper.LoadFromMetadataStructure(sourceId, LinkElementPostion.Source); /* * Here the source and target will switch the sides */ #region load Source from Target switch (sourceType) { case LinkElementType.System: { model.Source = MappingHelper.LoadfromSystem(LinkElementPostion.Source, mappingManager); if (!model.SelectionList.Any()) { model.SelectionList = MappingHelper.LoadSelectionList(); } break; } case LinkElementType.MetadataStructure: { model.Source = MappingHelper.LoadFromMetadataStructure(sourceId, LinkElementPostion.Source, mappingManager); if (!model.SelectionList.Any()) { model.SelectionList = MappingHelper.LoadSelectionList(); } break; } } #endregion #region load Target switch (targetType) { case LinkElementType.System: { model.Target = MappingHelper.LoadfromSystem(LinkElementPostion.Target, mappingManager); if (!model.SelectionList.Any()) { model.SelectionList = MappingHelper.LoadSelectionList(); } break; } case LinkElementType.MetadataStructure: { model.Target = MappingHelper.LoadFromMetadataStructure(targetId, LinkElementPostion.Target, mappingManager); if (!model.SelectionList.Any()) { model.SelectionList = MappingHelper.LoadSelectionList(); } break; } } #endregion if (model.Source != null && model.Target != null) { //get linkelements LinkElement source = mappingManager.GetLinkElement(sourceId, sourceType); LinkElement target = mappingManager.GetLinkElement(targetId, targetType); if (source != null && target != null) { //get root mapping Mapping rootMapping = mappingManager.GetMapping(source, target); if (rootMapping != null) { //get complex mappings model.ParentMappings = MappingHelper.LoadMappings(rootMapping); } } } return(View("Index", model)); } finally { mappingManager.Dispose(); } }
public ActionResult ReloadMapping(long sourceId = 1, long targetId = 0, LinkElementType sourceType = LinkElementType.System, LinkElementType targetType = LinkElementType.System, LinkElementPostion position = LinkElementPostion.Target) { MappingManager mappingManager = new MappingManager(); try { List <ComplexMappingModel> model = new List <ComplexMappingModel>(); // load from mds example LinkElementRootModel source = null; switch (sourceType) { case LinkElementType.System: { source = MappingHelper.LoadfromSystem(LinkElementPostion.Source, mappingManager); break; } case LinkElementType.MetadataStructure: { source = MappingHelper.LoadFromMetadataStructure(targetId, LinkElementPostion.Source, mappingManager); break; } } LinkElementRootModel target = null; switch (targetType) { case LinkElementType.System: { target = MappingHelper.LoadfromSystem(LinkElementPostion.Target, mappingManager); break; } case LinkElementType.MetadataStructure: { target = MappingHelper.LoadFromMetadataStructure(targetId, LinkElementPostion.Target, mappingManager); break; } } if (target != null) { //get linkelements LinkElement sourceLE = mappingManager.GetLinkElement(sourceId, sourceType); LinkElement targetLE = mappingManager.GetLinkElement(targetId, targetType); if (sourceLE != null && targetLE != null) { //get root mapping Mapping rootMapping = mappingManager.GetMapping(sourceLE, targetLE); if (rootMapping != null) { //get complex mappings model = MappingHelper.LoadMappings(rootMapping); } } } return(PartialView("Mappings", model)); } finally { mappingManager.Dispose(); } }
/// <summary> /// get all values from systen parties values /// /// </summary> /// <param name="mappings"></param> /// <returns></returns> private static List <MappingPartyResultElemenet> getAllValuesFromSystem(IEnumerable <Entities.Mapping.Mapping> mappings, string value) { using (MappingManager _mappingManager = new MappingManager()) using (PartyTypeManager partyTypeManager = new PartyTypeManager()) using (PartyManager partyManager = new PartyManager()) { List <MappingPartyResultElemenet> tmp = new List <MappingPartyResultElemenet>(); IEnumerable <long> parentIds = mappings.Where(m => m.Parent != null).Select(m => m.Parent.Id).Distinct(); IEnumerable <Entities.Mapping.Mapping> selectedMappings; // all Masks are the same string mask = ""; PartyType partyType = null; List <Party> parties = null; foreach (var pId in parentIds) { Entities.Mapping.Mapping parentMapping = _mappingManager.GetMapping(pId); selectedMappings = mappings.Where(m => m.Parent != null && m.Parent.Id.Equals(pId)); long parentTypeId = parentMapping.Source.ElementId; long sourceId = selectedMappings.FirstOrDefault().Source.ElementId; //mappings.FirstOrDefault().TransformationRule.Mask; if (parentTypeId == 0) { partyType = partyTypeManager.PartyTypeRepository.Query() .FirstOrDefault(p => p.CustomAttributes.Any(c => c.Id.Equals(sourceId))); parties = partyManager.PartyRepository.Query().Where(p => p.PartyType.Equals(partyType)).ToList(); } else { partyType = partyTypeManager.PartyTypeRepository.Get(parentTypeId); parties = partyManager.PartyRepository.Query().Where(p => p.PartyType.Id.Equals(parentTypeId)).ToList(); } //get all mapped element ids var elementIds = mappings.Select(m => m.Source.ElementId); // get all attributes based on the element id list var attributeValues = partyManager.PartyCustomAttributeValueRepository.Query(y => elementIds.Contains(y.CustomAttribute.Id)).ToList(); attributeValues = attributeValues.Where(y => y.Value.ToLower().Contains(value.ToLower())).ToList(); //get all party ids var partyIds = attributeValues.Select(a => a.Party.Id).Distinct(); foreach (var partyId in partyIds) { MappingPartyResultElemenet resultObject = new MappingPartyResultElemenet(); resultObject.PartyId = partyId; //get mask from first mapping mask = mappings.FirstOrDefault().TransformationRule.Mask; var allMappedAttrValues = partyManager.PartyCustomAttributeValueRepository.Query(y => y.Party.Id.Equals(partyId) && elementIds.Contains(y.CustomAttribute.Id)).ToList(); foreach (var attrValue in allMappedAttrValues) { //get mapping for the attrvalue var mapping = mappings.Where(m => m.Source.ElementId.Equals(attrValue.CustomAttribute.Id)).FirstOrDefault(); List <string> regExResultList = transform(attrValue.Value, mapping.TransformationRule); string placeHolderName = attrValue.CustomAttribute.Name; mask = setOrReplace(mask, regExResultList, placeHolderName); resultObject.Value = mask; } if (mask.ToLower().Contains(value.ToLower())) { tmp.Add(resultObject); } } } return(tmp); } }
/// <summary> /// get all values from systen parties values /// /// </summary> /// <param name="mappings"></param> /// <returns></returns> private static List <string> getAllValuesFromSystem(IEnumerable <Entities.Mapping.Mapping> mappings, string value) { MappingManager _mappingManager = new MappingManager(); PartyTypeManager partyTypeManager = new PartyTypeManager(); PartyManager partyManager = new PartyManager(); List <string> tmp = new List <string>(); IEnumerable <long> parentIds = mappings.Where(m => m.Parent != null).Select(m => m.Parent.Id).Distinct(); IEnumerable <Entities.Mapping.Mapping> selectedMappings; // all Masks are the same string mask = ""; PartyType partyType = null; List <Party> parties = null; foreach (var pId in parentIds) { Entities.Mapping.Mapping parentMapping = _mappingManager.GetMapping(pId); selectedMappings = mappings.Where(m => m.Parent != null && m.Parent.Id.Equals(pId)); long parentTypeId = parentMapping.Source.ElementId; long sourceId = selectedMappings.FirstOrDefault().Source.ElementId; //mappings.FirstOrDefault().TransformationRule.Mask; if (parentTypeId == 0) { partyType = partyTypeManager.PartyTypeRepository.Query() .FirstOrDefault(p => p.CustomAttributes.Any(c => c.Id.Equals(sourceId))); parties = partyManager.PartyRepository.Get().Where(p => p.PartyType.Equals(partyType)).ToList(); } else { partyType = partyTypeManager.PartyTypeRepository.Get(parentTypeId); parties = partyManager.PartyRepository.Get().Where(p => p.PartyType.Id.Equals(parentTypeId)).ToList(); } if (parties != null) { foreach (var p in parties) { mask = mappings.FirstOrDefault().TransformationRule.Mask; foreach (var mapping in mappings) { long attributeId = mapping.Source.ElementId; PartyCustomAttributeValue attrValue = partyManager.PartyCustomAttributeValueRepository.Get() .Where(v => v.CustomAttribute.Id.Equals(attributeId) && v.Party.Id.Equals(p.Id)) .FirstOrDefault(); List <string> regExResultList = transform(attrValue.Value, mapping.TransformationRule); string placeHolderName = attrValue.CustomAttribute.Name; mask = setOrReplace(mask, regExResultList, placeHolderName); } if (mask.ToLower().Contains(value.ToLower())) { tmp.Add(mask); } } } } return(tmp); }
public void ShouldReturnMapping(string source, string destination) { ITextMapping map = MappingManager.GetMapping(source, destination); Assert.NotNull(map); }
public void ShouldThrowExceptionForNonExistent(string source, string destination) { Assert.Throws <NullReferenceException>(() => MappingManager.GetMapping(source, destination)); }