|
|
|
@ -3,6 +3,7 @@ |
|
|
|
// Copyright(c) 2020 SimonG. All Rights Reserved. |
|
|
|
// Copyright(c) 2020 SimonG. All Rights Reserved. |
|
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
using System; |
|
|
|
|
|
|
|
using System.IO; |
|
|
|
using System.Net; |
|
|
|
using System.Net; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using GBase.Logging; |
|
|
|
using GBase.Logging; |
|
|
|
@ -17,17 +18,28 @@ namespace GBase.Server |
|
|
|
private const string IP_ADDRESS_ARGUMENT_PREFIX = "-ip"; |
|
|
|
private const string IP_ADDRESS_ARGUMENT_PREFIX = "-ip"; |
|
|
|
private const string PORT_ARGUMENT_PREFIX = "-p"; |
|
|
|
private const string PORT_ARGUMENT_PREFIX = "-p"; |
|
|
|
private const string ENDPOINT_ARGUMENT_PREFIX = "-e"; |
|
|
|
private const string ENDPOINT_ARGUMENT_PREFIX = "-e"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private const string LOG_FILE_PATH_ARGUMENT_PREFIX = "-lp"; |
|
|
|
|
|
|
|
private const string LOG_FILE_NAME_ARGUMENT_PREFIX = "-ln"; |
|
|
|
|
|
|
|
|
|
|
|
private const string HELP_ARGUMENT_PREFIX = "-help"; |
|
|
|
private const string HELP_ARGUMENT_PREFIX = "-help"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private readonly string _defaultLogFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "GBase", "Server", "Logs"); |
|
|
|
|
|
|
|
private readonly string _defaultLogFileName = $"GBaseServer_Log_{DateTime.Now:yyyy_MM_dd}_{DateTime.Now:hh_mm_ss}.txt"; |
|
|
|
|
|
|
|
|
|
|
|
private bool _protocolInitialized; |
|
|
|
private bool _protocolInitialized; |
|
|
|
private bool _ipAddressInitialized; |
|
|
|
private bool _ipAddressInitialized; |
|
|
|
private bool _portInitialized; |
|
|
|
private bool _portInitialized; |
|
|
|
private bool _endpointInitialized; |
|
|
|
private bool _endpointInitialized; |
|
|
|
|
|
|
|
private bool _logFilePathInitialized; |
|
|
|
|
|
|
|
private bool _logFileNameInitialized; |
|
|
|
|
|
|
|
|
|
|
|
public ServerProtocol Protocol { get; private set; } |
|
|
|
public ServerProtocol Protocol { get; private set; } |
|
|
|
public IPAddress IpAddress { get; private set; } |
|
|
|
public IPAddress IpAddress { get; private set; } |
|
|
|
public int Port { get; private set; } |
|
|
|
public int Port { get; private set; } |
|
|
|
public string Endpoint { get; private set; } |
|
|
|
public string Endpoint { get; private set; } |
|
|
|
|
|
|
|
public string LogFilePath { get; private set; } |
|
|
|
|
|
|
|
public string LogFileName { get; private set; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task ParseArguments(string[] args) |
|
|
|
public async Task ParseArguments(string[] args) |
|
|
|
@ -66,6 +78,22 @@ namespace GBase.Server |
|
|
|
Endpoint = args[index]; |
|
|
|
Endpoint = args[index]; |
|
|
|
_endpointInitialized = true; |
|
|
|
_endpointInitialized = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if (args[index] == LOG_FILE_PATH_ARGUMENT_PREFIX) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
index++; |
|
|
|
|
|
|
|
await VerifyArgsLength(index, args.Length); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LogFilePath = args[index]; |
|
|
|
|
|
|
|
_logFilePathInitialized = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (args[index] == LOG_FILE_NAME_ARGUMENT_PREFIX) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
index++; |
|
|
|
|
|
|
|
await VerifyArgsLength(index, args.Length); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LogFileName = args[index]; |
|
|
|
|
|
|
|
_logFileNameInitialized = true; |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
await PrintHelp(); |
|
|
|
await PrintHelp(); |
|
|
|
@ -88,6 +116,14 @@ namespace GBase.Server |
|
|
|
|
|
|
|
|
|
|
|
private async Task<bool> VerifySettings() |
|
|
|
private async Task<bool> VerifySettings() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
//optional settings |
|
|
|
|
|
|
|
if (!_logFilePathInitialized) |
|
|
|
|
|
|
|
LogFilePath = _defaultLogFilePath; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!_logFileNameInitialized) |
|
|
|
|
|
|
|
LogFileName = _defaultLogFileName; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//mandatory settings |
|
|
|
if (_protocolInitialized && _ipAddressInitialized && _portInitialized && _endpointInitialized) |
|
|
|
if (_protocolInitialized && _ipAddressInitialized && _portInitialized && _endpointInitialized) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
@ -115,7 +151,11 @@ namespace GBase.Server |
|
|
|
await Log.Write<GBaseServerSettings>($"{PROTOCOL_ARGUMENT_PREFIX}: The used protocol (e.g 'http' or 'https')"); |
|
|
|
await Log.Write<GBaseServerSettings>($"{PROTOCOL_ARGUMENT_PREFIX}: The used protocol (e.g 'http' or 'https')"); |
|
|
|
await Log.Write<GBaseServerSettings>($"{IP_ADDRESS_ARGUMENT_PREFIX}: The used ip address"); |
|
|
|
await Log.Write<GBaseServerSettings>($"{IP_ADDRESS_ARGUMENT_PREFIX}: The used ip address"); |
|
|
|
await Log.Write<GBaseServerSettings>($"{PORT_ARGUMENT_PREFIX}: The used port"); |
|
|
|
await Log.Write<GBaseServerSettings>($"{PORT_ARGUMENT_PREFIX}: The used port"); |
|
|
|
await Log.Write<GBaseServerSettings>($"{Endpoint}: The used endpoint"); |
|
|
|
await Log.Write<GBaseServerSettings>($"{ENDPOINT_ARGUMENT_PREFIX}: The used endpoint"); |
|
|
|
|
|
|
|
await Log.Write<GBaseServerSettings>(""); |
|
|
|
|
|
|
|
await Log.Write<GBaseServerSettings>("Optional Arguments:"); |
|
|
|
|
|
|
|
await Log.Write<GBaseServerSettings>($"{LOG_FILE_PATH_ARGUMENT_PREFIX}: The path to the server log file (default: '{_defaultLogFilePath}')"); |
|
|
|
|
|
|
|
await Log.Write<GBaseServerSettings>($"{LOG_FILE_NAME_ARGUMENT_PREFIX}: The name of the server log file (default: 'GBaseServer_Log_$day_$time.txt')"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |