214 lines
10 KiB
C#
214 lines
10 KiB
C#
// See https://aka.ms/new-console-template for more information
|
|
using CloudBuilder.CodeGenerator.Config;
|
|
using CloudBuilder.CodeGenerator.Data;
|
|
using CloudBuilder.CodeGenerator.Utility;
|
|
using CloudBuilder.Core.Application.Builders;
|
|
using CloudBuilder.Core.Authorization;
|
|
using CloudBuilder.Core.DatabaseAccessor;
|
|
using CloudBuilder.Core.DatabaseAccessor.Entity;
|
|
using CloudBuilder.Core.Extensions;
|
|
using CloudBuilder.Core.Service;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Connections;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using RazorEngineCore;
|
|
using System.Diagnostics;
|
|
using System.Reflection;
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
|
|
public partial class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
try
|
|
{
|
|
string logFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log\\log.txt");
|
|
|
|
if (!Directory.Exists(Path.GetDirectoryName(logFileName))) Directory.CreateDirectory(Path.GetDirectoryName(logFileName));
|
|
using (StreamWriter w = File.AppendText(logFileName))
|
|
{
|
|
w.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}]Start:");
|
|
}
|
|
|
|
Assembly assembly = null;
|
|
|
|
if (args != null && args.Length > 0)
|
|
{
|
|
Console.WriteLine(args[0]);
|
|
assembly = Assembly.LoadFrom(args[0]);
|
|
}
|
|
|
|
if (assembly == null) return;
|
|
|
|
using (StreamWriter w = File.AppendText(logFileName))
|
|
{
|
|
w.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}]Succeed:" + assembly.FullName);
|
|
}
|
|
|
|
ModelData modelData = null;
|
|
ToolInitConfig toolInitConfig = ToolInitConfig.GetInstance();
|
|
string template = null;
|
|
string outputText = null;
|
|
string outputFileName = null;
|
|
|
|
|
|
ClassInfo[] dataInfos = RazorEngineHelper.PackTypeScriptClassInfo(assembly);
|
|
|
|
using (StreamWriter w = File.AppendText(logFileName))
|
|
{
|
|
w.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}]PackTypeScriptClassInfo:" + dataInfos.Count());
|
|
}
|
|
|
|
foreach (var item in dataInfos)
|
|
{
|
|
modelData = new ModelData();
|
|
modelData.ClassInfo = item;
|
|
modelData.ClassInfos = new ClassInfo[] { item };
|
|
modelData.NamespaceObject = toolInitConfig.NamespaceObjects.Where(x => x.TemplateType == "TypeScript" && x.Assembly == Path.GetFileNameWithoutExtension(assembly.Location)).FirstOrDefault();
|
|
if (modelData.NamespaceObject == null) continue;
|
|
|
|
outputFileName = Path.Combine(modelData.NamespaceObject.OutFilePath, item.ClassName.StringToProtectedProerty() + modelData.NamespaceObject.FileNameSuffix);
|
|
if (string.IsNullOrEmpty(outputFileName)) continue;
|
|
|
|
template = File.ReadAllText(Path.Combine(toolInitConfig.TemplatePath, modelData.NamespaceObject.TemplateFileName));
|
|
if (string.IsNullOrEmpty(template)) continue;
|
|
|
|
outputText = RazorEngineHelper.CompiledTemplate(template, modelData);
|
|
if (string.IsNullOrEmpty(outputText)) continue;
|
|
|
|
if (!Directory.Exists(Path.GetDirectoryName(outputFileName))) Directory.CreateDirectory(Path.GetDirectoryName(outputFileName));
|
|
|
|
File.WriteAllText(outputFileName, outputText);
|
|
|
|
|
|
if (!Directory.Exists(Path.GetDirectoryName(logFileName))) Directory.CreateDirectory(Path.GetDirectoryName(logFileName));
|
|
using (StreamWriter w = File.AppendText(logFileName))
|
|
{
|
|
w.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}]Succeed:" + outputFileName);
|
|
}
|
|
}
|
|
|
|
template = null;
|
|
outputText = null;
|
|
outputFileName = null;
|
|
|
|
ClassInfo[] classInfos = RazorEngineHelper.PackIServiceClassInfo(assembly);
|
|
|
|
using (StreamWriter w = File.AppendText(logFileName))
|
|
{
|
|
w.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}]PackIServiceClassInfo:" + classInfos.Count());
|
|
}
|
|
|
|
foreach (var item in classInfos)
|
|
{
|
|
//没有要生成公共方法的接口不处理
|
|
if (item.ClassMethodInfos.Length == 0) continue;
|
|
|
|
modelData = new ModelData();
|
|
modelData.ClassInfo = item;
|
|
|
|
if (item.ClassMethodInfos.Select(x => x.MethodName).Where(x => x.StartsWith("PrintBy")).Count() > 0)
|
|
{
|
|
modelData.ClassInfo.IsDownload = true;
|
|
}
|
|
|
|
modelData.ClassInfos = new ClassInfo[] { item };
|
|
|
|
modelData.NamespaceObject = toolInitConfig.NamespaceObjects.Where(x => x.TemplateType == "Controller" && x.Assembly == Path.GetFileNameWithoutExtension(assembly.Location)).FirstOrDefault();
|
|
|
|
using (StreamWriter w = File.AppendText(logFileName))
|
|
{
|
|
w.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}]Controller:" + (modelData.NamespaceObject == null ? ("配置文件不存在【TemplateType、Assembly】" + Path.GetFileNameWithoutExtension(assembly.Location)) : modelData.NamespaceObject.OutFilePath));
|
|
}
|
|
|
|
if (modelData.NamespaceObject == null) continue;
|
|
|
|
outputFileName = Path.Combine(modelData.NamespaceObject.OutFilePath, item.ClassName.Replace("Service", "") + modelData.NamespaceObject.FileNameSuffix);
|
|
|
|
using (StreamWriter w = File.AppendText(logFileName))
|
|
{
|
|
w.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}]Controller:" + (string.IsNullOrEmpty(outputFileName) ? "空文件" : outputFileName));
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(outputFileName)) continue;
|
|
|
|
template = File.ReadAllText(Path.Combine(toolInitConfig.TemplatePath, modelData.NamespaceObject.TemplateFileName));
|
|
if (string.IsNullOrEmpty(template)) continue;
|
|
|
|
outputText = RazorEngineHelper.CompiledTemplate(template, modelData);
|
|
if (string.IsNullOrEmpty(outputText)) continue;
|
|
|
|
if (!Directory.Exists(Path.GetDirectoryName(outputFileName))) Directory.CreateDirectory(Path.GetDirectoryName(outputFileName));
|
|
|
|
File.WriteAllText(outputFileName, outputText);
|
|
|
|
|
|
if (!Directory.Exists(Path.GetDirectoryName(logFileName))) Directory.CreateDirectory(Path.GetDirectoryName(logFileName));
|
|
using (StreamWriter w = File.AppendText(logFileName))
|
|
{
|
|
w.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}]Succeed:" + outputFileName);
|
|
}
|
|
//================================CloudBuilder.Security.Service >.Security
|
|
modelData.NamespaceObject = toolInitConfig.NamespaceObjects.Where(x => x.TemplateType == "Request" &&
|
|
Path.GetFileNameWithoutExtension(assembly.Location).Contains(x.Namespace.Replace(x.Assembly, ""))).FirstOrDefault();
|
|
if (modelData.NamespaceObject == null) continue;
|
|
|
|
outputFileName = Path.Combine(modelData.NamespaceObject.OutFilePath, item.ClassName.Replace("Service", "") + modelData.NamespaceObject.FileNameSuffix);
|
|
if (string.IsNullOrEmpty(outputFileName)) continue;
|
|
|
|
template = File.ReadAllText(Path.Combine(toolInitConfig.TemplatePath, modelData.NamespaceObject.TemplateFileName));
|
|
if (string.IsNullOrEmpty(template)) continue;
|
|
|
|
outputText = RazorEngineHelper.CompiledTemplate(template, modelData);
|
|
if (string.IsNullOrEmpty(outputText)) continue;
|
|
|
|
if (!Directory.Exists(Path.GetDirectoryName(outputFileName))) Directory.CreateDirectory(Path.GetDirectoryName(outputFileName));
|
|
|
|
File.WriteAllText(outputFileName, outputText);
|
|
|
|
|
|
if (!Directory.Exists(Path.GetDirectoryName(logFileName))) Directory.CreateDirectory(Path.GetDirectoryName(logFileName));
|
|
using (StreamWriter w = File.AppendText(logFileName))
|
|
{
|
|
w.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}]Succeed:" + outputFileName);
|
|
}
|
|
//================================
|
|
modelData.NamespaceObject = toolInitConfig.NamespaceObjects.Where(x => x.TemplateType == "TypeScriptService" && x.Assembly == Path.GetFileNameWithoutExtension(assembly.Location)).FirstOrDefault();
|
|
if (modelData.NamespaceObject == null) continue;
|
|
|
|
outputFileName = Path.Combine(modelData.NamespaceObject.OutFilePath, item.ClassName.StringToProtectedProerty() + modelData.NamespaceObject.FileNameSuffix);
|
|
if (string.IsNullOrEmpty(outputFileName)) continue;
|
|
|
|
template = File.ReadAllText(Path.Combine(toolInitConfig.TemplatePath, modelData.NamespaceObject.TemplateFileName));
|
|
if (string.IsNullOrEmpty(template)) continue;
|
|
|
|
outputText = RazorEngineHelper.CompiledTemplate(template, modelData);
|
|
if (string.IsNullOrEmpty(outputText)) continue;
|
|
|
|
if (!Directory.Exists(Path.GetDirectoryName(outputFileName))) Directory.CreateDirectory(Path.GetDirectoryName(outputFileName));
|
|
|
|
File.WriteAllText(outputFileName, outputText);
|
|
|
|
|
|
if (!Directory.Exists(Path.GetDirectoryName(logFileName))) Directory.CreateDirectory(Path.GetDirectoryName(logFileName));
|
|
using (StreamWriter w = File.AppendText(logFileName))
|
|
{
|
|
w.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}]Succeed:" + outputFileName);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string logFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log\\log.txt");
|
|
if (!Directory.Exists(Path.GetDirectoryName(logFileName))) Directory.CreateDirectory(Path.GetDirectoryName(logFileName));
|
|
using (StreamWriter w = File.AppendText(logFileName))
|
|
{
|
|
w.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}]Exception:" + ex.Message);
|
|
}
|
|
}
|
|
}
|
|
} |