コード例 #1
0
        /// <summary>
        ///	Overridden to validate the activity properties and populate the error collection.
        /// Only one child activity is allowed.  If multiple acitivties need to be executed,
        /// place them in a sequence or other appropriate composite activities.
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = new ValidationErrorCollection(base.Validate(manager, obj));

            ForEach foreachActivity = obj as ForEach;

            if (foreachActivity == null)
            {
                throw new ArgumentException("Validate parameter 'obj' is not a ForEach activity.");
            }

            if (foreachActivity.EnabledActivities.Count > 1)
            {
                validationErrors.Add(new ValidationError("Only one child is allowed in the ForEach activity.", InvalidNumberOfChildren));
            }

            return(validationErrors);
        }
コード例 #2
0
        // When a child activity is closed, it's removed from the execution context,
        // and the execution proceed to the next iteration.
        private void OnChildClose(Object sender, ActivityExecutionStatusChangedEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("OnChildClose parameter 'e' is null.");
            }
            if (sender == null)
            {
                throw new ArgumentNullException("OnChildClose parameter 'sender' is null.");
            }

            ActivityExecutionContext context = sender as ActivityExecutionContext;

            if (context == null)
            {
                throw new ArgumentException("OnChildClose parameter 'sender' is not ActivityExecutionContext.");
            }

            ForEach foreachActivity = context.Activity as ForEach;

            if (foreachActivity == null)
            {
                throw new ArgumentException("OnChildClose parameter 'sender' does not contain a 'ForEach' activity.");
            }

            // Remove the event handler first.
            e.Activity.Closed -= this.OnChildClose;

            // Then remove the child activity from the execution context.
            context.ExecutionContextManager.CompleteExecutionContext(context.ExecutionContextManager.GetExecutionContext(e.Activity));

            // Move on to the next iteration.
            if (this.ExecutionStatus == ActivityExecutionStatus.Canceling)
            {
                context.CloseActivity();
            }
            else if (this.ExecutionStatus == ActivityExecutionStatus.Executing)
            {
                if (!ExecuteNext(context))
                {
                    context.CloseActivity();
                }
            }
        }