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);
        }
        private ICollection <string> GetAllSynchronizationHandles(System.Workflow.ComponentModel.Activity activity)
        {
            WalkerEventHandler   handler = null;
            ICollection <string> is2     = (ICollection <string>)activity.GetValue(System.Workflow.ComponentModel.Activity.SynchronizationHandlesProperty);

            if ((is2 == null) || (is2.Count == 0))
            {
                return(is2);
            }
            List <string> handles = new List <string>(is2);

            if (activity is CompositeActivity)
            {
                Walker walker = new Walker();
                if (handler == null)
                {
                    handler = delegate(Walker w, WalkerEventArgs e) {
                        if (e.CurrentActivity != activity)
                        {
                            ICollection <string> collection = (ICollection <string>)e.CurrentActivity.GetValue(System.Workflow.ComponentModel.Activity.SynchronizationHandlesProperty);
                            if (collection != null)
                            {
                                handles.AddRange(collection);
                            }
                        }
                    };
                }
                walker.FoundActivity += handler;
                walker.Walk(activity);
            }
            handles.Sort();
            for (int i = 1; i < handles.Count; i++)
            {
                if (handles[i] == handles[i - 1])
                {
                    handles.RemoveAt(--i);
                }
            }
            handles.TrimExcess();
            return(handles);
        }
        internal void ReleaseLocks(bool transactional)
        {
            if (this.currentActivity == null)
            {
                throw new ObjectDisposedException("ActivityExecutionContext");
            }
            this.Activity.RemoveProperty(LockAcquiredCallbackProperty);
            ICollection <string> allSynchronizationHandles = this.GetAllSynchronizationHandles(this.Activity);

            if ((allSynchronizationHandles != null) && (allSynchronizationHandles.Count != 0))
            {
                List <System.Workflow.ComponentModel.Activity> list = new List <System.Workflow.ComponentModel.Activity>();
                for (System.Workflow.ComponentModel.Activity activity = this.Activity.Parent; activity != null; activity = activity.Parent)
                {
                    if (activity.SupportsSynchronization || (activity.Parent == null))
                    {
                        Dictionary <string, GrantedLock> dictionary = (Dictionary <string, GrantedLock>)activity.GetValue(GrantedLocksProperty);
                        if (transactional)
                        {
                            Dictionary <string, GrantedLock> dictionary2 = new Dictionary <string, GrantedLock>();
                            if (dictionary != null)
                            {
                                foreach (KeyValuePair <string, GrantedLock> pair in dictionary)
                                {
                                    dictionary2.Add(pair.Key, (GrantedLock)pair.Value.Clone());
                                }
                            }
                            activity.SetValue(CachedGrantedLocksProperty, dictionary2);
                        }
                        if (dictionary != null)
                        {
                            foreach (string str in allSynchronizationHandles)
                            {
                                if (dictionary.ContainsKey(str))
                                {
                                    if (dictionary[str].WaitList.Count == 0)
                                    {
                                        dictionary.Remove(str);
                                    }
                                    else if (dictionary[str].Holder != this.Activity)
                                    {
                                        dictionary[str].WaitList.Remove(this.Activity);
                                    }
                                    else
                                    {
                                        System.Workflow.ComponentModel.Activity item = dictionary[str].WaitList[0];
                                        dictionary[str].WaitList.RemoveAt(0);
                                        dictionary[str].Holder = item;
                                        if (!list.Contains(item))
                                        {
                                            list.Add(item);
                                        }
                                    }
                                }
                            }
                            if (dictionary.Count == 0)
                            {
                                activity.RemoveProperty(GrantedLocksProperty);
                            }
                        }
                    }
                    ICollection <string> is3 = (ICollection <string>)activity.GetValue(System.Workflow.ComponentModel.Activity.SynchronizationHandlesProperty);
                    if ((is3 != null) && (is3.Count != 0))
                    {
                        break;
                    }
                }
                foreach (System.Workflow.ComponentModel.Activity activity3 in list)
                {
                    if (this.AcquireLocks(activity3))
                    {
                        ((ActivityExecutorDelegateInfo <EventArgs>)activity3.GetValue(LockAcquiredCallbackProperty)).InvokeDelegate(this.Activity.ContextActivity, EventArgs.Empty, false, transactional);
                    }
                }
            }
        }