Exemplo n.º 1
0
        internal static StringCollection GetCompensatableTargets(CompensateActivity compensate)
        {
            StringCollection strings = new StringCollection();

            for (CompositeActivity parent = compensate.Parent; parent != null; parent = parent.Parent)
            {
                if (((parent is CompensationHandlerActivity) || (parent is FaultHandlersActivity)) || (parent is CancellationHandlerActivity))
                {
                    parent = parent.Parent;
                    if (parent != null)
                    {
                        if (Helpers.IsCustomActivity(parent))
                        {
                            strings.Add(parent.UserData[UserDataKeys.CustomActivityDefaultName] as string);
                        }
                        else
                        {
                            strings.Add(parent.Name);
                        }
                        foreach (Activity activity2 in parent.EnabledActivities)
                        {
                            if (activity2 is ICompensatableActivity)
                            {
                                strings.Add(activity2.Name);
                            }
                        }
                    }
                    return(strings);
                }
            }
            return(strings);
        }
        internal static StringCollection GetCompensatableTargets(CompensateActivity compensate)
        {
            StringCollection  targetList = new StringCollection();
            CompositeActivity parent     = compensate.Parent;

            while (parent != null)
            {
                if ((parent is CompensationHandlerActivity) || (parent is FaultHandlersActivity) || (parent is CancellationHandlerActivity))
                {
                    parent = parent.Parent;
                    if (parent != null)
                    {
                        if (Helpers.IsCustomActivity(parent))
                        {
                            targetList.Add(parent.UserData[UserDataKeys.CustomActivityDefaultName] as string);
                        }
                        else
                        {
                            targetList.Add(parent.Name);
                        }

                        foreach (Activity activity in parent.EnabledActivities)
                        {
                            if (activity is ICompensatableActivity)
                            {
                                targetList.Add(activity.Name);
                            }
                        }
                    }
                    break;
                }
                parent = parent.Parent;
            }
            return(targetList);
        }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = base.Validate(manager, obj);

            CompensateActivity compensate = obj as CompensateActivity;

            if (compensate == null)
            {
                throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(CompensateActivity).FullName), "obj");
            }

            // Compensate must be in a CompensationHandler or FaultHandler
            CompositeActivity parent = compensate.Parent;

            while (parent != null)
            {
                if (parent is CompensationHandlerActivity || parent is FaultHandlerActivity || parent is CancellationHandlerActivity)
                {
                    break;
                }

                parent = parent.Parent;
            }

            if (parent == null)
            {
                validationErrors.Add(new ValidationError(SR.GetString(SR.Error_CompensateBadNesting), ErrorNumbers.Error_CompensateBadNesting));
            }

            ValidationError  error   = null;
            StringCollection targets = CompensateActivity.GetCompensatableTargets(compensate);

            if (String.IsNullOrEmpty(compensate.TargetActivityName))
            {
                error = ValidationError.GetNotSetValidationError("TargetActivityName");
            }
            else if (!targets.Contains(compensate.TargetActivityName))
            {
                error = new ValidationError(SR.GetString(SR.Error_CompensateBadTargetTX, "TargetActivityName", compensate.TargetActivityName, compensate.QualifiedName), ErrorNumbers.Error_CompensateBadTargetTX, false, "TargetActivityName");
            }
            if (error != null)
            {
                validationErrors.Add(error);
            }

            return(validationErrors);
        }
Exemplo n.º 4
0
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection errors     = base.Validate(manager, obj);
            CompensateActivity        compensate = obj as CompensateActivity;

            if (compensate == null)
            {
                throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(CompensateActivity).FullName }), "obj");
            }
            CompositeActivity parent = compensate.Parent;

            while (parent != null)
            {
                if (((parent is CompensationHandlerActivity) || (parent is FaultHandlerActivity)) || (parent is CancellationHandlerActivity))
                {
                    break;
                }
                parent = parent.Parent;
            }
            if (parent == null)
            {
                errors.Add(new ValidationError(SR.GetString("Error_CompensateBadNesting"), 0x509));
            }
            ValidationError  item = null;
            StringCollection compensatableTargets = CompensateActivity.GetCompensatableTargets(compensate);

            if (string.IsNullOrEmpty(compensate.TargetActivityName))
            {
                item = ValidationError.GetNotSetValidationError("TargetActivityName");
            }
            else if (!compensatableTargets.Contains(compensate.TargetActivityName))
            {
                item = new ValidationError(SR.GetString("Error_CompensateBadTargetTX", new object[] { "TargetActivityName", compensate.TargetActivityName, compensate.QualifiedName }), 0x563, false, "TargetActivityName");
            }
            if (item != null)
            {
                errors.Add(item);
            }
            return(errors);
        }