protected virtual void GenerateCode(CodeCompileUnit unit, CodeDomProvider provider, CodeGenerationResults content, string itemPath) { CodeCompileUnit cloneUnit = CloneUnit(unit); foreach (CodeNamespace ns in unit.Namespaces) { cloneUnit.Namespaces.Clear(); cloneUnit.Namespaces.Add(CloneNamespace(ns)); foreach (CodeTypeDeclaration codeType in ns.Types) { string file = Path.Combine(Path.GetDirectoryName(itemPath), Path.ChangeExtension(codeType.Name, Path.GetExtension(itemPath))); if (!content.ContainsFile(file)) { cloneUnit.Namespaces[0].Types.Clear(); cloneUnit.Namespaces[0].Types.Add(codeType); using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture)) { provider.GenerateCodeFromCompileUnit(cloneUnit, stringWriter, new CodeGeneratorOptions()); content.Add(file, stringWriter.ToString()); } } } } }
public virtual CodeGenerationResults Generate(IArtifactLink link) { CodeGenerationResults result = new CodeGenerationResults(); result.Add(link.ItemPath, HelloWorld); return(result); }
public CodeGenerationResults Generate(IArtifactLink link) { CodeGenerationResults result = new CodeGenerationResults(); if (link is IModelReference) { this.serviceProvider = Utility.GetData <IServiceProvider>(link); ProjectNode project = Utility.GetData <ProjectNode>(link); ModelElement modelElement = ((IModelReference)link).ModelElement; TextTemplateArtifactLinkWrapper textTemplateArtifactLink = new TextTemplateArtifactLinkWrapper(link); textTemplateArtifactLink.ResourceResolver = ResourceResolver; string template = GetTemplateBasedOnProject(textTemplateArtifactLink, project); if (modelElement != null && !string.IsNullOrEmpty(template)) { Engine engine = new Engine(); DomainModel model = (DomainModel)modelElement.Store.GetDomainModel(modelElement.GetDomainClass().DomainModel.Id); TextTemplateHost host = new TextTemplateHost(model, modelElement, modelElement, GetService <ICodeGenerationService>()); host.ResourceResolver = textTemplateArtifactLink.ResourceResolver; string content = engine.ProcessTemplate(template, host); if (host.GenerateOutput) { this.projectReferences = new List <Guid>(host.ProjectReferences); this.assemblyReferences = GetAssemblyReferences(link); if (host.CompilerErrors.Count > 0) { foreach (CompilerError error in host.CompilerErrors) { LogError(error); } } // Will create a file with the 'ErrorGeneratingOutput' text in the generated file. result.Add(link.ItemPath, content); } } } return(result); }
public virtual CodeGenerationResults Generate(IArtifactLink link) { CodeGenerationResults result = new CodeGenerationResults(); result.Add(link.ItemPath, HelloWorld); return result; }
public CodeGenerationResults Generate(IArtifactLink link) { CodeGenerationResults result = new CodeGenerationResults(); string serviceImplementationName = string.Empty; string serviceContractName = string.Empty; string serviceNamespace = string.Empty; const string behavior = "_Behavior"; if (link is IModelReference) { this.serviceProvider = Utility.GetData <IServiceProvider>(link); ProjectNode project = Utility.GetData <ProjectNode>(link); ServiceDescription serviceDescription = ((IModelReference)link).ModelElement as ServiceDescription; Configuration configuration = GetConfiguration(link, project); // abort if we got errors in config file if (configuration == null) { return(result); } try { ServiceReference serviceReference = (ServiceReference)serviceDescription; SCModel.Service service = GetMelReference <SCModel.Service>(serviceReference.ServiceImplementationType); serviceImplementationName = ResolveTypeReference(service); serviceContractName = GetServiceContractName(service.ServiceContract); serviceNamespace = service.ServiceContract.Namespace; ServiceModelConfigurationManager manager = new ServiceModelConfigurationManager(configuration); ServiceElement serviceElement = new ServiceElement(); serviceElement.Name = serviceImplementationName; serviceElement.BehaviorConfiguration = string.Concat(serviceImplementationName, behavior); foreach (Endpoint endpoint in serviceDescription.Endpoints) { ServiceEndpointElement endpointElement = new ServiceEndpointElement(); endpointElement.Name = endpoint.Name; endpointElement.Contract = serviceContractName; endpointElement.Binding = ((WcfEndpoint)endpoint.ObjectExtender).BindingType.ToString(); endpointElement.Address = new Uri(endpoint.Address ?? string.Empty, UriKind.RelativeOrAbsolute); endpointElement.BindingNamespace = serviceNamespace; serviceElement.Endpoints.Add(endpointElement); } manager.UpdateService(serviceElement); ServiceBehaviorElement behaviorElement = new ServiceBehaviorElement(); behaviorElement.Name = string.Concat(serviceImplementationName, behavior); ServiceDebugElement debugElement = new ServiceDebugElement(); debugElement.IncludeExceptionDetailInFaults = false; behaviorElement.Add(debugElement); if (((WcfServiceDescription)serviceDescription.ObjectExtender).EnableMetadataPublishing) { ServiceMetadataPublishingElement metadataPublishingElement = new ServiceMetadataPublishingElement(); metadataPublishingElement.HttpGetEnabled = true; behaviorElement.Add(metadataPublishingElement); ServiceEndpointElement mexEndpointElement = ServiceModelConfigurationManager.GetMetadataExchangeEndpoint(); serviceElement.Endpoints.Add(mexEndpointElement); } manager.UpdateBehavior(behaviorElement); manager.Save(); result.Add(link.ItemPath, File.ReadAllText(configuration.FilePath)); } finally { if (configuration != null && File.Exists(configuration.FilePath)) { File.Delete(configuration.FilePath); } } } return(result); }