public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
 {
     ValidationErrorCollection errors = base.Validate(manager, obj);
     EventHandlersActivity activity = obj as EventHandlersActivity;
     if (activity == null)
     {
         throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(EventHandlersActivity).FullName }), "obj");
     }
     if (activity.Parent == null)
     {
         errors.Add(new ValidationError(SR.GetString("Error_MustHaveParent"), 0x522));
         return errors;
     }
     if (!(activity.Parent is EventHandlingScopeActivity))
     {
         errors.Add(new ValidationError(SR.GetString("Error_EventHandlersDeclParentNotScope", new object[] { activity.Parent.QualifiedName }), 0x522));
     }
     bool flag = false;
     foreach (Activity activity2 in activity.EnabledActivities)
     {
         if (!(activity2 is EventDrivenActivity))
         {
             flag = true;
         }
     }
     if (flag)
     {
         errors.Add(new ValidationError(SR.GetString("Error_ListenNotAllEventDriven"), 0x514));
     }
     return errors;
 }
 public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
 {
     ValidationErrorCollection errors = new ValidationErrorCollection(base.Validate(manager, obj));
     ListenActivity activity = obj as ListenActivity;
     if (activity == null)
     {
         throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(ListenActivity).FullName }), "obj");
     }
     if (activity.EnabledActivities.Count < 2)
     {
         errors.Add(new ValidationError(SR.GetString("Error_ListenLessThanTwoChildren"), 0x513));
     }
     bool flag = false;
     foreach (Activity activity2 in activity.EnabledActivities)
     {
         if (!(activity2 is EventDrivenActivity))
         {
             flag = true;
         }
     }
     if (flag)
     {
         errors.Add(new ValidationError(SR.GetString("Error_ListenNotAllEventDriven"), 0x514));
     }
     return errors;
 }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            if (manager == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("manager");
            }

            ValidationErrorCollection validationErrors = ValidationHelpers.ValidateObject(manager, obj);
            if (validationErrors.Count == 0)
            {
                if (manager.Context == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                        new InvalidOperationException(SR2.GetString(SR2.Error_ContextStackMissing)));
                }

                Activity rootActivity = manager.Context[typeof(Activity)] as Activity;
                if (rootActivity == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                        new InvalidOperationException(SR2.GetString(SR2.Error_ContextStackItemMissing, typeof(Activity).Name)));
                }
                else
                {
                    validationErrors.AddRange(ValidationHelper.ValidateAllServiceOperationsImplemented(manager, rootActivity));
                }
            }

            return validationErrors;
        }
예제 #4
0
        protected string GetFullPropertyName(ValidationManager manager)
        {
            if (manager == null)
                throw new ArgumentNullException("manager");

            string fullName = string.Empty;

            // iterate the properties in the stack starting with the last one
            int iterator = 0;
            while (manager.Context[iterator] != null)
            {
                if (manager.Context[iterator] is PropertyValidationContext)
                {
                    PropertyValidationContext propertyValidationContext = manager.Context[iterator] as PropertyValidationContext;
                    if (propertyValidationContext.PropertyName == string.Empty)
                        fullName = string.Empty;  // property chain broke... dicard properties after break
                    else if (fullName == string.Empty)
                        fullName = propertyValidationContext.PropertyName;
                    else
                        fullName = propertyValidationContext.PropertyName + "." + fullName;
                }
                iterator++;
            }

            return fullName;
        }
        public override ValidationErrorCollection Validate(
            ValidationManager manager,
            object obj)
        {
            ValidationErrorCollection validationErrors = base.Validate(manager, obj);

            SendActivity sendActivity = obj as SendActivity;
            if (sendActivity == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("obj",
                    SR2.GetString(SR2.Error_ArgumentTypeInvalid, "obj", typeof(SendActivity)));
            }

            ITypeProvider typeProvider = manager.GetService(typeof(ITypeProvider)) as ITypeProvider;
            if (typeProvider == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                    SR2.GetString(SR2.General_MissingService, typeof(ITypeProvider).Name)));
            }

            if (sendActivity.ServiceOperationInfo == null)
            {
                validationErrors.Add(
                    new ValidationError(
                    SR2.GetString(SR2.Error_ServiceOperationInfoNotSpecified,
                    sendActivity.Name),
                    WorkflowServicesErrorNumbers.Error_OperationInfoNotSpecified,
                    false,
                    "ServiceOperationInfo"));
            }
            else
            {
                // validate operation info
                //
                ValidationErrorCollection operationInfoValidationErrors =
                    ValidationHelper.ValidateOperationInfo(
                    sendActivity,
                    sendActivity.ServiceOperationInfo,
                    manager);

                validationErrors.AddRange(operationInfoValidationErrors);

                // do not validate parameter binding if the operation info is not valid
                // we might generate noise and false positives.
                //
                if (operationInfoValidationErrors.Count == 0)
                {
                    validationErrors.AddRange(
                        ValidationHelper.ValidateParameterBindings(sendActivity, sendActivity.ServiceOperationInfo,
                        sendActivity.ParameterBindings, manager));
                }

                // validate the endpoint
                //
                validationErrors.AddRange(
                    ValidationHelper.ValidateChannelToken(sendActivity, manager));
            }

            return validationErrors;
        }
 protected string GetFullPropertyName(ValidationManager manager)
 {
     if (manager == null)
     {
         throw new ArgumentNullException("manager");
     }
     string propertyName = string.Empty;
     for (int i = 0; manager.Context[i] != null; i++)
     {
         if (manager.Context[i] is PropertyValidationContext)
         {
             PropertyValidationContext context = manager.Context[i] as PropertyValidationContext;
             if (context.PropertyName == string.Empty)
             {
                 propertyName = string.Empty;
             }
             else if (propertyName == string.Empty)
             {
                 propertyName = context.PropertyName;
             }
             else
             {
                 propertyName = context.PropertyName + "." + propertyName;
             }
         }
     }
     return propertyName;
 }
예제 #7
0
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = base.Validate(manager, obj);

            EventDrivenActivity eventDriven = obj as EventDrivenActivity;
            if (eventDriven == null)
                throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(EventDrivenActivity).FullName), "obj");

            // check parent 
            if (!(eventDriven.Parent is ListenActivity) &&
                !(eventDriven.Parent is EventHandlersActivity) &&
                !(eventDriven.Parent is StateActivity)
                )
                validationErrors.Add(new ValidationError(SR.GetError_EventDrivenParentNotListen(), ErrorNumbers.Error_EventDrivenParentNotListen));

            // validate Event property
            string message = string.Empty;
            int errorNumber = -1;
            Activity firstActivity = (eventDriven.EnabledActivities.Count > 0) ? eventDriven.EnabledActivities[0] : null;
            if (firstActivity == null)
            {
                message = SR.GetString(SR.Error_EventDrivenNoFirstActivity);
                errorNumber = ErrorNumbers.Error_EventDrivenNoFirstActivity;
            }
            else if (!(firstActivity is IEventActivity))
            {
                message = SR.GetError_EventDrivenInvalidFirstActivity();
                errorNumber = ErrorNumbers.Error_EventDrivenInvalidFirstActivity;
            }
            if (message.Length > 0)
                validationErrors.Add(new ValidationError(message, errorNumber));

            return validationErrors;
        }
 public virtual ValidationErrorCollection ValidateProperties(ValidationManager manager, object obj)
 {
     if (manager == null)
     {
         throw new ArgumentNullException("manager");
     }
     if (obj == null)
     {
         throw new ArgumentNullException("obj");
     }
     ValidationErrorCollection errors = new ValidationErrorCollection();
     Activity activity = manager.Context[typeof(Activity)] as Activity;
     Walker walker = new Walker(true);
     walker.FoundProperty += delegate (Walker w, WalkerEventArgs args) {
         if ((args.CurrentProperty != null) && (DependencyProperty.FromName(args.CurrentProperty.Name, args.CurrentProperty.DeclaringType) == null))
         {
             object[] customAttributes = args.CurrentProperty.GetCustomAttributes(typeof(ValidationOptionAttribute), true);
             if (((customAttributes.Length > 0) ? ((ValidationOptionAttribute) customAttributes[0]).ValidationOption : ValidationOption.Optional) != ValidationOption.None)
             {
                 errors.AddRange(this.ValidateProperty(args.CurrentProperty, args.CurrentPropertyOwner, args.CurrentValue, manager));
                 args.Action = WalkerAction.Skip;
             }
         }
     };
     walker.WalkProperties(activity, obj);
     return errors;
 }
 public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
 {
     ValidationErrorCollection errors = base.Validate(manager, obj);
     EventDrivenActivity activity = obj as EventDrivenActivity;
     if (activity == null)
     {
         throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(EventDrivenActivity).FullName }), "obj");
     }
     if ((!(activity.Parent is ListenActivity) && !(activity.Parent is EventHandlersActivity)) && !(activity.Parent is StateActivity))
     {
         errors.Add(new ValidationError(SR.GetError_EventDrivenParentNotListen(), 0x510));
     }
     string errorText = string.Empty;
     int errorNumber = -1;
     Activity activity2 = (activity.EnabledActivities.Count > 0) ? activity.EnabledActivities[0] : null;
     if (activity2 == null)
     {
         errorText = SR.GetString("Error_EventDrivenNoFirstActivity");
         errorNumber = 0x511;
     }
     else if (!(activity2 is IEventActivity))
     {
         errorText = SR.GetError_EventDrivenInvalidFirstActivity();
         errorNumber = 0x512;
     }
     if (errorText.Length > 0)
     {
         errors.Add(new ValidationError(errorText, errorNumber));
     }
     return errors;
 }
 public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
 {
     ValidationErrorCollection errors = base.Validate(manager, obj);
     ParallelActivity activity = obj as ParallelActivity;
     if (activity == null)
     {
         throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(ParallelActivity).FullName }), "obj");
     }
     if (activity.EnabledActivities.Count < 2)
     {
         errors.Add(new ValidationError(SR.GetString("Error_ParallelLessThanTwoChildren"), 0x517));
     }
     bool flag = false;
     foreach (Activity activity2 in activity.EnabledActivities)
     {
         if (activity2.GetType() != typeof(SequenceActivity))
         {
             flag = true;
         }
     }
     if (flag)
     {
         errors.Add(new ValidationError(SR.GetString("Error_ParallelNotAllSequence"), 0x518));
     }
     return errors;
 }
 public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
 {
     ValidationErrorCollection errors = base.Validate(manager, obj);
     StateFinalizationActivity compositeActivity = obj as StateFinalizationActivity;
     if (compositeActivity == null)
     {
         throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(StateFinalizationActivity).FullName }), "obj");
     }
     StateActivity parent = compositeActivity.Parent as StateActivity;
     if (parent == null)
     {
         errors.Add(new ValidationError(SR.GetError_StateFinalizationParentNotState(), 0x606));
         return errors;
     }
     foreach (Activity activity3 in parent.EnabledActivities)
     {
         StateFinalizationActivity activity4 = activity3 as StateFinalizationActivity;
         if ((activity4 != null) && (activity4 != compositeActivity))
         {
             errors.Add(new ValidationError(SR.GetError_MultipleStateFinalizationActivities(), 0x61a));
             break;
         }
     }
     if (StateMachineHelpers.ContainsEventActivity(compositeActivity))
     {
         errors.Add(new ValidationError(SR.GetError_EventActivityNotValidInStateFinalization(), 0x603));
     }
     return errors;
 }
 public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
 {
     ValidationErrorCollection errors = base.Validate(manager, obj);
     if (!(obj is ConditionedActivityGroup))
     {
         throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(ConditionedActivityGroup).FullName }), "obj");
     }
     return errors;
 }
예제 #13
0
        public virtual ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            if (manager == null)
                throw new ArgumentNullException("manager");
            if (obj == null)
                throw new ArgumentNullException("obj");

            return new ValidationErrorCollection();
        }
 public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
 {
     ValidationErrorCollection errors = base.Validate(manager, obj);
     if (!(obj is ActivityCondition))
     {
         throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(ActivityCondition).FullName }), "obj");
     }
     errors.AddRange(this.ValidateProperties(manager, obj));
     return errors;
 }
 public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
 {
     if (!(obj is CallExternalMethodActivity))
     {
         throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(CallExternalMethodActivity).FullName }), "obj");
     }
     ValidationErrorCollection errors = base.Validate(manager, obj);
     errors.AddRange(CorrelationSetsValidator.Validate(manager, obj));
     errors.AddRange(ParameterBindingValidator.Validate(manager, obj));
     return errors;
 }
 internal static ValidationErrorCollection ValidateActivity(ValidationManager manager, Activity activity)
 {
     ValidationErrorCollection errors = ValidateObject(manager, activity);
     foreach (ValidationError error in errors)
     {
         if (!error.UserData.Contains(typeof(Activity)))
         {
             error.UserData[typeof(Activity)] = activity;
         }
     }
     return errors;
 }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = base.Validate(manager, obj);

            ActivityCondition conditionDeclaration = obj as ActivityCondition;
            if (conditionDeclaration == null)
                throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(ActivityCondition).FullName), "obj");

            validationErrors.AddRange(ValidateProperties(manager, obj));

            return validationErrors;
        }
 public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
 {
     ValidationErrorCollection errors = base.Validate(manager, obj);
     MethodBind bind = obj as MethodBind;
     if (bind == null)
     {
         throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(MethodBind).FullName }), "obj");
     }
     PropertyValidationContext validationContext = manager.Context[typeof(PropertyValidationContext)] as PropertyValidationContext;
     if (validationContext == null)
     {
         throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(BindValidationContext).Name }));
     }
     Activity activity = manager.Context[typeof(Activity)] as Activity;
     if (activity == null)
     {
         throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(Activity).Name }));
     }
     ValidationError item = null;
     if (string.IsNullOrEmpty(bind.Name))
     {
         item = new ValidationError(SR.GetString("Error_PropertyNotSet", new object[] { "Name" }), 0x116) {
             PropertyName = base.GetFullPropertyName(manager) + ".Name"
         };
     }
     else
     {
         BindValidationContext context2 = manager.Context[typeof(BindValidationContext)] as BindValidationContext;
         if (context2 == null)
         {
             Type baseType = BindHelpers.GetBaseType(manager, validationContext);
             if (baseType != null)
             {
                 AccessTypes accessType = BindHelpers.GetAccessType(manager, validationContext);
                 context2 = new BindValidationContext(baseType, accessType);
             }
         }
         if (context2 != null)
         {
             Type targetType = context2.TargetType;
             if (item == null)
             {
                 errors.AddRange(this.ValidateMethod(manager, activity, bind, new BindValidationContext(targetType, context2.Access)));
             }
         }
     }
     if (item != null)
     {
         errors.Add(item);
     }
     return errors;
 }
예제 #19
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;
        }
예제 #20
0
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = new ValidationErrorCollection(base.Validate(manager, obj));

            StateActivity state = obj as StateActivity;
            if (state == null)
                throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(StateActivity).FullName), "obj");

            // First we validate contaiment
            if (state.Parent != null)
            {
                if (StateMachineHelpers.IsStateMachine(state))
                {
                    validationErrors.Add(new ValidationError(SR.GetError_StateMachineWorkflowMustBeARootActivity(), ErrorNumbers.Error_StateMachineWorkflowMustBeARootActivity));
                    return validationErrors;
                }
                else
                {
                    // Make sure that a State is always contained in
                    // another State or StateMachineWorkflow. State machine
                    // within a sequential workflow is not supported
                    if (!(state.Parent is StateActivity))
                    {
                        validationErrors.Add(new ValidationError(SR.GetError_InvalidStateActivityParent(), ErrorNumbers.Error_InvalidStateActivityParent));
                        return validationErrors;
                    }
                }
            }

            if (state.Parent == null && !StateMachineHelpers.IsStateMachine(state))
            {
                ValidateCustomStateActivity(state, validationErrors);
            }

            if (StateMachineHelpers.IsLeafState(state))
            {
                ValidateLeafState(state, validationErrors);
            }
            else if (StateMachineHelpers.IsRootState(state))
            {
                ValidateRootState(state, validationErrors);
            }
            else
            {
                ValidateState(state, validationErrors);
            }

            ValidateEventDrivenActivities(state, validationErrors);

            return validationErrors;
        }
예제 #21
0
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = base.Validate(manager, obj);

            FieldBind bind = obj as FieldBind;
            if (bind == null)
                throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(FieldBind).FullName), "obj");

            PropertyValidationContext validationContext = manager.Context[typeof(PropertyValidationContext)] as PropertyValidationContext;
            if (validationContext == null)
                throw new InvalidOperationException(SR.GetString(SR.Error_ContextStackItemMissing, typeof(BindValidationContext).Name));

            Activity activity = manager.Context[typeof(Activity)] as Activity;
            if (activity == null)
                throw new InvalidOperationException(SR.GetString(SR.Error_ContextStackItemMissing, typeof(Activity).Name));

            ValidationError error = null;
            if (string.IsNullOrEmpty(bind.Name))
            {
                error = new ValidationError(SR.GetString(SR.Error_PropertyNotSet, "Name"), ErrorNumbers.Error_PropertyNotSet);
                error.PropertyName = GetFullPropertyName(manager) + ".Name";
            }
            else
            {
                BindValidationContext validationBindContext = manager.Context[typeof(BindValidationContext)] as BindValidationContext;
                if (validationBindContext == null)
                {
                    Type baseType = BindHelpers.GetBaseType(manager, validationContext);
                    if (baseType != null)
                    {
                        AccessTypes accessType = BindHelpers.GetAccessType(manager, validationContext);
                        validationBindContext = new BindValidationContext(baseType, accessType);
                    }
                    //else
                    //{
                    //    error = new ValidationError(SR.GetString(SR.Error_BindBaseTypeNotSpecified, validationContext.PropertyName), ErrorNumbers.Error_BindBaseTypeNotSpecified);
                    //    error.PropertyName = GetFullPropertyName(manager) + ".Name";
                    //}
                }
                if (validationBindContext != null)
                {
                    Type targetType = validationBindContext.TargetType;
                    if (error == null)
                        validationErrors.AddRange(this.ValidateField(manager, activity, bind, new BindValidationContext(targetType, validationBindContext.Access)));
                }
            }
            if (error != null)
                validationErrors.Add(error);

            return validationErrors;
        }
 public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
 {
     ValidationErrorCollection errors = new ValidationErrorCollection(base.Validate(manager, obj));
     WhileActivity activity = obj as WhileActivity;
     if (activity == null)
     {
         throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(WhileActivity).FullName }), "obj");
     }
     if (activity.EnabledActivities.Count != 1)
     {
         errors.Add(new ValidationError(SR.GetString("Error_WhileShouldHaveOneChild"), 0x60b));
     }
     return errors;
 }
 public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
 {
     ValidationErrorCollection errors = base.Validate(manager, obj);
     ReplicatorActivity activity = obj as ReplicatorActivity;
     if (activity == null)
     {
         throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(ReplicatorActivity).FullName }), "obj");
     }
     if (activity.EnabledActivities.Count != 1)
     {
         errors.Add(new ValidationError(SR.GetString("Error_GeneratorShouldContainSingleActivity"), 0x526));
     }
     return errors;
 }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            if (manager == null)
                throw new ArgumentNullException("manager");

            Activity activity = obj as Activity;
            if (activity == null)
                throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(Activity).FullName), "obj");

            if (manager.Context == null)
                throw new ArgumentException("manager", SR.GetString(SR.Error_MissingContextProperty));

            manager.Context.Push(activity);

            ValidationErrorCollection errors = new ValidationErrorCollection();
            errors.AddRange(base.Validate(manager, obj));

            if (activity.Parent == null)
            {
                errors.AddRange(ValidationHelpers.ValidateUniqueIdentifiers(activity));

                if (activity.Enabled == false)
                {
                    ValidationError error = new ValidationError(SR.GetString(SR.Error_RootIsNotEnabled), ErrorNumbers.Error_RootIsNotEnabled);
                    error.PropertyName = "Enabled";
                    errors.Add(error);
                }
            }

            // validate ID property, only if it is not root activity
            Activity rootActivity = Helpers.GetRootActivity(activity);
            if (activity != rootActivity)
            {
                ValidationError identifierError = ValidationHelpers.ValidateNameProperty("Name", manager, activity.Name);
                if (identifierError != null)
                    errors.Add(identifierError);
            }

            try
            {
                errors.AddRange(ValidateProperties(manager, obj));
            }
            finally
            {
                System.Diagnostics.Debug.Assert(manager.Context.Current == activity, "Unwinding contextStack: the item that is about to be popped is not the one we pushed.");
                manager.Context.Pop();
            }

            return errors;
        }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection errors = base.Validate(manager, obj);

             MsmqSendActivity act = (MsmqSendActivity)obj;

             if ( !act.IsBindingSet(MsmqSendActivity.QueueProperty) )
             {
            if ( act.GetValue(MsmqSendActivity.QueueProperty) == null )
            {
               errors.Add(ValidationError.GetNotSetValidationError("Queue"));
            }
             }
             if ( !act.IsBindingSet(MsmqSendActivity.MessageToSendProperty) )
             {
            if ( act.GetValue(MsmqSendActivity.MessageToSendProperty) == null )
            {
               errors.Add(ValidationError.GetNotSetValidationError("MessageToSend"));
            }
             }

             // if the queue is transactional, one of our parents
             // must be a TransactionScope
             if ( act.IsTransactionalQueue )
             {
            bool isInTransaction = false;
            Activity parent = act.Parent;

            while ( parent != null )
            {
               if ( parent is TransactionScopeActivity )
               {
                  isInTransaction = true;
                  break;
               }
               parent = parent.Parent;
            }

            if ( !isInTransaction )
            {
               ValidationError error =
                  new ValidationError(Resources.Send_MustBeInTransaction, 9001);
               errors.Add(error);
            }
             }

             return errors;
        }
 public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
 {
     if (manager == null)
     {
         throw new ArgumentNullException("manager");
     }
     Activity context = obj as Activity;
     if (context == null)
     {
         throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(Activity).FullName }), "obj");
     }
     if (manager.Context == null)
     {
         throw new ArgumentException("manager", SR.GetString("Error_MissingContextProperty"));
     }
     manager.Context.Push(context);
     ValidationErrorCollection errors = new ValidationErrorCollection();
     errors.AddRange(base.Validate(manager, obj));
     if (context.Parent == null)
     {
         errors.AddRange(ValidationHelpers.ValidateUniqueIdentifiers(context));
         if (!context.Enabled)
         {
             ValidationError item = new ValidationError(SR.GetString("Error_RootIsNotEnabled"), 0x628) {
                 PropertyName = "Enabled"
             };
             errors.Add(item);
         }
     }
     Activity rootActivity = Helpers.GetRootActivity(context);
     if (context != rootActivity)
     {
         ValidationError error2 = ValidationHelpers.ValidateNameProperty("Name", manager, context.Name);
         if (error2 != null)
         {
             errors.Add(error2);
         }
     }
     try
     {
         errors.AddRange(this.ValidateProperties(manager, obj));
     }
     finally
     {
         manager.Context.Pop();
     }
     return errors;
 }
 public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
 {
     ValidationErrorCollection errors = new ValidationErrorCollection();
     errors.AddRange(base.Validate(manager, obj));
     CodeCondition condition = obj as CodeCondition;
     if (((condition != null) && (condition.GetInvocationList<EventHandler<ConditionalEventArgs>>(CodeCondition.ConditionEvent).Length == 0)) && (condition.GetBinding(CodeCondition.ConditionEvent) == null))
     {
         Hashtable hashtable = condition.GetValue(WorkflowMarkupSerializer.EventsProperty) as Hashtable;
         if ((hashtable != null) && (hashtable["Condition"] != null))
         {
             return errors;
         }
         errors.Add(ValidationError.GetNotSetValidationError(base.GetFullPropertyName(manager) + ".Condition"));
     }
     return errors;
 }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            if (manager == null)
                throw new ArgumentNullException("manager");
            if (obj == null)
                throw new ArgumentNullException("obj");

            ValidationErrorCollection validationErrors = base.Validate(manager, obj);
            DependencyObject dependencyObject = obj as DependencyObject;
            if (dependencyObject == null)
                throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(DependencyObject).FullName), "obj");

            ArrayList allProperties = new ArrayList();

            // Validate all the settable dependency properties
            // attached property can not be found through the call to DependencyProperty.FromType()
            foreach (DependencyProperty prop in DependencyProperty.FromType(dependencyObject.GetType()))
            {
                // This property is attached to some other object.  We should not validate it here
                // because the context is wrong.
                if (!prop.IsAttached)
                    allProperties.Add(prop);
            }
            // 


            foreach (DependencyProperty prop in dependencyObject.MetaDependencyProperties)
            {
                if (prop.IsAttached)
                {
                    if (obj.GetType().GetProperty(prop.Name, BindingFlags.Public | BindingFlags.Instance) == null)
                        allProperties.Add(prop);
                }
            }

            foreach (DependencyProperty prop in allProperties)
            {
                object[] validationVisibilityAtrributes = prop.DefaultMetadata.GetAttributes(typeof(ValidationOptionAttribute));
                ValidationOption validationVisibility = (validationVisibilityAtrributes.Length > 0) ? ((ValidationOptionAttribute)validationVisibilityAtrributes[0]).ValidationOption : ValidationOption.Optional;
                if (validationVisibility != ValidationOption.None)
                    validationErrors.AddRange(ValidateDependencyProperty(dependencyObject, prop, manager));
            }

            return validationErrors;
        }
 public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
 {
     ValidationErrorCollection errors = base.Validate(manager, obj);
     SuspendActivity activity = obj as SuspendActivity;
     if (activity == null)
     {
         throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(SuspendActivity).FullName }), "obj");
     }
     for (CompositeActivity activity2 = activity.Parent; activity2 != null; activity2 = activity2.Parent)
     {
         if (activity2.SupportsTransaction)
         {
             errors.Add(new ValidationError(SR.GetString("Error_SuspendInAtomicScope"), 0x525));
             return errors;
         }
     }
     return errors;
 }
 public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
 {
     ValidationErrorCollection errors = base.Validate(manager, obj);
     CancellationHandlerActivity activity = obj as CancellationHandlerActivity;
     if (activity == null)
     {
         throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(CancellationHandlerActivity).FullName }), "obj");
     }
     if (activity.EnabledActivities.Count == 0)
     {
         errors.Add(new ValidationError(SR.GetString("Warning_EmptyBehaviourActivity", new object[] { typeof(CancellationHandlerActivity).FullName, activity.QualifiedName }), 0x1a3, true));
     }
     if (activity.AlternateFlowActivities.Count > 0)
     {
         errors.Add(new ValidationError(SR.GetString("Error_ModelingConstructsCanNotContainModelingConstructs"), 0x61f));
     }
     return errors;
 }
        private ValidationErrorCollection ValidateDependencyProperty(DependencyObject dependencyObject, DependencyProperty dependencyProperty, ValidationManager manager)
        {
            ValidationErrorCollection errors = new ValidationErrorCollection();

            Attribute[]      attributes    = dependencyProperty.DefaultMetadata.GetAttributes(typeof(ValidationOptionAttribute));
            ValidationOption option        = (attributes.Length > 0) ? ((ValidationOptionAttribute)attributes[0]).ValidationOption : ValidationOption.Optional;
            Activity         propertyOwner = manager.Context[typeof(Activity)] as Activity;

            if (propertyOwner == null)
            {
                throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(Activity).FullName }));
            }
            PropertyValidationContext context = new PropertyValidationContext(propertyOwner, dependencyProperty);

            manager.Context.Push(context);
            try
            {
                if (dependencyProperty.DefaultMetadata.DefaultValue != null)
                {
                    if (!dependencyProperty.PropertyType.IsValueType && (dependencyProperty.PropertyType != typeof(string)))
                    {
                        errors.Add(new ValidationError(SR.GetString("Error_PropertyDefaultIsReference", new object[] { dependencyProperty.Name }), 0x1a8));
                    }
                    else if (!dependencyProperty.PropertyType.IsAssignableFrom(dependencyProperty.DefaultMetadata.DefaultValue.GetType()))
                    {
                        errors.Add(new ValidationError(SR.GetString("Error_PropertyDefaultTypeMismatch", new object[] { dependencyProperty.Name, dependencyProperty.PropertyType.FullName, dependencyProperty.DefaultMetadata.DefaultValue.GetType().FullName }), 0x1a9));
                    }
                }
                object propValue = null;
                if (dependencyObject.IsBindingSet(dependencyProperty))
                {
                    propValue = dependencyObject.GetBinding(dependencyProperty);
                }
                else if (!dependencyProperty.IsEvent)
                {
                    propValue = dependencyObject.GetValue(dependencyProperty);
                }
                if ((propValue == null) || (propValue == dependencyProperty.DefaultMetadata.DefaultValue))
                {
                    if (dependencyProperty.IsEvent)
                    {
                        propValue = dependencyObject.GetHandler(dependencyProperty);
                        if (propValue == null)
                        {
                            propValue = WorkflowMarkupSerializationHelpers.GetEventHandlerName(dependencyObject, dependencyProperty.Name);
                        }
                        if ((propValue is string) && !string.IsNullOrEmpty((string)propValue))
                        {
                            errors.AddRange(this.ValidateEvent(propertyOwner, dependencyProperty, propValue, manager));
                        }
                    }
                    else
                    {
                        propValue = dependencyObject.GetValue(dependencyProperty);
                    }
                }
                bool flag = (propertyOwner.Parent != null) || ((propertyOwner is CompositeActivity) && (((CompositeActivity)propertyOwner).EnabledActivities.Count != 0));
                if (((option == ValidationOption.Required) && ((propValue == null) || ((propValue is string) && string.IsNullOrEmpty((string)propValue)))) && (dependencyProperty.DefaultMetadata.IsMetaProperty && flag))
                {
                    errors.Add(ValidationError.GetNotSetValidationError(base.GetFullPropertyName(manager)));
                    return(errors);
                }
                if (propValue == null)
                {
                    return(errors);
                }
                if (propValue is IList)
                {
                    PropertyValidationContext context2 = new PropertyValidationContext(propValue, null, string.Empty);
                    manager.Context.Push(context2);
                    try
                    {
                        foreach (object obj3 in (IList)propValue)
                        {
                            errors.AddRange(ValidationHelpers.ValidateObject(manager, obj3));
                        }
                        return(errors);
                    }
                    finally
                    {
                        manager.Context.Pop();
                    }
                }
                if (dependencyProperty.ValidatorType != null)
                {
                    Validator validator = null;
                    try
                    {
                        validator = Activator.CreateInstance(dependencyProperty.ValidatorType) as Validator;
                        if (validator == null)
                        {
                            errors.Add(new ValidationError(SR.GetString("Error_CreateValidator", new object[] { dependencyProperty.ValidatorType.FullName }), 0x106));
                            return(errors);
                        }
                        errors.AddRange(validator.Validate(manager, propValue));
                        return(errors);
                    }
                    catch
                    {
                        errors.Add(new ValidationError(SR.GetString("Error_CreateValidator", new object[] { dependencyProperty.ValidatorType.FullName }), 0x106));
                        return(errors);
                    }
                }
                errors.AddRange(ValidationHelpers.ValidateObject(manager, propValue));
            }
            finally
            {
                manager.Context.Pop();
            }
            return(errors);
        }
예제 #32
0
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection errors = base.Validate(manager, obj);
            ActivityBind bind = obj as ActivityBind;

            if (bind == null)
            {
                throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(ActivityBind).FullName }), "obj");
            }
            Activity activity = manager.Context[typeof(Activity)] as Activity;

            if (activity == null)
            {
                throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(Activity).Name }));
            }
            PropertyValidationContext validationContext = manager.Context[typeof(PropertyValidationContext)] as PropertyValidationContext;

            if (validationContext == null)
            {
                throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(BindValidationContext).Name }));
            }
            ValidationError item = null;

            if (string.IsNullOrEmpty(bind.Name))
            {
                item = new ValidationError(SR.GetString("Error_IDNotSetForActivitySource"), 0x613)
                {
                    PropertyName = base.GetFullPropertyName(manager) + ".Name"
                };
                errors.Add(item);
                return(errors);
            }
            Activity refActivity = Helpers.ParseActivityForBind(activity, bind.Name);

            if (refActivity == null)
            {
                if (bind.Name.StartsWith("/"))
                {
                    item = new ValidationError(SR.GetString("Error_CannotResolveRelativeActivity", new object[] { bind.Name }), 0x128);
                }
                else
                {
                    item = new ValidationError(SR.GetString("Error_CannotResolveActivity", new object[] { bind.Name }), 0x129);
                }
                item.PropertyName = base.GetFullPropertyName(manager) + ".Name";
                errors.Add(item);
            }
            if (string.IsNullOrEmpty(bind.Path))
            {
                item = new ValidationError(SR.GetString("Error_PathNotSetForActivitySource"), 0x12b)
                {
                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                };
                errors.Add(item);
            }
            if ((refActivity != null) && (errors.Count == 0))
            {
                string path       = bind.Path;
                string str2       = string.Empty;
                int    startIndex = path.IndexOfAny(new char[] { '.', '/', '[' });
                if (startIndex != -1)
                {
                    str2 = path.Substring(startIndex);
                    str2 = str2.StartsWith(".") ? str2.Substring(1) : str2;
                    path = path.Substring(0, startIndex);
                }
                Type       baseType   = BindHelpers.GetBaseType(manager, validationContext);
                MemberInfo memberInfo = null;
                Type       srcType    = null;
                if (!string.IsNullOrEmpty(path))
                {
                    srcType = BindValidatorHelper.GetActivityType(manager, refActivity);
                    if (srcType != null)
                    {
                        memberInfo = MemberBind.GetMemberInfo(srcType, path);
                        if ((memberInfo == null) && str2.StartsWith("[", StringComparison.Ordinal))
                        {
                            string str3  = bind.Path.Substring(startIndex);
                            int    index = str3.IndexOf(']');
                            if (index != -1)
                            {
                                string str4 = str3.Substring(0, index + 1);
                                str2 = ((index + 1) < str3.Length) ? str3.Substring(index + 1) : string.Empty;
                                str2 = str2.StartsWith(".") ? str2.Substring(1) : str2;
                                str3 = str4;
                            }
                            path       = path + str3;
                            memberInfo = MemberBind.GetMemberInfo(srcType, path);
                        }
                    }
                }
                Validator validator = null;
                object    obj2      = null;
                if (memberInfo != null)
                {
                    string str5 = !string.IsNullOrEmpty(refActivity.QualifiedName) ? refActivity.QualifiedName : bind.Name;
                    if (memberInfo is FieldInfo)
                    {
                        obj2      = new FieldBind(str5 + "." + path, str2);
                        validator = new FieldBindValidator();
                    }
                    else if (memberInfo is MethodInfo)
                    {
                        if (typeof(Delegate).IsAssignableFrom(baseType))
                        {
                            obj2      = new MethodBind(str5 + "." + path);
                            validator = new MethodBindValidator();
                        }
                        else
                        {
                            item = new ValidationError(SR.GetString("Error_InvalidMemberType", new object[] { path, base.GetFullPropertyName(manager) }), 0x629)
                            {
                                PropertyName = base.GetFullPropertyName(manager)
                            };
                            errors.Add(item);
                        }
                    }
                    else if (memberInfo is PropertyInfo)
                    {
                        if (refActivity == activity)
                        {
                            obj2      = new PropertyBind(str5 + "." + path, str2);
                            validator = new PropertyBindValidator();
                        }
                        else
                        {
                            obj2      = bind;
                            validator = this;
                        }
                    }
                    else if (memberInfo is EventInfo)
                    {
                        obj2      = bind;
                        validator = this;
                    }
                }
                else if (((memberInfo == null) && (baseType != null)) && typeof(Delegate).IsAssignableFrom(baseType))
                {
                    obj2      = bind;
                    validator = this;
                }
                if ((validator != null) && (obj2 != null))
                {
                    if ((validator == this) && (obj2 is ActivityBind))
                    {
                        errors.AddRange(this.ValidateActivityBind(manager, obj2));
                        return(errors);
                    }
                    errors.AddRange(validator.Validate(manager, obj2));
                    return(errors);
                }
                if (item == null)
                {
                    item = new ValidationError(SR.GetString("Error_PathCouldNotBeResolvedToMember", new object[] { bind.Path, !string.IsNullOrEmpty(refActivity.QualifiedName) ? refActivity.QualifiedName : refActivity.GetType().Name }), 0x60d)
                    {
                        PropertyName = base.GetFullPropertyName(manager)
                    };
                    errors.Add(item);
                }
            }
            return(errors);
        }
예제 #33
0
        private ValidationErrorCollection ValidateMethod(ValidationManager manager, Activity activity, MethodBind bind, BindValidationContext validationBindContext)
        {
            ValidationErrorCollection errors = new ValidationErrorCollection();

            if ((validationBindContext.Access & AccessTypes.Write) != 0)
            {
                ValidationError item = new ValidationError(SR.GetString("Error_HandlerReadOnly"), 0x133)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
                errors.Add(item);
                return(errors);
            }
            if (!TypeProvider.IsAssignable(typeof(Delegate), validationBindContext.TargetType))
            {
                ValidationError error2 = new ValidationError(SR.GetString("Error_TypeNotDelegate", new object[] { validationBindContext.TargetType.FullName }), 0x134)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
                errors.Add(error2);
                return(errors);
            }
            string   name = bind.Name;
            Activity enclosingActivity = Helpers.GetEnclosingActivity(activity);

            if ((name.IndexOf('.') != -1) && (enclosingActivity != null))
            {
                enclosingActivity = Helpers.GetDataSourceActivity(activity, bind.Name, out name);
            }
            if (enclosingActivity == null)
            {
                ValidationError error3 = new ValidationError(SR.GetString("Error_NoEnclosingContext", new object[] { activity.Name }), 0x130)
                {
                    PropertyName = base.GetFullPropertyName(manager) + ".Name"
                };
                errors.Add(error3);
                return(errors);
            }
            string errorText       = string.Empty;
            int    errorNumber     = -1;
            Type   dataSourceClass = Helpers.GetDataSourceClass(enclosingActivity, manager);

            if (dataSourceClass == null)
            {
                errorText   = SR.GetString("Error_TypeNotResolvedInMethodName", new object[] { base.GetFullPropertyName(manager) + ".Name" });
                errorNumber = 0x135;
            }
            else
            {
                try
                {
                    ValidationHelpers.ValidateIdentifier(manager, name);
                }
                catch (Exception exception)
                {
                    errors.Add(new ValidationError(exception.Message, 0x119));
                }
                MethodInfo method = validationBindContext.TargetType.GetMethod("Invoke");
                if (method == null)
                {
                    throw new Exception(SR.GetString("Error_DelegateNoInvoke", new object[] { validationBindContext.TargetType.FullName }));
                }
                List <Type> list = new List <Type>();
                foreach (ParameterInfo info2 in method.GetParameters())
                {
                    list.Add(info2.ParameterType);
                }
                MethodInfo info3 = Helpers.GetMethodExactMatch(dataSourceClass, name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, null, list.ToArray(), null);
                if (info3 == null)
                {
                    if (dataSourceClass.GetMethod(name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance) != null)
                    {
                        errorText   = SR.GetString("Error_MethodSignatureMismatch", new object[] { base.GetFullPropertyName(manager) + ".Name" });
                        errorNumber = 310;
                    }
                    else
                    {
                        errorText   = SR.GetString("Error_MethodNotExists", new object[] { base.GetFullPropertyName(manager) + ".Name", bind.Name });
                        errorNumber = 0x137;
                    }
                }
                else if (!method.ReturnType.Equals(info3.ReturnType))
                {
                    errorText   = SR.GetString("Error_MethodReturnTypeMismatch", new object[] { base.GetFullPropertyName(manager), method.ReturnType.FullName });
                    errorNumber = 0x139;
                }
            }
            if (errorText.Length > 0)
            {
                ValidationError error4 = new ValidationError(errorText, errorNumber)
                {
                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                };
                errors.Add(error4);
            }
            return(errors);
        }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = base.Validate(manager, obj);

            Activity activity = obj as Activity;

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

            WorkflowTransactionOptions atomicTransaction = TransactedContextFilter.GetTransactionOptions(activity);

            if (atomicTransaction != null)
            {
                // Atomic scopes can't have exception handlers.
                CompositeActivity exceptionHandlers = FaultAndCancellationHandlingFilter.GetFaultHandlers(activity);
                if (exceptionHandlers != null)
                {
                    ValidationError error = new ValidationError(SR.GetString(SR.Error_AtomicScopeWithFaultHandlersActivityDecl, activity.Name), ErrorNumbers.Error_AtomicScopeWithFaultHandlersActivityDecl);
                    validationErrors.Add(error);
                }

                // Atomic scopes can't have cancel handlers.
                Activity cancellationHandler = FaultAndCancellationHandlingFilter.GetCancellationHandler(activity);
                if (cancellationHandler != null)
                {
                    ValidationError error = new ValidationError(SR.GetString(SR.Error_AtomicScopeWithCancellationHandlerActivity, activity.Name), ErrorNumbers.Error_AtomicScopeWithCancellationHandlerActivity);
                    validationErrors.Add(error);
                }

                // check that this transaction scope is not nested inside another transaction scope
                Activity parent = activity.Parent;
                while (parent != null)
                {
                    if (parent.SupportsTransaction)
                    {
                        validationErrors.Add(new ValidationError(SR.GetString(SR.Error_AtomicScopeNestedInNonLRT), ErrorNumbers.Error_AtomicScopeNestedInNonLRT));
                        break;
                    }
                    parent = parent.Parent;
                }

                // check that an activity with PersistOnClose/SupportsTransaction/ICompensatableActivity attribute is not nested inside the transaction scope
                Queue <Activity> nestedEnabledActivities = new Queue <Activity>(Helpers.GetAllEnabledActivities((CompositeActivity)activity));
                while (nestedEnabledActivities.Count > 0)
                {
                    Activity nestedEnabledActivity = nestedEnabledActivities.Dequeue();
                    if (nestedEnabledActivity.PersistOnClose)
                    {
                        validationErrors.Add(new ValidationError(SR.GetString(SR.Error_LRTScopeNestedInNonLRT), ErrorNumbers.Error_LRTScopeNestedInNonLRT));
                        break;
                    }
                    if (nestedEnabledActivity is ICompensatableActivity)
                    {
                        validationErrors.Add(new ValidationError(SR.GetString(SR.Error_NestedCompensatableActivity, nestedEnabledActivity.QualifiedName), ErrorNumbers.Error_NestedCompensatableActivity));
                        break;
                    }

                    if (nestedEnabledActivity is CompositeActivity)
                    {
                        foreach (Activity nestedEnabledActivity2 in Helpers.GetAllEnabledActivities((CompositeActivity)nestedEnabledActivity))
                        {
                            nestedEnabledActivities.Enqueue(nestedEnabledActivity2);
                        }
                    }
                }

                // check timeout property
                if (atomicTransaction.TimeoutDuration.Ticks < 0)
                {
                    ValidationError timeoutError = new ValidationError(SR.GetString(SR.Error_NegativeValue, new object[] { atomicTransaction.TimeoutDuration.ToString(), "TimeoutDuration" }), ErrorNumbers.Error_NegativeValue);
                    timeoutError.PropertyName = "TimeoutDuration";
                    validationErrors.Add(timeoutError);
                }
            }
            return(validationErrors);
        }
        private ValidationErrorCollection ValidateEvent(Activity activity, DependencyProperty dependencyProperty, object propValue, ValidationManager manager)
        {
            ValidationErrorCollection errors = new ValidationErrorCollection();

            if ((propValue is string) && !string.IsNullOrEmpty((string)propValue))
            {
                bool     flag              = false;
                Type     type              = null;
                Activity rootActivity      = Helpers.GetRootActivity(activity);
                Activity enclosingActivity = Helpers.GetEnclosingActivity(activity);
                string   str = rootActivity.GetValue(WorkflowMarkupSerializer.XClassProperty) as string;
                if ((rootActivity == enclosingActivity) && !string.IsNullOrEmpty(str))
                {
                    ITypeProvider service = manager.GetService(typeof(ITypeProvider)) as ITypeProvider;
                    if (service == null)
                    {
                        throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(ITypeProvider).FullName }));
                    }
                    type = service.GetType(str);
                }
                else
                {
                    type = enclosingActivity.GetType();
                }
                if (type != null)
                {
                    MethodInfo method = dependencyProperty.PropertyType.GetMethod("Invoke");
                    if (method != null)
                    {
                        List <Type> list = new List <Type>();
                        foreach (ParameterInfo info2 in method.GetParameters())
                        {
                            list.Add(info2.ParameterType);
                        }
                        MethodInfo info3 = Helpers.GetMethodExactMatch(type, propValue as string, BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, null, list.ToArray(), null);
                        if ((info3 != null) && TypeProvider.IsAssignable(method.ReturnType, info3.ReturnType))
                        {
                            flag = true;
                        }
                    }
                }
                if (!flag)
                {
                    ValidationError item = new ValidationError(SR.GetString("Error_CantResolveEventHandler", new object[] { dependencyProperty.Name, propValue as string }), 0x60f)
                    {
                        PropertyName = base.GetFullPropertyName(manager)
                    };
                    errors.Add(item);
                }
            }
            return(errors);
        }
예제 #36
0
 internal static ValidationErrorCollection ValidateProperty(ValidationManager manager, Activity activity, object obj, PropertyValidationContext propertyValidationContext)
 {
     return(ValidateProperty(manager, activity, obj, propertyValidationContext, null));
 }
예제 #37
0
        private ValidationErrorCollection ValidateActivity(ValidationManager manager, ActivityBind bind, BindValidationContext validationContext)
        {
            ValidationError           item   = null;
            ValidationErrorCollection errors = new ValidationErrorCollection();
            Activity activity = manager.Context[typeof(Activity)] as Activity;

            if (activity == null)
            {
                throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(Activity).Name }));
            }
            Activity request = Helpers.ParseActivityForBind(activity, bind.Name);

            if (request == null)
            {
                item = bind.Name.StartsWith("/", StringComparison.Ordinal) ? new ValidationError(SR.GetString("Error_CannotResolveRelativeActivity", new object[] { bind.Name }), 0x128) : new ValidationError(SR.GetString("Error_CannotResolveActivity", new object[] { bind.Name }), 0x129);
                item.PropertyName = base.GetFullPropertyName(manager) + ".Name";
            }
            else if ((bind.Path == null) || (bind.Path.Length == 0))
            {
                item = new ValidationError(SR.GetString("Error_PathNotSetForActivitySource"), 0x12b)
                {
                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                };
            }
            else
            {
                if (!bind.Name.StartsWith("/", StringComparison.Ordinal) && !ValidationHelpers.IsActivitySourceInOrder(request, activity))
                {
                    item = new ValidationError(SR.GetString("Error_BindActivityReference", new object[] { request.QualifiedName, activity.QualifiedName }), 0x12a, true)
                    {
                        PropertyName = base.GetFullPropertyName(manager) + ".Name"
                    };
                }
                IDesignerHost          service = manager.GetService(typeof(IDesignerHost)) as IDesignerHost;
                WorkflowDesignerLoader loader  = manager.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                if ((service != null) && (loader != null))
                {
                    Type srcType = null;
                    if (service.RootComponent == request)
                    {
                        ITypeProvider provider = manager.GetService(typeof(ITypeProvider)) as ITypeProvider;
                        if (provider == null)
                        {
                            throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(ITypeProvider).FullName }));
                        }
                        srcType = provider.GetType(service.RootComponentClassName);
                    }
                    else
                    {
                        request.GetType();
                    }
                    if (srcType != null)
                    {
                        MemberInfo memberInfo = MemberBind.GetMemberInfo(srcType, bind.Path);
                        if ((memberInfo == null) || ((memberInfo is PropertyInfo) && !(memberInfo as PropertyInfo).CanRead))
                        {
                            item = new ValidationError(SR.GetString("Error_InvalidMemberPath", new object[] { request.QualifiedName, bind.Path }), 300)
                            {
                                PropertyName = base.GetFullPropertyName(manager) + ".Path"
                            };
                        }
                        else
                        {
                            Type memberType = null;
                            if (memberInfo is FieldInfo)
                            {
                                memberType = ((FieldInfo)memberInfo).FieldType;
                            }
                            else if (memberInfo is PropertyInfo)
                            {
                                memberType = ((PropertyInfo)memberInfo).PropertyType;
                            }
                            else if (memberInfo is EventInfo)
                            {
                                memberType = ((EventInfo)memberInfo).EventHandlerType;
                            }
                            if (!DoesTargetTypeMatch(validationContext.TargetType, memberType, validationContext.Access))
                            {
                                if (typeof(WorkflowParameterBinding).IsAssignableFrom(memberInfo.DeclaringType))
                                {
                                    item = new ValidationError(SR.GetString("Warning_ParameterBinding", new object[] { bind.Path, request.QualifiedName, validationContext.TargetType.FullName }), 0x624, true)
                                    {
                                        PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                    };
                                }
                                else
                                {
                                    item = new ValidationError(SR.GetString("Error_TargetTypeMismatch", new object[] { memberInfo.Name, memberType.FullName, validationContext.TargetType.FullName }), 0x12d)
                                    {
                                        PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                    };
                                }
                            }
                        }
                    }
                }
                else
                {
                    MemberInfo info2 = MemberBind.GetMemberInfo(request.GetType(), bind.Path);
                    if ((info2 == null) || ((info2 is PropertyInfo) && !(info2 as PropertyInfo).CanRead))
                    {
                        item = new ValidationError(SR.GetString("Error_InvalidMemberPath", new object[] { request.QualifiedName, bind.Path }), 300)
                        {
                            PropertyName = base.GetFullPropertyName(manager) + ".Path"
                        };
                    }
                    else
                    {
                        DependencyProperty dependencyProperty = DependencyProperty.FromName(info2.Name, info2.DeclaringType);
                        object             obj2 = BindHelpers.ResolveActivityPath(request, bind.Path);
                        if (obj2 == null)
                        {
                            Type fromType = null;
                            if (info2 is FieldInfo)
                            {
                                fromType = ((FieldInfo)info2).FieldType;
                            }
                            else if (info2 is PropertyInfo)
                            {
                                fromType = ((PropertyInfo)info2).PropertyType;
                            }
                            else if (info2 is EventInfo)
                            {
                                fromType = ((EventInfo)info2).EventHandlerType;
                            }
                            if (!TypeProvider.IsAssignable(typeof(ActivityBind), fromType) && !DoesTargetTypeMatch(validationContext.TargetType, fromType, validationContext.Access))
                            {
                                if (typeof(WorkflowParameterBinding).IsAssignableFrom(info2.DeclaringType))
                                {
                                    item = new ValidationError(SR.GetString("Warning_ParameterBinding", new object[] { bind.Path, request.QualifiedName, validationContext.TargetType.FullName }), 0x624, true)
                                    {
                                        PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                    };
                                }
                                else
                                {
                                    item = new ValidationError(SR.GetString("Error_TargetTypeMismatch", new object[] { info2.Name, fromType.FullName, validationContext.TargetType.FullName }), 0x12d)
                                    {
                                        PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                    };
                                }
                            }
                        }
                        else if ((obj2 is ActivityBind) && (request.Parent != null))
                        {
                            ActivityBind         bind2   = obj2 as ActivityBind;
                            bool                 flag    = false;
                            BindRecursionContext context = manager.Context[typeof(BindRecursionContext)] as BindRecursionContext;
                            if (context == null)
                            {
                                context = new BindRecursionContext();
                                manager.Context.Push(context);
                                flag = true;
                            }
                            if (context.Contains(activity, bind))
                            {
                                item = new ValidationError(SR.GetString("Bind_ActivityDataSourceRecursionDetected"), 0x12f)
                                {
                                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                };
                            }
                            else
                            {
                                context.Add(activity, bind);
                                PropertyValidationContext propertyValidationContext = null;
                                if (dependencyProperty != null)
                                {
                                    propertyValidationContext = new PropertyValidationContext(request, dependencyProperty);
                                }
                                else
                                {
                                    propertyValidationContext = new PropertyValidationContext(request, info2 as PropertyInfo, info2.Name);
                                }
                                errors.AddRange(ValidationHelpers.ValidateProperty(manager, request, bind2, propertyValidationContext, validationContext));
                            }
                            if (flag)
                            {
                                manager.Context.Pop();
                            }
                        }
                        else if ((validationContext.TargetType != null) && !DoesTargetTypeMatch(validationContext.TargetType, obj2.GetType(), validationContext.Access))
                        {
                            item = new ValidationError(SR.GetString("Error_TargetTypeMismatch", new object[] { info2.Name, obj2.GetType().FullName, validationContext.TargetType.FullName }), 0x12d)
                            {
                                PropertyName = base.GetFullPropertyName(manager) + ".Path"
                            };
                        }
                    }
                }
            }
            if (item != null)
            {
                errors.Add(item);
            }
            return(errors);
        }
 protected internal ValidationErrorCollection ValidateProperty(PropertyInfo propertyInfo, object propertyOwner, object propertyValue, ValidationManager manager)
 {
     ValidationErrorCollection errors = new ValidationErrorCollection();
     object[] customAttributes = propertyInfo.GetCustomAttributes(typeof(ValidationOptionAttribute), true);
     if (customAttributes.Length > 0)
     {
         ValidationOption validationOption = ((ValidationOptionAttribute) customAttributes[0]).ValidationOption;
     }
     PropertyValidationContext context = new PropertyValidationContext(propertyOwner, propertyInfo, propertyInfo.Name);
     manager.Context.Push(context);
     try
     {
         if (propertyValue == null)
         {
             return errors;
         }
         errors.AddRange(ValidationHelpers.ValidateObject(manager, propertyValue));
         if (!(propertyValue is IList))
         {
             return errors;
         }
         PropertyValidationContext context2 = new PropertyValidationContext(propertyValue, null, "");
         manager.Context.Push(context2);
         try
         {
             foreach (object obj2 in (IList) propertyValue)
             {
                 errors.AddRange(ValidationHelpers.ValidateObject(manager, obj2));
             }
             return errors;
         }
         finally
         {
             manager.Context.Pop();
         }
     }
     finally
     {
         manager.Context.Pop();
     }
     return errors;
 }
예제 #39
0
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection errors = base.Validate(manager, obj);
            Activity activity = obj as Activity;

            if (activity == null)
            {
                throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(Activity).FullName }), "obj");
            }
            WorkflowTransactionOptions transactionOptions = TransactedContextFilter.GetTransactionOptions(activity);

            if (transactionOptions != null)
            {
                if (FaultAndCancellationHandlingFilter.GetFaultHandlers(activity) != null)
                {
                    ValidationError item = new ValidationError(SR.GetString("Error_AtomicScopeWithFaultHandlersActivityDecl", new object[] { activity.Name }), 0x52c);
                    errors.Add(item);
                }
                if (FaultAndCancellationHandlingFilter.GetCancellationHandler(activity) != null)
                {
                    ValidationError error2 = new ValidationError(SR.GetString("Error_AtomicScopeWithCancellationHandlerActivity", new object[] { activity.Name }), 0x575);
                    errors.Add(error2);
                }
                for (Activity activity4 = activity.Parent; activity4 != null; activity4 = activity4.Parent)
                {
                    if (activity4.SupportsTransaction)
                    {
                        errors.Add(new ValidationError(SR.GetString("Error_AtomicScopeNestedInNonLRT"), 0x52e));
                        break;
                    }
                }
                Queue <Activity> queue = new Queue <Activity>(Helpers.GetAllEnabledActivities((CompositeActivity)activity));
                while (queue.Count > 0)
                {
                    Activity activity5 = queue.Dequeue();
                    if (activity5.PersistOnClose)
                    {
                        errors.Add(new ValidationError(SR.GetString("Error_LRTScopeNestedInNonLRT"), 0x52f));
                        break;
                    }
                    if (activity5 is ICompensatableActivity)
                    {
                        errors.Add(new ValidationError(SR.GetString("Error_NestedCompensatableActivity", new object[] { activity5.QualifiedName }), 0x1a6));
                        break;
                    }
                    if (activity5 is CompositeActivity)
                    {
                        foreach (Activity activity6 in Helpers.GetAllEnabledActivities((CompositeActivity)activity5))
                        {
                            queue.Enqueue(activity6);
                        }
                    }
                }
                if (transactionOptions.TimeoutDuration.Ticks < 0L)
                {
                    ValidationError error3 = new ValidationError(SR.GetString("Error_NegativeValue", new object[] { transactionOptions.TimeoutDuration.ToString(), "TimeoutDuration" }), 0x531)
                    {
                        PropertyName = "TimeoutDuration"
                    };
                    errors.Add(error3);
                }
            }
            return(errors);
        }