Exemplo n.º 1
0
 public ManagedMetaProperty(ManagedMetaObject owner, Type type, DataInfoFramework.Annotation.ManagedPropertyAttribute attribute)
 {
     Owner       = owner;
     Type        = type;
     IsReference = false;
     IsKey       = false;
     Attribute   = attribute;
 }
 public void ReloadConnections(ManagedMetaObject classMeta, ModelContainer modelContainer)
 {
     foreach (var referenceProperty in classMeta.Properties.Where(x => x.IsReference))
     {
         var propertyInfo = classMeta.Type.GetProperty(referenceProperty.Name);
         var property     = propertyInfo.GetValue(this);
         var methodInfo   = referenceProperty.Type.GetMethod(nameof(ManagedReference <ManagedObjectBase, ManagedObjectBase> .LoadConnectedObject));
         var method       = methodInfo.Invoke(property, new [] { modelContainer });
     }
 }
Exemplo n.º 3
0
        public ManagedMetaObject CreateMetaObject(Type source)
        {
            var metaObject = new ManagedMetaObject();

            metaObject.Name = source.Name;
            metaObject.Type = source;

            CreateProperties(source, metaObject);

            return(metaObject);
        }
Exemplo n.º 4
0
        private List <ManagedMetaProperty> CreateProperties(Type source, ManagedMetaObject metaObject)
        {
            var propList = new List <ManagedMetaProperty>();

            foreach (var property in source.GetProperties())
            {
                ManagedMetaProperty metaProp = null;
                var propertyType             = property.PropertyType;

                Attribute[] attrs = System.Attribute.GetCustomAttributes(property);
                var         attr  = attrs.FirstOrDefault(x => typeof(DataInfoFramework.Annotation.ManagedPropertyAttribute).IsAssignableFrom(x.GetType())) as DataInfoFramework.Annotation.ManagedPropertyAttribute;
                if (attr != null)
                {
                    metaProp = new ManagedMetaProperty(metaObject, propertyType, attr)
                    {
                        Name = property.Name
                    };

                    if (attr is DataInfoFramework.Annotation.ManagedKeyPropertyAttribute)
                    {
                        metaProp.IsKey = true;
                    }
                    else if (attr is DataInfoFramework.Annotation.ManagedReferencePropertyAttribute)
                    {
                        metaProp.IsReference = true;
                    }
                }

                if (metaProp != null)
                {
                    propList.Add(metaProp);
                }
            }

            metaObject.Properties.AddRange(propList.OrderBy(x => x.Attribute.Priority));

            return(metaObject.Properties);
        }
Exemplo n.º 5
0
        private string CreateInsertCommand(IEnumerable <Model.Base.ManagedObjectBase> dataSet, Model.Base.ManagedMetaObject metaObjectDescriptor, TableDescription tableDescription)
        {
            if (!dataSet.Any())
            {
                return(null);
            }

            var commandText = @String.Empty;

            commandText += "INSERT INTO";
            commandText += $" `{tableDescription.Name}`";
            commandText += $" (";

            var columns = new List <string>();

            foreach (var columnDescription in tableDescription.Columns)
            {
                columns.Add($"`{columnDescription.Name}`");
            }
            commandText += $"{string.Join(", ", columns)}";
            commandText += $")";

            commandText += $" VALUES";

            var sValues = new List <string>();

            foreach (var entry in dataSet)
            {
                entry.Verison = ModelContainer.VersionHead;

                var sValue = new List <string>();
                foreach (var columnDescription in tableDescription.Columns)
                {
                    var value = GetValueString(metaObjectDescriptor, columnDescription, entry);
                    sValue.Add($"'{value.ToString()}'");
                }
                sValues.Add($"(" + String.Join(", ", sValue) + $")");
            }

            commandText += $" {string.Join(", ", sValues)}";
            commandText += ";";

            return(commandText);
        }