Пример #1
0
        public object Clone()
        {
            GrantedLock clonedGrantedLock = new GrantedLock(this.holder);

            clonedGrantedLock.waitList.InsertRange(0, this.waitList);
            return(clonedGrantedLock);
        }
Пример #2
0
        private bool AcquireLocks(Activity activity)
        {
            // If this activity doesn't have any handles, we have nothing to do.
            ICollection <string> handles = GetAllSynchronizationHandles(activity);

            if (handles == null || handles.Count == 0)
            {
                return(true);
            }

            Activity parent = activity.Parent;

            while (parent != null)
            {
                if (parent.SupportsSynchronization || parent.Parent == null)
                {
                    Dictionary <string, GrantedLock> grantedLocks = (Dictionary <string, GrantedLock>)parent.GetValue(GrantedLocksProperty);
                    if (grantedLocks == null)
                    {
                        grantedLocks = new Dictionary <string, GrantedLock>();
                        parent.SetValue(GrantedLocksProperty, grantedLocks);
                    }
                    foreach (string handle in handles)
                    {
                        bool acquiredLocks = true;
                        if (!grantedLocks.ContainsKey(handle))
                        {
                            grantedLocks[handle] = new GrantedLock(activity);
                        }
                        else if (grantedLocks[handle].Holder != activity)
                        {
                            grantedLocks[handle].WaitList.Add(activity);
                            acquiredLocks = false;
                        }
                        if (!acquiredLocks)
                        {
                            return(false);
                        }
                    }
                }

                // If we reach a parent which has at least one handle, then we do not need to
                // go any further as the parent would already have acquired all our locks for
                // itself. Note that we still need to acquire our locks in the same parent if
                // the parent ProvidesSychronization, hence, this if check is *not* after
                // "parent = parent.Parent"!
                ICollection <string> synchronizationHandlesOnParent = (ICollection <string>)parent.GetValue(Activity.SynchronizationHandlesProperty);
                if (synchronizationHandlesOnParent != null && synchronizationHandlesOnParent.Count != 0)
                {
                    break;
                }

                parent = parent.Parent;
            }
            return(true);
        }
        private bool AcquireLocks(System.Workflow.ComponentModel.Activity activity)
        {
            ICollection <string> allSynchronizationHandles = this.GetAllSynchronizationHandles(activity);

            if ((allSynchronizationHandles != null) && (allSynchronizationHandles.Count != 0))
            {
                for (System.Workflow.ComponentModel.Activity activity2 = activity.Parent; activity2 != null; activity2 = activity2.Parent)
                {
                    if (activity2.SupportsSynchronization || (activity2.Parent == null))
                    {
                        Dictionary <string, GrantedLock> dictionary = (Dictionary <string, GrantedLock>)activity2.GetValue(GrantedLocksProperty);
                        if (dictionary == null)
                        {
                            dictionary = new Dictionary <string, GrantedLock>();
                            activity2.SetValue(GrantedLocksProperty, dictionary);
                        }
                        foreach (string str in allSynchronizationHandles)
                        {
                            bool flag = true;
                            if (!dictionary.ContainsKey(str))
                            {
                                dictionary[str] = new GrantedLock(activity);
                            }
                            else if (dictionary[str].Holder != activity)
                            {
                                dictionary[str].WaitList.Add(activity);
                                flag = false;
                            }
                            if (!flag)
                            {
                                return(false);
                            }
                        }
                    }
                    ICollection <string> is3 = (ICollection <string>)activity2.GetValue(System.Workflow.ComponentModel.Activity.SynchronizationHandlesProperty);
                    if ((is3 != null) && (is3.Count != 0))
                    {
                        break;
                    }
                }
            }
            return(true);
        }
 public object Clone()
 {
     GrantedLock @lock = new GrantedLock(this.holder);
     @lock.waitList.InsertRange(0, this.waitList);
     return @lock;
 }