예제 #1
0
        public bool Compare()
        {
            bool result = true;

            if (this.m_Value != null && this.m_Clone != null)
            {
                Type           type       = this.m_Value.GetType();
                PropertyInfo[] properties = type.GetProperties();
                foreach (PropertyInfo property in properties)
                {
                    if (property.Name == "Item" || property.Name == "PublishedDocument")
                    {
                        continue;
                    }

                    if (property.PropertyType.FullName.Contains("System") == false ||
                        property.PropertyType.FullName.Contains("Collection") == true ||
                        property.PropertyType.FullName.Contains("List") == true)
                    {
                        if (property.PropertyType.FullName.Contains("Collection") == false && property.PropertyType.FullName.Contains("List") == false)
                        {
                            object object1           = property.GetValue(this.m_Value, null);
                            object object2           = property.GetValue(this.m_Clone, null);
                            DocumentTestBuilders dtb = new DocumentTestBuilders(object1, object2);
                            result = dtb.Compare();
                            if (result == false)
                            {
                                break;
                            }
                        }
                        else
                        {
                            result = this.HandleCollection(property, this.m_Value, this.m_Clone);
                            if (result == false)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        PersistenceHelper persistenceHelper = new PersistenceHelper();
                        result = PersistenceHelper.ArePropertiesEqual(property, this.m_Value, this.m_Clone);
                        if (result == false)
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                result = this.CheckNulls(this.m_Value, this.m_Clone);
                if (result == false)
                {
                    string s = "nope";
                }
            }
            return(result);
        }
예제 #2
0
        private void ProcessObjectForUpdate(object objectToUpdate, Type objectType, object originalValues, Queue <SqlCommand> commandQueue)
        {
            if (PersistenceHelper.ArePersistentPropertiesEqual(objectToUpdate, originalValues) == false)
            {
                PersistentClass persistentClassAttribute = (PersistentClass)objectType.GetCustomAttributes(typeof(PersistentClass), false).Single();

                PropertyInfo   keyProperty       = objectType.GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(PersistentPrimaryKeyProperty))).Single();
                PropertyBridge keyPropertyBridge = PropertyBridgeFactory.GetPropertyBridge(keyProperty, objectToUpdate);

                if (persistentClassAttribute.HasPersistentBaseClass == true)
                {
                    Type rootType = PersistenceHelper.GetRootType(objectToUpdate);
                    List <PropertyBridge> basePropertyBridgeList = this.GetPropertyBridgeList(rootType, objectToUpdate, originalValues);
                    if (basePropertyBridgeList.Count != 0)
                    {
                        commandQueue.Enqueue(this.CreateSqlCommand(keyPropertyBridge, basePropertyBridgeList, persistentClassAttribute.BaseStorageName));
                    }
                }

                if (persistentClassAttribute.IsPersisted == true)
                {
                    List <PropertyBridge> propertyBridgeList = this.GetPropertyBridgeList(objectType, objectToUpdate, originalValues);
                    if (propertyBridgeList.Count != 0)
                    {
                        commandQueue.Enqueue(this.CreateSqlCommand(keyPropertyBridge, propertyBridgeList, persistentClassAttribute.StorageName));
                    }
                }
            }
        }
예제 #3
0
        private List <PropertyBridge> GetPropertyBridgeList(Type type, object objectToUpdate, object originalValues)
        {
            List <PropertyBridge> propertyBridgeList = new List <PropertyBridge>();
            List <PropertyInfo>   properties         = PersistenceHelper.GetPropertiesToHandle(type);

            foreach (PropertyInfo property in properties)
            {
                var originalValue = property.GetValue(originalValues, null);
                var currentValue  = property.GetValue(objectToUpdate, null);

                if (currentValue == null && originalValue != null)
                {
                    PropertyBridge propertyBridge = PropertyBridgeFactory.GetPropertyBridge(property, objectToUpdate);
                    propertyBridgeList.Add(propertyBridge);
                }
                if (currentValue != null && originalValue == null)
                {
                    PropertyBridge propertyBridge = PropertyBridgeFactory.GetPropertyBridge(property, objectToUpdate);
                    propertyBridgeList.Add(propertyBridge);
                }
                else if (currentValue != null && originalValue != null)
                {
                    if (currentValue.Equals(originalValue) == false)
                    {
                        PropertyBridge propertyBridge = PropertyBridgeFactory.GetPropertyBridge(property, objectToUpdate);
                        propertyBridgeList.Add(propertyBridge);
                    }
                }
            }

            return(propertyBridgeList);
        }
예제 #4
0
        public bool Compare()
        {
            bool result = true;
            if(this.m_Value != null && this.m_Clone != null)
            {
                Type type = this.m_Value.GetType();
                PropertyInfo[] properties = type.GetProperties();
                foreach (PropertyInfo property in properties)
                {
                    if(property.Name == "Item" || property.Name == "PublishedDocument")
                    {
                        continue;
                    }

                    if (property.PropertyType.FullName.Contains("System") == false ||
                        property.PropertyType.FullName.Contains("Collection") == true ||
                        property.PropertyType.FullName.Contains("List") == true)
                    {
                        if (property.PropertyType.FullName.Contains("Collection") == false && property.PropertyType.FullName.Contains("List") == false)
                        {
                            object object1 = property.GetValue(this.m_Value, null);
                            object object2 = property.GetValue(this.m_Clone, null);
                            DocumentTestBuilders dtb = new DocumentTestBuilders(object1, object2);
                            result = dtb.Compare();
                            if (result == false)
                                break;
                        }
                        else
                        {
                            result = this.HandleCollection(property, this.m_Value, this.m_Clone);
                            if (result == false)
                                break;
                        }
                    }
                    else
                    {
                        PersistenceHelper persistenceHelper = new PersistenceHelper();
                        result = PersistenceHelper.ArePropertiesEqual(property, this.m_Value, this.m_Clone);
                        if (result == false)
                            break;
                    }
                }
            }
            else
            {
                result = this.CheckNulls(this.m_Value, this.m_Clone);
                if (result == false)
                {
                    string s = "nope";
                }
            }
            return result;
        }
예제 #5
0
        private List <PropertyBridge> GetPropertyBridgeList(Type type, object o)
        {
            List <PropertyBridge> propertyBridgeList = new List <PropertyBridge>();
            List <PropertyInfo>   properties         = PersistenceHelper.GetPropertiesToHandle(type);

            foreach (PropertyInfo property in properties)
            {
                var currentValue = property.GetValue(o, null);
                if (currentValue != null)
                {
                    PropertyBridge propertyBridge = PropertyBridgeFactory.GetPropertyBridge(property, o);
                    propertyBridgeList.Add(propertyBridge);
                }
            }

            return(propertyBridgeList);
        }
예제 #6
0
        private void ProcessObjectForInsert(object objectToInsert, Type objectType, Queue <SqlCommand> insertCommands, Queue <SqlCommand> insertLastCommands)
        {
            PersistentClass persistentClassAttribute = (PersistentClass)objectType.GetCustomAttributes(typeof(PersistentClass), false).Single();
            PropertyInfo    keyProperty = objectType.GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(PersistentPrimaryKeyProperty))).Single();
            PersistentPrimaryKeyProperty keyAttribute = (PersistentPrimaryKeyProperty)keyProperty.GetCustomAttributes(typeof(PersistentPrimaryKeyProperty), false).Single();
            PropertyBridge keyPropertyBridge          = PropertyBridgeFactory.GetPropertyBridge(keyProperty, objectToInsert);
            string         keyPropertyValue           = (string)keyPropertyBridge.GetPropertyValue();

            if (this.m_InsertSubclassOnly == false)
            {
                if (persistentClassAttribute.HasPersistentBaseClass == true)
                {
                    Type rootType = PersistenceHelper.GetRootType(objectToInsert);
                    List <PropertyBridge> basePropertyBridgeList = this.GetPropertyBridgeList(rootType, objectToInsert);
                    if (persistentClassAttribute.IsManyToManyRelationship == true)
                    {
                        SqlCommand sqlCommand = this.CreateSqlCommand(keyPropertyBridge, basePropertyBridgeList, persistentClassAttribute.BaseStorageName, keyAttribute.IsAutoGenerated);
                        insertLastCommands.Enqueue(sqlCommand);
                    }
                    else
                    {
                        SqlCommand sqlCommand = this.CreateSqlCommand(keyPropertyBridge, basePropertyBridgeList, persistentClassAttribute.BaseStorageName, keyAttribute.IsAutoGenerated);
                        insertCommands.Enqueue(sqlCommand);
                    }
                }
            }

            if (persistentClassAttribute.IsPersisted == true)
            {
                List <PropertyBridge> propertyBridgeList = this.GetPropertyBridgeList(objectType, objectToInsert);
                if (persistentClassAttribute.IsManyToManyRelationship == true)
                {
                    SqlCommand sqlCommandToAdd = this.CreateSqlCommand(keyPropertyBridge, propertyBridgeList, persistentClassAttribute.StorageName, keyAttribute.IsAutoGenerated);
                    insertLastCommands.Enqueue(sqlCommandToAdd);
                }
                else
                {
                    SqlCommand sqlCommand = this.CreateSqlCommand(keyPropertyBridge, propertyBridgeList, persistentClassAttribute.StorageName, keyAttribute.IsAutoGenerated);
                    insertCommands.Enqueue(sqlCommand);
                }
            }
        }