74 lines
3.0 KiB
C#
74 lines
3.0 KiB
C#
using System.Net;
|
|
|
|
namespace NWService
|
|
{
|
|
public class OptionConsole
|
|
{
|
|
public static ServiceMode GetServiceMode(LanguageXml language)
|
|
{
|
|
var arry = Enum.GetValues(typeof(ServiceMode));
|
|
for (int i = 0 ; i < arry.Length ; i++)
|
|
{
|
|
Console.WriteLine("[{0}]: {1}", i, language.GetMessage(arry.GetValue(i).ToString(), arry.GetValue(i).ToString()));
|
|
}
|
|
|
|
Console.Write("{0} ", language.GetMessage("select_service_mode", "Please type service mode:"));
|
|
string tInput = Console.ReadLine();
|
|
if (string.IsNullOrWhiteSpace(tInput) || !int.TryParse(tInput, out int mode))
|
|
{
|
|
throw new ArgumentException(string.Format("{0}", language.GetMessage("exception_invalid_input_mode", "invalid input mode.")));
|
|
}
|
|
|
|
if (mode < 0 || mode > arry.Length)
|
|
{
|
|
throw new ArgumentException(string.Format("{0}", language.GetMessage("exception_invalid_input_mode", "invalid input mode.")));
|
|
}
|
|
|
|
return (ServiceMode) mode;
|
|
}
|
|
|
|
public static IPAddress GetIPAddress(List<IPAddress> localIPv4, LanguageXml language)
|
|
{
|
|
for (int i = 0 ; i < localIPv4.Count(); i++)
|
|
{
|
|
Console.WriteLine("#{0}: {1}", i + 1, localIPv4[i]);
|
|
}
|
|
|
|
Console.WriteLine("[0]: {0}", language.GetMessage("select_target_ipaddr", "Type target IPAddress."));
|
|
Console.WriteLine("[1-]: {0}", language.GetMessage("select_local_ipaddr", "Select local IPAddress."));
|
|
Console.Write("{0} ", language.GetMessage("type_mode", "Please type select mode:"));
|
|
|
|
string tMode = Console.ReadLine();
|
|
if (string.IsNullOrWhiteSpace(tMode))
|
|
{
|
|
throw new ArgumentException(string.Format("{0}", language.GetMessage("exception_invalid_input_mode", "invalid input mode.")));
|
|
}
|
|
|
|
if (!int.TryParse(tMode, out int mode))
|
|
{
|
|
throw new ArgumentException(string.Format("{0}", language.GetMessage("exception_invalid_input_mode", "invalid input mode.")));
|
|
}
|
|
|
|
if (mode == 0)
|
|
{
|
|
Console.Write("{0} ", language.GetMessage("type_target_ipaddr", "Please type target IPAddress:"));
|
|
string tmpAddr = Console.ReadLine();
|
|
if (!IPAddress.TryParse(tmpAddr, out IPAddress addr))
|
|
{
|
|
throw new ArgumentException(string.Format("{0}", language.GetMessage("exception_invalid_input_ipaddr", "invalid input IPAddress.")));
|
|
}
|
|
|
|
return addr;
|
|
}
|
|
|
|
mode = mode - 1;
|
|
|
|
if (mode < 0 || mode > localIPv4.Count())
|
|
{
|
|
throw new ArgumentException(string.Format("{0}", language.GetMessage("exception_invalid_input_mode", "invalid input mode.")));
|
|
}
|
|
|
|
return localIPv4[mode];
|
|
}
|
|
}
|
|
} |