public void Visit(Service service) { if (!string.IsNullOrEmpty(GenServiceTweak) && _config.ContainsTweak(GenServiceTweak)) { EnsureCheckHealthAvail(service); var serviceContext = _contextGenerator.ServiceFromIdl(service); Render(serviceContext, "service"); } if (!string.IsNullOrEmpty(GenClientTweak) && _config.ContainsTweak(GenClientTweak)) { var clientContext = _contextGenerator.ClientFromIdl(service); Render(clientContext, "client"); } }
private void Render(CSharpContext context, string templateName) { var template = templateLoader.Load(templateName); Enforce.IsNotNull(template, string.Format("No template for '{0}' found!", templateName)); template.Add("context", context); var tweakMap = new Dictionary <string, bool>(); var tweakValues = Enum.GetValues(typeof(GeneratorTweak)); foreach (var tweak in tweakValues) { tweakMap.Add(tweak.ToString(), config.ContainsTweak((GeneratorTweak)tweak)); } template.Add("tweaks", tweakMap); var globalValues = new Dictionary <string, string>(); var codeGenVersion = Assembly.GetExecutingAssembly().GetName().Version; globalValues.Add("CodeGenVersion", codeGenVersion.ToString()); template.Add("global", globalValues); var packages = context.CSharpNamespace.Split('.'); DirectoryInfo folder = outputFolder; foreach (string pkg in packages) { folder = folder.CreateSubdirectory(pkg); } var filename = Path.Combine(folder.FullName, context.CSharpName + ".cs"); using (StreamWriter writer = new StreamWriter(filename, false, Encoding.UTF8)) { template.Write(new AutoIndentWriter(writer)); writer.Flush(); } }
public void Visit(Service service) { if (!string.IsNullOrEmpty(GenClientTweak) && _config.ContainsTweak(GenClientTweak)) { var clientContext = _contextGenerator.ClientFromIdl(service); foreach (var method in service.Methods) { var methodContext = _contextGenerator.MethodFromIdl(method); clientContext.AddMethod(methodContext); } Render(clientContext, "client"); } if (!string.IsNullOrEmpty(GenServiceTweak) && _config.ContainsTweak(GenServiceTweak)) { var serviceContext = _contextGenerator.ServiceFromIdl(service); foreach (var method in service.Methods) { var methodContext = _contextGenerator.MethodFromIdl(method); serviceContext.AddMethod(methodContext); } Render(serviceContext, "service"); } }
public ServiceContext ServiceFromTrip(Service service) { var name = MangleCSharpServiceName(service.Name); var csharpType = typeRegistry.FindType(defaultNamespace, name); var csharpParents = new HashSet <string>(); string serviceName, serviceNamespace; GetServiceNameAndNamespace(service, out serviceName, out serviceNamespace); var serviceContext = new ServiceContext(service.DocStringLines, name, csharpType.TypeNamespace, csharpType.TypeName, csharpParents, serviceName, serviceNamespace); if (generatorConfig.ContainsTweak(GeneratorTweak.ADD_DISPOSABLE_INTERFACE)) { csharpParents.Add("IDisposable"); //serviceContext.AddMethod(DISPOSE_METHOD_CONTEXT); } return(serviceContext); }