protected virtual void HandleSlaveOneOnePropertySet(object obj, IPropertyMap propertyMap, object value, object oldValue)
        {
            this.Context.LogManager.Info(this, "Managing inverse one-one property relationship synchronization", "Writing to object of type: " + obj.GetType().ToString() + ", Property: " + propertyMap.Name);             // do not localize

            IPropertyMap invPropertyMap = propertyMap.GetInversePropertyMap();

            if (invPropertyMap == null)
            {
                return;
            }
            IObjectManager om  = this.Context.ObjectManager;
            IUnitOfWork    uow = this.Context.UnitOfWork;

            if (value != null)
            {
                om.EnsurePropertyIsLoaded(value, invPropertyMap);
                om.SetPropertyValue(value, invPropertyMap.Name, obj);
                om.SetNullValueStatus(value, invPropertyMap.Name, false);
                om.SetUpdatedStatus(value, invPropertyMap.Name, true);
                uow.RegisterDirty(value);
                this.Context.LogManager.Debug(this, "Wrote back-reference to inverse property", "Wrote to object of type: " + value.GetType().ToString() + ", Inverse Property: " + invPropertyMap.Name);                 // do not localize
            }

            if (oldValue != null)
            {
                om.EnsurePropertyIsLoaded(oldValue, invPropertyMap);
                om.SetPropertyValue(oldValue, invPropertyMap.Name, null);
                om.SetNullValueStatus(oldValue, invPropertyMap.Name, false);
                om.SetUpdatedStatus(oldValue, invPropertyMap.Name, true);
                uow.RegisterDirty(oldValue);
                this.Context.LogManager.Debug(this, "Wrote null to inverse property", "Wrote to object of type: " + oldValue.GetType().ToString() + ", Inverse Property: " + invPropertyMap.Name);                 // do not localize
            }
        }
        protected virtual void HandleSlaveManyManyPropertySet(object obj, IPropertyMap propertyMap, IList newList, IList oldList)
        {
            this.Context.LogManager.Info(this, "Managing inverse many-many property relationship synchronization", "Writing to object of type: " + obj.GetType().ToString() + ", Property: " + propertyMap.Name);             // do not localize

            IPropertyMap invPropertyMap = propertyMap.GetInversePropertyMap();

            if (invPropertyMap == null)
            {
                return;
            }
            ArrayList          added   = GetListDiff(oldList, newList);
            ArrayList          removed = GetListDiff(newList, oldList);
            IObjectManager     om      = this.Context.ObjectManager;
            IUnitOfWork        uow     = this.Context.UnitOfWork;
            IList              list;
            IInterceptableList mList;
            bool   stackMute = false;
            object value;

            foreach (object iValue in added)
            {
                value = iValue;
                om.EnsurePropertyIsLoaded(value, invPropertyMap);
                list  = (IList)om.GetPropertyValue(value, invPropertyMap.Name);
                mList = list as IInterceptableList;
                if (mList != null)
                {
                    stackMute        = mList.MuteNotify;
                    mList.MuteNotify = true;
                }
                list.Add(obj);
                if (mList != null)
                {
                    mList.MuteNotify = stackMute;
                }
                uow.RegisterDirty(value);
                om.SetUpdatedStatus(value, invPropertyMap.Name, true);
            }
            foreach (object iValue in removed)
            {
                value = iValue;
                om.EnsurePropertyIsLoaded(value, invPropertyMap);
                list  = (IList)om.GetPropertyValue(value, invPropertyMap.Name);
                mList = list as IInterceptableList;
                if (mList != null)
                {
                    stackMute        = mList.MuteNotify;
                    mList.MuteNotify = true;
                }
                list.Remove(obj);
                if (mList != null)
                {
                    mList.MuteNotify = stackMute;
                }
                uow.RegisterDirty(value);
                om.SetUpdatedStatus(value, invPropertyMap.Name, true);
            }
        }
Esempio n. 3
0
        protected virtual void PerformRemoveAction(InverseAction action)
        {
            object             obj          = action.Obj;
            string             propertyName = action.PropertyName;
            object             value        = action.Value;
            IPropertyMap       propertyMap  = this.Context.DomainMap.MustGetClassMap(obj.GetType()).MustGetPropertyMap(propertyName);
            IObjectManager     om           = this.Context.ObjectManager;
            IList              list;
            IInterceptableList mList;
            bool stackMute = false;

            om.EnsurePropertyIsLoaded(obj, propertyMap);
            list  = (IList)om.GetPropertyValue(obj, propertyName);
            mList = list as IInterceptableList;
            if (mList != null)
            {
                stackMute        = mList.MuteNotify;
                mList.MuteNotify = true;
            }
            list.Remove(value);
            if (mList != null)
            {
                mList.MuteNotify = stackMute;
            }
            om.SetUpdatedStatus(obj, propertyName, true);

            this.Context.LogManager.Debug(this, "Performed cached inverse action", "Action type: " + action.ActionType.ToString() + ", Wrote to object of type: " + obj.GetType().ToString() + ", Property: " + propertyName + ", Value object type: " + value.GetType().ToString());               // do not localize
        }
Esempio n. 4
0
        protected virtual void HandleOneOnePropertySet(object obj, IPropertyMap propertyMap, object value, object oldValue)
        {
            this.Context.LogManager.Info(this, "Managing inverse one-one property relationship synchronization", "Writing to object of type: " + obj.GetType().ToString() + ", Property: " + propertyMap.Name);             // do not localize

            PropertyStatus propStatus;

            IPropertyMap invPropertyMap = propertyMap.GetInversePropertyMap();

            if (invPropertyMap == null)
            {
                return;
            }
            IObjectManager om = this.Context.ObjectManager;

            if (value != null)
            {
                propStatus = om.GetPropertyStatus(value, invPropertyMap.Name);
                if (propStatus == PropertyStatus.NotLoaded)
                {
                    AddAction(InverseActionType.Set, value, invPropertyMap.Name, obj, obj);
                }
                else
                {
                    om.EnsurePropertyIsLoaded(value, invPropertyMap);
                    om.SetPropertyValue(value, invPropertyMap.Name, obj);
                    om.SetNullValueStatus(value, invPropertyMap.Name, false);
                    om.SetUpdatedStatus(value, invPropertyMap.Name, true);
                }
            }

            if (oldValue != null)
            {
                propStatus = om.GetPropertyStatus(value, invPropertyMap.Name);
                if (propStatus == PropertyStatus.NotLoaded)
                {
                    AddAction(InverseActionType.Set, value, invPropertyMap.Name, null, obj);
                }
                else
                {
                    om.EnsurePropertyIsLoaded(oldValue, invPropertyMap);
                    om.SetPropertyValue(oldValue, invPropertyMap.Name, null);
                    om.SetNullValueStatus(oldValue, invPropertyMap.Name, false);
                    om.SetUpdatedStatus(oldValue, invPropertyMap.Name, true);
                }
            }
        }
Esempio n. 5
0
        protected virtual void PerformSetAction(InverseAction action)
        {
            object         obj          = action.Obj;
            string         propertyName = action.PropertyName;
            object         value        = action.Value;
            IPropertyMap   propertyMap  = this.Context.DomainMap.MustGetClassMap(obj.GetType()).MustGetPropertyMap(propertyName);
            IObjectManager om           = this.Context.ObjectManager;

            om.EnsurePropertyIsLoaded(obj, propertyMap);
            om.SetPropertyValue(obj, propertyName, value);
            om.SetNullValueStatus(obj, propertyName, false);
            om.SetUpdatedStatus(obj, propertyName, true);

            if (value == null)
            {
                this.Context.LogManager.Debug(this, "Performed cached inverse action", "Action type: " + action.ActionType.ToString() + ", Wrote to object of type: " + obj.GetType().ToString() + ", Property: " + propertyName + ", Value: null");                 // do not localize
            }
            else
            {
                this.Context.LogManager.Debug(this, "Performed cached inverse action", "Action type: " + action.ActionType.ToString() + ", Wrote to object of type: " + obj.GetType().ToString() + ", Property: " + propertyName + ", Value object type: " + value.GetType().ToString());                   // do not localize
            }
        }
Esempio n. 6
0
        protected virtual void HandleOneManyPropertySet(object obj, IPropertyMap propertyMap, object value, object oldValue)
        {
            this.Context.LogManager.Info(this, "Managing inverse one-many property relationship synchronization", "Writing to object of type: " + obj.GetType().ToString() + ", Property: " + propertyMap.Name);             // do not localize

            PropertyStatus propStatus;
            IPropertyMap   invPropertyMap = propertyMap.GetInversePropertyMap();

            if (invPropertyMap == null)
            {
                return;
            }
            IObjectManager     om = this.Context.ObjectManager;
            IList              list;
            IInterceptableList mList;
            bool stackMute = false;

            if (value != null)
            {
                propStatus = om.GetPropertyStatus(value, invPropertyMap.Name);
                if (propStatus == PropertyStatus.NotLoaded)
                {
                    AddAction(InverseActionType.Add, value, invPropertyMap.Name, obj, obj);
                }
                else
                {
                    om.EnsurePropertyIsLoaded(value, invPropertyMap);
                    list  = (IList)om.GetPropertyValue(value, invPropertyMap.Name);
                    mList = list as IInterceptableList;
                    if (mList != null)
                    {
                        stackMute        = mList.MuteNotify;
                        mList.MuteNotify = true;
                    }
                    list.Add(obj);
                    if (mList != null)
                    {
                        mList.MuteNotify = stackMute;
                    }
                    om.SetUpdatedStatus(value, invPropertyMap.Name, true);
                }
            }

            if (oldValue != null)
            {
                propStatus = om.GetPropertyStatus(oldValue, invPropertyMap.Name);
                if (propStatus == PropertyStatus.NotLoaded)
                {
                    AddAction(InverseActionType.Remove, oldValue, invPropertyMap.Name, obj, obj);
                }
                else
                {
                    om.EnsurePropertyIsLoaded(oldValue, invPropertyMap);
                    list  = (IList)om.GetPropertyValue(oldValue, invPropertyMap.Name);
                    mList = list as IInterceptableList;
                    if (mList != null)
                    {
                        stackMute        = mList.MuteNotify;
                        mList.MuteNotify = true;
                    }
                    list.Remove(obj);
                    if (mList != null)
                    {
                        mList.MuteNotify = stackMute;
                    }
                }
            }
        }
Esempio n. 7
0
        protected virtual void HandleManyManyPropertySet(object obj, IPropertyMap propertyMap, IList newList, IList oldList)
        {
            this.Context.LogManager.Info(this, "Managing inverse many-many property relationship synchronization", "Writing to object of type: " + obj.GetType().ToString() + ", Property: " + propertyMap.Name);             // do not localize

            PropertyStatus propStatus;
            IPropertyMap   invPropertyMap = propertyMap.GetInversePropertyMap();

            if (invPropertyMap == null)
            {
                return;
            }
            ArrayList          added   = GetListDiff(oldList, newList);
            ArrayList          removed = GetListDiff(newList, oldList);
            IObjectManager     om      = this.Context.ObjectManager;
            IList              list;
            IInterceptableList mList;
            bool   stackMute = false;
            object value;

            foreach (object iValue in added)
            {
                value      = iValue;
                propStatus = om.GetPropertyStatus(value, invPropertyMap.Name);
                if (propStatus == PropertyStatus.NotLoaded)
                {
                    value = iValue;
                    AddAction(InverseActionType.Add, value, invPropertyMap.Name, obj, obj);
                }
                else
                {
                    //we still ensure so that the object is also always loaded...
                    om.EnsurePropertyIsLoaded(value, invPropertyMap);
                    list  = (IList)om.GetPropertyValue(value, invPropertyMap.Name);
                    mList = list as IInterceptableList;
                    if (mList != null)
                    {
                        stackMute        = mList.MuteNotify;
                        mList.MuteNotify = true;
                    }
                    list.Add(obj);
                    if (mList != null)
                    {
                        mList.MuteNotify = stackMute;
                    }
                    om.SetUpdatedStatus(value, invPropertyMap.Name, true);
                }
            }
            foreach (object iValue in removed)
            {
                value      = iValue;
                propStatus = om.GetPropertyStatus(value, invPropertyMap.Name);
                if (propStatus == PropertyStatus.NotLoaded)
                {
                    value = iValue;
                    AddAction(InverseActionType.Remove, value, invPropertyMap.Name, obj, obj);
                }
                else
                {
                    //we still ensure so that the object is also always loaded...
                    om.EnsurePropertyIsLoaded(value, invPropertyMap);
                    list  = (IList)om.GetPropertyValue(value, invPropertyMap.Name);
                    mList = list as IInterceptableList;
                    if (mList != null)
                    {
                        stackMute        = mList.MuteNotify;
                        mList.MuteNotify = true;
                    }
                    list.Remove(obj);
                    if (mList != null)
                    {
                        mList.MuteNotify = stackMute;
                    }
                    om.SetUpdatedStatus(value, invPropertyMap.Name, true);
                }
            }
        }
        private void LoadProperty(object obj, IPropertyMap propertyMap, IObjectManager om, object source, IPropertyMap sourcePropertyMap, IObjectManager sourceOm, RefreshBehaviorType refreshBehavior)
        {
            if (!Monitor.TryEnter(sourceContext, this.Context.Timeout))
                throw new NPersistTimeoutException("Could not acquire exclusive lock on root context before timeout: " + this.Context.Timeout.ToString() + " ms" );

            try
            {
                sourceOm.EnsurePropertyIsLoaded(source, sourcePropertyMap.Name);

                bool nullValueStatus;
                object value;
                if (propertyMap.ReferenceType == ReferenceType.None)
                {
                    if (!(propertyMap.IsCollection))
                    {
                        value = sourceOm.GetPropertyValue(source, sourcePropertyMap.Name);
                        nullValueStatus = sourceOm.GetNullValueStatus(source, sourcePropertyMap.Name);

                        om.SetPropertyValue(obj, propertyMap.Name, value);
                        if (nullValueStatus)
                        {
                            om.SetOriginalPropertyValue(obj, propertyMap.Name, DBNull.Value);
                        }
                        else
                        {
                            om.SetOriginalPropertyValue(obj, propertyMap.Name, value);
                        }
                        om.SetNullValueStatus(obj, propertyMap.Name, nullValueStatus);
                    }
                    else
                    {
                        //Using CloneList will work when it is only primitive values
                        //(or immutable objects such as strings and dates)
                        //that can be copied between contexts
                        IList list = (IList) sourceOm.GetPropertyValue(source, sourcePropertyMap.Name);
                        IList listClone = this.Context.ListManager.CloneList(obj, propertyMap, list);
                        //IList listCloneOrg = this.Context.ListManager.CloneList(obj, propertyMap, list);
                        IList listCloneOrg = new ArrayList( list);
                        om.SetPropertyValue(obj, propertyMap.Name, listClone);
                        om.SetOriginalPropertyValue(obj, propertyMap.Name, listCloneOrg);
                    }
                }
                else
                {
                    if (!(propertyMap.IsCollection))
                    {
                        object refObject = sourceOm.GetPropertyValue(source, sourcePropertyMap.Name);

                        if (refObject == null)
                        {
                            om.SetPropertyValue(obj, propertyMap.Name, null);
                            om.SetOriginalPropertyValue(obj, propertyMap.Name, null);

                            om.SetNullValueStatus(obj, propertyMap.Name, true);
                        }
                        else
                        {
                            string identity = sourceOm.GetObjectIdentity(refObject);

                            Type refType = ToLeafType(refObject);

                            //Impossible to solve for inheritance scenarios when mapping presentation model to domain model!!!!
                            //We could try checking which presentation domain map which class map that maps to the
                            //domain class map, but that could be a many-one relationship (many presentation model classes
                            //map to the same domain model class!)
                            //								IClassMap sourceOrgClassMap = this.sourceContext.DomainMap.GetClassMap(orgObject.GetType() );
                            //								IClassMap leafOrgClassMap = this.sourceContext.DomainMap.GetClassMap(sourceOrgClassMap.Name );
                            //								IClassMap theClassMap = this.sourceContext.DomainMap.GetClassMap (sourceOrgClassMap.Name );

                            value = this.Context.GetObjectById(identity, refType, true);
                            nullValueStatus = sourceOm.GetNullValueStatus(source, sourcePropertyMap.Name);

                            om.SetPropertyValue(obj, propertyMap.Name, value);
                            om.SetOriginalPropertyValue(obj, propertyMap.Name, value);

                            om.SetNullValueStatus(obj, propertyMap.Name, nullValueStatus);
                        }
                    }
                    else
                    {
                        //Using CloneList will not work when there are reference values (to mutable objects)
                        //that can be copied between contexts
                        IList orgList = (IList) sourceOm.GetPropertyValue(source, sourcePropertyMap.Name);
                        IList list = (IList) om.GetPropertyValue(obj, sourcePropertyMap.Name);

                        this.LoadReferenceList(list, orgList, refreshBehavior);

                        //for the org-list we can use ListManager.CloneList and clone the list of leaf objects
                        //IList listOrg = this.Context.ListManager.CloneList(obj, propertyMap, list);
                        IList listOrg = new ArrayList( list);
                        om.SetPropertyValue(obj, propertyMap.Name, list);
                        om.SetOriginalPropertyValue(obj, propertyMap.Name, listOrg);

                    }
                }
            }
            finally
            {
                Monitor.Exit(sourceContext);
            }
        }