/// <summary>Modifies the code document object model prior to the contract generation process.</summary> /// <param name="context">The code generated context to use to modify the code document prior to generation.</param> public void GenerateContract(ServiceContractGenerationContext context) { // Disable generation of the Event-Based Async Pattern, which has a conflicting naming scheme. context.ServiceContractGenerator.Options &= ~ServiceContractGenerationOptions.EventBasedAsynchronousMethods; string contractName = context.Contract.Name; string clientTypeName = TaskAsyncWsdlImportExtension.DeriveClientTypeName(contractName); // Look up the client class, and create it if it doesn't already exist. if (TaskAsyncWsdlImportExtension.FindClientType(clientTypeName, context.ServiceContractGenerator.TargetCompileUnit.Namespaces) == null) { // Create the new type CodeTypeDeclaration newClient = new CodeTypeDeclaration(clientTypeName) { Attributes = MemberAttributes.Public, IsPartial = true }; newClient.BaseTypes.Add(new CodeTypeReference(typeof(ClientBase<>)) { TypeArguments = { new CodeTypeReference(contractName) } }); newClient.BaseTypes.Add(new CodeTypeReference(contractName)); // Add the new type to the right namespace CodeNamespace contractNamespace = (from ns in context.ServiceContractGenerator.TargetCompileUnit.Namespaces.Cast<CodeNamespace>() from type in ns.Types.Cast<CodeTypeDeclaration>() where type == context.ContractType select ns).FirstOrDefault(); contractNamespace.Types.Add(newClient); } }
public OperationContractGenerationContext(System.ServiceModel.Description.ServiceContractGenerator serviceContractGenerator, ServiceContractGenerationContext contract, OperationDescription operation, CodeTypeDeclaration declaringType, CodeMemberMethod method) : this(serviceContractGenerator, contract, operation, declaringType) { if (method == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("method")); } this.syncMethod = method; this.beginMethod = null; this.endMethod = null; }
public OperationContractGenerationContext ( ServiceContractGenerator serviceContractGenerator, ServiceContractGenerationContext contract, OperationDescription operation, CodeTypeDeclaration declaringType, CodeMemberMethod method) : this (serviceContractGenerator, contract, operation, declaringType, method, null, null) { }
public OperationContractGenerationContext(ServiceContractGenerator serviceContractGenerator, ServiceContractGenerationContext contract, OperationDescription operation, CodeTypeDeclaration declaringType, CodeMemberMethod syncMethod, CodeMemberMethod taskMethod) : this(serviceContractGenerator, contract, operation, declaringType) { if (syncMethod == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("syncMethod")); if (taskMethod == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("taskMethod")); this.syncMethod = syncMethod; this.taskMethod = taskMethod; }
OperationContractGenerationContext(ServiceContractGenerator serviceContractGenerator, ServiceContractGenerationContext contract, OperationDescription operation, CodeTypeDeclaration declaringType) { if (serviceContractGenerator == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("serviceContractGenerator")); if (contract == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("contract")); if (declaringType == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("declaringType")); this.serviceContractGenerator = serviceContractGenerator; this.contract = contract; this.operation = operation; this.declaringType = declaringType; }
public void FindClientType (ServiceContractGenerationContext context) { var cd = context.Contract; string name = cd.Name + "Client"; if (name [0] == 'I') name = name.Substring (1); foreach (CodeNamespace cns in context.ServiceContractGenerator.TargetCompileUnit.Namespaces) foreach (CodeTypeDeclaration ct in cns.Types) if (ct == context.ContractType) foreach (CodeTypeDeclaration ct2 in cns.Types) if (ct2.Name == name) { ClientType = ct2; return; } throw new Exception (String.Format ("Contract '{0}' not found", name)); }
public OperationContractGenerationContext ( ServiceContractGenerator serviceContractGenerator, ServiceContractGenerationContext contract, OperationDescription operation, CodeTypeDeclaration declaringType, CodeMemberMethod method, CodeMemberMethod beginMethod, CodeMemberMethod endMethod) { generator = serviceContractGenerator; this.contract = contract; this.operation = operation; declaring_type = declaringType; this.method = method; this.begin_method = beginMethod; this.end_method = endMethod; }
// calls a specific set of contract-level extensions static internal void CallContractExtensions(IEnumerable <IServiceContractGenerationExtension> extensions, ServiceContractGenerationContext context) { foreach (IServiceContractGenerationExtension extension in extensions) { extension.GenerateContract(context); } }
// IServiceContractGenerationExtensions public void GenerateContract ( ServiceContractGenerationContext context) { this.context = context; ml_context.Contract = this; }
void IServiceContractGenerationExtension.GenerateContract(ServiceContractGenerationContext context) { ReadConfiguration(context.ServiceContractGenerator.Configuration); if (!String.IsNullOrEmpty(documentation)) XmlCommentsImporter.AddXmlComment(context.ContractType, documentation, XmlCommentsImporter.options); AddXmlCommentsToDataContracts(context); }
protected virtual void PostProcessCodeMembers(ServiceContractGenerationContext context, IEnumerable<CodeTypeMember> members) { if (XmlCommentsImporter.options.Documentable) { context.ServiceContractGenerator.Options = ServiceContractGenerationOptions.None; RemoveIExtensibleDataObjectFromDeclaration(members); } }
private OperationContractGenerationContext(ServiceContractGenerator serviceContractGenerator, ServiceContractGenerationContext contract, OperationDescription operation, CodeTypeDeclaration declaringType) { if (serviceContractGenerator == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("serviceContractGenerator")); } if (contract == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("contract")); } if (declaringType == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("declaringType")); } _serviceContractGenerator = serviceContractGenerator; _contract = contract; _operation = operation; _declaringType = declaringType; }
public OperationContractGenerationContext(ServiceContractGenerator serviceContractGenerator, ServiceContractGenerationContext contract, OperationDescription operation, CodeTypeDeclaration declaringType, CodeMemberMethod method) : this(serviceContractGenerator, contract, operation, declaringType) { if (method == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("method")); } _syncMethod = method; _beginMethod = null; _endMethod = null; }
private void AddXmlCommentsToDataContracts(ServiceContractGenerationContext context) { Dictionary<string, CodeTypeMember> codeMembers = CodeDomUtils.EnumerareCodeMembers(context.ServiceContractGenerator.TargetCompileUnit); Dictionary<string, string> documentedItems = new Dictionary<string, string>(); WsdlUtils.EnumerateDocumentedItems(importer.wsdlDocuments, documentedItems); WsdlUtils.EnumerateDocumentedItems(importer.xmlSchemas, documentedItems); foreach (KeyValuePair<string, string> documentedItem in documentedItems) { CodeTypeMember codeMember; if (codeMembers.TryGetValue(documentedItem.Key, out codeMember)) XmlCommentsImporter.AddXmlComment(codeMember, documentedItem.Value, XmlCommentsImporter.options); } PostProcessCodeMembers(context, codeMembers.Values); }
void IServiceContractGenerationExtension.GenerateContract(ServiceContractGenerationContext context) { CodeTypeDeclaration clientType = context.TypeFactory.CreateClassType(); clientType.Name = NamingHelper.GetUniqueName(GetClientClassName(context.ContractType.Name), new NamingHelper.DoesNameExist(ClientClassGenerator.DoesMethodNameExist), context.Operations); CodeTypeReference contractTypeReference = context.ContractTypeReference; if (context.DuplexCallbackType == null) { clientType.BaseTypes.Add(new CodeTypeReference(context.ServiceContractGenerator.GetCodeTypeReference(typeof(ClientBase <>)).BaseType, new CodeTypeReference[] { context.ContractTypeReference })); } else { clientType.BaseTypes.Add(new CodeTypeReference(context.ServiceContractGenerator.GetCodeTypeReference(typeof(DuplexClientBase <>)).BaseType, new CodeTypeReference[] { context.ContractTypeReference })); } clientType.BaseTypes.Add(context.ContractTypeReference); if (ClientCtorParamNames.Length != ClientCtorParamTypes.Length) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Invalid client generation constructor table initialization", new object[0]))); } for (int i = 0; i < ClientCtorParamNames.Length; i++) { if (ClientCtorParamNames[i].Length != ClientCtorParamTypes[i].Length) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Invalid client generation constructor table initialization", new object[0]))); } CodeConstructor constructor = new CodeConstructor { Attributes = MemberAttributes.Public }; if (context.DuplexCallbackType != null) { constructor.Parameters.Add(new CodeParameterDeclarationExpression(typeof(InstanceContext), inputInstanceName)); constructor.BaseConstructorArgs.Add(new CodeVariableReferenceExpression(inputInstanceName)); } for (int j = 0; j < ClientCtorParamNames[i].Length; j++) { constructor.Parameters.Add(new CodeParameterDeclarationExpression(ClientCtorParamTypes[i][j], ClientCtorParamNames[i][j])); constructor.BaseConstructorArgs.Add(new CodeVariableReferenceExpression(ClientCtorParamNames[i][j])); } clientType.Members.Add(constructor); } foreach (OperationContractGenerationContext context2 in context.Operations) { if (!context2.Operation.IsServerInitiated()) { CodeTypeReference declaringTypeReference = context2.DeclaringTypeReference; GenerateClientClassMethod(clientType, contractTypeReference, context2.SyncMethod, this.tryAddHelperMethod, declaringTypeReference); if (context2.IsAsync) { CodeMemberMethod beginMethod = GenerateClientClassMethod(clientType, contractTypeReference, context2.BeginMethod, this.tryAddHelperMethod, declaringTypeReference); CodeMemberMethod endMethod = GenerateClientClassMethod(clientType, contractTypeReference, context2.EndMethod, this.tryAddHelperMethod, declaringTypeReference); if (this.generateEventAsyncMethods) { GenerateEventAsyncMethods(context, clientType, context2.SyncMethod.Name, beginMethod, endMethod); } } } } context.Namespace.Types.Add(clientType); context.ClientType = clientType; context.ClientTypeReference = ServiceContractGenerator.NamespaceHelper.GetCodeTypeReference(context.Namespace, clientType); }
public OperationContractGenerationContext(ServiceContractGenerator serviceContractGenerator, ServiceContractGenerationContext contract, OperationDescription operation, System.CodeDom.CodeTypeDeclaration declaringType, System.CodeDom.CodeMemberMethod syncMethod, System.CodeDom.CodeMemberMethod beginMethod, System.CodeDom.CodeMemberMethod endMethod) { }
CodeTypeReference ExportInterface (ContractDescription cd, CodeNamespace cns) { CodeTypeDeclaration type = GetTypeDeclaration (cns, cd.Name); if (type != null) return new CodeTypeReference (type.Name); type = new CodeTypeDeclaration (); type.TypeAttributes = TypeAttributes.Interface; type.TypeAttributes |= TypeAttributes.Public; cns.Types.Add (type); type.Name = identifiers.AddUnique (cd.Name, null); CodeAttributeDeclaration ad = new CodeAttributeDeclaration ( new CodeTypeReference ( typeof (ServiceContractAttribute))); ad.Arguments.Add (new CodeAttributeArgument ("Namespace", new CodePrimitiveExpression (cd.Namespace))); type.CustomAttributes.Add (ad); contract_context = new ServiceContractGenerationContext (this, cd, type); AddOperationMethods (type, cd); return new CodeTypeReference (type.Name); }
ContractCacheEntry ExportInterface_internal (ContractDescription cd, CodeNamespace cns) { if (generated_contracts.ContainsKey (cd)) return generated_contracts [cd]; var type = new CodeTypeDeclaration (); type.TypeAttributes = TypeAttributes.Interface; type.TypeAttributes |= TypeAttributes.Public; cns.Types.Add (type); type.Name = identifiers.AddUnique (cd.Name, null); var configName = type.Name; CodeAttributeDeclaration ad = new CodeAttributeDeclaration ( new CodeTypeReference ( typeof (ServiceContractAttribute))); ad.Arguments.Add (new CodeAttributeArgument ("Namespace", new CodePrimitiveExpression (cd.Namespace))); ad.Arguments.Add (new CodeAttributeArgument ("ConfigurationName", new CodePrimitiveExpression (configName))); type.CustomAttributes.Add (ad); contract_context = new ServiceContractGenerationContext (this, cd, type); AddOperationMethods (type, cd); var cache = new ContractCacheEntry (cd, configName, type); generated_contracts.Add (cd, cache); return cache; }
public void GenerateContract(ServiceContractGenerationContext context) { Debug.WriteLine("In generate contract."); context.ContractType.Comments.AddRange(FormatComments(text)); }
public OperationContractGenerationContext(ServiceContractGenerator serviceContractGenerator, ServiceContractGenerationContext contract, OperationDescription operation, CodeTypeDeclaration declaringType, CodeMemberMethod syncMethod, CodeMemberMethod taskMethod) : this(serviceContractGenerator, contract, operation, declaringType) { if (syncMethod == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("syncMethod")); } if (taskMethod == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("taskMethod")); } this.syncMethod = syncMethod; this.taskMethod = taskMethod; }
// calls a specific set of operation-level extensions on each operation in the contract static internal void CallOperationExtensions(IEnumerable <IOperationContractGenerationExtension> extensions, ServiceContractGenerationContext context) { foreach (OperationContractGenerationContext operationContext in context.Operations) { CallOperationExtensions(extensions, operationContext); } }