コード例 #1
0
 ProtocolImporter FindImporterByName(string protocolName)
 {
     for (int i = 0; i < importers.Length; i++)
     {
         ProtocolImporter importer = importers[i];
         if (string.Compare(ProtocolName, importer.ProtocolName, StringComparison.OrdinalIgnoreCase) == 0)
         {
             return(importer);
         }
     }
     throw new ArgumentException(Res.GetString(Res.ProtocolWithNameIsNotRecognized1, protocolName), "protocolName");
 }
コード例 #2
0
 private ProtocolImporter FindImporterByName(string protocolName)
 {
     for (int i = 0; i < this.importers.Length; i++)
     {
         ProtocolImporter importer = this.importers[i];
         if (string.Compare(this.ProtocolName, importer.ProtocolName, StringComparison.OrdinalIgnoreCase) == 0)
         {
             return(importer);
         }
     }
     throw new ArgumentException(System.Web.Services.Res.GetString("ProtocolWithNameIsNotRecognized1", new object[] { protocolName }), "protocolName");
 }
コード例 #3
0
 ProtocolImporter FindImporterByName(string protocolName)
 {
     for (int i = 0; i < importers.Length; i++)
     {
         ProtocolImporter importer = importers[i];
         if (string.Compare(ProtocolName, importer.ProtocolName, true, CultureInfo.InvariantCulture) == 0)
         {
             return(importer);
         }
     }
     // SOAP12: disable soap 1.2 proxy generation
     if (string.Compare(ProtocolName, "Soap12", true, CultureInfo.InvariantCulture) == 0)
     {
         throw new InvalidOperationException(Res.GetString(Res.WebSoap12NotSupported));
     }
     throw new ArgumentException(Res.GetString(Res.ProtocolWithNameIsNotRecognized1, protocolName), "protocolName");
 }
コード例 #4
0
        void GenerateCode(string typeName, MimeTextMatchCollection matches, CodeGenerationOptions options)
        {
            CodeIdentifiers     members   = new CodeIdentifiers();
            CodeTypeDeclaration codeClass = WebCodeGenerator.AddClass(ImportContext.CodeNamespace, typeName, string.Empty, new string[0], null, CodeFlags.IsPublic,
                                                                      ImportContext.ServiceImporter.CodeGenerator.Supports(GeneratorSupport.PartialTypes));

            string[] fieldTypeNames = new string[matches.Count];
            for (int i = 0; i < matches.Count; i++)
            {
                MimeTextMatch match = matches[i];
                string        name  = members.AddUnique(CodeIdentifier.MakeValid(match.Name.Length == 0 ? methodName + "Match" : match.Name), match);
                CodeAttributeDeclarationCollection metadata = new CodeAttributeDeclarationCollection();
                if (match.Pattern.Length == 0)
                {
                    throw new ArgumentException(Res.GetString(Res.WebTextMatchMissingPattern));
                }

                CodeExpression pattern       = new CodePrimitiveExpression(match.Pattern);
                int            numPropValues = 0;
                if (match.Group != 1)
                {
                    numPropValues++;
                }
                if (match.Capture != 0)
                {
                    numPropValues++;
                }
                if (match.IgnoreCase)
                {
                    numPropValues++;
                }
                if (match.Repeats != 1 && match.Repeats != int.MaxValue)
                {
                    numPropValues++;
                }
                CodeExpression[] propertyValues = new CodeExpression[numPropValues];
                string[]         propertyNames  = new string[propertyValues.Length];
                numPropValues = 0;
                if (match.Group != 1)
                {
                    propertyValues[numPropValues] = new CodePrimitiveExpression(match.Group);
                    propertyNames[numPropValues]  = "Group";
                    numPropValues++;
                }
                if (match.Capture != 0)
                {
                    propertyValues[numPropValues] = new CodePrimitiveExpression(match.Capture);
                    propertyNames[numPropValues]  = "Capture";
                    numPropValues++;
                }
                if (match.IgnoreCase)
                {
                    propertyValues[numPropValues] = new CodePrimitiveExpression(match.IgnoreCase);
                    propertyNames[numPropValues]  = "IgnoreCase";
                    numPropValues++;
                }
                if (match.Repeats != 1 && match.Repeats != int.MaxValue)
                {
                    propertyValues[numPropValues] = new CodePrimitiveExpression(match.Repeats);
                    propertyNames[numPropValues]  = "MaxRepeats";
                    numPropValues++;
                }
                WebCodeGenerator.AddCustomAttribute(metadata, typeof(MatchAttribute), new CodeExpression[] { pattern }, propertyNames, propertyValues);

                string fieldTypeName;
                if (match.Matches.Count > 0)
                {
                    fieldTypeName     = ImportContext.ClassNames.AddUnique(CodeIdentifier.MakeValid(match.Type.Length == 0 ? name : match.Type), match);
                    fieldTypeNames[i] = fieldTypeName;
                }
                else
                {
                    fieldTypeName = typeof(string).FullName;
                }
                if (match.Repeats != 1)
                {
                    fieldTypeName += "[]";
                }

                CodeTypeMember member = WebCodeGenerator.AddMember(codeClass, fieldTypeName, name, null, metadata, CodeFlags.IsPublic, options);

                if (match.Matches.Count == 0 && match.Type.Length > 0)
                {
                    ImportContext.Warnings |= ServiceDescriptionImportWarnings.OptionalExtensionsIgnored;
                    ProtocolImporter.AddWarningComment(member.Comments, Res.GetString(Res.WebTextMatchIgnoredTypeWarning));
                }
            }

            for (int i = 0; i < fieldTypeNames.Length; i++)
            {
                string fieldTypeName = fieldTypeNames[i];
                if (fieldTypeName != null)
                {
                    GenerateCode(fieldTypeName, matches[i].Matches, options);
                }
            }
        }
コード例 #5
0
        private ServiceDescriptionImportWarnings Import(CodeNamespace codeNamespace, System.Xml.Serialization.ImportContext importContext, Hashtable exportContext, StringCollection warnings)
        {
            Hashtable hashtable2;

            this.allSchemas = new XmlSchemas();
            foreach (XmlSchema schema in this.schemas)
            {
                this.allSchemas.Add(schema);
            }
            foreach (ServiceDescription description in this.serviceDescriptions)
            {
                foreach (XmlSchema schema2 in description.Types.Schemas)
                {
                    this.allSchemas.Add(schema2);
                }
            }
            Hashtable references = new Hashtable();

            if (!this.allSchemas.Contains("http://schemas.xmlsoap.org/wsdl/"))
            {
                this.allSchemas.AddReference(ServiceDescription.Schema);
                references[ServiceDescription.Schema] = ServiceDescription.Schema;
            }
            if (!this.allSchemas.Contains("http://schemas.xmlsoap.org/soap/encoding/"))
            {
                this.allSchemas.AddReference(ServiceDescription.SoapEncodingSchema);
                references[ServiceDescription.SoapEncodingSchema] = ServiceDescription.SoapEncodingSchema;
            }
            this.allSchemas.Compile(null, false);
            foreach (ServiceDescription description2 in this.serviceDescriptions)
            {
                foreach (Message message in description2.Messages)
                {
                    foreach (MessagePart part in message.Parts)
                    {
                        bool flag;
                        bool flag2;
                        this.FindUse(part, out flag, out flag2);
                        if ((part.Element != null) && !part.Element.IsEmpty)
                        {
                            if (flag)
                            {
                                throw new InvalidOperationException(System.Web.Services.Res.GetString("CanTSpecifyElementOnEncodedMessagePartsPart", new object[] { part.Name, message.Name }));
                            }
                            XmlSchemaElement element = (XmlSchemaElement)this.allSchemas.Find(part.Element, typeof(XmlSchemaElement));
                            if (element != null)
                            {
                                AddSchema(element.Parent as XmlSchema, flag, flag2, this.abstractSchemas, this.concreteSchemas, references);
                                if ((element.SchemaTypeName != null) && !element.SchemaTypeName.IsEmpty)
                                {
                                    XmlSchemaType type = (XmlSchemaType)this.allSchemas.Find(element.SchemaTypeName, typeof(XmlSchemaType));
                                    if (type != null)
                                    {
                                        AddSchema(type.Parent as XmlSchema, flag, flag2, this.abstractSchemas, this.concreteSchemas, references);
                                    }
                                }
                            }
                        }
                        if ((part.Type != null) && !part.Type.IsEmpty)
                        {
                            XmlSchemaType type2 = (XmlSchemaType)this.allSchemas.Find(part.Type, typeof(XmlSchemaType));
                            if (type2 != null)
                            {
                                AddSchema(type2.Parent as XmlSchema, flag, flag2, this.abstractSchemas, this.concreteSchemas, references);
                            }
                        }
                    }
                }
            }
            foreach (XmlSchemas schemas in new XmlSchemas[] { this.abstractSchemas, this.concreteSchemas })
            {
                hashtable2 = new Hashtable();
                foreach (XmlSchema schema3 in schemas)
                {
                    this.AddImport(schema3, hashtable2);
                }
                foreach (XmlSchema schema4 in hashtable2.Keys)
                {
                    if ((references[schema4] == null) && !schemas.Contains(schema4))
                    {
                        schemas.Add(schema4);
                    }
                }
            }
            hashtable2 = new Hashtable();
            foreach (XmlSchema schema5 in this.allSchemas)
            {
                if (!this.abstractSchemas.Contains(schema5) && !this.concreteSchemas.Contains(schema5))
                {
                    this.AddImport(schema5, hashtable2);
                }
            }
            foreach (XmlSchema schema6 in hashtable2.Keys)
            {
                if (references[schema6] == null)
                {
                    if (!this.abstractSchemas.Contains(schema6))
                    {
                        this.abstractSchemas.Add(schema6);
                    }
                    if (!this.concreteSchemas.Contains(schema6))
                    {
                        this.concreteSchemas.Add(schema6);
                    }
                }
            }
            if (this.abstractSchemas.Count > 0)
            {
                foreach (XmlSchema schema7 in references.Values)
                {
                    this.abstractSchemas.AddReference(schema7);
                }
                foreach (string str in SchemaCompiler.Compile(this.abstractSchemas))
                {
                    warnings.Add(str);
                }
            }
            if (this.concreteSchemas.Count > 0)
            {
                foreach (XmlSchema schema8 in references.Values)
                {
                    this.concreteSchemas.AddReference(schema8);
                }
                foreach (string str2 in SchemaCompiler.Compile(this.concreteSchemas))
                {
                    warnings.Add(str2);
                }
            }
            if (this.ProtocolName.Length > 0)
            {
                ProtocolImporter importer = this.FindImporterByName(this.ProtocolName);
                if (importer.GenerateCode(codeNamespace, importContext, exportContext))
                {
                    return(importer.Warnings);
                }
            }
            else
            {
                for (int i = 0; i < this.importers.Length; i++)
                {
                    ProtocolImporter importer2 = this.importers[i];
                    if (importer2.GenerateCode(codeNamespace, importContext, exportContext))
                    {
                        return(importer2.Warnings);
                    }
                }
            }
            return(ServiceDescriptionImportWarnings.NoCodeGenerated);
        }
コード例 #6
0
        private void GenerateCode(string typeName, MimeTextMatchCollection matches, CodeGenerationOptions options)
        {
            CodeIdentifiers     identifiers = new CodeIdentifiers();
            CodeTypeDeclaration codeClass   = WebCodeGenerator.AddClass(base.ImportContext.CodeNamespace, typeName, string.Empty, new string[0], null, CodeFlags.IsPublic, base.ImportContext.ServiceImporter.CodeGenerator.Supports(GeneratorSupport.PartialTypes));

            string[] strArray = new string[matches.Count];
            for (int i = 0; i < matches.Count; i++)
            {
                string        fullName;
                MimeTextMatch match      = matches[i];
                string        memberName = identifiers.AddUnique(CodeIdentifier.MakeValid((match.Name.Length == 0) ? (this.methodName + "Match") : match.Name), match);
                CodeAttributeDeclarationCollection metadata = new CodeAttributeDeclarationCollection();
                if (match.Pattern.Length == 0)
                {
                    throw new ArgumentException(Res.GetString("WebTextMatchMissingPattern"));
                }
                CodeExpression expression = new CodePrimitiveExpression(match.Pattern);
                int            index      = 0;
                if (match.Group != 1)
                {
                    index++;
                }
                if (match.Capture != 0)
                {
                    index++;
                }
                if (match.IgnoreCase)
                {
                    index++;
                }
                if ((match.Repeats != 1) && (match.Repeats != 0x7fffffff))
                {
                    index++;
                }
                CodeExpression[] propValues = new CodeExpression[index];
                string[]         propNames  = new string[propValues.Length];
                index = 0;
                if (match.Group != 1)
                {
                    propValues[index] = new CodePrimitiveExpression(match.Group);
                    propNames[index]  = "Group";
                    index++;
                }
                if (match.Capture != 0)
                {
                    propValues[index] = new CodePrimitiveExpression(match.Capture);
                    propNames[index]  = "Capture";
                    index++;
                }
                if (match.IgnoreCase)
                {
                    propValues[index] = new CodePrimitiveExpression(match.IgnoreCase);
                    propNames[index]  = "IgnoreCase";
                    index++;
                }
                if ((match.Repeats != 1) && (match.Repeats != 0x7fffffff))
                {
                    propValues[index] = new CodePrimitiveExpression(match.Repeats);
                    propNames[index]  = "MaxRepeats";
                    index++;
                }
                WebCodeGenerator.AddCustomAttribute(metadata, typeof(MatchAttribute), new CodeExpression[] { expression }, propNames, propValues);
                if (match.Matches.Count > 0)
                {
                    fullName    = base.ImportContext.ClassNames.AddUnique(CodeIdentifier.MakeValid((match.Type.Length == 0) ? memberName : match.Type), match);
                    strArray[i] = fullName;
                }
                else
                {
                    fullName = typeof(string).FullName;
                }
                if (match.Repeats != 1)
                {
                    fullName = fullName + "[]";
                }
                CodeTypeMember member = WebCodeGenerator.AddMember(codeClass, fullName, memberName, null, metadata, CodeFlags.IsPublic, options);
                if ((match.Matches.Count == 0) && (match.Type.Length > 0))
                {
                    HttpProtocolImporter importContext = base.ImportContext;
                    importContext.Warnings |= ServiceDescriptionImportWarnings.OptionalExtensionsIgnored;
                    ProtocolImporter.AddWarningComment(member.Comments, Res.GetString("WebTextMatchIgnoredTypeWarning"));
                }
            }
            for (int j = 0; j < strArray.Length; j++)
            {
                string str3 = strArray[j];
                if (str3 != null)
                {
                    this.GenerateCode(str3, matches[j].Matches, options);
                }
            }
        }
コード例 #7
0
        private ServiceDescriptionImportWarnings Import(CodeNamespace codeNamespace, ImportContext importContext, Hashtable exportContext, StringCollection warnings)
        {
            allSchemas = new XmlSchemas();
            foreach (XmlSchema schema in schemas)
            {
                allSchemas.Add(schema);
            }
            foreach (ServiceDescription description in serviceDescriptions)
            {
                foreach (XmlSchema schema in description.Types.Schemas)
                {
                    allSchemas.Add(schema);
                }
            }
            Hashtable references = new Hashtable();

            if (!allSchemas.Contains(ServiceDescription.Namespace))
            {
                allSchemas.AddReference(ServiceDescription.Schema);
                references[ServiceDescription.Schema] = ServiceDescription.Schema;
            }
            if (!allSchemas.Contains(Soap.Encoding))
            {
                allSchemas.AddReference(ServiceDescription.SoapEncodingSchema);
                references[ServiceDescription.SoapEncodingSchema] = ServiceDescription.SoapEncodingSchema;
            }
            allSchemas.Compile(null, false);

            // Segregate the schemas containing abstract types from those
            // containing regular XML definitions.  This is important because
            // when you import something returning the ur-type (object), then
            // you need to import ALL types/elements within ALL schemas.  We
            // don't want the RPC-based types leaking over into the XML-based
            // element definitions.  This also occurs when you have derivation:
            // we need to search the schemas for derived types: but WHICH schemas
            // should we search.
            foreach (ServiceDescription description in serviceDescriptions)
            {
                foreach (Message message in description.Messages)
                {
                    foreach (MessagePart part in message.Parts)
                    {
                        bool isEncoded;
                        bool isLiteral;
                        FindUse(part, out isEncoded, out isLiteral);
                        if (part.Element != null && !part.Element.IsEmpty)
                        {
                            if (isEncoded)
                            {
                                throw new InvalidOperationException(Res.GetString(Res.CanTSpecifyElementOnEncodedMessagePartsPart, part.Name, message.Name));
                            }
                            XmlSchemaElement element = (XmlSchemaElement)allSchemas.Find(part.Element, typeof(XmlSchemaElement));
                            if (element != null)
                            {
                                AddSchema(element.Parent as XmlSchema, isEncoded, isLiteral, abstractSchemas, concreteSchemas, references);
                                if (element.SchemaTypeName != null && !element.SchemaTypeName.IsEmpty)
                                {
                                    XmlSchemaType type = (XmlSchemaType)allSchemas.Find(element.SchemaTypeName, typeof(XmlSchemaType));
                                    if (type != null)
                                    {
                                        AddSchema(type.Parent as XmlSchema, isEncoded, isLiteral, abstractSchemas, concreteSchemas, references);
                                    }
                                }
                            }
                        }
                        if (part.Type != null && !part.Type.IsEmpty)
                        {
                            XmlSchemaType type = (XmlSchemaType)allSchemas.Find(part.Type, typeof(XmlSchemaType));
                            if (type != null)
                            {
                                AddSchema(type.Parent as XmlSchema, isEncoded, isLiteral, abstractSchemas, concreteSchemas, references);
                            }
                        }
                    }
                }
            }

            Hashtable imports;

            foreach (XmlSchemas xmlschemas in new XmlSchemas[] { abstractSchemas, concreteSchemas })
            {
                // collect all imports
                imports = new Hashtable();
                foreach (XmlSchema schema in xmlschemas)
                {
                    AddImport(schema, imports);
                }
                // make sure we add them to the corresponding schema collections
                foreach (XmlSchema schema in imports.Keys)
                {
                    if (references[schema] == null && !xmlschemas.Contains(schema))
                    {
                        xmlschemas.Add(schema);
                    }
                }
            }

            // If a schema was not referenced by either a literal or an encoded message part,
            // add it to both collections. There's no way to tell which it should be.
            imports = new Hashtable();
            foreach (XmlSchema schema in allSchemas)
            {
                if (!abstractSchemas.Contains(schema) && !concreteSchemas.Contains(schema))
                {
                    AddImport(schema, imports);
                }
            }

            // make sure we add them to the corresponding schema collections
            foreach (XmlSchema schema in imports.Keys)
            {
                if (references[schema] != null)
                {
                    continue;
                }
                if (!abstractSchemas.Contains(schema))
                {
                    abstractSchemas.Add(schema);
                }
                if (!concreteSchemas.Contains(schema))
                {
                    concreteSchemas.Add(schema);
                }
            }
            if (abstractSchemas.Count > 0)
            {
                foreach (XmlSchema schema in references.Values)
                {
                    abstractSchemas.AddReference(schema);
                }
                StringCollection schemaWarnings = SchemaCompiler.Compile(abstractSchemas);
                foreach (string warning in schemaWarnings)
                {
                    warnings.Add(warning);
                }
            }
            if (concreteSchemas.Count > 0)
            {
                foreach (XmlSchema schema in references.Values)
                {
                    concreteSchemas.AddReference(schema);
                }
                StringCollection schemaWarnings = SchemaCompiler.Compile(concreteSchemas);
                foreach (string warning in schemaWarnings)
                {
                    warnings.Add(warning);
                }
            }
            if (ProtocolName.Length > 0)
            {
                // If a protocol was specified, only try that one
                ProtocolImporter importer = FindImporterByName(ProtocolName);
                if (importer.GenerateCode(codeNamespace, importContext, exportContext))
                {
                    return(importer.Warnings);
                }
            }
            else
            {
                // Otherwise, do "best" protocol (first one that generates something)
                for (int i = 0; i < importers.Length; i++)
                {
                    ProtocolImporter importer = importers[i];
                    if (importer.GenerateCode(codeNamespace, importContext, exportContext))
                    {
                        return(importer.Warnings);
                    }
                }
            }
            return(ServiceDescriptionImportWarnings.NoCodeGenerated);
        }
コード例 #8
0
        private CodeMemberMethod GenerateMethod(HttpMethodInfo method)
        {
            MimeParameterCollection parameters = (method.MimeParameters != null) ? method.MimeParameters : method.UrlParameters;

            string[] parameterTypeNames = new string[parameters.Count];
            string[] parameterNames     = new string[parameters.Count];
            for (int i = 0; i < parameters.Count; i++)
            {
                MimeParameter parameter = parameters[i];
                parameterNames[i]     = parameter.Name;
                parameterTypeNames[i] = parameter.TypeName;
            }
            CodeAttributeDeclarationCollection metadata = new CodeAttributeDeclarationCollection();

            CodeExpression[] expressionArray = new CodeExpression[2];
            if (method.MimeReturn.ReaderType == null)
            {
                expressionArray[0] = new CodeTypeOfExpression(typeof(NopReturnReader).FullName);
            }
            else
            {
                expressionArray[0] = new CodeTypeOfExpression(method.MimeReturn.ReaderType.FullName);
            }
            if (method.MimeParameters != null)
            {
                expressionArray[1] = new CodeTypeOfExpression(method.MimeParameters.WriterType.FullName);
            }
            else
            {
                expressionArray[1] = new CodeTypeOfExpression(typeof(UrlParameterWriter).FullName);
            }
            WebCodeGenerator.AddCustomAttribute(metadata, typeof(HttpMethodAttribute), expressionArray, new string[0], new CodeExpression[0]);
            CodeMemberMethod method2 = WebCodeGenerator.AddMethod(base.CodeTypeDeclaration, method.Name, new CodeFlags[parameterTypeNames.Length], parameterTypeNames, parameterNames, method.MimeReturn.TypeName, metadata, CodeFlags.IsPublic | ((base.Style == ServiceDescriptionImportStyle.Client) ? ((CodeFlags)0) : CodeFlags.IsAbstract));

            AppendMetadata(method.MimeReturn.Attributes, method2.ReturnTypeCustomAttributes);
            method2.Comments.Add(new CodeCommentStatement(System.Web.Services.Res.GetString("CodeRemarks"), true));
            for (int j = 0; j < parameters.Count; j++)
            {
                AppendMetadata(parameters[j].Attributes, method2.Parameters[j].CustomAttributes);
            }
            if (base.Style == ServiceDescriptionImportStyle.Client)
            {
                bool             flag         = (base.ServiceImporter.CodeGenerationOptions & CodeGenerationOptions.GenerateOldAsync) != CodeGenerationOptions.None;
                bool             flag2        = (((base.ServiceImporter.CodeGenerationOptions & CodeGenerationOptions.GenerateNewAsync) != CodeGenerationOptions.None) && base.ServiceImporter.CodeGenerator.Supports(GeneratorSupport.DeclareEvents)) && base.ServiceImporter.CodeGenerator.Supports(GeneratorSupport.DeclareDelegates);
                CodeExpression[] invokeParams = new CodeExpression[3];
                this.CreateInvokeParams(invokeParams, method, parameterNames);
                CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "Invoke", invokeParams);
                if (method.MimeReturn.ReaderType != null)
                {
                    method2.Statements.Add(new CodeMethodReturnStatement(new CodeCastExpression(method.MimeReturn.TypeName, expression)));
                }
                else
                {
                    method2.Statements.Add(new CodeExpressionStatement(expression));
                }
                metadata = new CodeAttributeDeclarationCollection();
                string[] array = new string[parameterTypeNames.Length + 2];
                parameterTypeNames.CopyTo(array, 0);
                array[parameterTypeNames.Length]     = typeof(AsyncCallback).FullName;
                array[parameterTypeNames.Length + 1] = typeof(object).FullName;
                string[] strArray4 = new string[parameterNames.Length + 2];
                parameterNames.CopyTo(strArray4, 0);
                strArray4[parameterNames.Length]     = "callback";
                strArray4[parameterNames.Length + 1] = "asyncState";
                if (flag)
                {
                    CodeMemberMethod method3 = WebCodeGenerator.AddMethod(base.CodeTypeDeclaration, "Begin" + method.Name, new CodeFlags[array.Length], array, strArray4, typeof(IAsyncResult).FullName, metadata, CodeFlags.IsPublic);
                    method3.Comments.Add(new CodeCommentStatement(System.Web.Services.Res.GetString("CodeRemarks"), true));
                    invokeParams = new CodeExpression[5];
                    this.CreateInvokeParams(invokeParams, method, parameterNames);
                    invokeParams[3] = new CodeArgumentReferenceExpression("callback");
                    invokeParams[4] = new CodeArgumentReferenceExpression("asyncState");
                    expression      = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "BeginInvoke", invokeParams);
                    method3.Statements.Add(new CodeMethodReturnStatement(expression));
                    CodeMemberMethod method4 = WebCodeGenerator.AddMethod(base.CodeTypeDeclaration, "End" + method.Name, new CodeFlags[1], new string[] { typeof(IAsyncResult).FullName }, new string[] { "asyncResult" }, method.MimeReturn.TypeName, metadata, CodeFlags.IsPublic);
                    method4.Comments.Add(new CodeCommentStatement(System.Web.Services.Res.GetString("CodeRemarks"), true));
                    CodeExpression expression2 = new CodeArgumentReferenceExpression("asyncResult");
                    expression = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "EndInvoke", new CodeExpression[] { expression2 });
                    if (method.MimeReturn.ReaderType != null)
                    {
                        method4.Statements.Add(new CodeMethodReturnStatement(new CodeCastExpression(method.MimeReturn.TypeName, expression)));
                    }
                    else
                    {
                        method4.Statements.Add(new CodeExpressionStatement(expression));
                    }
                }
                if (!flag2)
                {
                    return(method2);
                }
                metadata = new CodeAttributeDeclarationCollection();
                string       name = method.Name;
                string       str2 = ProtocolImporter.MethodSignature(name, method.MimeReturn.TypeName, new CodeFlags[parameterTypeNames.Length], parameterTypeNames);
                DelegateInfo info = (DelegateInfo)base.ExportContext[str2];
                if (info == null)
                {
                    string handlerType = base.ClassNames.AddUnique(name + "CompletedEventHandler", name);
                    string handlerArgs = base.ClassNames.AddUnique(name + "CompletedEventArgs", name);
                    info = new DelegateInfo(handlerType, handlerArgs);
                }
                string handlerName    = base.MethodNames.AddUnique(name + "Completed", name);
                string methodName     = base.MethodNames.AddUnique(name + "Async", name);
                string callbackMember = base.MethodNames.AddUnique(name + "OperationCompleted", name);
                string callbackName   = base.MethodNames.AddUnique("On" + name + "OperationCompleted", name);
                WebCodeGenerator.AddEvent(base.CodeTypeDeclaration.Members, info.handlerType, handlerName);
                WebCodeGenerator.AddCallbackDeclaration(base.CodeTypeDeclaration.Members, callbackMember);
                string           userState = ProtocolImporter.UniqueName("userState", parameterNames);
                CodeMemberMethod method5   = WebCodeGenerator.AddAsyncMethod(base.CodeTypeDeclaration, methodName, parameterTypeNames, parameterNames, callbackMember, callbackName, userState);
                invokeParams = new CodeExpression[5];
                this.CreateInvokeParams(invokeParams, method, parameterNames);
                invokeParams[3] = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), callbackMember);
                invokeParams[4] = new CodeArgumentReferenceExpression(userState);
                expression      = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "InvokeAsync", invokeParams);
                method5.Statements.Add(expression);
                bool methodHasOutParameters = method.MimeReturn.ReaderType != null;
                WebCodeGenerator.AddCallbackImplementation(base.CodeTypeDeclaration, callbackName, handlerName, info.handlerArgs, methodHasOutParameters);
                if (base.ExportContext[str2] != null)
                {
                    return(method2);
                }
                WebCodeGenerator.AddDelegate(base.ExtraCodeClasses, info.handlerType, methodHasOutParameters ? info.handlerArgs : typeof(AsyncCompletedEventArgs).FullName);
                if (methodHasOutParameters)
                {
                    base.ExtraCodeClasses.Add(WebCodeGenerator.CreateArgsClass(info.handlerArgs, new string[] { method.MimeReturn.TypeName }, new string[] { "Result" }, base.ServiceImporter.CodeGenerator.Supports(GeneratorSupport.PartialTypes)));
                }
                base.ExportContext[str2] = info;
            }
            return(method2);
        }
コード例 #9
0
        private ServiceDescriptionImportWarnings Import(CodeNamespace codeNamespace)
        {
            allSchemas = new XmlSchemas();
            foreach (XmlSchema schema in schemas)
            {
                allSchemas.Add(schema);
            }

            foreach (ServiceDescription description in serviceDescriptions)
            {
                foreach (XmlSchema schema in description.Types.Schemas)
                {
                    allSchemas.Add(schema);
                }
            }

            // Segregate the schemas containing abstract types from those
            // containing regular XML definitions.  This is important because
            // when you import something returning the ur-type (object), then
            // you need to import ALL types/elements within ALL schemas.  We
            // don't want the RPC-based types leaking over into the XML-based
            // element definitions.  This also occurs when you have derivation:
            // we need to search the schemas for derived types: but WHICH schemas
            // should we search.
            foreach (ServiceDescription description in serviceDescriptions)
            {
                foreach (Message message in description.Messages)
                {
                    foreach (MessagePart part in message.Parts)
                    {
                        bool isEncoded;
                        bool isLiteral;
                        FindUse(part, out isEncoded, out isLiteral);
                        if (part.Element != null && !part.Element.IsEmpty)
                        {
                            if (isEncoded)
                            {
                                throw new Exception(Res.GetString(Res.CanTSpecifyElementOnEncodedMessagePartsPart, part.Name, message.Name));
                            }
                            string    ns     = part.Element.Namespace;
                            XmlSchema schema = allSchemas[ns];
                            if (schema != null)
                            {
                                if (isEncoded && abstractSchemas[ns] == null)
                                {
                                    abstractSchemas.Add(schema);
                                }
                                if (isLiteral && concreteSchemas[ns] == null)
                                {
                                    concreteSchemas.Add(schema);
                                }
                            }
                        }
                        if (part.Type != null && !part.Type.IsEmpty)
                        {
                            string    ns     = part.Type.Namespace;
                            XmlSchema schema = allSchemas[ns];
                            if (schema != null)
                            {
                                if (isEncoded && abstractSchemas[ns] == null)
                                {
                                    abstractSchemas.Add(schema);
                                }
                                if (isLiteral && concreteSchemas[ns] == null)
                                {
                                    concreteSchemas.Add(schema);
                                }
                            }
                        }
                    }
                }
            }
            foreach (XmlSchemas schemas in new XmlSchemas[] { abstractSchemas, concreteSchemas })
            {
                XmlSchemas additionalSchemas = new XmlSchemas();
                foreach (XmlSchema schema in schemas)
                {
                    foreach (object include in schema.Includes)
                    {
                        if (include is XmlSchemaImport)
                        {
                            XmlSchemaImport import = (XmlSchemaImport)include;
                            if (import.Schema != null && !schemas.Contains(import.Schema) && !additionalSchemas.Contains(import.Schema))
                            {
                                additionalSchemas.Add(import.Schema);
                            }
                            else if (import.Namespace != null && allSchemas[import.Namespace] != null && schemas[import.Namespace] == null && additionalSchemas[import.Namespace] == null)
                            {
                                additionalSchemas.Add(allSchemas[import.Namespace]);
                            }
                        }
                    }
                }
                foreach (XmlSchema schema in additionalSchemas)
                {
                    schemas.Add(schema);
                }
            }

            // If a schema was not referenced by either a literal or an encoded message part,
            // add it to both collections. There's no way to tell which it should be.
            foreach (XmlSchema schema in allSchemas)
            {
                if (!abstractSchemas.Contains(schema) && !concreteSchemas.Contains(schema))
                {
                    abstractSchemas.Add(schema);
                    concreteSchemas.Add(schema);
                }
            }

            if (ProtocolName.Length > 0)
            {
                // If a protocol was specified, only try that one
                ProtocolImporter importer = FindImporterByName(ProtocolName);
                if (importer.GenerateCode(codeNamespace))
                {
                    return(importer.Warnings);
                }
            }
            else
            {
                // Otherwise, do "best" protocol (first one that generates something)
                for (int i = 0; i < importers.Length; i++)
                {
                    ProtocolImporter importer = importers[i];
                    if (importer.GenerateCode(codeNamespace))
                    {
                        return(importer.Warnings);
                    }
                }
            }

            return(ServiceDescriptionImportWarnings.NoCodeGenerated);
        }