62 lines
2.4 KiB
C#
62 lines
2.4 KiB
C#
namespace RoutesBuilder
|
|
{
|
|
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
public class Program
|
|
{
|
|
public static void Main()
|
|
{
|
|
var prefixes = new StringBuilder();
|
|
|
|
var solutionDirectory = new DirectoryInfo(@"..\..\..\").FullName;
|
|
var laaProductionWeb = Path.Combine(solutionDirectory, @"LaaProductionWeb\LaaProductionWeb");
|
|
var appInfrastructure = Path.Combine(laaProductionWeb, "App_Infrastructure");
|
|
var apiControllers = new DirectoryInfo(Path.Combine(laaProductionWeb, "API"));
|
|
var controllers = apiControllers
|
|
.GetFiles("*Controller.cs", SearchOption.AllDirectories)
|
|
.Select(x => x.FullName);
|
|
|
|
prefixes.AppendLine($"namespace LaaProductionWeb.App_Infrastructure");
|
|
prefixes.AppendLine("{");
|
|
prefixes.AppendLine($"\tusing System;");
|
|
prefixes.AppendLine();
|
|
prefixes.AppendLine($"\tpublic class RoutePrefixes");
|
|
prefixes.AppendLine("\t{");
|
|
prefixes.AppendLine("\t\tpublic static readonly String BaseURL = Appsettings.APIURL.TrimEnd('/');");
|
|
|
|
foreach (var controllerFile in controllers)
|
|
{
|
|
var @namespace = File.ReadLines(controllerFile).FirstOrDefault();
|
|
@namespace = @namespace
|
|
.Replace(nameof(@namespace), String.Empty)
|
|
.Replace("LaaProductionWeb", String.Empty)
|
|
.Trim();
|
|
var controllerName = Path
|
|
.GetFileNameWithoutExtension(controllerFile)
|
|
.Replace("Controller", String.Empty)
|
|
.Trim();
|
|
var route = $"{@namespace}.{controllerName}"
|
|
.Trim()
|
|
.Trim('.');
|
|
var routeName = route
|
|
.Replace('.', '_')
|
|
.ToUpper();
|
|
var routePrefix = route
|
|
.Replace('.', '/')
|
|
.ToLower();
|
|
prefixes.AppendLine();
|
|
prefixes.AppendLine($"\t\tpublic const String {routeName} = \"{routePrefix}\";");
|
|
}
|
|
|
|
prefixes.AppendLine("\t}");
|
|
prefixes.AppendLine("}");
|
|
|
|
File.WriteAllText(Path.Combine(appInfrastructure, $"RoutePrefixes.cs"), prefixes.ToString());
|
|
Console.WriteLine(prefixes);
|
|
}
|
|
}
|
|
}
|