Fix Server shutdown

This commit is contained in:
Li 2022-11-27 11:19:41 +13:00
parent 7ed10a6bca
commit 245f2d3e48
8 changed files with 276 additions and 112 deletions

View file

@ -11,7 +11,7 @@ namespace HISP.Cli
private static StreamWriter sw = null;
private static FileStream fs = null;
private static string logFile;
private static EventWaitHandle shutdownHandle;
private static EventWaitHandle shutdownHandle = null;
public static bool ShuttingDown = false;
public static string BaseDir;
@ -44,22 +44,34 @@ namespace HISP.Cli
public static void OnShutdown()
{
if(fs != null)
try
{
fs.Flush();
fs.Close();
fs.Dispose();
fs = null;
}
if(sw != null)
{
sw.Flush();
sw.Close();
sw.Dispose();
sw = null;
}
if (sw != null)
{
sw.Flush();
sw.Close();
sw.Dispose();
sw = null;
}
shutdownHandle.Set();
}
catch (Exception) { };
try
{
if (fs != null)
{
fs.Flush();
fs.Close();
fs.Dispose();
fs = null;
}
}
catch (Exception) { };
if(shutdownHandle != null)
shutdownHandle.Set();
}
private static string formatMessage(string type, string text)
@ -70,7 +82,12 @@ namespace HISP.Cli
string newline = "\n";
#endif
return DateTime.Now.ToString("MM-dd-yyyy HH:mm:dd") + ": [" + type + "] " + text + newline;
string msg = DateTime.Now.ToString("MM dd yyyy HH:mm:dd") + ": [" + type + "] ";
if (text.Length > (Console.WindowWidth - msg.Length) - newline.Length)
text = text.Substring(0, (Console.WindowWidth - msg.Length) - newline.Length);
return msg + text + newline;
}
public static void LogToFile(bool error, string type,string text)
@ -89,6 +106,7 @@ namespace HISP.Cli
Console.Error.WriteAsync(formatMessage(type, text));
else
Console.Out.WriteAsync(formatMessage(type, text));
}
catch (Exception) { };
}

View file

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.8.59.0")]
[assembly: AssemblyFileVersion("1.8.59.0")]
[assembly: AssemblyVersion("1.8.61.0")]
[assembly: AssemblyFileVersion("1.8.61.0")]

View file

@ -1,5 +1,5 @@
Package: hisp
Version: 1.8.59
Version: 1.8.61
Depends: coreutils,systemd,mariadb-server,libsqlite3-dev,zlib1g-dev,libicu-dev,libkrb5-dev
Maintainer: Li
Homepage: https://islehorse.com