public ConfigurationClass() { //this.ConnectionString = ConfigurationManager.ConnectionStrings["DBServer"].ToString(); this.ConnectionString = ConfigurationManager.ConnectionStrings["dbServer"].ToString(); this.RabbittMQ = new RabbittConfig(); this.RabbittMQ.ImportQueueName = ConfigurationManager.AppSettings["RabbitMQ_Import_Queue"].ToString(); this.RabbittMQ.ExcelQueueName = ConfigurationManager.AppSettings["RabbitMQ_Excel_Queue"].ToString(); this.RabbittMQ.Server = ConfigurationManager.AppSettings["RabbitMQ_Server"].ToString(); this.Paths = new PathsClass(); this.Paths.MainFolder = ConfigurationManager.AppSettings["ProccesFolder"].ToString(); this.Paths.InFolder = ConfigurationManager.AppSettings["ProccesFolder_in"].ToString(); this.Paths.OutFolder = ConfigurationManager.AppSettings["ProccesFolder_Out"].ToString(); this.Paths.TemplateFolder = ConfigurationManager.AppSettings["Template"].ToString(); this.LoadersDLLDirectory = ConfigurationManager.AppSettings["LoadersDLLDirectory"].ToString(); }
public void GenerateInterface(PathsClass paths, Workspace workspace) { var builder = new StringBuilder(); builder.AppendLine("using System.Threading.Tasks;") .AppendLine($"using static {(string.IsNullOrEmpty(Options.IncludedFileNamespace) ? "" : Options.IncludedFileNamespace + ".")}GenerationUtils;") .AppendLine(); if (Options.SchemaNamespace != null) { builder.AI().AppendLine($"namespace {Options.SchemaNamespace}") .AI().AppendLine("{") .Indent(); } builder.AI().AppendLine($"public class {paths.Name}") .AI().AppendLine("{"); builder.Indent(); foreach (var method in paths.Methods) { var paramNames = method.Parameters.Keys.ToDictionary(o => o, o => o.Prettify()); if (method.Documentation != null) { builder.AI().AppendLine("///<summary>") .AI().AppendLine($"///{method.Documentation.Summary}") .AI().AppendLine("///</summary>"); } foreach (var param in method.Parameters) { if (param.Value.Documentation != null) { builder.AI().AppendLine($"///<param name=\"{paramNames[param.Key]}\">{param.Value.Documentation.Summary}</param>"); } } builder.AI().Append($"public Task{(method.ResponseType == null ? "" : $"<{GetCSType(method.ResponseType)}>")} {method.Name}("); if (method.RequestType != null) { builder.Append($"{GetCSType(method.RequestType)} body"); if (method.Parameters.Count > 0) { builder.Append(", "); } } foreach (var param in method.Parameters) { builder.Append($"{GetCSType(param.Value.Type)} {paramNames[param.Key]}"); if (param.Key != method.Parameters.Keys.Last()) { builder.Append(", "); } } builder.AppendLine(")") .Indent(); builder.AI().Append("=> Sender.Request"); if (method.ResponseType != null) { builder.Append($"<{GetCSType(method.ResponseType)}>"); } string path = PathParamsRegex.Replace(method.Path, o => paramNames[o.Value]); builder.Append($"(\"{method.HttpMethod.ToString().ToLower()}\", $\"{path}"); bool isFirstQueryParam = true; foreach (var param in method.Parameters.Where(o => o.Value.Position == ParameterPosition.Query)) { if (isFirstQueryParam) { builder.Append("?"); } else { builder.Append("&"); } builder.Append($"{param.Key}={{{paramNames[param.Key]}}}"); isFirstQueryParam = false; } //TODO Header parameters builder.Append("\""); if (method.RequestType != null) { builder.Append(", body"); } builder.AppendLine(");"); builder.Unindent(); } builder.Unindent(); builder.AI().AppendLine("}"); if (Options.SchemaNamespace != null) { builder.Unindent() .AI().AppendLine("}"); } workspace.WriteToFile("Interfaces/" + paths.Name + ".cs", builder.ToString()); }