MimeParameter ImportUrlParameter(MessagePart part) { // CONSIDER, check to see that it's a primitive type MimeParameter parameter = new MimeParameter(); parameter.Name = CodeIdentifier.MakeValid(part.Name); parameter.TypeName = IsRepeatingParameter(part) ? typeof(string[]).FullName : typeof(string).FullName; return(parameter); }
MimeParameter ImportUrlParameter(MessagePart part) { // MimeParameter parameter = new MimeParameter(); parameter.Name = CodeIdentifier.MakeValid(XmlConvert.DecodeName(part.Name)); parameter.TypeName = IsRepeatingParameter(part) ? typeof(string[]).FullName : typeof(string).FullName; return(parameter); }
internal MimeParameterCollection ImportStringParametersMessage() { MimeParameterCollection parameters = new MimeParameterCollection(); foreach (MessagePart part in InputMessage.Parts) { MimeParameter parameter = ImportUrlParameter(part); if (parameter == null) { return(null); } parameters.Add(parameter); } return(parameters); }
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 param = parameters[i]; parameterNames[i] = param.Name; parameterTypeNames[i] = param.TypeName; } CodeAttributeDeclarationCollection metadata = new CodeAttributeDeclarationCollection(); CodeExpression[] formatterTypes = new CodeExpression[2]; if (method.MimeReturn.ReaderType == null) { formatterTypes[0] = new CodeTypeOfExpression(typeof(NopReturnReader).FullName); } else { formatterTypes[0] = new CodeTypeOfExpression(method.MimeReturn.ReaderType.FullName); } if (method.MimeParameters != null) { formatterTypes[1] = new CodeTypeOfExpression(method.MimeParameters.WriterType.FullName); } else { formatterTypes[1] = new CodeTypeOfExpression(typeof(UrlParameterWriter).FullName); } WebCodeGenerator.AddCustomAttribute(metadata, typeof(HttpMethodAttribute), formatterTypes, new string[0], new CodeExpression[0]); CodeMemberMethod mainCodeMethod = WebCodeGenerator.AddMethod(this.CodeTypeDeclaration, method.Name, new CodeFlags[parameterTypeNames.Length], parameterTypeNames, parameterNames, method.MimeReturn.TypeName, metadata, CodeFlags.IsPublic | (Style == ServiceDescriptionImportStyle.Client ? 0 : CodeFlags.IsAbstract)); AppendMetadata(method.MimeReturn.Attributes, mainCodeMethod.ReturnTypeCustomAttributes); mainCodeMethod.Comments.Add(new CodeCommentStatement("<remarks/>", true)); for (int i = 0; i < parameters.Count; i++) { AppendMetadata(parameters[i].Attributes, mainCodeMethod.Parameters[i].CustomAttributes); } if (Style == ServiceDescriptionImportStyle.Client) { CodeExpression[] invokeParams = new CodeExpression[3]; CreateInvokeParams(invokeParams, method, parameterNames); CodeExpression invoke = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "Invoke", invokeParams); if (method.MimeReturn.ReaderType != null) { invoke = new CodeCastExpression(method.MimeReturn.TypeName, invoke); } if (method.MimeReturn.ReaderType != null) { mainCodeMethod.Statements.Add(new CodeMethodReturnStatement(invoke)); } else { mainCodeMethod.Statements.Add(new CodeExpressionStatement(invoke)); } metadata = new CodeAttributeDeclarationCollection(); string[] asyncParameterTypeNames = new string[parameterTypeNames.Length + 2]; parameterTypeNames.CopyTo(asyncParameterTypeNames, 0); asyncParameterTypeNames[parameterTypeNames.Length] = typeof(AsyncCallback).FullName; asyncParameterTypeNames[parameterTypeNames.Length + 1] = typeof(object).FullName; string[] asyncParameterNames = new string[parameterNames.Length + 2]; parameterNames.CopyTo(asyncParameterNames, 0); asyncParameterNames[parameterNames.Length] = "callback"; asyncParameterNames[parameterNames.Length + 1] = "asyncState"; CodeMemberMethod beginCodeMethod = WebCodeGenerator.AddMethod(this.CodeTypeDeclaration, "Begin" + method.Name, new CodeFlags[asyncParameterTypeNames.Length], asyncParameterTypeNames, asyncParameterNames, typeof(IAsyncResult).FullName, metadata, CodeFlags.IsPublic); beginCodeMethod.Comments.Add(new CodeCommentStatement("<remarks/>", true)); invokeParams = new CodeExpression[5]; CreateInvokeParams(invokeParams, method, parameterNames); invokeParams[3] = new CodeArgumentReferenceExpression("callback"); invokeParams[4] = new CodeArgumentReferenceExpression("asyncState"); invoke = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "BeginInvoke", invokeParams); beginCodeMethod.Statements.Add(new CodeMethodReturnStatement(invoke)); CodeMemberMethod endCodeMethod = WebCodeGenerator.AddMethod(this.CodeTypeDeclaration, "End" + method.Name, new CodeFlags[1], new string[] { typeof(IAsyncResult).FullName }, new string[] { "asyncResult" }, method.MimeReturn.TypeName, metadata, CodeFlags.IsPublic); endCodeMethod.Comments.Add(new CodeCommentStatement("<remarks/>", true)); CodeExpression expr = new CodeArgumentReferenceExpression("asyncResult"); invoke = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "EndInvoke", new CodeExpression[] { expr }); if (method.MimeReturn.ReaderType != null) { invoke = new CodeCastExpression(method.MimeReturn.TypeName, invoke); } if (method.MimeReturn.ReaderType != null) { endCodeMethod.Statements.Add(new CodeMethodReturnStatement(invoke)); } else { endCodeMethod.Statements.Add(new CodeExpressionStatement(invoke)); } } return(mainCodeMethod); }
MimeParameter ImportUrlParameter(MessagePart part) { // MimeParameter parameter = new MimeParameter(); parameter.Name = CodeIdentifier.MakeValid(XmlConvert.DecodeName(part.Name)); parameter.TypeName = IsRepeatingParameter(part) ? typeof(string[]).FullName : typeof(string).FullName; return parameter; }
internal void CopyTo(MimeParameter[] array, int index) { List.CopyTo(array, index); }
internal void Remove(MimeParameter parameter) { List.Remove(parameter); }
internal bool Contains(MimeParameter parameter) { return(base.List.Contains(parameter)); }
internal int IndexOf(MimeParameter parameter) { return List.IndexOf(parameter); }
internal void Insert(int index, MimeParameter parameter) { List.Insert(index, parameter); }
internal int Add(MimeParameter parameter) { return List.Add(parameter); }
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); }
internal void Remove(MimeParameter parameter) { base.List.Remove(parameter); }
internal void Insert(int index, MimeParameter parameter) { base.List.Insert(index, parameter); }
internal int IndexOf(MimeParameter parameter) { return(base.List.IndexOf(parameter)); }
internal bool Contains(MimeParameter parameter) { return List.Contains(parameter); }
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 param = parameters[i]; parameterNames[i] = param.Name; parameterTypeNames[i] = param.TypeName; } CodeAttributeDeclarationCollection metadata = new CodeAttributeDeclarationCollection(); CodeExpression[] formatterTypes = new CodeExpression[2]; if (method.MimeReturn.ReaderType == null) { formatterTypes[0] = new CodeTypeOfExpression(typeof(NopReturnReader).FullName); } else { formatterTypes[0] = new CodeTypeOfExpression(method.MimeReturn.ReaderType.FullName); } if (method.MimeParameters != null) { formatterTypes[1] = new CodeTypeOfExpression(method.MimeParameters.WriterType.FullName); } else { formatterTypes[1] = new CodeTypeOfExpression(typeof(UrlParameterWriter).FullName); } WebCodeGenerator.AddCustomAttribute(metadata, typeof(HttpMethodAttribute), formatterTypes, new string[0], new CodeExpression[0]); CodeMemberMethod mainCodeMethod = WebCodeGenerator.AddMethod(this.CodeTypeDeclaration, method.Name, new CodeFlags[parameterTypeNames.Length], parameterTypeNames, parameterNames, method.MimeReturn.TypeName, metadata, CodeFlags.IsPublic | (Style == ServiceDescriptionImportStyle.Client ? 0 : CodeFlags.IsAbstract)); AppendMetadata(method.MimeReturn.Attributes, mainCodeMethod.ReturnTypeCustomAttributes); mainCodeMethod.Comments.Add(new CodeCommentStatement(Res.GetString(Res.CodeRemarks), true)); for (int i = 0; i < parameters.Count; i++) { AppendMetadata(parameters[i].Attributes, mainCodeMethod.Parameters[i].CustomAttributes); } if (Style == ServiceDescriptionImportStyle.Client) { bool oldAsync = (ServiceImporter.CodeGenerationOptions & CodeGenerationOptions.GenerateOldAsync) != 0; bool newAsync = (ServiceImporter.CodeGenerationOptions & CodeGenerationOptions.GenerateNewAsync) != 0 && ServiceImporter.CodeGenerator.Supports(GeneratorSupport.DeclareEvents) && ServiceImporter.CodeGenerator.Supports(GeneratorSupport.DeclareDelegates); CodeExpression[] invokeParams = new CodeExpression[3]; CreateInvokeParams(invokeParams, method, parameterNames); CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "Invoke", invokeParams); if (method.MimeReturn.ReaderType != null) { mainCodeMethod.Statements.Add(new CodeMethodReturnStatement(new CodeCastExpression(method.MimeReturn.TypeName, invoke))); } else { mainCodeMethod.Statements.Add(new CodeExpressionStatement(invoke)); } metadata = new CodeAttributeDeclarationCollection(); string[] asyncParameterTypeNames = new string[parameterTypeNames.Length + 2]; parameterTypeNames.CopyTo(asyncParameterTypeNames, 0); asyncParameterTypeNames[parameterTypeNames.Length] = typeof(AsyncCallback).FullName; asyncParameterTypeNames[parameterTypeNames.Length + 1] = typeof(object).FullName; string[] asyncParameterNames = new string[parameterNames.Length + 2]; parameterNames.CopyTo(asyncParameterNames, 0); asyncParameterNames[parameterNames.Length] = "callback"; asyncParameterNames[parameterNames.Length + 1] = "asyncState"; if (oldAsync) { CodeMemberMethod beginCodeMethod = WebCodeGenerator.AddMethod(this.CodeTypeDeclaration, "Begin" + method.Name, new CodeFlags[asyncParameterTypeNames.Length], asyncParameterTypeNames, asyncParameterNames, typeof(IAsyncResult).FullName, metadata, CodeFlags.IsPublic); beginCodeMethod.Comments.Add(new CodeCommentStatement(Res.GetString(Res.CodeRemarks), true)); invokeParams = new CodeExpression[5]; CreateInvokeParams(invokeParams, method, parameterNames); invokeParams[3] = new CodeArgumentReferenceExpression("callback"); invokeParams[4] = new CodeArgumentReferenceExpression("asyncState"); invoke = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "BeginInvoke", invokeParams); beginCodeMethod.Statements.Add(new CodeMethodReturnStatement(invoke)); CodeMemberMethod endCodeMethod = WebCodeGenerator.AddMethod(this.CodeTypeDeclaration, "End" + method.Name, new CodeFlags[1], new string[] { typeof(IAsyncResult).FullName }, new string[] { "asyncResult" }, method.MimeReturn.TypeName, metadata, CodeFlags.IsPublic); endCodeMethod.Comments.Add(new CodeCommentStatement(Res.GetString(Res.CodeRemarks), true)); CodeExpression expr = new CodeArgumentReferenceExpression("asyncResult"); invoke = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "EndInvoke", new CodeExpression[] { expr }); if (method.MimeReturn.ReaderType != null) { endCodeMethod.Statements.Add(new CodeMethodReturnStatement(new CodeCastExpression(method.MimeReturn.TypeName, invoke))); } else { endCodeMethod.Statements.Add(new CodeExpressionStatement(invoke)); } } if (newAsync) { metadata = new CodeAttributeDeclarationCollection(); string uniqueMethodName = method.Name; string methodKey = MethodSignature(uniqueMethodName, method.MimeReturn.TypeName, new CodeFlags[parameterTypeNames.Length], parameterTypeNames); DelegateInfo delegateInfo = (DelegateInfo)ExportContext[methodKey]; if (delegateInfo == null) { string handlerType = ClassNames.AddUnique(uniqueMethodName + "CompletedEventHandler", uniqueMethodName); string handlerArgs = ClassNames.AddUnique(uniqueMethodName + "CompletedEventArgs", uniqueMethodName); delegateInfo = new DelegateInfo(handlerType, handlerArgs); } string handlerName = MethodNames.AddUnique(uniqueMethodName + "Completed", uniqueMethodName); string asyncName = MethodNames.AddUnique(uniqueMethodName + "Async", uniqueMethodName); string callbackMember = MethodNames.AddUnique(uniqueMethodName + "OperationCompleted", uniqueMethodName); string callbackName = MethodNames.AddUnique("On" + uniqueMethodName + "OperationCompleted", uniqueMethodName); // public event xxxCompletedEventHandler xxxCompleted; WebCodeGenerator.AddEvent(this.CodeTypeDeclaration.Members, delegateInfo.handlerType, handlerName); // private SendOrPostCallback xxxOperationCompleted; WebCodeGenerator.AddCallbackDeclaration(this.CodeTypeDeclaration.Members, callbackMember); // create the pair of xxxAsync methods string userState = UniqueName("userState", parameterNames); CodeMemberMethod asyncCodeMethod = WebCodeGenerator.AddAsyncMethod(this.CodeTypeDeclaration, asyncName, parameterTypeNames, parameterNames, callbackMember, callbackName, userState); // Generate InvokeAsync call invokeParams = new CodeExpression[5]; CreateInvokeParams(invokeParams, method, parameterNames); invokeParams[3] = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), callbackMember); invokeParams[4] = new CodeArgumentReferenceExpression(userState); invoke = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "InvokeAsync", invokeParams); asyncCodeMethod.Statements.Add(invoke); // private void On_xxx_OperationCompleted(object arg) {..} bool methodHasReturn = method.MimeReturn.ReaderType != null; WebCodeGenerator.AddCallbackImplementation(this.CodeTypeDeclaration, callbackName, handlerName, delegateInfo.handlerArgs, methodHasReturn); if (ExportContext[methodKey] == null) { // public delegate void xxxCompletedEventHandler(object sender, System.ComponentModel.AsyncCompletedEventArgs args); WebCodeGenerator.AddDelegate(ExtraCodeClasses, delegateInfo.handlerType, methodHasReturn ? delegateInfo.handlerArgs : typeof(AsyncCompletedEventArgs).FullName); if (methodHasReturn) { ExtraCodeClasses.Add(WebCodeGenerator.CreateArgsClass(delegateInfo.handlerArgs, new string[] { method.MimeReturn.TypeName }, new string[] { "Result" }, ServiceImporter.CodeGenerator.Supports(GeneratorSupport.PartialTypes))); } ExportContext[methodKey] = delegateInfo; } } } return(mainCodeMethod); }
internal int Add(MimeParameter parameter) { return(base.List.Add(parameter)); }