コード例 #1
0
        protected override void PreFilterProperties(IDictionary properties)
        {
            base.PreFilterProperties(properties);

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

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

            WebServiceOutputActivity webServiceResponse = this.Activity as WebServiceOutputActivity;

            webServiceResponse.GetParameterPropertyDescriptors(properties);
        }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection errors   = base.Validate(manager, obj);
            WebServiceOutputActivity  activity = obj as WebServiceOutputActivity;

            if (activity == null)
            {
                throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(WebServiceOutputActivity).FullName }), "obj");
            }
            if (!Helpers.IsActivityLocked(activity))
            {
                List <ParameterInfo>    list;
                List <ParameterInfo>    list2;
                WebServiceInputActivity activity2 = null;
                if (string.IsNullOrEmpty(activity.InputActivityName))
                {
                    errors.Add(ValidationError.GetNotSetValidationError("InputActivityName"));
                    return(errors);
                }
                ITypeProvider service = (ITypeProvider)manager.GetService(typeof(ITypeProvider));
                if (service == null)
                {
                    throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(ITypeProvider).FullName }));
                }
                bool flag = false;
                foreach (Activity activity3 in WebServiceActivityHelpers.GetPreceedingActivities(activity))
                {
                    if (((activity3 is WebServiceOutputActivity) && (string.Compare(((WebServiceOutputActivity)activity3).InputActivityName, activity.InputActivityName, StringComparison.Ordinal) == 0)) || ((activity3 is WebServiceFaultActivity) && (string.Compare(((WebServiceFaultActivity)activity3).InputActivityName, activity.InputActivityName, StringComparison.Ordinal) == 0)))
                    {
                        if (activity3 is WebServiceOutputActivity)
                        {
                            errors.Add(new ValidationError(SR.GetString("Error_DuplicateWebServiceResponseFound", new object[] { activity3.QualifiedName, activity.InputActivityName }), 0x56a));
                            return(errors);
                        }
                        errors.Add(new ValidationError(SR.GetString("Error_DuplicateWebServiceFaultFound", new object[] { activity3.QualifiedName, activity.InputActivityName }), 0x574));
                        return(errors);
                    }
                }
                foreach (Activity activity4 in WebServiceActivityHelpers.GetPreceedingActivities(activity))
                {
                    if (string.Compare(activity4.QualifiedName, activity.InputActivityName, StringComparison.Ordinal) == 0)
                    {
                        if (activity4 is WebServiceInputActivity)
                        {
                            activity2 = activity4 as WebServiceInputActivity;
                            flag      = true;
                            break;
                        }
                        flag = false;
                        errors.Add(new ValidationError(SR.GetString("Error_WebServiceReceiveNotValid", new object[] { activity.InputActivityName }), 0x564));
                        return(errors);
                    }
                }
                if (!flag)
                {
                    errors.Add(new ValidationError(SR.GetString("Error_WebServiceReceiveNotFound", new object[] { activity.InputActivityName }), 0x55e));
                    return(errors);
                }
                Type interfaceType = null;
                if (activity2.InterfaceType != null)
                {
                    interfaceType = service.GetType(activity2.InterfaceType.AssemblyQualifiedName);
                }
                if (interfaceType == null)
                {
                    errors.Add(new ValidationError(SR.GetString("Error_WebServiceReceiveNotConfigured", new object[] { activity2.Name }), 0x566));
                    return(errors);
                }
                if (string.IsNullOrEmpty(activity2.MethodName))
                {
                    errors.Add(new ValidationError(SR.GetString("Error_WebServiceReceiveNotConfigured", new object[] { activity2.Name }), 0x566));
                    return(errors);
                }
                MethodInfo interfaceMethod = Helpers.GetInterfaceMethod(interfaceType, activity2.MethodName);
                if (interfaceMethod == null)
                {
                    errors.Add(new ValidationError(SR.GetString("Error_WebServiceReceiveNotConfigured", new object[] { activity2.Name }), 0x566));
                    return(errors);
                }
                ValidationErrorCollection errors2 = WebServiceActivityHelpers.ValidateParameterTypes(interfaceMethod);
                if (errors2.Count > 0)
                {
                    foreach (ValidationError error in errors2)
                    {
                        error.PropertyName = "InputActivityName";
                    }
                    errors.AddRange(errors2);
                    return(errors);
                }
                WebServiceActivityHelpers.GetParameterInfo(interfaceMethod, out list, out list2);
                if (list2.Count == 0)
                {
                    errors.Add(new ValidationError(SR.GetString("Error_WebServiceResponseNotNeeded"), 0x565));
                    return(errors);
                }
                foreach (ParameterInfo info2 in list2)
                {
                    string name  = info2.Name;
                    Type   type2 = info2.ParameterType.IsByRef ? info2.ParameterType.GetElementType() : info2.ParameterType;
                    if (info2.Position == -1)
                    {
                        name = "(ReturnValue)";
                    }
                    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 item = new ValidationError(SR.GetString("Error_TypeNotPublicSerializable", new object[] { name, type2.FullName }), 0x567)
                        {
                            PropertyName = (string.Compare(name, "(ReturnValue)", StringComparison.Ordinal) == 0) ? name : ParameterInfoBasedPropertyDescriptor.GetParameterPropertyName(activity2.GetType(), name)
                        };
                        errors.Add(item);
                    }
                    else if (!activity.ParameterBindings.Contains(name) || (binding == null))
                    {
                        ValidationError notSetValidationError = ValidationError.GetNotSetValidationError(name);
                        notSetValidationError.PropertyName = (string.Compare(name, "(ReturnValue)", StringComparison.Ordinal) == 0) ? name : ParameterInfoBasedPropertyDescriptor.GetParameterPropertyName(activity2.GetType(), name);
                        errors.Add(notSetValidationError);
                    }
                    else
                    {
                        AccessTypes read = AccessTypes.Read;
                        if ((info2.IsOut || info2.IsRetval) || (info2.Position == -1))
                        {
                            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 error4 in errors3)
                        {
                            if (string.Compare(name, "(ReturnValue)", StringComparison.Ordinal) != 0)
                            {
                                error4.PropertyName = ParameterInfoBasedPropertyDescriptor.GetParameterPropertyName(activity2.GetType(), name);
                            }
                        }
                        errors.AddRange(errors3);
                    }
                }
                if (activity.ParameterBindings.Count > list2.Count)
                {
                    errors.Add(new ValidationError(SR.GetString("Warning_AdditionalBindingsFound"), 0x630, true));
                }
            }
            return(errors);
        }
コード例 #3
0
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = base.Validate(manager, obj);

            WebServiceOutputActivity webServiceResponse = obj as WebServiceOutputActivity;

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

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

            WebServiceInputActivity webServiceReceive = null;

            if (String.IsNullOrEmpty(webServiceResponse.InputActivityName))
            {
                validationErrors.Add(ValidationError.GetNotSetValidationError("InputActivityName"));
            }
            else
            {
                ITypeProvider typeProvider = (ITypeProvider)manager.GetService(typeof(ITypeProvider));
                if (typeProvider == null)
                {
                    throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(ITypeProvider).FullName));
                }

                bool foundMatchingReceive = false;
                foreach (Activity activity in WebServiceActivityHelpers.GetPreceedingActivities(webServiceResponse))
                {
                    if ((activity is WebServiceOutputActivity && String.Compare(((WebServiceOutputActivity)activity).InputActivityName, webServiceResponse.InputActivityName, StringComparison.Ordinal) == 0) ||
                        (activity is WebServiceFaultActivity && String.Compare(((WebServiceFaultActivity)activity).InputActivityName, webServiceResponse.InputActivityName, StringComparison.Ordinal) == 0))
                    {
                        if (activity is WebServiceOutputActivity)
                        {
                            validationErrors.Add(new ValidationError(SR.GetString(SR.Error_DuplicateWebServiceResponseFound, activity.QualifiedName, webServiceResponse.InputActivityName), ErrorNumbers.Error_DuplicateWebServiceResponseFound));
                        }
                        else
                        {
                            validationErrors.Add(new ValidationError(SR.GetString(SR.Error_DuplicateWebServiceFaultFound, activity.QualifiedName, webServiceResponse.InputActivityName), ErrorNumbers.Error_DuplicateWebServiceFaultFound));
                        }
                        return(validationErrors);
                    }
                }

                foreach (Activity activity in WebServiceActivityHelpers.GetPreceedingActivities(webServiceResponse))
                {
                    if (String.Compare(activity.QualifiedName, webServiceResponse.InputActivityName, StringComparison.Ordinal) == 0)
                    {
                        if (activity is WebServiceInputActivity)
                        {
                            webServiceReceive    = activity as WebServiceInputActivity;
                            foundMatchingReceive = true;
                        }
                        else
                        {
                            foundMatchingReceive = false;
                            validationErrors.Add(new ValidationError(SR.GetString(SR.Error_WebServiceReceiveNotValid, webServiceResponse.InputActivityName), ErrorNumbers.Error_WebServiceReceiveNotValid));
                            return(validationErrors);
                        }
                        break;
                    }
                }

                if (!foundMatchingReceive)
                {
                    validationErrors.Add(new ValidationError(SR.GetString(SR.Error_WebServiceReceiveNotFound, webServiceResponse.InputActivityName), ErrorNumbers.Error_WebServiceReceiveNotFound));
                    return(validationErrors);
                }
                else
                {
                    Type interfaceType = null;
                    if (webServiceReceive.InterfaceType != null)
                    {
                        interfaceType = typeProvider.GetType(webServiceReceive.InterfaceType.AssemblyQualifiedName);
                    }

                    if (interfaceType == null)
                    {
                        validationErrors.Add(new ValidationError(SR.GetString(SR.Error_WebServiceReceiveNotConfigured, webServiceReceive.Name), ErrorNumbers.Error_WebServiceReceiveNotConfigured));
                    }
                    else
                    {
                        // Validate method
                        if (String.IsNullOrEmpty(webServiceReceive.MethodName))
                        {
                            validationErrors.Add(new ValidationError(SR.GetString(SR.Error_WebServiceReceiveNotConfigured, webServiceReceive.Name), ErrorNumbers.Error_WebServiceReceiveNotConfigured));
                        }
                        else
                        {
                            MethodInfo methodInfo = Helpers.GetInterfaceMethod(interfaceType, webServiceReceive.MethodName);

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

                                    if (outParameters.Count == 0)
                                    {
                                        validationErrors.Add(new ValidationError(SR.GetString(SR.Error_WebServiceResponseNotNeeded), ErrorNumbers.Error_WebServiceResponseNotNeeded));
                                    }
                                    else
                                    {
                                        // Check to see if all output parameters have a valid bindings.
                                        foreach (ParameterInfo paramInfo in outParameters)
                                        {
                                            string paramName = paramInfo.Name;
                                            Type   paramType = paramInfo.ParameterType.IsByRef ? paramInfo.ParameterType.GetElementType() : paramInfo.ParameterType;

                                            if (paramInfo.Position == -1)
                                            {
                                                paramName = "(ReturnValue)";
                                            }

                                            object paramValue = null;
                                            if (webServiceResponse.ParameterBindings.Contains(paramName))
                                            {
                                                if (webServiceResponse.ParameterBindings[paramName].IsBindingSet(WorkflowParameterBinding.ValueProperty))
                                                {
                                                    paramValue = webServiceResponse.ParameterBindings[paramName].GetBinding(WorkflowParameterBinding.ValueProperty);
                                                }
                                                else
                                                {
                                                    paramValue = webServiceResponse.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 = (String.Compare(paramName, "(ReturnValue)", StringComparison.Ordinal) == 0) ? paramName : ParameterInfoBasedPropertyDescriptor.GetParameterPropertyName(webServiceReceive.GetType(), paramName);
                                                validationErrors.Add(validationError);
                                            }
                                            else if (!webServiceResponse.ParameterBindings.Contains(paramName) || paramValue == null)
                                            {
                                                ValidationError validationError = ValidationError.GetNotSetValidationError(paramName);
                                                validationError.PropertyName = (String.Compare(paramName, "(ReturnValue)", StringComparison.Ordinal) == 0) ? paramName : ParameterInfoBasedPropertyDescriptor.GetParameterPropertyName(webServiceReceive.GetType(), paramName);
                                                validationErrors.Add(validationError);
                                            }
                                            else
                                            {
                                                AccessTypes access = AccessTypes.Read;
                                                if (paramInfo.IsOut || paramInfo.IsRetval || paramInfo.Position == -1)
                                                {
                                                    access = AccessTypes.Write;
                                                }

                                                ValidationErrorCollection variableErrors = ValidationHelpers.ValidateProperty(manager, webServiceResponse, paramValue,
                                                                                                                              new PropertyValidationContext(webServiceResponse.ParameterBindings[paramName], null, paramName), new BindValidationContext(paramInfo.ParameterType.IsByRef ? paramInfo.ParameterType.GetElementType() : paramInfo.ParameterType, access));
                                                foreach (ValidationError variableError in variableErrors)
                                                {
                                                    if (String.Compare(paramName, "(ReturnValue)", StringComparison.Ordinal) != 0)
                                                    {
                                                        variableError.PropertyName = ParameterInfoBasedPropertyDescriptor.GetParameterPropertyName(webServiceReceive.GetType(), paramName);
                                                    }
                                                }
                                                validationErrors.AddRange(variableErrors);
                                            }
                                        }

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