public void AddNode(object obj, object waitFor)
        {
            TopologicalNode node        = GetNode(obj);
            TopologicalNode waitForNode = GetNode(waitFor);

            node.AddWaitFor(waitForNode);
        }
        public void RemoveNode(object obj)
        {
            TopologicalNode node = (TopologicalNode)graph[obj];

            if (node != null)
            {
                node.RemoveWaiting();
            }
        }
        public TopologicalNode GetNode(object obj)
        {
            TopologicalNode node = (TopologicalNode)graph[obj];

            if (node == null)
            {
                node = new TopologicalNode(obj);
            }
            graph[obj] = node;
            return(node);
        }
        internal bool IsWaiting(object obj)
        {
            TopologicalNode node = (TopologicalNode)graph[obj];

            if (node != null)
            {
                if (node.WaitFor.Count > 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 5
0
        private bool MayForceDelete(object delObj)
        {
            TopologicalNode node = (TopologicalNode)m_topologicalDelete.Graph[delObj];

            if (node == null)
            {
                return(true);
            }

            IObjectManager om = this.Context.ObjectManager;

            foreach (TopologicalNode waitForNode in node.WaitFor)
            {
                if (!ExamineWaitForNode(om, delObj, waitForNode.Obj))
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 6
0
 public void AddWaitFor(TopologicalNode waitForNode)
 {
     this.waitFor.Add(waitForNode);
     waitForNode.Waiting.Add(this);
 }
Esempio n. 7
0
        protected virtual void RemoveDeleted(object forObj, int exceptionLimit)
        {
            this.Context.LogManager.Debug(this, "Removing objects that are up for deletion", "");             // do not localize

            try
            {
                long      cnt;
                long      staleCnt      = 0;
                bool      tryForce      = false;
                ArrayList removeObjects = new ArrayList();
                cnt = m_listDeleted.Count;
                IObjectManager     om = this.Context.ObjectManager;
                IPersistenceEngine pe = this.Context.PersistenceEngine;
                while (cnt > 0)
                {
                    try
                    {
                        removeObjects.Clear();
                        foreach (object obj in m_listDeleted)
                        {
                            try
                            {
                                if (forObj != null)
                                {
                                    if (obj == forObj)
                                    {
                                        removeObjects.Add(obj);
                                    }
                                }
                                else
                                {
                                    if (tryForce)
                                    {
                                        if (MayForceDelete(obj))
                                        {
                                            //Force an update all the referencing objects, which should have had their
                                            //references to our object set to null in advance during the delete operation.
                                            //This way all the references to our object should be set to null in the database.
                                            TopologicalNode node = (TopologicalNode)m_topologicalDelete.Graph[obj];
                                            if (node != null)
                                            {
                                                foreach (TopologicalNode waitForNode in node.WaitFor)
                                                {
                                                    IList dummyStillDirty = new ArrayList();
                                                    pe.UpdateObject(waitForNode.Obj, dummyStillDirty);
                                                    AddSpeciallyUpdated(waitForNode.Obj);
                                                }
                                            }
                                            tryForce = false;
                                            removeObjects.Add(obj);
                                        }
                                    }
                                    else
                                    {
                                        if (MayRemove(obj))
                                        {
                                            removeObjects.Add(obj);
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                if (exceptionLimit > 0 && exceptions.Count >= exceptionLimit - 1)
                                {
                                    throw ex;
                                }
                                exceptions.Add(ex);
                            }
                        }
                        foreach (object obj in removeObjects)
                        {
                            try
                            {
                                m_listDeleted.Remove(obj);
                                m_listRemoved.Add(obj);
                                m_topologicalDelete.RemoveNode(obj);
                                pe.RemoveObject(obj);
                                this.Context.LogManager.Debug(this, "Removed object", "");                                  // do not localize
                            }
                            catch (Exception ex)
                            {
                                if (exceptionLimit > 0 && exceptions.Count >= exceptionLimit - 1)
                                {
                                    throw ex;
                                }
                                exceptions.Add(ex);
                            }
                        }
                        if (m_listDeleted.Count == cnt)
                        {
                            if (staleCnt > 0)
                            {
                                throw new UnitOfWorkException("The objects that are up for deletion in the unit of work are arranged in an unresolvable graph!");
                            }
                            else
                            {
                                tryForce = true;
                                staleCnt++;
                            }
                        }
                        else
                        {
                            staleCnt = 0;
                        }
                        if (forObj != null)
                        {
                            cnt = 0;
                        }
                        else
                        {
                            cnt = m_listDeleted.Count;
                        }
                    }
                    catch (Exception ex)
                    {
                        if (exceptionLimit > 0 && exceptions.Count >= exceptionLimit - 1)
                        {
                            throw ex;
                        }
                        exceptions.Add(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                if (exceptionLimit > 0 && exceptions.Count >= exceptionLimit - 1)
                {
                    throw ex;
                }
                exceptions.Add(ex);
            }
        }