public String GetJSON(MetaEntityNamespaceCollection namespaces)
        {
            builderForText output = new builderForText();

            WriteJSON(output, namespaces);
            return(output.GetContent().Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine));
        }
        public void WriteJSON(ITextRender output, MetaEntityNamespaceCollection namespaces)
        {
            var instructions = ConvertToInstructions(namespaces);
            MetaPropertyInstruction rootInstruction = new MetaPropertyInstruction("", instructions);

            rootInstruction.WriteToOutput(output, true);
        }
        public DataSet GetDataSet(MetaEntityNamespaceCollection namespaces)
        {
            DataTable valueTable = GetVerticalDataTable(namespaces);


            DataSet output = new DataSet();

            output.Tables.Add(valueTable);

            foreach (var item in Items)
            {
                var itemProperty = EntityClassDefinition.FindProperty(item.name);
                if (itemProperty.type.HasFlag(MetaEntityClassPropertyType.collection))
                {
                    MetaEntityClass itemClass = namespaces.FindClass(itemProperty.PropertyTypeName);

                    DataTable collectionTable = itemClass.CreateDataTableForEntities(MetaEntityClassPropertyType.valueCollection);
                    collectionTable.SetTitle(itemProperty.name);

                    foreach (var subitem in item.Items)
                    {
                        itemClass.CreateDataTableRow(collectionTable, subitem, MetaEntityClassPropertyType.valueCollection);
                    }
                    output.Tables.Add(collectionTable);
                }
                else
                {
                    var itemVerticalTable = item.GetVerticalDataTable(namespaces, itemProperty.name);

                    output.Tables.Add(itemVerticalTable);
                }
            }

            return(output);
        }
        //public Dictionary<String, MetaEntity> ChildEntities { get; set; } = new Dictionary<String, MetaEntity>();

        // public Dictionary<String, MetaEntityCollection> EntityCollections { get; set; } = new Dictionary<String, MetaEntityCollection>();

        public void CheckClassDefinition(MetaEntityNamespaceCollection namespaces, String rootclassname)
        {
            if (EntityClassName.isNullOrEmpty())
            {
                EntityClassName = rootclassname;
            }

            if (EntityClassDefinition == null)
            {
                EntityClassDefinition = namespaces.SelectTarget(EntityClassName) as MetaEntityClass;
            }
        }
        public List <MetaPropertyInstruction> ConvertToInstructions(MetaEntityNamespaceCollection namespaces, Boolean includeItems = true)
        {
            List <MetaPropertyInstruction> output = new List <MetaPropertyInstruction>();

            CheckClassDefinition(namespaces, EntityClassName);

            output.Add(new MetaPropertyInstruction(nameof(name), name));
            output.Add(new MetaPropertyInstruction(nameof(EntityClassName), EntityClassName));

            foreach (var setter in Setters)
            {
                var setterProperty = EntityClassDefinition.FindProperty(setter.name);

                output.Add(new MetaPropertyInstruction(setter, setterProperty));
            }

            if (includeItems)
            {
                foreach (var item in Items)
                {
                    var itemProperty = EntityClassDefinition.FindProperty(item.name);
                    if (itemProperty.type.HasFlag(MetaEntityClassPropertyType.collection))
                    {
                        List <MetaPropertyInstruction> itemInstructions = new List <MetaPropertyInstruction>();
                        foreach (var subitem in item.Items)
                        {
                            var subinstructions = subitem.ConvertToInstructions(namespaces);
                            if (subinstructions.Any())
                            {
                                itemInstructions.Add(new MetaPropertyInstruction(subitem.name, subinstructions));
                            }
                        }
                        if (itemInstructions.Any())
                        {
                            output.Add(new MetaPropertyInstruction(itemProperty.name, itemInstructions));
                        }
                    }
                    else
                    {
                        var subinstructions = item.ConvertToInstructions(namespaces);
                        output.Add(new MetaPropertyInstruction(itemProperty.name, subinstructions));
                    }
                }
            }

            return(output);
        }
        public void Finalize(MetaEntityNamespaceCollection namespaces)
        {
            CheckClassDefinition(namespaces, "");

            if (!EntityClassDefinition.namePropertyName.isNullOrEmpty())
            {
                if (name.isNullOrEmpty())
                {
                    var nameSetter = GetSetter(EntityClassDefinition.namePropertyName);
                    if (nameSetter != null)
                    {
                        name = nameSetter.Value.toStringSafe("");
                    }
                }
            }

            foreach (var item in Items)
            {
                item.Finalize(namespaces);
            }
        }
        public DataTable GetVerticalDataTable(MetaEntityNamespaceCollection namespaces, String tableName = "")
        {
            var instructions = ConvertToInstructions(namespaces, false);

            DataTable table = new DataTable();

            table.SetTitle(tableName.or(name, EntityClassName));


            var column_name = table.Columns.Add("name");


            var column_value = table.Columns.Add("value");


            var column_contentType = table.Columns.Add("contentType");


            foreach (var inst in instructions)
            {
                var dr = table.NewRow();

                dr[column_value] = inst.value;

                dr[column_name] = inst.name;

                if (inst.property != null)
                {
                    dr[column_contentType] = inst.property.ContentType.ToString();
                }

                table.Rows.Add(dr);
            }

            return(table);
        }
Exemple #8
0
 public void Deploy(MetaEntityNamespaceCollection namespaces, MetaEntityExtractionSettings settings)
 {
     Namespaces = namespaces;
     Settings   = settings;
     RootEntityClassSelection.SetSelection(namespaces.SelectTarget(Settings.RootEntityClassNamepath));
 }
        /// <summary>
        /// Collects all classes from properties and their
        /// </summary>
        /// <param name="rootClass">The root class.</param>
        /// <param name="namespaces">The namespaces.</param>
        /// <param name="includeSelf">if set to <c>true</c> [include self].</param>
        /// <returns></returns>
        public static List <MetaEntityClass> CollectRelevantClasses(this MetaEntityClass rootClass, MetaEntityNamespaceCollection namespaces, Boolean includeSelf = true)
        {
            List <MetaEntityClass> output = new List <MetaEntityClass>();

            if (includeSelf)
            {
                output.Add(rootClass);
            }

            List <MetaEntityClass> iteration = new List <MetaEntityClass>()
            {
                rootClass
            };

            while (iteration.Any())
            {
                List <MetaEntityClass> next_iteration = new List <MetaEntityClass>();
                foreach (var cf in iteration)
                {
                    foreach (MetaEntityClassProperty property in cf.Properties)
                    {
                        if (property.type.HasFlag(MetaEntityClassPropertyType.entity))
                        {
                            var entityClass = namespaces.FindClass(property.ValueTypeName);
                            if (!output.Any(x => x.GetNamepath() == entityClass.GetNamepath()))
                            {
                                next_iteration.Add(entityClass);
                                output.Add(entityClass);
                            }
                        }
                    }
                }

                iteration = next_iteration;
            }

            return(output);
        }