Ejemplo n.º 1
0
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = base.Validate(manager, obj);

            WebServiceInputActivity webServiceReceive = obj as WebServiceInputActivity;

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

            if (Helpers.IsActivityLocked(webServiceReceive))
            {
                return(validationErrors);
            }

            if (webServiceReceive.IsActivating)
            {
                if (WebServiceActivityHelpers.GetPreceedingActivities(webServiceReceive).GetEnumerator().MoveNext() == true)
                {
                    ValidationError error = new ValidationError(SR.GetString(SR.Error_ActivationActivityNotFirst), ErrorNumbers.Error_ActivationActivityNotFirst);
                    error.PropertyName = "IsActivating";
                    validationErrors.Add(error);
                    return(validationErrors);
                }

                if (WebServiceActivityHelpers.IsInsideLoop(webServiceReceive, null))
                {
                    ValidationError error = new ValidationError(SR.GetString(SR.Error_ActivationActivityInsideLoop), ErrorNumbers.Error_ActivationActivityInsideLoop);
                    error.PropertyName = "IsActivating";
                    validationErrors.Add(error);
                    return(validationErrors);
                }
            }
            else
            {
                if (WebServiceActivityHelpers.GetPreceedingActivities(webServiceReceive, true).GetEnumerator().MoveNext() == false)
                {
                    ValidationError error = new ValidationError(SR.GetString(SR.Error_WebServiceReceiveNotMarkedActivate), ErrorNumbers.Error_WebServiceReceiveNotMarkedActivate);
                    error.PropertyName = "IsActivating";
                    validationErrors.Add(error);
                    return(validationErrors);
                }
            }

            ITypeProvider typeProvider = (ITypeProvider)manager.GetService(typeof(ITypeProvider));

            if (typeProvider == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(ITypeProvider).FullName));
            }

            Type interfaceType = null;

            if (webServiceReceive.InterfaceType != null)
            {
                interfaceType = typeProvider.GetType(webServiceReceive.InterfaceType.AssemblyQualifiedName);
            }

            if (interfaceType == null)
            {
                ValidationError error = new ValidationError(SR.GetString(SR.Error_TypePropertyInvalid, "InterfaceType"), ErrorNumbers.Error_PropertyNotSet);
                error.PropertyName = "InterfaceType";
                validationErrors.Add(error);
            }
            else if (!interfaceType.IsInterface)
            {
                ValidationError error = new ValidationError(SR.GetString(SR.Error_InterfaceTypeNotInterface, "InterfaceType"), ErrorNumbers.Error_InterfaceTypeNotInterface);
                error.PropertyName = "InterfaceType";
                validationErrors.Add(error);
            }
            else
            {
                // Validate method
                if (String.IsNullOrEmpty(webServiceReceive.MethodName))
                {
                    validationErrors.Add(ValidationError.GetNotSetValidationError("MethodName"));
                }
                else
                {
                    MethodInfo methodInfo = Helpers.GetInterfaceMethod(interfaceType, webServiceReceive.MethodName);

                    if (methodInfo == null)
                    {
                        ValidationError error = new ValidationError(SR.GetString(SR.Error_MethodNotExists, "MethodName", webServiceReceive.MethodName), ErrorNumbers.Error_MethodNotExists);
                        error.PropertyName = "MethodName";
                        validationErrors.Add(error);
                    }
                    else
                    {
                        ValidationErrorCollection parameterTypeErrors = WebServiceActivityHelpers.ValidateParameterTypes(methodInfo);
                        if (parameterTypeErrors.Count > 0)
                        {
                            foreach (ValidationError parameterTypeError in parameterTypeErrors)
                            {
                                parameterTypeError.PropertyName = "MethodName";
                            }
                            validationErrors.AddRange(parameterTypeErrors);
                        }
                        else
                        {
                            List <ParameterInfo> inputParameters, outParameters;
                            WebServiceActivityHelpers.GetParameterInfo(methodInfo, out inputParameters, out outParameters);

                            // Check to see if all input parameters have a valid binding.
                            foreach (ParameterInfo paramInfo in inputParameters)
                            {
                                string paramName             = paramInfo.Name;
                                string parameterPropertyName = ParameterInfoBasedPropertyDescriptor.GetParameterPropertyName(webServiceReceive.GetType(), paramName);

                                Type   paramType  = paramInfo.ParameterType.IsByRef ? paramInfo.ParameterType.GetElementType() : paramInfo.ParameterType;
                                object paramValue = null;
                                if (webServiceReceive.ParameterBindings.Contains(paramName))
                                {
                                    if (webServiceReceive.ParameterBindings[paramName].IsBindingSet(WorkflowParameterBinding.ValueProperty))
                                    {
                                        paramValue = webServiceReceive.ParameterBindings[paramName].GetBinding(WorkflowParameterBinding.ValueProperty);
                                    }
                                    else
                                    {
                                        paramValue = webServiceReceive.ParameterBindings[paramName].GetValue(WorkflowParameterBinding.ValueProperty);
                                    }
                                }

                                if (!paramType.IsPublic || !paramType.IsSerializable)
                                {
                                    ValidationError validationError = new ValidationError(SR.GetString(SR.Error_TypeNotPublicSerializable, paramName, paramType.FullName), ErrorNumbers.Error_TypeNotPublicSerializable);
                                    validationError.PropertyName = parameterPropertyName;
                                    validationErrors.Add(validationError);
                                }
                                else if (!webServiceReceive.ParameterBindings.Contains(paramName) || paramValue == null)
                                {
                                    ValidationError validationError = ValidationError.GetNotSetValidationError(paramName);
                                    validationError.PropertyName = parameterPropertyName;
                                    validationErrors.Add(validationError);
                                }
                                else
                                {
                                    AccessTypes access = AccessTypes.Read;
                                    if (paramInfo.ParameterType.IsByRef)
                                    {
                                        access |= AccessTypes.Write;
                                    }

                                    ValidationErrorCollection variableErrors = ValidationHelpers.ValidateProperty(manager, webServiceReceive, paramValue,
                                                                                                                  new PropertyValidationContext(webServiceReceive.ParameterBindings[paramName], null, paramName), new BindValidationContext(paramInfo.ParameterType.IsByRef ? paramInfo.ParameterType.GetElementType() : paramInfo.ParameterType, access));
                                    foreach (ValidationError validationError in variableErrors)
                                    {
                                        validationError.PropertyName = parameterPropertyName;
                                    }
                                    validationErrors.AddRange(variableErrors);
                                }
                            }

                            if (webServiceReceive.ParameterBindings.Count > inputParameters.Count)
                            {
                                validationErrors.Add(new ValidationError(SR.GetString(SR.Warning_AdditionalBindingsFound), ErrorNumbers.Warning_AdditionalBindingsFound, true));
                            }

                            bool foundMatchingResponse = false;
                            foreach (Activity succeedingActivity in WebServiceActivityHelpers.GetSucceedingActivities(webServiceReceive))
                            {
                                if ((succeedingActivity is WebServiceOutputActivity && ((WebServiceOutputActivity)succeedingActivity).InputActivityName == webServiceReceive.Name) ||
                                    (succeedingActivity is WebServiceFaultActivity && ((WebServiceFaultActivity)succeedingActivity).InputActivityName == webServiceReceive.Name))
                                {
                                    foundMatchingResponse = true;
                                    break;
                                }
                            }

                            // If the method has out parameters or is the method has a return value,
                            // check to see if there are any corresponding WebServiceResponse activities.
                            if ((outParameters.Count > 0 || methodInfo.ReturnType != typeof(void)) && !foundMatchingResponse)
                            {
                                validationErrors.Add(new ValidationError(SR.GetString(SR.Error_WebServiceResponseNotFound), ErrorNumbers.Error_WebServiceResponseNotFound));
                            }
                        }
                    }
                }
            }
            return(validationErrors);
        }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection errors   = base.Validate(manager, obj);
            WebServiceInputActivity   activity = obj as WebServiceInputActivity;

            if (activity == null)
            {
                throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(WebServiceInputActivity).FullName }), "obj");
            }
            if (!Helpers.IsActivityLocked(activity))
            {
                List <ParameterInfo> list;
                List <ParameterInfo> list2;
                if (activity.IsActivating)
                {
                    if (WebServiceActivityHelpers.GetPreceedingActivities(activity).GetEnumerator().MoveNext())
                    {
                        ValidationError item = new ValidationError(SR.GetString("Error_ActivationActivityNotFirst"), 0x568)
                        {
                            PropertyName = "IsActivating"
                        };
                        errors.Add(item);
                        return(errors);
                    }
                    if (WebServiceActivityHelpers.IsInsideLoop(activity, null))
                    {
                        ValidationError error2 = new ValidationError(SR.GetString("Error_ActivationActivityInsideLoop"), 0x579)
                        {
                            PropertyName = "IsActivating"
                        };
                        errors.Add(error2);
                        return(errors);
                    }
                }
                else if (!WebServiceActivityHelpers.GetPreceedingActivities(activity, true).GetEnumerator().MoveNext())
                {
                    ValidationError error3 = new ValidationError(SR.GetString("Error_WebServiceReceiveNotMarkedActivate"), 0x569)
                    {
                        PropertyName = "IsActivating"
                    };
                    errors.Add(error3);
                    return(errors);
                }
                ITypeProvider service = (ITypeProvider)manager.GetService(typeof(ITypeProvider));
                if (service == null)
                {
                    throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(ITypeProvider).FullName }));
                }
                Type interfaceType = null;
                if (activity.InterfaceType != null)
                {
                    interfaceType = service.GetType(activity.InterfaceType.AssemblyQualifiedName);
                }
                if (interfaceType == null)
                {
                    ValidationError error4 = new ValidationError(SR.GetString("Error_TypePropertyInvalid", new object[] { "InterfaceType" }), 0x116)
                    {
                        PropertyName = "InterfaceType"
                    };
                    errors.Add(error4);
                    return(errors);
                }
                if (!interfaceType.IsInterface)
                {
                    ValidationError error5 = new ValidationError(SR.GetString("Error_InterfaceTypeNotInterface", new object[] { "InterfaceType" }), 0x570)
                    {
                        PropertyName = "InterfaceType"
                    };
                    errors.Add(error5);
                    return(errors);
                }
                if (string.IsNullOrEmpty(activity.MethodName))
                {
                    errors.Add(ValidationError.GetNotSetValidationError("MethodName"));
                    return(errors);
                }
                MethodInfo interfaceMethod = Helpers.GetInterfaceMethod(interfaceType, activity.MethodName);
                if (interfaceMethod == null)
                {
                    ValidationError error6 = new ValidationError(SR.GetString("Error_MethodNotExists", new object[] { "MethodName", activity.MethodName }), 0x137)
                    {
                        PropertyName = "MethodName"
                    };
                    errors.Add(error6);
                    return(errors);
                }
                ValidationErrorCollection errors2 = WebServiceActivityHelpers.ValidateParameterTypes(interfaceMethod);
                if (errors2.Count > 0)
                {
                    foreach (ValidationError error7 in errors2)
                    {
                        error7.PropertyName = "MethodName";
                    }
                    errors.AddRange(errors2);
                    return(errors);
                }
                WebServiceActivityHelpers.GetParameterInfo(interfaceMethod, out list, out list2);
                foreach (ParameterInfo info2 in list)
                {
                    string name = info2.Name;
                    string parameterPropertyName = ParameterInfoBasedPropertyDescriptor.GetParameterPropertyName(activity.GetType(), name);
                    Type   type2   = info2.ParameterType.IsByRef ? info2.ParameterType.GetElementType() : info2.ParameterType;
                    object binding = null;
                    if (activity.ParameterBindings.Contains(name))
                    {
                        if (activity.ParameterBindings[name].IsBindingSet(WorkflowParameterBinding.ValueProperty))
                        {
                            binding = activity.ParameterBindings[name].GetBinding(WorkflowParameterBinding.ValueProperty);
                        }
                        else
                        {
                            binding = activity.ParameterBindings[name].GetValue(WorkflowParameterBinding.ValueProperty);
                        }
                    }
                    if (!type2.IsPublic || !type2.IsSerializable)
                    {
                        ValidationError error8 = new ValidationError(SR.GetString("Error_TypeNotPublicSerializable", new object[] { name, type2.FullName }), 0x567)
                        {
                            PropertyName = parameterPropertyName
                        };
                        errors.Add(error8);
                    }
                    else if (!activity.ParameterBindings.Contains(name) || (binding == null))
                    {
                        ValidationError notSetValidationError = ValidationError.GetNotSetValidationError(name);
                        notSetValidationError.PropertyName = parameterPropertyName;
                        errors.Add(notSetValidationError);
                    }
                    else
                    {
                        AccessTypes read = AccessTypes.Read;
                        if (info2.ParameterType.IsByRef)
                        {
                            read |= AccessTypes.Write;
                        }
                        ValidationErrorCollection errors3 = System.Workflow.Activities.Common.ValidationHelpers.ValidateProperty(manager, activity, binding, new PropertyValidationContext(activity.ParameterBindings[name], null, name), new BindValidationContext(info2.ParameterType.IsByRef ? info2.ParameterType.GetElementType() : info2.ParameterType, read));
                        foreach (ValidationError error10 in errors3)
                        {
                            error10.PropertyName = parameterPropertyName;
                        }
                        errors.AddRange(errors3);
                    }
                }
                if (activity.ParameterBindings.Count > list.Count)
                {
                    errors.Add(new ValidationError(SR.GetString("Warning_AdditionalBindingsFound"), 0x630, true));
                }
                bool flag = false;
                foreach (Activity activity2 in WebServiceActivityHelpers.GetSucceedingActivities(activity))
                {
                    if (((activity2 is WebServiceOutputActivity) && (((WebServiceOutputActivity)activity2).InputActivityName == activity.Name)) || ((activity2 is WebServiceFaultActivity) && (((WebServiceFaultActivity)activity2).InputActivityName == activity.Name)))
                    {
                        flag = true;
                        break;
                    }
                }
                if (((list2.Count > 0) || (interfaceMethod.ReturnType != typeof(void))) && !flag)
                {
                    errors.Add(new ValidationError(SR.GetString("Error_WebServiceResponseNotFound"), 0x55d));
                }
            }
            return(errors);
        }