예제 #1
0
            void Visit(ContractDescription contractDescription)
            {
                bool isDuplex = IsDuplex(contractDescription);

                this.contractMemberScope = new UniqueCodeIdentifierScope();
                this.callbackMemberScope = isDuplex ? new UniqueCodeIdentifierScope() : null;

                UniqueCodeNamespaceScope codeNamespaceScope = new UniqueCodeNamespaceScope(parent.NamespaceManager.EnsureNamespace(contractDescription.Namespace));

                CodeTypeDeclaration contract          = typeFactory.CreateInterfaceType();
                CodeTypeReference   contractReference = codeNamespaceScope.AddUnique(contract, contractDescription.CodeName, Strings.DefaultContractName);

                CodeTypeDeclaration callbackContract          = null;
                CodeTypeReference   callbackContractReference = null;

                if (isDuplex)
                {
                    callbackContract          = typeFactory.CreateInterfaceType();
                    callbackContractReference = codeNamespaceScope.AddUnique(callbackContract, contractDescription.CodeName + Strings.CallbackTypeSuffix, Strings.DefaultContractName);
                }

                this.context                             = new ServiceContractGenerationContext(parent, contractDescription, contract, callbackContract);
                this.context.Namespace                   = codeNamespaceScope.CodeNamespace;
                this.context.TypeFactory                 = this.typeFactory;
                this.context.ContractTypeReference       = contractReference;
                this.context.DuplexCallbackTypeReference = callbackContractReference;

                AddServiceContractAttribute(this.context);
            }
예제 #2
0
            private void Visit(ContractDescription contractDescription)
            {
                bool flag = IsDuplex(contractDescription);

                this.contractMemberScope = new UniqueCodeIdentifierScope();
                this.callbackMemberScope = flag ? new UniqueCodeIdentifierScope() : null;
                UniqueCodeNamespaceScope scope        = new UniqueCodeNamespaceScope(this.parent.NamespaceManager.EnsureNamespace(contractDescription.Namespace));
                CodeTypeDeclaration      codeType     = this.typeFactory.CreateInterfaceType();
                CodeTypeReference        reference    = scope.AddUnique(codeType, contractDescription.CodeName, "IContract");
                CodeTypeDeclaration      declaration2 = null;
                CodeTypeReference        reference2   = null;

                if (flag)
                {
                    declaration2 = this.typeFactory.CreateInterfaceType();
                    reference2   = scope.AddUnique(declaration2, contractDescription.CodeName + "Callback", "IContract");
                }
                this.context                             = new ServiceContractGenerationContext(this.parent, contractDescription, codeType, declaration2);
                this.context.Namespace                   = scope.CodeNamespace;
                this.context.TypeFactory                 = this.typeFactory;
                this.context.ContractTypeReference       = reference;
                this.context.DuplexCallbackTypeReference = reference2;
                this.AddServiceContractAttribute(this.context);
            }
예제 #3
0
            void Visit(OperationDescription operationDescription)
            {
                bool isCallback = operationDescription.IsServerInitiated();
                CodeTypeDeclaration       declaringType = isCallback ? context.DuplexCallbackType : context.ContractType;
                UniqueCodeIdentifierScope memberScope   = isCallback ? this.callbackMemberScope : this.contractMemberScope;

                Fx.Assert(declaringType != null, "missing callback type");

                string syncMethodName = memberScope.AddUnique(operationDescription.CodeName, Strings.DefaultOperationName);

                CodeMemberMethod syncMethod = new CodeMemberMethod();

                syncMethod.Name = syncMethodName;
                declaringType.Members.Add(syncMethod);

                OperationContractGenerationContext operationContext;
                CodeMemberMethod beginMethod = null;
                CodeMemberMethod endMethod   = null;

                if (asyncMethods)
                {
                    beginMethod      = new CodeMemberMethod();
                    beginMethod.Name = ServiceReflector.BeginMethodNamePrefix + syncMethodName;
                    beginMethod.Parameters.Add(new CodeParameterDeclarationExpression(context.ServiceContractGenerator.GetCodeTypeReference(typeof(AsyncCallback)), Strings.AsyncCallbackArgName));
                    beginMethod.Parameters.Add(new CodeParameterDeclarationExpression(context.ServiceContractGenerator.GetCodeTypeReference(typeof(object)), Strings.AsyncStateArgName));
                    beginMethod.ReturnType = context.ServiceContractGenerator.GetCodeTypeReference(typeof(IAsyncResult));
                    declaringType.Members.Add(beginMethod);

                    endMethod      = new CodeMemberMethod();
                    endMethod.Name = ServiceReflector.EndMethodNamePrefix + syncMethodName;
                    endMethod.Parameters.Add(new CodeParameterDeclarationExpression(context.ServiceContractGenerator.GetCodeTypeReference(typeof(IAsyncResult)), Strings.AsyncResultArgName));
                    declaringType.Members.Add(endMethod);

                    operationContext = new OperationContractGenerationContext(parent, context, operationDescription, declaringType, syncMethod, beginMethod, endMethod);
                }
                else
                {
                    operationContext = new OperationContractGenerationContext(parent, context, operationDescription, declaringType, syncMethod);
                }

                if (taskMethod)
                {
                    if (isCallback)
                    {
                        if (beginMethod == null)
                        {
                            operationContext = new OperationContractGenerationContext(parent, context, operationDescription, declaringType, syncMethod);
                        }
                        else
                        {
                            operationContext = new OperationContractGenerationContext(parent, context, operationDescription, declaringType, syncMethod, beginMethod, endMethod);
                        }
                    }
                    else
                    {
                        CodeMemberMethod taskBasedAsyncMethod = new CodeMemberMethod {
                            Name = syncMethodName + ServiceReflector.AsyncMethodNameSuffix
                        };
                        declaringType.Members.Add(taskBasedAsyncMethod);
                        if (beginMethod == null)
                        {
                            operationContext = new OperationContractGenerationContext(parent, context, operationDescription, declaringType, syncMethod, taskBasedAsyncMethod);
                        }
                        else
                        {
                            operationContext = new OperationContractGenerationContext(parent, context, operationDescription, declaringType, syncMethod, beginMethod, endMethod, taskBasedAsyncMethod);
                        }
                    }
                }

                operationContext.DeclaringTypeReference = operationDescription.IsServerInitiated() ? context.DuplexCallbackTypeReference : context.ContractTypeReference;

                context.Operations.Add(operationContext);

                AddOperationContractAttributes(operationContext);
            }