Exemplo n.º 1
0
        public void HandleOneToMany(ISerializableObject handledItem, OneToManyAttribute attr, FieldInfo field)
        {
            OneToManyStrategy s = new DirectAccessIteratorStrategy();
            Type type           = field.FieldType.GetGenericArguments()[0];

            s.UpdateOneToMany(field.GetValue(handledItem), handledItem, type, _serializer);
        }
Exemplo n.º 2
0
        public void HandleOneToMany(ISerializableObject handledItem, OneToManyAttribute attr, FieldInfo field)
        {
            if (_mode == DOWNMODE)
            {
                if (attr.DeleteType == DeleteTypes.CASCADE)
                {
                    IEnumerable en = (IEnumerable)field.GetValue(handledItem);
                    List <ISerializableObject> remove = new List <ISerializableObject>();
                    foreach (ISerializableObject iso in en)
                    {
                        remove.Add(iso);
                    }

                    foreach (ISerializableObject iso in remove)
                    {
                        _serializer.Connector.Delete(iso);
                    }
                }
                else if (attr.DeleteType == DeleteTypes.NOACTION)
                {
                    //noop
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
        }
Exemplo n.º 3
0
        private void OnBeforeDeleteInternal()
        {
            //We want to persist all the Inverse OneToManyCollection upon deletion. Let's remove all lists that doesn't
            //need persistance first (all objects therein will be deleted in the database via delete cascades anyways)
            foreach (var pi in DwarfHelper.GetOneToManyProperties(this))
            {
                var propertyAtt = OneToManyAttribute.GetAttribute(pi.ContainedProperty);

                if (propertyAtt == null)
                {
                    throw new NullReferenceException(pi.Name + " is missing the OneToMany attribute...");
                }

                if (!propertyAtt.IsInverse)
                {
                    continue;
                }

                var obj = (IDwarfList)pi.GetValue(this);

                var owningProp = oneToManyAlternateKeys.ContainsKey(pi.Name) ? oneToManyAlternateKeys[pi.Name] : GetType().Name;

                obj.Cast <IDwarf>().ForEachX(x => PropertyHelper.SetValue(x, owningProp, null));
                obj.SaveAllInternal <T>();
            }

            if (DbContextHelper <T> .DbContext.IsAuditLoggingSuspended || DwarfContext <T> .GetConfiguration().AuditLogService == null)
            {
                return;
            }

            var traces = (from ep in DwarfHelper.GetDBProperties(GetType()).Where(x => !x.Name.Equals("Id"))
                          let oldValue = originalValues[ep.Name]
                                         where oldValue != null && (oldValue is string? !string.IsNullOrEmpty(oldValue.ToString()) : true)
                                         select new AuditLogEventTrace {
                PropertyName = ep.Name, OriginalValue = oldValue
            }).ToArray();

            var collectionTraces = (from ep in DwarfHelper.GetGemListProperties(GetType())
                                    let oldValue = (IGemList)ep.GetValue(this)
                                                   where oldValue != null && oldValue.Count > 0
                                                   select new AuditLogEventTrace {
                PropertyName = ep.Name, OriginalValue = oldValue
            }).ToArray();

            var many2ManyTraces = (from ep in DwarfHelper.GetManyToManyProperties(GetType())
                                   let oldValue = ep.GetValue(this)
                                                  where oldValue != null && ((IList)oldValue).Count > 0
                                                  select new AuditLogEventTrace {
                PropertyName = ep.Name, OriginalValue = oldValue
            }).ToArray();

            DwarfContext <T> .GetConfiguration().AuditLogService.Logg(this, AuditLogTypes.Deleted, traces.Union(collectionTraces).Union(many2ManyTraces).ToArray());
        }
Exemplo n.º 4
0
        public List <Tuple <string, Object> > GetColumnsAndValues(Object instance, bool isInherited = false)
        {
            List <Tuple <string, Object> > list = new List <Tuple <string, Object> > {
            };
            Type instanceType = instance.GetType();

            PropertyInfo[] properties;

            if (isInherited)
            {
                properties = GetTypeAllProperties(instanceType);
            }
            else
            {
                properties = GetTypeProperties(instanceType);
            }

            foreach (PropertyInfo property in properties)
            {
                MethodInfo      strGetter = property.GetGetMethod(nonPublic: true);
                var             value     = strGetter.Invoke(instance, null);
                string          columnName;
                ColumnAttribute columnAttribute = (ColumnAttribute)property.GetCustomAttribute(typeof(ColumnAttribute), false);

                if (columnAttribute == null)
                {
                    continue;
                }

                if (columnAttribute._columnName == null)
                {
                    columnName = property.Name;
                }
                else
                {
                    columnName = columnAttribute._columnName;
                }

                OneToOneAttribute   oneToOneAttribute   = (OneToOneAttribute)property.GetCustomAttribute(typeof(OneToOneAttribute), false);
                OneToManyAttribute  oneToManyAttribute  = (OneToManyAttribute)property.GetCustomAttribute(typeof(OneToManyAttribute), false);
                ManyToManyAttribute manyToManyAttribute = (ManyToManyAttribute)property.GetCustomAttribute(typeof(ManyToManyAttribute), false);

                if (oneToOneAttribute == null && oneToManyAttribute == null && manyToManyAttribute == null)
                {
                    list.Add(new Tuple <string, Object>(columnName, value));
                }
            }

            return(list);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Automatically handles default persistance operations over DwarfLists for OneToManyRelationships.
        /// Should a manual persistance be used via PersistOneToMany, do so before the base call in AppendStore
        /// </summary>
        private void PersistOneToManyCollections()
        {
            foreach (var pi in DwarfHelper.GetOneToManyProperties(this))
            {
                if (!IsCollectionInitialized(pi.ContainedProperty))
                {
                    continue;
                }

                var propertyName = pi.Name;
                var propertyAtt  = OneToManyAttribute.GetAttribute(pi.ContainedProperty);

                if (propertyAtt == null)
                {
                    throw new NullReferenceException(propertyName + " is missing the OneToMany attribute...");
                }

                var obj = (IDwarfList)PropertyHelper.GetValue(this, propertyName);

                var list = obj.Cast <IDwarf>().ToList();

                var owningProp = oneToManyAlternateKeys.ContainsKey(propertyName) ? oneToManyAlternateKeys[propertyName] : GetType().Name;
                list.ForEach(x => PropertyHelper.SetValue(x, owningProp, this));
                var deleteObjects = obj.GetDeletedItems();

                if (propertyAtt.IsInverse)
                {
                    deleteObjects.ForEach(x => PropertyHelper.SetValue(x, owningProp, null));
                    deleteObjects.SaveAllInternal <T>();
                }
                else
                {
                    deleteObjects.DeleteAllInternal <T>();
                }

                list.SaveAllInternal <T>();

                oneToManyAlternateKeys.Remove(propertyName);
            }
        }
Exemplo n.º 6
0
            public void HandleOneToMany(ISerializableObject handledItem, OneToManyAttribute attr, FieldInfo field)
            {
                IEnumerable set = (IEnumerable)field.GetValue(handledItem);

                foreach (ISerializableObject iso in set)
                {
                    try
                    {
                        SyncContainer s = _pooledObjects[AttributeWorker.RowGuid(iso)];
                        if (!_owner._children.Contains(s))
                        {
                            _owner._children.Add(s);
                        }
                        if (!s._parents.Contains(_owner))
                        {
                            s._parents.Add(_owner);
                        }
                    }
                    catch (KeyNotFoundException)
                    {
                    }
                }
            }
Exemplo n.º 7
0
        public List <Tuple <string, Object> > GetInheritedColumnsAndValues(List <PropertyInfo> inheritedProperties)
        {
            List <Tuple <string, Object> > list = new List <Tuple <string, object> >();

            foreach (var property in inheritedProperties)
            {
                Type            propertyType = property.PropertyType;
                string          columnName;
                ColumnAttribute columnAttribute = (ColumnAttribute)property.GetCustomAttribute(typeof(ColumnAttribute), false);

                if (columnAttribute == null)
                {
                    continue;
                }

                if (columnAttribute._columnName == null)
                {
                    columnName = property.Name;
                }
                else
                {
                    columnName = columnAttribute._columnName;
                }

                OneToOneAttribute   oneToOneAttribute   = (OneToOneAttribute)property.GetCustomAttribute(typeof(OneToOneAttribute), false);
                OneToManyAttribute  oneToManyAttribute  = (OneToManyAttribute)property.GetCustomAttribute(typeof(OneToManyAttribute), false);
                ManyToManyAttribute manyToManyAttribute = (ManyToManyAttribute)property.GetCustomAttribute(typeof(ManyToManyAttribute), false);

                if (oneToOneAttribute == null && oneToManyAttribute == null && manyToManyAttribute == null)
                {
                    list.Add(new Tuple <string, Object>(columnName, propertyType));
                }
            }

            return(list);
        }
Exemplo n.º 8
0
        /// <summary> Write a OneToMany XML Element from attributes in a member. </summary>
        public virtual void WriteOneToMany(System.Xml.XmlWriter writer, System.Reflection.MemberInfo member, OneToManyAttribute attribute, BaseAttribute parentAttribute, System.Type mappedClass)
        {
            writer.WriteStartElement( "one-to-many" );
            // Attribute: <class>
            if(attribute.Class != null)
            writer.WriteAttributeString("class", GetAttributeValue(attribute.Class, mappedClass));
            // Attribute: <not-found>
            if(attribute.NotFound != NotFoundMode.Unspecified)
            writer.WriteAttributeString("not-found", GetXmlEnumValue(typeof(NotFoundMode), attribute.NotFound));
            // Attribute: <node>
            if(attribute.Node != null)
            writer.WriteAttributeString("node", GetAttributeValue(attribute.Node, mappedClass));
            // Attribute: <embed-xml>
            if( attribute.EmbedXmlSpecified )
            writer.WriteAttributeString("embed-xml", attribute.EmbedXml ? "true" : "false");
            // Attribute: <entity-name>
            if(attribute.EntityName != null)
            writer.WriteAttributeString("entity-name", GetAttributeValue(attribute.EntityName, mappedClass));

            WriteUserDefinedContent(writer, member, null, attribute);

            writer.WriteEndElement();
        }
Exemplo n.º 9
0
 public void HandleOneToMany(ISerializableObject handledItem, OneToManyAttribute attr, FieldInfo field)
 {
 }
Exemplo n.º 10
0
        /// <summary>
        /// Δημιουργεί ένα νέο αντικείμενο μεταδεδομένων στήλης / πεδίου οντότητας
        /// </summary>
        /// <param name="FieldInfo"></param>
        public ColumnMetadata(FieldInfo FieldInfo)
        {
            this.FieldInfo = FieldInfo ?? throw new ArgumentNullException(nameof(FieldInfo));

            this.FieldInfo = FieldInfo;
            this.FieldName = FieldInfo.Name;
            this.FieldType = FieldInfo.FieldType;

            //Get Attributes
            ColumnAttribute       column       = this.FieldInfo.GetCustomAttribute <ColumnAttribute>();
            CustomColumnAttribute customColumn = this.FieldInfo.GetCustomAttribute <CustomColumnAttribute>();

            ManyToOneAttribute manyToOne = this.FieldInfo.GetCustomAttribute <ManyToOneAttribute>();
            OneToManyAttribute oneToMany = this.FieldInfo.GetCustomAttribute <OneToManyAttribute>();

            if (column == null && customColumn == null && oneToMany == null)
            {
                throw new MetadataException("This field does not contain any Column information");
            }

            this.IsIdentifier = (this.FieldInfo.GetCustomAttribute <IdentityAttribute>() != null);

            if (column != null)
            {
                this.ColumnName = column.ColumnName;
                this.ColumnType = GetType(column.ColumnType);
                this.IsNullable = column.Nullable;
                this.IsUnique   = column.Unique;
            }
            if (customColumn != null)
            {
                this.IsCustomColumn = true;
                //This is hardcoded since our database names the column that stores the value "CustomFieldValue"
                this.ColumnName = "CustomFieldValue";
                this.ColumnType = GetType(customColumn.ColumnType);
                //Default values
                this.IsNullable = true;
                this.IsUnique   = false;

                this.CustomFieldTable     = customColumn.CustomTableName;
                this.CustomFieldId        = customColumn.CustomFieldId;
                this.CustomFieldReference = customColumn.IdentifierColumn;
            }
            if (manyToOne != null)
            {
                this.IsRelationship = true;
                this.TargetEntity   = manyToOne.TargetEntity;
                this.RelationshipReferenceColumn = manyToOne.IdentifierColumn;
                this.RelationshipType            = RelationshipType.ManyToOne;
            }
            if (oneToMany != null)
            {
                this.IsRelationship = true;
                this.TargetEntity   = oneToMany.TargetEntity;
                this.RelationshipReferenceColumn = oneToMany.IdentifierColumn;
                this.RelationshipType            = RelationshipType.OneToMany;
            }
            //ADDED Row Guid
            this.IsRowGuid = (this.FieldInfo.GetCustomAttribute <GuidAttribute>() != null);

            var version = this.FieldInfo.GetCustomAttribute <VersionAttribute>();

            IsVersion = (version != null);
        }
Exemplo n.º 11
0
 public OneToManyRelation(Table parentTable, Table childTable, MemberInfo member,
                          string memberPath, Type memberValueType,
                          OneToManyAttribute relationAttribute) :
     base(parentTable, childTable, member, memberPath, memberValueType, relationAttribute)
 {
 }