/// <summary> /// Obtiene metadata desde una entidad. /// </summary> /// <param name="type">Tipo de entidad</param> /// <param name="assemblyInput"></param> /// <param name="typeNamespace">namespace del input (se buscará el input vinculado a la clase, a través de los índices)</param> /// <param name="docs">Implmentación Documentación</param> /// <returns>Colección de metadata</returns> public static PropertySearchInfo[] GetPropertySearchInfo(Type type, Assembly assemblyInput, string typeNamespace, IMdmDocumentation docs) { var classAtribute = Mdm.Reflection.Attributes.GetAttributes <EntityIndexAttribute>(type); if (classAtribute == null || !classAtribute.Any()) { return(Array.Empty <PropertySearchInfo>()); } var inputType = Mdm.Reflection.GetEntityType(classAtribute.FirstOrDefault().Index, assemblyInput, typeNamespace); if (inputType == null) { return(Array.Empty <PropertySearchInfo>()); } return(GetPropertyByIndex(type, classAtribute.FirstOrDefault().Index, inputType, docs)); }
/// <summary> /// Obtiene el modelo de una implementación de trifenix connect /// </summary> /// <param name="propertySearchInfo">información de cada propiedad de la entidad</param> /// <param name="doc">Implementación de la documetación</param> /// <param name="index">índice de la entidad</param> /// <returns></returns> public static EntityMetadata GetModel(IEnumerable <PropertySearchInfo> propertySearchInfo, IMdmDocumentation doc, int index) { // obtiene el modelo general de la entidad var modelInfo = doc.GetInfoFromEntity(index); // genera modelo de datos var modelDictionary = new EntityMetadata() { Index = index, Description = modelInfo.Description, ShortName = modelInfo.ShortName, Title = modelInfo.Title, BoolData = GetDictionaryFromRelated(propertySearchInfo, false, (int)KindProperty.BOOL), StringData = GetDictionaryFromRelated(propertySearchInfo, false, (int)KindProperty.STR), DateData = GetDictionaryFromRelated(propertySearchInfo, false, (int)KindProperty.DATE), DoubleData = GetDictionaryFromRelated(propertySearchInfo, false, (int)KindProperty.DBL), EnumData = GetEnumDictionaryFromRelated(propertySearchInfo), GeoData = GetDictionaryFromRelated(propertySearchInfo, false, (int)KindProperty.GEO), NumData = GetDictionaryFromRelated(propertySearchInfo, false, (int)KindProperty.NUM32), relData = GetDictionaryFromRelated(propertySearchInfo, true, (int)KindEntityProperty.REFERENCE), }; // los siguientes tipos existen en un entitySearch // pero para este caso serán agrupados de manera más general. var suggestions = GetDictionaryFromRelated(propertySearchInfo, false, (int)KindProperty.SUGGESTION); var num64 = GetDictionaryFromRelated(propertySearchInfo, false, (int)KindProperty.NUM64); var suggestionNotInString = suggestions.Where(sg => !modelDictionary.StringData.Any(s => s.Key == sg.Key)); var num64NotInNum = num64.Where(sg => !modelDictionary.NumData.Any(s => s.Key == sg.Key)); var relLocal = GetDictionaryFromRelated(propertySearchInfo, true, (int)KindEntityProperty.LOCAL_REFERENCE); if (suggestionNotInString.Any()) { foreach (var item in suggestionNotInString) { modelDictionary.StringData.Add(item.Key, item.Value); } } if (num64NotInNum.Any()) { foreach (var item in num64NotInNum) { modelDictionary.NumData.Add(item.Key, item.Value); } } if (relLocal.Any()) { foreach (var item in relLocal) { modelDictionary.relData.Add(item.Key, item.Value); } } return(modelDictionary); }
/// <summary> /// Obtiene una colección de metadata desde una entidad. /// </summary> /// <param name="type">Clase de tipo modelo, donde debe obtener la metadata</param> /// <param name="index">índice de la entidad</param> /// <param name="inputType">Clase de tipo input, donde podrá obtener la metadata</param> /// <param name="docs">Implmentación de IMdmDocumentation para generar la documentación</param> /// <returns>Colección de metadata</returns> public static PropertySearchInfo[] GetPropertyByIndex(Type type, int index, Type inputType, IMdmDocumentation docs) { // obtiene el atributo de la clase, que determina el índice de la entidad var searchAttributesProps = type.GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(BaseIndexAttribute), true)); // asigna la metadata de la propiedad, además, si es requerido o si es único. var elemTypeInputProps = inputType.GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(BaseIndexAttribute), true)) .Select(s => new { info = s, search = Mdm.Reflection.Attributes.GetAttribute <BaseIndexAttribute>(s), required = Mdm.Reflection.Attributes.GetAttribute <RequiredAttribute>(s), unique = Mdm.Reflection.Attributes.GetAttribute <UniqueAttribute>(s) }); // crea un listado de metadata para la entidad. var props = searchAttributesProps.Select(s => { // buscando atributos. var searchAttribute = (BaseIndexAttribute)s.GetCustomAttributes(typeof(BaseIndexAttribute), true).FirstOrDefault(); var searchAttributeInput = elemTypeInputProps.FirstOrDefault(p => p.search.Index == searchAttribute.Index && p.search.IsEntity == searchAttribute.IsEntity); var grp = s.GetCustomAttributes(typeof(GroupAttribute), true).Select(s => (GroupAttribute)s).ToList(); return(new PropertySearchInfo { IsEnumerable = Mdm.Reflection.IsEnumerableProperty(s), Name = s.Name, Index = searchAttribute.Index, Related = (KindProperty)(!searchAttribute.IsEntity?searchAttribute.KindIndex:0), RelatedEntity = (KindEntityProperty)(searchAttribute.IsEntity?searchAttribute.KindIndex:0), Enums = !searchAttribute.IsEntity && searchAttribute.KindIndex == (int)KindProperty.ENUM ? Mdm.Reflection.GetDescription(s.PropertyType) : new Dictionary <int, string>(), IndexClass = index, Info = searchAttribute.IsEntity? docs.GetInfoFromEntity(index): docs.GetInfoFromProperty((KindProperty)searchAttribute.KindIndex, searchAttribute.Index), IsRequired = searchAttributeInput?.required != null, IsUnique = searchAttributeInput?.unique != null, AutoNumeric = searchAttribute.GetType() == typeof(AutoNumericDependantAttribute), Visible = searchAttribute.Visible, HasInput = searchAttributeInput != null, IsEntity = searchAttribute.IsEntity, Group = grp?.Select(s => s.Group).ToArray() ?? Array.Empty <GroupInput>() }); }).ToArray(); //si existe alguna propiedad que esté en el input y no esté en la entidad. if (elemTypeInputProps.Any(s => !props.Any(a => a.Name.Equals(s.info.Name)))) { var extra = elemTypeInputProps.Where(s => !props.Any(a => a.Name.Equals(s.info.Name))); var list = props.ToList(); foreach (var item in extra) { list.Add(new PropertySearchInfo { IsEnumerable = Mdm.Reflection.IsEnumerableProperty(item.info), Name = item.info.Name, Index = item.search.Index, Related = (KindProperty)(!item.search.IsEntity ? item.search.KindIndex : 0), RelatedEntity = (KindEntityProperty)(item.search.IsEntity ? item.search.KindIndex : 0), Enums = !item.search.IsEntity && item.search.KindIndex == (int)KindProperty.ENUM ? Mdm.Reflection.GetDescription(item.info.PropertyType) : new Dictionary <int, string>(), IndexClass = index, Info = item.search.IsEntity ? docs.GetInfoFromEntity(item.search.Index) : docs.GetInfoFromProperty((KindProperty)item.search.KindIndex, item.search.Index), IsRequired = item?.required != null, IsUnique = item?.unique != null, IsEntity = item.search.IsEntity, }); } props = list.ToArray(); } return(props); }