示例#1
0
        internal static ReceiveContext GetRootReceiveContext(Activity activity)
        {
            if (activity == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("activity");
            }

            Activity contextActivity = activity.ContextActivity;

            if (contextActivity == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new InvalidOperationException(SR2.GetString(SR2.Error_ContextOwnerActivityMissing)));
            }

            Activity owner = contextActivity.RootActivity;

            if (owner == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new InvalidOperationException(SR2.GetString(SR2.Error_ContextOwnerActivityMissing)));
            }

            ReceiveContextCollection collection =
                owner.GetValue(ReceiveContextCollection.ReceiveContextCollectionProperty) as ReceiveContextCollection;

            if (collection == null)
            {
                return(null);
            }

            if (!collection.Contains(ContextToken.RootContextName))
            {
                return(null);
            }

            ReceiveContext receiveContext = collection[ContextToken.RootContextName];

            receiveContext.EnsureInitialized(owner.ContextGuid);

            return(receiveContext);
        }
示例#2
0
        static void RegisterRootReceiveContext(Activity activity, Guid workflowId)
        {
            if (activity == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("activity");
            }

            Activity contextActivity = activity.ContextActivity;

            if (contextActivity == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new InvalidOperationException(SR2.GetString(SR2.Error_ContextOwnerActivityMissing)));
            }

            Activity owner = contextActivity.RootActivity;

            if (owner == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new InvalidOperationException(SR2.GetString(SR2.Error_ContextOwnerActivityMissing)));
            }

            ReceiveContextCollection collection =
                owner.GetValue(ReceiveContextCollection.ReceiveContextCollectionProperty) as ReceiveContextCollection;

            if (collection == null)
            {
                collection = new ReceiveContextCollection();
                owner.SetValue(ReceiveContextCollection.ReceiveContextCollectionProperty, collection);
            }

            if (!collection.Contains(ContextToken.RootContextName))
            {
                collection.Add(new ReceiveContext(ContextToken.RootContextName, workflowId, true));
            }
        }
示例#3
0
        static void RegisterReceiveContext(ReceiveActivity activity,
                                           Guid workflowId,
                                           string contextName,
                                           string ownerActivityName)
        {
            if (activity == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("activity");
            }
            if (string.IsNullOrEmpty(contextName))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("contextName",
                                                                             SR2.GetString(SR2.Error_ArgumentValueNullOrEmptyString));
            }

            Activity contextActivity = activity.ContextActivity;
            Activity owner           = null;

            if (contextActivity == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new InvalidOperationException(SR2.GetString(SR2.Error_ContextOwnerActivityMissing)));
            }

            if (string.IsNullOrEmpty(ownerActivityName))
            {
                owner = contextActivity.RootActivity;
            }
            else
            {
                while (contextActivity != null)
                {
                    owner = contextActivity.GetActivityByName(ownerActivityName, true);
                    if (owner != null)
                    {
                        break;
                    }

                    contextActivity = contextActivity.Parent;
                    if (contextActivity != null)
                    {
                        contextActivity = contextActivity.ContextActivity;
                    }
                }
            }

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

            if (owner == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new InvalidOperationException(SR2.GetString(SR2.Error_ContextOwnerActivityMissing)));
            }

            ReceiveContextCollection collection =
                owner.GetValue(ReceiveContextCollection.ReceiveContextCollectionProperty) as ReceiveContextCollection;

            if (collection == null)
            {
                collection = new ReceiveContextCollection();
                owner.SetValue(ReceiveContextCollection.ReceiveContextCollectionProperty, collection);
            }

            if (!collection.Contains(contextName))
            {
                collection.Add(new ReceiveContext(contextName, workflowId, false));
            }
        }
示例#4
0
        internal static ReceiveContext GetReceiveContext(Activity activity,
                                                         string contextName,
                                                         string ownerActivityName)
        {
            if (activity == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("activity");
            }
            if (string.IsNullOrEmpty(contextName))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("contextToken",
                                                                             SR2.GetString(SR2.Error_ArgumentValueNullOrEmptyString));
            }

            Activity contextActivity = activity.ContextActivity;
            Activity owner           = null;

            if (contextActivity == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new InvalidOperationException(SR2.GetString(SR2.Error_ContextOwnerActivityMissing)));
            }

            if (string.IsNullOrEmpty(ownerActivityName))
            {
                owner = contextActivity.RootActivity;
            }
            else
            {
                while (contextActivity != null)
                {
                    owner = contextActivity.GetActivityByName(ownerActivityName, true);
                    if (owner != null)
                    {
                        break;
                    }

                    contextActivity = contextActivity.Parent;
                    if (contextActivity != null)
                    {
                        contextActivity = contextActivity.ContextActivity;
                    }
                }
            }

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

            if (owner == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new InvalidOperationException(SR2.GetString(SR2.Error_ContextOwnerActivityMissing)));
            }

            ReceiveContextCollection collection =
                owner.GetValue(ReceiveContextCollection.ReceiveContextCollectionProperty) as ReceiveContextCollection;

            if (collection == null)
            {
                return(null);
            }

            if (!collection.Contains(contextName))
            {
                return(null);
            }

            ReceiveContext receiveContext = collection[contextName];

            receiveContext.EnsureInitialized(owner.ContextGuid);

            return(receiveContext);
        }