mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2025-12-22 09:29:50 +00:00
DnsServerApp: main method updated to work correctly with console and as a background daemon.
This commit is contained in:
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using DnsServerCore;
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace DnsServerApp
|
||||
{
|
||||
@@ -31,14 +32,26 @@ namespace DnsServerApp
|
||||
if (args.Length == 1)
|
||||
configFolder = args[0];
|
||||
|
||||
DnsWebService service = new DnsWebService(configFolder, new Uri("https://technitium.com/download/dns/updateca2.bin"));
|
||||
DnsWebService service = null;
|
||||
|
||||
try
|
||||
{
|
||||
service = new DnsWebService(configFolder, new Uri("https://technitium.com/download/dns/updateca2.bin"));
|
||||
service.Start();
|
||||
|
||||
Console.WriteLine("Technitium DNS Server was started successfully.");
|
||||
Console.WriteLine("Using config folder: " + service.ConfigFolder);
|
||||
Console.WriteLine("");
|
||||
Console.WriteLine("Note: Open http://localhost:" + service.WebServicePort + "/ in web browser to access web console.");
|
||||
Console.WriteLine("");
|
||||
|
||||
if (Console.IsInputRedirected)
|
||||
{
|
||||
//app running as background service
|
||||
Thread.Sleep(Timeout.Infinite);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Press [CTRL + X] to stop...");
|
||||
|
||||
while (true)
|
||||
@@ -48,9 +61,21 @@ namespace DnsServerApp
|
||||
if (key.Modifiers == ConsoleModifiers.Control && key.Key == ConsoleKey.X)
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (service != null)
|
||||
{
|
||||
Console.WriteLine("Technitium DNS Server is stopping...");
|
||||
service.Dispose();
|
||||
Console.WriteLine("Technitium DNS Server was stopped successfully.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using DnsServerCore;
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace DnsServerApp
|
||||
{
|
||||
@@ -31,14 +32,26 @@ namespace DnsServerApp
|
||||
if (args.Length == 1)
|
||||
configFolder = args[0];
|
||||
|
||||
DnsWebService service = new DnsWebService(configFolder, new Uri("https://technitium.com/download/dns/updatewa2.bin"));
|
||||
DnsWebService service = null;
|
||||
|
||||
try
|
||||
{
|
||||
service = new DnsWebService(configFolder, new Uri("https://technitium.com/download/dns/updatewa2.bin"));
|
||||
service.Start();
|
||||
|
||||
Console.WriteLine("Technitium DNS Server was started successfully.");
|
||||
Console.WriteLine("Using config folder: " + service.ConfigFolder);
|
||||
Console.WriteLine("");
|
||||
Console.WriteLine("Note: Open http://localhost:" + service.WebServicePort + "/ in web browser to access web console.");
|
||||
Console.WriteLine("");
|
||||
|
||||
if (Console.IsInputRedirected)
|
||||
{
|
||||
//app running as background service
|
||||
Thread.Sleep(Timeout.Infinite);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Press [CTRL + X] to stop...");
|
||||
|
||||
while (true)
|
||||
@@ -48,9 +61,21 @@ namespace DnsServerApp
|
||||
if (key.Modifiers == ConsoleModifiers.Control && key.Key == ConsoleKey.X)
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (service != null)
|
||||
{
|
||||
Console.WriteLine("Technitium DNS Server is stopping...");
|
||||
service.Dispose();
|
||||
Console.WriteLine("Technitium DNS Server was stopped successfully.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user