private static void MappForengKey(DnJsonSchema schema) { schema.Propriedades.ForEach(property => { if (property.Agregacao == null) { return; } property.Agregacao.ChavesLocais.ToList().ForEach(key => { var fkProperty = schema.Propriedades.Single(x => x.NomeDaPropriedadeCaseSensitive.Equals(key)); fkProperty.EhChaveExterna = true; fkProperty.DestinoDeChaveExterna = property.Tipo.GetCustomAttribute <DnFormularioJsonAtributo>(); if (fkProperty.DestinoDeChaveExterna != null) { fkProperty.DestinoDeChaveExterna.Tipo = property.Tipo; } }); }); }
public static DnJsonSchema GetDnJsonSchema(this Type type, bool tablet) { if (type == null) { throw new ArgumentNullException(nameof(type)); } type = type.GetListTypeNonNull(); var form = GetDnJsonFormAttributeByType(type); form.NomeDaPropriedade = type.Name.ToDnJsonStringNormalized(); form.Tipo = type.GetNonNullableType(); var root = new DnJsonSchema { Formulario = form, Propriedades = new List <DnPropriedadeJsonAtributo>() }; type.GetProperties().ToList().ForEach(property => { if (property == null) { return; } var attr = GetDnJsonPropertyAttributeByProperty(property); attr.Propriedade = property; if (attr.Formulario == EnumTipoDeComponenteDeFormularioDeTela.Nenhum) { return; } if (attr.Agregacao != null) { if (attr.Agregacao.GetType()?.Is(typeof(DnAgregacaoDeMuitosParaMuitosAtributo)) == true) { } if (property.PropertyType.IsList()) { // return; //Todo - Ignorando agregação em lista enquanto não é implementada } attr.Agregacao.DefinirTipo(property.PropertyType.GetListTypeNonNull().Name); attr.Agregacao.DefinirNome(property.Name); attr.Agregacao.Filtro = property.GetCustomAttribute <DnFiltroAtributo>(); if (attr.Agregacao.Filtro != null) { attr.Agregacao.Filtro.NomeDaPropriedade = property.Name.ToDnJsonStringNormalized(); if (attr.Agregacao.Filtro.CamposParaLimpar != null) { attr.Agregacao.Filtro.CamposParaLimpar = attr.Agregacao.Filtro.CamposParaLimpar.Select(x => x.ToDnJsonStringNormalized()).ToArray(); } } } if (attr.Composicao != null) { attr.Composicao.DefinirTipo(property.PropertyType.GetListTypeNonNull().Name); attr.Composicao.DefinirNome(property.Name); attr.Composicao.Formulario = GetDnJsonSchema(property.PropertyType, tablet); } if (property.IsDefined(typeof(RequiredAttribute)) || property.IsDefined(typeof(DnRequeridoAtributo))) { attr.EhRequerido = true; } if (property.PropertyType.IsNullableEnum()) { attr.EhEnumerador = true; attr.Enumeradores = new List <KeyValuePair <string, string> >(); foreach (var field in property.PropertyType.GetEnumFields()) { if (field.Name.Equals("value__", StringComparison.InvariantCultureIgnoreCase)) { continue; } var value = field.GetCustomAttribute <EnumMemberAttribute>()?.Value ?? field.Name; attr.Enumeradores.Add(new KeyValuePair <string, string>(field.Name, value)); } } attr.NomeDaPropriedadeCaseSensitive = property.Name; attr.NomeDaPropriedade = property.Name.ToDnJsonStringNormalized(); root.Propriedades.Add(attr); }); root.Propriedades = root.Propriedades .GroupBy(x => x.Grupo) .SelectMany(x => x) .ToList(); root.Propriedades.Where(x => x.Formulario == EnumTipoDeComponenteDeFormularioDeTela.Hidden).ToList().ForEach(property => { property.LayoutDeGrid = 0; property.Linha = 0; }); var properties = root.Propriedades.Where(x => x.Formulario != EnumTipoDeComponenteDeFormularioDeTela.Hidden).ToList(); properties.ForEach(property => { if (tablet) { property.LayoutDeGrid *= 2; } if (property.LayoutDeGrid == 0 || property.LayoutDeGrid > 12) { property.LayoutDeGrid = 12; } property.Linha = 0; }); { var grid = 0; var row = 1; var lastGroup = properties.FirstOrDefault()?.Grupo ?? ""; properties.ForEach(x => { if (lastGroup != x.Grupo) { grid = 0; row++; lastGroup = x.Grupo; } if (grid + x.LayoutDeGrid > 12) { row++; grid = x.LayoutDeGrid; } else { grid += x.LayoutDeGrid; } x.Linha = row; }); } { var props = new List <DnPropriedadeJsonAtributo>(); var row = 1; properties.ForEach(property => { if (row != property.Linha) { AdjustColumns(props); props.Clear(); row++; } props.Add(property); }); if (props.Count > 0) { AdjustColumns(props); } } MappForengKey(root); return(root); }