Example #1
0
        public MetaEntity CreateEntity(MetaEntityNamespace classCollection, String entityName = "")
        {
            MetaEntity output = new MetaEntity();

            output.EntityClassDefinition = this;
            output.EntityClassName       = name;
            output.name = entityName;

            MetaEntityItemSelection itemSelector = new MetaEntityItemSelection();


            foreach (var property in Properties)
            {
                if (property.type.HasFlag(MetaEntityClassPropertyType.value))
                {
                    if (property.type.HasFlag(MetaEntityClassPropertyType.collection))
                    {
                        output.Setters.Add(new MetaPropertySetter()
                        {
                            Parent = output, name = property.name, Value = new List <Object>()
                        });
                    }
                    else
                    {
                        output.Setters.Add(new MetaPropertySetter()
                        {
                            Parent = output, name = property.name
                        });
                    }
                }
                else if (property.type.HasFlag(MetaEntityClassPropertyType.entity))
                {
                    // itemSelector.SetSelection(classCollection.SelectTarget(property.PropertyTypeName));

                    var entityClass = classCollection.FindClass(property.PropertyTypeName);  // itemSelector.SelectedClass;

                    var subEntity = entityClass.CreateEntity(classCollection, property.name);
                    subEntity.Parent = output;

                    output.Items.Add(subEntity);

                    //classCollection.CreateEntity(property.name));
                }
            }

            return(output);
        }
Example #2
0
        public void CreateDataTableRow(DataTable output, MetaEntity entity, MetaEntityClassPropertyType typesToInclude = MetaEntityClassPropertyType.value | MetaEntityClassPropertyType.valueCollection)
        {
            var types = typesToInclude.getEnumListFromFlags <MetaEntityClassPropertyType>();
            var dr    = output.NewRow();

            if (output.Columns.Contains(nameof(MetaEntity.name)))
            {
                dr[nameof(MetaEntity.name)] = entity.name;
            }
            if (output.Columns.Contains(nameof(MetaEntity.EntityClassName)))
            {
                dr[nameof(MetaEntity.EntityClassName)] = entity.EntityClassName;
            }


            foreach (var property in Properties)
            {
                if (types.Contains(property.type))
                {
                    String column_name = property.GetSelectExpression();

                    if (output.Columns.Contains(column_name))
                    {
                        var setter = entity.Setters.FirstOrDefault(x => x.name.Equals(property.name));
                        if (setter != null)
                        {
                            if (property.type.HasFlag(MetaEntityClassPropertyType.collection))
                            {
                                MetaPropertyInstruction instruction = new MetaPropertyInstruction(setter, property);
                                dr[column_name] = instruction.value;
                            }
                            else
                            {
                                if (setter.Value != null)
                                {
                                    dr[column_name] = setter.Value;
                                }
                            }
                        }
                    }
                }
            }

            output.Rows.Add(dr);
        }
Example #3
0
        public Boolean AcceptData(MetaTable table)
        {
            var interpretation  = table.description.Interpretation;
            var EntitySelector  = table.description.MetaEntitySetterExpression;
            var EntityClassName = table.description.MetaEntityClassName.or(Settings.RootEntityClassNamepath);


            MetaEntity selectedEntity = CurrentEntity.SelectTarget(EntitySelector) as MetaEntity;

            selectedEntity.CheckClassDefinition(Namespaces, EntityClassName);

            if (selectedEntity.EntityClassDefinition == RootEntityClassSelection.SelectedClass)
            {
                interpretation = MetaTableInterpretation.singleEntity;
            }

            MetaEntityItemSelection ReflectionSelection = new MetaEntityItemSelection(selectedEntity.EntityClassDefinition);

            switch (interpretation)
            {
            case MetaTableInterpretation.singleEntity:
                MetaTableEntry firstEntry = table.entries.items.FirstOrDefault();
                selectedEntity.AcceptEntryProperties(firstEntry);
                break;

            case MetaTableInterpretation.multiEntities:

                foreach (var entry in table.entries.items)
                {
                    var subentity = selectedEntity.EntityClassDefinition.CreateEntity(ReflectionSelection.SelectedNamespace, "");
                    subentity.AcceptEntryProperties(entry);
                    selectedEntity.Items.Add(subentity);
                }
                break;

            default:
            case MetaTableInterpretation.triplets:
                return(false);

                break;
            }
            return(true);
        }