internal static void FilterDependencyProperties(IServiceProvider serviceProvider, Activity activity) { IExtenderListService service = serviceProvider.GetService(typeof(IExtenderListService)) as IExtenderListService; if (service != null) { Dictionary<string, DependencyProperty> dictionary = new Dictionary<string, DependencyProperty>(); foreach (DependencyProperty property in activity.MetaDependencyProperties) { dictionary.Add(property.Name, property); } List<string> list = new List<string>(); foreach (IExtenderProvider provider in service.GetExtenderProviders()) { if (!provider.CanExtend(activity)) { ProvidePropertyAttribute[] customAttributes = provider.GetType().GetCustomAttributes(typeof(ProvidePropertyAttribute), true) as ProvidePropertyAttribute[]; foreach (ProvidePropertyAttribute attribute in customAttributes) { list.Add(attribute.PropertyName); } } } foreach (string str in list) { if (dictionary.ContainsKey(str)) { activity.RemoveProperty(dictionary[str]); } } } }
internal void ReleaseLocks(bool transactional) { if (this.currentActivity == null) { throw new ObjectDisposedException("ActivityExecutionContext"); } // remove the callback. this.Activity.RemoveProperty(LockAcquiredCallbackProperty); // The assumption is that lock contentions will be few. Hence, we optimize serialization // size over performance, for ex. do not persist the list of locks that have already been // granted. ICollection <string> handles = GetAllSynchronizationHandles(this.Activity); if (handles == null || handles.Count == 0) { return; } List <Activity> waitingActivities = new List <Activity>(); Activity parent = Activity.Parent; while (parent != null) { if (parent.SupportsSynchronization || parent.Parent == null) { Dictionary <string, GrantedLock> grantedLocks = (Dictionary <string, GrantedLock>)parent.GetValue(GrantedLocksProperty); // if its an transactional release of locks, then release it and then keep it // cached, so that in case of rollback, we can reacuire locks if (transactional) { Dictionary <string, GrantedLock> cachedGrantedLocks = new Dictionary <string, GrantedLock>(); if (grantedLocks != null) { foreach (KeyValuePair <string, GrantedLock> grantedLockEntry in grantedLocks) { cachedGrantedLocks.Add(grantedLockEntry.Key, (GrantedLock)grantedLockEntry.Value.Clone()); } } parent.SetValue(CachedGrantedLocksProperty, cachedGrantedLocks); } if (grantedLocks != null) { foreach (string handle in handles) { if (!grantedLocks.ContainsKey(handle)) { continue; } else if (grantedLocks[handle].WaitList.Count == 0) { grantedLocks.Remove(handle); } else if (grantedLocks[handle].Holder != this.Activity) { grantedLocks[handle].WaitList.Remove(this.Activity); } else { // Grant the lock to the next waiting activity. Activity waitingActivity = grantedLocks[handle].WaitList[0]; grantedLocks[handle].WaitList.RemoveAt(0); grantedLocks[handle].Holder = waitingActivity; if (!waitingActivities.Contains(waitingActivity)) { waitingActivities.Add(waitingActivity); } } } if (grantedLocks.Count == 0) { parent.RemoveProperty(GrantedLocksProperty); } } } // 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; } // Try and acquire locks for all the waiting activities. foreach (Activity waitingActivity in waitingActivities) { if (AcquireLocks(waitingActivity)) { ActivityExecutorDelegateInfo <EventArgs> waitingActivityCallback = (ActivityExecutorDelegateInfo <EventArgs>)waitingActivity.GetValue(LockAcquiredCallbackProperty); waitingActivityCallback.InvokeDelegate(this.Activity.ContextActivity, EventArgs.Empty, false, transactional); } } }