protected override void OnActivityChanged(ActivityChangedEventArgs e)
 {
     base.OnActivityChanged(e);
     if (e.Member != null)
     {
         if ((e.Member.Name == "ProxyClass") && (base.Activity.Site != null))
         {
             InvokeWebServiceActivity activity = e.Activity as InvokeWebServiceActivity;
             System.Workflow.Activities.Common.PropertyDescriptorUtils.SetPropertyValue(base.Activity.Site, TypeDescriptor.GetProperties(base.Activity)["MethodName"], base.Activity, string.Empty);
             IExtendedUIService service = (IExtendedUIService)base.Activity.Site.GetService(typeof(IExtendedUIService));
             if (service == null)
             {
                 throw new Exception(SR.GetString("General_MissingService", new object[] { typeof(IExtendedUIService).FullName }));
             }
             if (activity.ProxyClass == null)
             {
                 this.url = null;
             }
             else
             {
                 Uri urlForProxyClass = service.GetUrlForProxyClass(activity.ProxyClass);
                 this.url = (urlForProxyClass != null) ? urlForProxyClass.ToString() : string.Empty;
             }
         }
         if (((e.Member.Name == "MethodName") || (e.Member.Name == "TargetWorkflow")) && (e.Activity is InvokeWebServiceActivity))
         {
             (e.Activity as InvokeWebServiceActivity).ParameterBindings.Clear();
         }
         if ((e.Member.Name == "ProxyClass") || (e.Member.Name == "MethodName"))
         {
             TypeDescriptor.Refresh(e.Activity);
         }
     }
 }
        protected override void OnActivityChanged(ActivityChangedEventArgs e)
        {
            base.OnActivityChanged(e);

            if (e.Member != null)
            {
                if (e.Member.Name == "ProxyClass")
                {
                    if (Activity.Site != null)
                    {
                        InvokeWebServiceActivity invokeWebServiceDecl = e.Activity as InvokeWebServiceActivity;
                        PropertyDescriptorUtils.SetPropertyValue(Activity.Site, TypeDescriptor.GetProperties(Activity)["MethodName"], Activity, String.Empty);

                        IExtendedUIService extUIService = (IExtendedUIService)Activity.Site.GetService(typeof(IExtendedUIService));
                        if (extUIService == null)
                        {
                            throw new Exception(SR.GetString(SR.General_MissingService, typeof(IExtendedUIService).FullName));
                        }

                        if (invokeWebServiceDecl.ProxyClass == null)
                        {
                            this.url = null;
                        }
                        else
                        {
                            Uri uri = extUIService.GetUrlForProxyClass(invokeWebServiceDecl.ProxyClass);
                            this.url = (uri != null) ? uri.ToString() : string.Empty;
                        }
                    }
                }

                if ((e.Member.Name == "MethodName" || e.Member.Name == "TargetWorkflow") &&
                    e.Activity is InvokeWebServiceActivity)
                {
                    (e.Activity as InvokeWebServiceActivity).ParameterBindings.Clear();
                }

                if (e.Member.Name == "ProxyClass" || e.Member.Name == "MethodName")
                {
                    TypeDescriptor.Refresh(e.Activity);
                }
            }
        }
        public override IComponent[] CreateComponentsWithUI(IDesignerHost host)
        {
            Uri  url                   = null;
            Type proxyClass            = null;
            IExtendedUIService service = host.GetService(typeof(IExtendedUIService)) as IExtendedUIService;

            if (service != null)
            {
                service.AddWebReference(out url, out proxyClass);
            }
            IComponent[] componentArray = base.CreateComponentsWithUI(host);
            if (componentArray.GetLength(0) > 0)
            {
                InvokeWebServiceActivity activity = componentArray[0] as InvokeWebServiceActivity;
                if (activity != null)
                {
                    activity.ProxyClass = proxyClass;
                }
            }
            return(componentArray);
        }
        protected override void PreFilterProperties(IDictionary properties)
        {
            base.PreFilterProperties(properties);
            if (properties["URL"] == null)
            {
                properties["URL"] = new WebServiceUrlPropertyDescriptor(Activity.Site, TypeDescriptor.CreateProperty(this.GetType(), "URL", typeof(string), DesignOnlyAttribute.Yes, MergablePropertyAttribute.No));
            }

            //

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

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

            InvokeWebServiceActivity invokeWebService = Activity as InvokeWebServiceActivity;

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

            if (activity == null)
            {
                throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(InvokeWebServiceActivity).FullName }), "obj");
            }
            if (activity.ProxyClass == null)
            {
                ValidationError item = new ValidationError(SR.GetString("Error_TypePropertyInvalid", new object[] { "ProxyClass" }), 0x116)
                {
                    PropertyName = "ProxyClass"
                };
                errors.Add(item);
                return(errors);
            }
            if (((ITypeProvider)manager.GetService(typeof(ITypeProvider))) == null)
            {
                throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(ITypeProvider).FullName }));
            }
            Type proxyClass = activity.ProxyClass;

            if ((activity.MethodName == null) || (activity.MethodName.Length == 0))
            {
                errors.Add(ValidationError.GetNotSetValidationError("MethodName"));
                return(errors);
            }
            MethodInfo method = proxyClass.GetMethod(activity.MethodName);

            if (method == null)
            {
                ValidationError error2 = new ValidationError(SR.GetString("Error_MethodNotExists", new object[] { "MethodName", activity.MethodName }), 0x137)
                {
                    PropertyName = "MethodName"
                };
                errors.Add(error2);
                return(errors);
            }
            ArrayList list = new ArrayList(method.GetParameters());

            if (method.ReturnType != typeof(void))
            {
                list.Add(method.ReturnParameter);
            }
            foreach (ParameterInfo info2 in list)
            {
                string name = info2.Name;
                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 (!activity.ParameterBindings.Contains(name) || (binding == null))
                {
                    ValidationError notSetValidationError = ValidationError.GetNotSetValidationError(name);
                    if (InvokeWebServiceActivity.ReservedParameterNames.Contains(name))
                    {
                        notSetValidationError.PropertyName = ParameterInfoBasedPropertyDescriptor.GetParameterPropertyName(activity.GetType(), name);
                    }
                    notSetValidationError.PropertyName = name;
                    errors.Add(notSetValidationError);
                }
                else
                {
                    AccessTypes read = AccessTypes.Read;
                    if (info2.IsOut || info2.IsRetval)
                    {
                        read = AccessTypes.Write;
                    }
                    else if (info2.ParameterType.IsByRef)
                    {
                        read |= AccessTypes.Write;
                    }
                    ValidationErrorCollection errors2 = 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));
                    if (InvokeWebServiceActivity.ReservedParameterNames.Contains(name))
                    {
                        foreach (ValidationError error4 in errors2)
                        {
                            error4.PropertyName = ParameterInfoBasedPropertyDescriptor.GetParameterPropertyName(activity.GetType(), name);
                        }
                    }
                    errors.AddRange(errors2);
                }
            }
            if (activity.ParameterBindings.Count > list.Count)
            {
                errors.Add(new ValidationError(SR.GetString("Warning_AdditionalBindingsFound"), 0x630, true));
            }
            return(errors);
        }
Esempio n. 6
0
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = base.Validate(manager, obj);

            InvokeWebServiceActivity invokeWebService = obj as InvokeWebServiceActivity;

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

            if (invokeWebService.ProxyClass == null)
            {
                ValidationError error = new ValidationError(SR.GetString(SR.Error_TypePropertyInvalid, "ProxyClass"), ErrorNumbers.Error_PropertyNotSet);
                error.PropertyName = "ProxyClass";
                validationErrors.Add(error);
            }
            else
            {
                ITypeProvider typeProvider = (ITypeProvider)manager.GetService(typeof(ITypeProvider));
                if (typeProvider == null)
                {
                    throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(ITypeProvider).FullName));
                }

                Type proxyClassType = invokeWebService.ProxyClass;

                // Validate method
                if (invokeWebService.MethodName == null || invokeWebService.MethodName.Length == 0)
                {
                    validationErrors.Add(ValidationError.GetNotSetValidationError("MethodName"));
                }
                else
                {
                    MethodInfo methodInfo = proxyClassType.GetMethod(invokeWebService.MethodName);
                    if (methodInfo == null)
                    {
                        ValidationError error = new ValidationError(SR.GetString(SR.Error_MethodNotExists, "MethodName", invokeWebService.MethodName), ErrorNumbers.Error_MethodNotExists);
                        error.PropertyName = "MethodName";
                        validationErrors.Add(error);
                    }
                    else
                    {
                        ArrayList paramInfos = new ArrayList(methodInfo.GetParameters());
                        if (methodInfo.ReturnType != typeof(void))
                        {
                            paramInfos.Add(methodInfo.ReturnParameter);
                        }

                        foreach (ParameterInfo paramInfo in paramInfos)
                        {
                            string paramName = paramInfo.Name;
                            if (paramInfo.Position == -1)
                            {
                                paramName = "(ReturnValue)";
                            }

                            object paramValue = null;
                            if (invokeWebService.ParameterBindings.Contains(paramName))
                            {
                                if (invokeWebService.ParameterBindings[paramName].IsBindingSet(WorkflowParameterBinding.ValueProperty))
                                {
                                    paramValue = invokeWebService.ParameterBindings[paramName].GetBinding(WorkflowParameterBinding.ValueProperty);
                                }
                                else
                                {
                                    paramValue = invokeWebService.ParameterBindings[paramName].GetValue(WorkflowParameterBinding.ValueProperty);
                                }
                            }
                            if (!invokeWebService.ParameterBindings.Contains(paramName) || paramValue == null)
                            {
                                ValidationError validationError = ValidationError.GetNotSetValidationError(paramName);
                                if (InvokeWebServiceActivity.ReservedParameterNames.Contains(paramName))
                                {
                                    validationError.PropertyName = ParameterInfoBasedPropertyDescriptor.GetParameterPropertyName(invokeWebService.GetType(), paramName);
                                }
                                validationError.PropertyName = paramName;
                                validationErrors.Add(validationError);
                            }
                            else
                            {
                                AccessTypes access = AccessTypes.Read;
                                if (paramInfo.IsOut || paramInfo.IsRetval)
                                {
                                    access = AccessTypes.Write;
                                }
                                else if (paramInfo.ParameterType.IsByRef)
                                {
                                    access |= AccessTypes.Write;
                                }

                                ValidationErrorCollection variableErrors = ValidationHelpers.ValidateProperty(manager, invokeWebService, paramValue,
                                                                                                              new PropertyValidationContext(invokeWebService.ParameterBindings[paramName], null, paramName), new BindValidationContext(paramInfo.ParameterType.IsByRef ? paramInfo.ParameterType.GetElementType() : paramInfo.ParameterType, access));
                                if (InvokeWebServiceActivity.ReservedParameterNames.Contains(paramName))
                                {
                                    foreach (ValidationError validationError in variableErrors)
                                    {
                                        validationError.PropertyName = ParameterInfoBasedPropertyDescriptor.GetParameterPropertyName(invokeWebService.GetType(), paramName);
                                    }
                                }
                                validationErrors.AddRange(variableErrors);
                            }
                        }

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