protected override void CacheMetadata(NativeActivityMetadata metadata)
        {
            if (this.Try != null)
            {
                metadata.AddChild(this.Try);
            }
            if (this.Finally != null)
            {
                metadata.AddChild(this.Finally);
            }
            Collection <ActivityDelegate> delegates = new Collection <ActivityDelegate>();

            if (this.catches != null)
            {
                foreach (Catch @catch in this.catches)
                {
                    ActivityDelegate action = @catch.GetAction();
                    if (action != null)
                    {
                        delegates.Add(action);
                    }
                }
            }
            metadata.AddImplementationVariable(this.state);
            metadata.SetDelegatesCollection(delegates);
            metadata.SetVariablesCollection(this.Variables);
            if ((this.Finally == null) && (this.Catches.Count == 0))
            {
                metadata.AddValidationError(System.Activities.SR.CatchOrFinallyExpected(base.DisplayName));
            }
        }
 public static void FillDelegate(ActivityDelegate activityDelegate, ActivityDelegateMetadata metadata)
 {
     foreach (ActivityDelegateArgumentMetadata argument in metadata)
     {
         activityDelegate.GetType().GetProperty(argument.Name).SetValue(activityDelegate, CreateDelegateArgument(argument), null);
     }
 }
예제 #3
0
            protected override void Execute(NativeActivityContext context)
            {
                IEnumerable <Activity> enumerable = this.ParentChain.Get(context);
                Rethrow  rethrow = this.RethrowActivity.Get(context);
                Activity item    = rethrow;
                bool     flag    = false;

                foreach (Activity activity2 in enumerable)
                {
                    if (activity2.ImplementationChildren.Contains(item))
                    {
                        flag = true;
                    }
                    TryCatch @catch = activity2 as TryCatch;
                    if ((@catch != null) && (item != null))
                    {
                        foreach (Catch catch2 in @catch.Catches)
                        {
                            ActivityDelegate action = catch2.GetAction();
                            if ((action != null) && (action.Handler == item))
                            {
                                if (flag)
                                {
                                    Constraint.AddValidationError(context, new ValidationError(System.Activities.SR.RethrowMustBeAPublicChild(rethrow.DisplayName), rethrow));
                                }
                                return;
                            }
                        }
                    }
                    item = activity2;
                }
                Constraint.AddValidationError(context, new ValidationError(System.Activities.SR.RethrowNotInATryCatch(rethrow.DisplayName), rethrow));
            }
예제 #4
0
        public virtual async Task <T> GetResult(CancellationToken?cancelToken = null)
        {
            Tuple <DateTime, T> cache = null;

            if (Cache.Value.ContainsKey(ActivityDelegate))
            {
                cache = Cache.Value[ActivityDelegate];
            }

            var timeStamp = new DateTime();
            var result    = default(T);

            if (cache != null)
            {
                timeStamp = cache.Item1;
                result    = cache.Item2;
            }

            if (DateTime.Now - timeStamp <= Timeout)
            {
                return(result);
            }

            result = await ActivityDelegate.GetResult(cancelToken);

            Cache.Value[ActivityDelegate] = new Tuple <DateTime, T>(DateTime.Now, result);

            return(result);
        }
예제 #5
0
        public ActivityDelegate Create()
        {
            ActivityDelegate         delegateObject = Activator.CreateInstance(this.DelegateType) as ActivityDelegate;
            ActivityDelegateMetadata metadata       = ActivityDelegateUtilities.GetMetadata(this.DelegateType);

            ActivityDelegateUtilities.FillDelegate(delegateObject, metadata);
            return(delegateObject);
        }
예제 #6
0
 protected override void VisitDelegate(ActivityDelegate activityDelegate, out bool exit)
 {
     if (activityDelegate.Handler != null)
     {
         this.dataContextActivities.Add(activityDelegate.Handler);
     }
     base.VisitDelegate(activityDelegate, out exit);
 }
예제 #7
0
            protected override void Execute(NativeActivityContext context)
            {
                IEnumerable <Activity> parentChain = this.ParentChain.Get(context);
                Rethrow  rethrowActivity           = this.RethrowActivity.Get(context);
                Activity previousActivity          = rethrowActivity;
                bool     privateRethrow            = false;

                // TryCatch with Rethrow is usually authored in the following way:
                //
                // TryCatch
                // {
                //   Try = DoWork
                //   Catch Handler = Sequence
                //                   {
                //                     ProcessException,
                //                     Rethrow
                //                   }
                // }
                // Notice that the chain of Activities is TryCatch->Sequence->Rethrow
                // We want to validate that Rethrow is in the catch block of TryCatch
                // We walk up the parent chain until we find TryCatch.  Then we check if one the catch handlers points to Sequence(the previous activity in the tree)
                foreach (Activity parent in parentChain)
                {
                    // Rethrow is only allowed under the public children of a TryCatch activity.
                    // If any of the activities in the tree is a private child, report a constraint violation.
                    if (parent.ImplementationChildren.Contains(previousActivity))
                    {
                        privateRethrow = true;
                    }

                    TryCatch tryCatch = parent as TryCatch;
                    if (tryCatch != null)
                    {
                        if (previousActivity != null)
                        {
                            foreach (Catch catchHandler in tryCatch.Catches)
                            {
                                ActivityDelegate catchAction = catchHandler.GetAction();
                                if (catchAction != null && catchAction.Handler == previousActivity)
                                {
                                    if (privateRethrow)
                                    {
                                        Constraint.AddValidationError(context, new ValidationError(SR.RethrowMustBeAPublicChild(rethrowActivity.DisplayName), rethrowActivity));
                                    }
                                    return;
                                }
                            }
                        }
                    }

                    previousActivity = parent;
                }

                Constraint.AddValidationError(context, new ValidationError(SR.RethrowNotInATryCatch(rethrowActivity.DisplayName), rethrowActivity));
            }
예제 #8
0
 internal bool AreMatch(ActivityDelegate updatedDelegate, ActivityDelegate originalDelegate)
 {
     if (updatedDelegate.Handler != null && originalDelegate.Handler != null)
     {
         return(this.matcher.GetMatch(updatedDelegate.Handler) == originalDelegate.Handler);
     }
     else
     {
         return(updatedDelegate.Handler == null && originalDelegate.Handler == null);
     }
 }
	/**
	 * Set up the delegate and visuals.
	 */
	public void InitWithActivityType (ActivityDelegate activity, string activityType, string supportingId) {
		this.activity = activity;
		this.activityType = activityType;
		this.supportingId = supportingId;
		if (activityType != ActivityType.RECRUIT) {
			icon.spriteName = activityType.ToString().ToLower() + "_icon";
			ring.color = UIColor.GetColourForActivityType (activityType);
		}
		string labelString = activityType.ToString ();
		labelString.Replace ("_", " ");
		labelString = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(labelString);
		label.text = labelString;
	}
예제 #10
0
            bool CompareDelegateEqualityAndAddActivitiesPair(ActivityDelegate currentDelegate, ActivityDelegate originalDelegate)
            {
                if (!ActivityComparer.CompareDelegateEquality(currentDelegate, originalDelegate))
                {
                    return(false);
                }

                if (currentDelegate.Handler != null)
                {
                    Fx.Assert(originalDelegate.Handler != null, "both handlers are either non-null or null.");
                    this.PrepareToMatchSubtree(currentDelegate.Handler, originalDelegate.Handler);
                }

                return(true);
            }
예제 #11
0
    /**
     * Set up the delegate and visuals.
     */
    public void InitWithActivityType(ActivityDelegate activity, string activityType, string supportingId)
    {
        this.activity     = activity;
        this.activityType = activityType;
        this.supportingId = supportingId;
        if (activityType != ActivityType.RECRUIT)
        {
            icon.spriteName = activityType.ToString().ToLower() + "_icon";
            ring.color      = UIColor.GetColourForActivityType(activityType);
        }
        string labelString = activityType.ToString();

        labelString.Replace("_", " ");
        labelString = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(labelString);
        label.text  = labelString;
    }
예제 #12
0
        protected virtual void VisitDelegate(ActivityDelegate activityDelegate, out bool exit)
        {
            VisitDelegateArguments(activityDelegate, out exit);
            if (exit)
            {
                return;
            }

            if (activityDelegate.Handler != null)
            {
                VisitCore(activityDelegate.Handler, out exit);
                if (exit)
                {
                    return;
                }
            }
        }
예제 #13
0
        protected virtual void VisitDelegateArguments(ActivityDelegate activityDelegate, out bool exit)
        {
            foreach (var delegateArgument in activityDelegate.RuntimeDelegateArguments)
            {
                if (delegateArgument.BoundArgument != null)
                {
                    VisitDelegateArgument(delegateArgument, out exit);

                    if (exit)
                    {
                        return;
                    }
                }
            }

            exit = false;
        }
예제 #14
0
        static bool CompareDelegateEquality(ActivityDelegate currentDelegate, ActivityDelegate originalDelegate)
        {
            Fx.Assert(currentDelegate != null && originalDelegate != null, "Both currentDelegate and originalDelegate must be non-null.");

            if (!ListEquals(currentDelegate.RuntimeDelegateArguments, originalDelegate.RuntimeDelegateArguments))
            {
                return(false);
            }

            bool isImplementation = currentDelegate.ParentCollectionType == ActivityCollectionType.Implementation;

            Fx.Assert(originalDelegate.ParentCollectionType == currentDelegate.ParentCollectionType, "Mismatched delegates");
            IdSpace currentIdSpace  = isImplementation ? currentDelegate.Owner.ParentOf : currentDelegate.Owner.MemberOf;
            IdSpace originalIdSpace = isImplementation ? originalDelegate.Owner.ParentOf : originalDelegate.Owner.MemberOf;

            return(CompareChildEquality(currentDelegate.Handler, currentIdSpace, originalDelegate.Handler, originalIdSpace));
        }
예제 #15
0
        private void OnHandlerChanged()
        {
            if (!this.isSetInternally)
            {
                if (this.Handler == null)
                {
                    this.ActivityDelegate = null;
                }
                else
                {
                    if (this.Factory != null && this.EditingContext != null)
                    {
                        try
                        {
                            ActivityDelegate instance = this.Factory.Create();
                            Fx.Assert(instance != null, "Factory should not return null");
                            ModelItem modelItem = this.EditingContext.Services.GetService <ModelTreeManager>().WrapAsModelItem(instance);
                            modelItem.Properties["Handler"].SetValue(this.Handler);
                            this.ActivityDelegate = modelItem;
                        }
                        catch (Exception ex)
                        {
                            if (Fx.IsFatal(ex))
                            {
                                throw;
                            }

                            string details = ex.Message;

                            if (ex is TargetInvocationException && ex.InnerException != null)
                            {
                                details = ex.InnerException.Message;
                            }

                            this.ReportError(string.Format(CultureInfo.CurrentUICulture, SR.CannotCreateInstance, TypeNameHelper.GetDisplayName(this.Factory.DelegateType, false)), details);

                            this.isSetInternally = true;
                            this.Handler         = null;
                            this.isSetInternally = false;
                        }
                    }
                }
            }
        }
예제 #16
0
        protected override void CacheMetadata(NativeActivityMetadata metadata)
        {
            if (Try != null)
            {
                metadata.AddChild(this.Try);
            }

            if (this.Finally != null)
            {
                metadata.AddChild(this.Finally);
            }

            Collection <ActivityDelegate> delegates = new Collection <ActivityDelegate>();

            if (this.catches != null)
            {
                foreach (Catch item in this.catches)
                {
                    ActivityDelegate catchDelegate = item.GetAction();
                    if (catchDelegate != null)
                    {
                        delegates.Add(catchDelegate);
                    }
                }
            }

            metadata.AddImplementationVariable(this.state);

            metadata.SetDelegatesCollection(delegates);

            metadata.SetVariablesCollection(this.Variables);

            if (this.Finally == null && this.Catches.Count == 0)
            {
                metadata.AddValidationError(SR.CatchOrFinallyExpected(this.DisplayName));
            }
        }
 internal bool AreMatch(ActivityDelegate updatedDelegate, ActivityDelegate originalDelegate)
 {
     if (updatedDelegate.Handler != null && originalDelegate.Handler != null)
     {
         return this.matcher.GetMatch(updatedDelegate.Handler) == originalDelegate.Handler;
     }
     else
     {
         return updatedDelegate.Handler == null && originalDelegate.Handler == null;
     }
 }