Ejemplo n.º 1
0
        public static IEnumerable <Property> Combine(IEnumerable <Property> properties)
        {
            List <Property> result       = new List <Property>();
            var             uncombinable = properties.Where(o => o.Meta == null || String.IsNullOrEmpty(o.Meta.ShorthandName));
            var             combinable   = properties.Except(uncombinable);

            // Add uncombinable part
            result.AddRange(uncombinable);

            // Combine combinable part
            foreach (var each in combinable.GroupBy(o => o.Meta.ShorthandName))
            {
                var      meta = PropertyMeta.GetMeta(each.Key);
                Property shorthand;
                if ((meta.ValueType as ShorthandType).ShorthandRule.TryCombine(each, meta, out shorthand))
                {
                    result.Add(shorthand);
                }
                else
                {
                    result.AddRange(each);
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
 internal DbColumn(DbTable table, string name, PropertyMeta meta)
 {
     _table    = table;
     _name     = name;
     _meta     = meta;
     _property = meta.ManagedProperty as IProperty;
 }
Ejemplo n.º 3
0
        public void ImportDefinitions(TreeNode Root)
        {
            int count = Root.Nodes.Count;

            Definitions = new List <ClassDefinition>();
            for (int i = 0; i < count; i++)
            {
                TreeNode        n1 = Root.Nodes[i];
                ClassDefinition t  = new ClassDefinition();
                t.name  = n1.Text;
                t.props = new List <Property>();
                for (int j = 0; j < n1.Nodes.Count; j++)
                {
                    Property p  = new Property();
                    TreeNode n2 = n1.Nodes[j];
                    p.name = n2.Text;
                    p.Meta = new List <PropertyMeta>();
                    for (int k = 0; k < n2.Nodes.Count / 2; k++)
                    {
                        TreeNode     s1 = n2.Nodes[k * 2];
                        TreeNode     t1 = n2.Nodes[k * 2 + 1];
                        PropertyMeta m  = new PropertyMeta();
                        m.size = Convert.ToInt32(s1.Text);
                        m.type = Convert.ToInt32(t1.Text);
                        p.Meta.Add(m);
                    }
                    t.props.Add(p);
                }
                Definitions.Add(t);
            }
            bool run = true;

            while (run)
            {
                run = false;
                for (int i = 0; i < Definitions.Count - 1; i++)
                {
                    if (string.Compare(Definitions[i].name, Definitions[i + 1].name) > 0)
                    {
                        run = true;
                        ClassDefinition t = Definitions[i];
                        Definitions[i]     = Definitions[i + 1];
                        Definitions[i + 1] = t;
                    }
                }
                for (int i = 0; i < Definitions.Count - 1; i++)
                {
                    for (int j = 0; j < Definitions[i].props.Count - 1; j++)
                    {
                        if (string.Compare(Definitions[i].props[j].name, Definitions[i].props[j + 1].name) > 0)
                        {
                            run = true;
                            Property p = Definitions[i].props[j];
                            Definitions[i].props[j]     = Definitions[i].props[j + 1];
                            Definitions[i].props[j + 1] = p;
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 private IPropertyMap PropertyMapFor(PropertyMeta sourceProperty, PropertyMeta targetProperty)
 {
     if (sourceProperty == null)
     {
         return(new NullPropertyMap(TargetType.Type, targetProperty));
     }
     return(new PropertyMap(TargetType.Type, sourceProperty, targetProperty, Registry));
 }
Ejemplo n.º 5
0
        internal LoadOptionItem(PropertyMeta childrenPropertyInfo)
        {
            if (childrenPropertyInfo == null)
            {
                throw new ArgumentNullException("propertyInfo");
            }

            this.PropertyMeta = childrenPropertyInfo;
        }
Ejemplo n.º 6
0
        private static ObjectMeta AddObjectMeta(Type type)
        {
            if (_objectMetas.TryGetValue(type, out var meta))
            {
                return(meta);
            }

            meta = new ObjectMeta();

            if (type.GetInterface("System.Collections.IDictionary") != null)
            {
                meta.IsDict = true;
            }

            meta.Properties = new Dictionary <string, PropertyMeta>();

            var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);

            foreach (var info in properties)
            {
                if (info.Name == "Item")
                {
                    var parameters = info.GetIndexParameters();
                    if (parameters.Length != 1)
                    {
                        continue;
                    }

                    meta.ElemType = parameters[0].ParameterType == typeof(string) ? info.PropertyType : typeof(object);

                    continue;
                }

                var prop = new PropertyMeta {
                    Info = info, Type = info.PropertyType
                };
                meta.Properties.Add(info.Name, prop);
            }

            var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public);

            foreach (var info in fields)
            {
                var data = new PropertyMeta {
                    Info = info, IsField = true, Type = info.FieldType
                };
                meta.Properties.Add(info.Name, data);
            }

            _objectMetas[type] = meta;
            return(meta);
        }
Ejemplo n.º 7
0
        internal LoadOptionItem(PropertyMeta fkPropertyInfo, Action <Entity, Entity> fkSetter)
        {
            if (fkPropertyInfo == null)
            {
                throw new ArgumentNullException("propertyInfo");
            }
            if (fkSetter == null)
            {
                throw new ArgumentNullException("fkSetter");
            }

            this.PropertyMeta = fkPropertyInfo;
            this._fkSetter    = fkSetter;
        }
 internal string GetPropertyKey <TContext, T>(Expression <Func <TContext, T> > expression)
 {
     if (expression.Body is MemberExpression member)
     {
         var    meta = new PropertyMeta(typeof(TContext), member.Member, typeof(T));
         string key  = properties.SingleOrDefault(p => p.Value.FullType == meta.FullType && p.Value.Name == meta.Name).Key;
         if (key == null)
         {
             key             = Guid.NewGuid().ToString();
             properties[key] = meta;
         }
         return(key);
     }
     else
     {
         throw new InvalidOperationException("Invalid lamda provided. only properties or fields allowed");
     }
 }
Ejemplo n.º 9
0
        public virtual async Task <IActionResult> DeleteMeta(int id, int metaId)
        {
            try
            {
                PropertyMeta meta = await _db.PropertyMetadata.FindAsync(metaId);

                _db.Entry(meta).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
                SaveMessage           = $"Successfully deleted {meta.Name}.";
                MessageType           = AlertType.Success;
                await _db.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                SaveMessage = $"Error deleting a property meta.";
                MessageType = AlertType.Danger;
                await _logService.AddExceptionAsync <BasePropertyController>(SaveMessage, ex);
            }
            return(RedirectToAction(nameof(Edit), new { id }));
        }
Ejemplo n.º 10
0
        public virtual async Task <IActionResult> AddMeta(int id, string name)
        {
            try
            {
                PropertyListing property = await _db.Properties.AsNoTracking().SingleOrDefaultAsync(p => p.Id == id);

                if (property == null)
                {
                    throw new Exception("Property not found.");
                }

                int?count = await _db.PropertyMetadata.Where(m => m.Name.Contains($"{name}")).CountAsync();

                if (!count.HasValue)
                {
                    count = 0;
                }

                PropertyMeta meta = new PropertyMeta()
                {
                    PropertyId = property.Id,
                    Name       = name,
                    Type       = "System.String"
                };
                meta.SetValue("");
                _db.Add(meta);
                await _db.SaveChangesAsync();

                SaveMessage = $"Successfully added new field: {meta.Name}.";
                MessageType = AlertType.Success;
            }
            catch (Exception ex)
            {
                SaveMessage = $"Error adding a property meta: {name}.";
                MessageType = AlertType.Danger;
                await _logService.AddExceptionAsync <BasePropertyController>(SaveMessage, ex);
            }

            return(RedirectToAction(nameof(Edit), new { id }));
        }
Ejemplo n.º 11
0
        private static IList <PropertyMeta> AddPropertyMetas(Type type)
        {
            if (_propertyMetas.TryGetValue(type, out var metas) && metas != null)
            {
                return(metas);
            }

            metas = new List <PropertyMeta>();

            var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);

            foreach (var info in properties)
            {
                if (info.Name == "Item")
                {
                    continue;
                }

                var meta = new PropertyMeta {
                    Info = info, IsField = false
                };
                metas.Add(meta);
            }

            var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public);

            foreach (var info in fields)
            {
                var meta = new PropertyMeta {
                    Info = info, IsField = true
                };
                metas.Add(meta);
            }

            _propertyMetas[type] = metas;
            return(metas);
        }
Ejemplo n.º 12
0
 internal OracleColumn(DbTable table, string name, PropertyMeta property) : base(table, name, property)
 {
 }
Ejemplo n.º 13
0
 public NullPropertyMap(Type parentType, PropertyMeta targetProperty) : base(parentType, targetProperty)
 {
 }
Ejemplo n.º 14
0
        public void Row2Object(IRow row)
        {
            try
            {
                string domainName    = row.GetCell(0).ToString();
                string domainDes     = row.GetCell(1)?.ToString();
                string domainlangStr = row.GetCell(2)?.ToString();
                string objectName    = row.GetCell(3)?.ToString();
                string objDescrip    = row.GetCell(4)?.ToString();
                string objLangStr    = row.GetCell(5)?.ToString();
                string propertyName  = row.GetCell(6).ToString();
                bool   IsKey         = row.GetCell(7)?.ToString() == null ? false : row.GetCell(7).ToString() == "TRUE";
                string dataType      = row.GetCell(8)?.ToString();
                bool   Nullable      = row.GetCell(9)?.ToString() == null ? true : row.GetCell(9).ToString() != "FALSE";
                string unit          = row.GetCell(10)?.ToString();
                string regularExp    = row.GetCell(11)?.ToString();
                string proDes        = row.GetCell(12)?.ToString();
                string proLanStr     = row.GetCell(13)?.ToString();


                DomainDef    domain    = null;
                DGObjectDef  objectDef = null;
                PropertyMeta property  = new PropertyMeta
                {
                    PropertyName = propertyName,
                    IsKey        = IsKey,
                    Nullable     = Nullable,
                    DataType     = dataType,
                    Unit         = unit,
                    Description  = proDes,
                    RegularExp   = regularExp
                };

                if (this.standardDef.DomainContainer.Exists(x => x.Code == domainName))
                {
                    domain = this.standardDef.DomainContainer.Find(x => x.Code == domainName);

                    if (domain.DGObjectContainer.Exists(x => x.Code == objectName))
                    {
                        objectDef = domain.DGObjectContainer.Find(x => x.Code == objectName);
                        if (!objectDef.PropertyContainer.Exists(x => x.PropertyName == property.PropertyName))
                        {
                            objectDef.PropertyContainer.Add(property);
                        }
                    }
                    else
                    {
                        objectDef = new DGObjectDef
                        {
                            Code        = objectName,
                            Desctiption = objDescrip,
                            LangStr     = objLangStr
                        };
                        objectDef.PropertyContainer.Add(property);
                        domain.DGObjectContainer.Add(objectDef);
                    }
                }
                else
                {
                    domain = new DomainDef
                    {
                        Code       = domainName,
                        Desciption = domainDes,
                        LangStr    = domainlangStr
                    };
                    objectDef = new DGObjectDef
                    {
                        Code        = objectName,
                        Desctiption = objDescrip,
                        LangStr     = objLangStr
                    };
                    objectDef.PropertyContainer.Add(property);
                    domain.DGObjectContainer.Add(objectDef);
                    this.standardDef.DomainContainer.Add(domain);
                }
            }
            catch (Exception e)
            {
                System.Windows.MessageBox.Show(e.Message);
            }
        }
Ejemplo n.º 15
0
        public void ImportDefinitions(TreeNode Root)
        {
            int count = Root.Nodes.Count;
            Definitions = new List<ClassDefinition>();
            for (int i = 0; i < count; i++)
            {
                TreeNode n1 = Root.Nodes[i];
                ClassDefinition t = new ClassDefinition();
                t.name = n1.Text;
                t.props = new List<Property>();
                for (int j = 0; j < n1.Nodes.Count; j++)
                {
                    Property p = new Property();
                    TreeNode n2 = n1.Nodes[j];
                    p.name = n2.Text;
                    p.Meta = new List<PropertyMeta>();
                    for (int k = 0; k < n2.Nodes.Count / 2 ; k++)
                    {
                        TreeNode s1 = n2.Nodes[k * 2];
                        TreeNode t1 = n2.Nodes[k * 2 + 1];
                        PropertyMeta m = new PropertyMeta();
                        m.size = Convert.ToInt32(s1.Text);
                        m.type = Convert.ToInt32(t1.Text);
                        p.Meta.Add(m);
                    }
                    t.props.Add(p);
                }
                Definitions.Add(t);
            }
            bool run=true;
            while (run)
            {
                run = false;
                for (int i = 0; i < Definitions.Count - 1; i++)
                    if (string.Compare(Definitions[i].name, Definitions[i + 1].name) > 0)
                    {
                        run = true;
                        ClassDefinition t = Definitions[i];
                        Definitions[i] = Definitions[i + 1];
                        Definitions[i + 1] = t;
                    }
                for (int i = 0; i < Definitions.Count - 1; i++)
                    for(int j=0;j<Definitions[i].props.Count-1;j++)
                        if (string.Compare(Definitions[i].props[j].name, Definitions[i].props[j + 1].name) > 0)
                        {
                            run=true;
                            Property p = Definitions[i].props[j];
                            Definitions[i].props[j] = Definitions[i].props[j + 1];
                            Definitions[i].props[j + 1] = p;
                        }

            }
        }
Ejemplo n.º 16
0
 internal override DbColumn CreateColumn(string columnName, PropertyMeta property)
 {
     return(new OracleColumn(this, columnName, property));
 }
Ejemplo n.º 17
0
 public PropertyMap(Type parentType, PropertyMeta sourceProperty, PropertyMeta targetProperty, IMapRegistry registry) : base(parentType, targetProperty)
 {
     Guard.NotNull(() => sourceProperty, () => targetProperty);
     _sourceProperty = sourceProperty;
     _map            = registry.GetMap(sourceProperty.Type, targetProperty.Type);
 }
Ejemplo n.º 18
0
 internal virtual DbColumn CreateColumn(string columnName, PropertyMeta property)
 {
     return(new DbColumn(this, columnName, property));
 }
Ejemplo n.º 19
0
 public PropertyReflector(object item, PropertyMeta property)
 {
     _item     = item;
     _property = property;
 }
Ejemplo n.º 20
0
 protected PropertyMapBase(Type parentType, PropertyMeta targetProperty)
 {
     TargetProperty = targetProperty;
     PropertyName   = targetProperty.Name;
     FullName       = string.Format("{0}.{1}", parentType.Name, targetProperty.Name);
 }