public static CorrelationToken GetCorrelationToken(Activity activity, string correlationTokenName, string ownerActivityName)
        {
            if (null == correlationTokenName)
            {
                throw new ArgumentNullException("correlationTokenName");
            }
            if (null == ownerActivityName)
            {
                throw new ArgumentNullException("ownerActivityName");
            }
            if (null == activity)
            {
                throw new ArgumentNullException("activity");
            }

            Activity contextActivity = ContextActivityUtils.ContextActivity(activity);
            Activity owner           = null;

            if (!String.IsNullOrEmpty(ownerActivityName))
            {
                while (contextActivity != null)
                {
                    owner = contextActivity.GetActivityByName(ownerActivityName, true);
                    if (owner != null)
                    {
                        break;
                    }
                    contextActivity = ContextActivityUtils.ParentContextActivity(contextActivity);
                }

                if (owner == null)
                {
                    owner = Helpers.ParseActivityForBind(activity, ownerActivityName);
                }
            }

            if (owner == null)
            {
                throw new InvalidOperationException(ExecutionStringManager.OwnerActivityMissing);
            }

            CorrelationTokenCollection collection = owner.GetValue(CorrelationTokenCollectionProperty) as CorrelationTokenCollection;

            if (collection == null)
            {
                collection = new CorrelationTokenCollection();
                owner.SetValue(CorrelationTokenCollection.CorrelationTokenCollectionProperty, collection);
            }

            if (!collection.Contains(correlationTokenName))
            {
                collection.Add(new CorrelationToken(correlationTokenName));
            }
            return(collection[correlationTokenName]);
        }
        internal static void UninitializeCorrelationTokens(Activity activity)
        {
            CorrelationTokenCollection collection = activity.GetValue(CorrelationTokenCollectionProperty) as CorrelationTokenCollection;

            if (collection != null)
            {
                foreach (CorrelationToken correlator in collection)
                {
                    correlator.Uninitialize(activity);
                }
            }
        }
Esempio n. 3
0
        internal static void UninitializeCorrelationTokens(Activity activity)
        {
            CorrelationTokenCollection tokens = activity.GetValue(CorrelationTokenCollectionProperty) as CorrelationTokenCollection;

            if (tokens != null)
            {
                foreach (CorrelationToken token in tokens)
                {
                    token.Uninitialize(activity);
                }
            }
        }
Esempio n. 4
0
        public static CorrelationToken GetCorrelationToken(Activity activity, string correlationTokenName, string ownerActivityName)
        {
            if (correlationTokenName == null)
            {
                throw new ArgumentNullException("correlationTokenName");
            }
            if (ownerActivityName == null)
            {
                throw new ArgumentNullException("ownerActivityName");
            }
            if (activity == null)
            {
                throw new ArgumentNullException("activity");
            }
            Activity activity2      = ContextActivityUtils.ContextActivity(activity);
            Activity activityByName = null;

            if (!string.IsNullOrEmpty(ownerActivityName))
            {
                while (activity2 != null)
                {
                    activityByName = activity2.GetActivityByName(ownerActivityName, true);
                    if (activityByName != null)
                    {
                        break;
                    }
                    activity2 = ContextActivityUtils.ParentContextActivity(activity2);
                }
                if (activityByName == null)
                {
                    activityByName = Helpers.ParseActivityForBind(activity, ownerActivityName);
                }
            }
            if (activityByName == null)
            {
                throw new InvalidOperationException(ExecutionStringManager.OwnerActivityMissing);
            }
            CorrelationTokenCollection tokens = activityByName.GetValue(CorrelationTokenCollectionProperty) as CorrelationTokenCollection;

            if (tokens == null)
            {
                tokens = new CorrelationTokenCollection();
                activityByName.SetValue(CorrelationTokenCollectionProperty, tokens);
            }
            if (!tokens.Contains(correlationTokenName))
            {
                tokens.Add(new CorrelationToken(correlationTokenName));
            }
            return(tokens[correlationTokenName]);
        }