【修复】解决不在Luban.Server或者Luban.ClientServer目录运行Luban.Server或者Luban.ClientServer时,生成代码发生无法找到Templates目录的问题。如果未指定-t参数,自动使用程序所在目录的Templates目录。

main
walon 2021-08-26 16:56:29 +08:00
parent 003f4cadb6
commit 77fe01dea6
4 changed files with 22 additions and 4 deletions

View File

@ -7,6 +7,7 @@ using Luban.Common.Utils;
using Luban.Server;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -33,7 +34,7 @@ namespace Luban.ClientServer
public string[] WatchDir { get; set; }
public string StringTemplateDir { get; set; } = "Templates";
public string StringTemplateDir { get; set; }
}
private static void PrintUsage(string err)
@ -205,6 +206,10 @@ Options:
ThreadPool.SetMinThreads(Math.Max(4, processorCount), 5);
ThreadPool.SetMaxThreads(Math.Max(16, processorCount * 4), 10);
if (string.IsNullOrEmpty(options.StringTemplateDir))
{
options.StringTemplateDir = FileUtil.GetPathRelateApplicationDirectory("Templates");
}
if (string.IsNullOrWhiteSpace(options.Host))
{
options.Host = "127.0.0.1";

View File

@ -10,6 +10,16 @@ namespace Luban.Common.Utils
{
private static readonly NLog.Logger s_logger = NLog.LogManager.GetCurrentClassLogger();
public static string GetApplicationDirectory()
{
return Path.GetDirectoryName(System.Reflection.Assembly.GetCallingAssembly().Location);
}
public static string GetPathRelateApplicationDirectory(string relatePath)
{
return Path.Combine(GetApplicationDirectory(), relatePath);
}
public static string GetFileName(string path)
{
int index = path.Replace('\\', '/').LastIndexOf('/');

View File

@ -1,8 +1,7 @@
{
"profiles": {
"Luban.Server": {
"commandName": "Project",
"commandLineArgs": "-p 8899 -t ../../../Templates"
"commandName": "Project"
}
}
}

View File

@ -21,7 +21,7 @@ namespace Luban.Server
public string LogLevel { get; set; } = "INFO";
[Option('t', "string template directory", Required = false, HelpText = "string template directory.")]
public string StringTemplateDir { get; set; } = "Templates";
public string StringTemplateDir { get; set; }
}
private static CommandLineOptions ParseOptions(String[] args)
@ -48,6 +48,10 @@ namespace Luban.Server
var options = ParseOptions(args);
if (string.IsNullOrEmpty(options.StringTemplateDir))
{
options.StringTemplateDir = FileUtil.GetPathRelateApplicationDirectory("Templates");
}
Job.Common.Utils.StringTemplateUtil.TemplateDir = options.StringTemplateDir;
Luban.Common.Utils.LogUtil.InitSimpleNLogConfigure(NLog.LogLevel.FromString(options.LogLevel));