Files
cms_thermo_active/Step/program.cs
T
2018-02-15 12:23:23 +01:00

70 lines
2.1 KiB
C#

using Microsoft.Owin.Hosting;
using Step.UI;
using System.Threading;
using TeamDev.SDK.MVVM;
using Step.Config;
using static Step.Config.ServerConfig;
using static Step.Utils.StepLogger;
using static Step.Utils.Constants;
using Step.Database;
using Step.Core;
using Step.Listeners;
using System;
using Step.Utils;
namespace Step
{
public class Application
{
public static readonly ManualResetEvent StopRequest = new ManualResetEvent(false);
//Set the Mutef of GUID
private static Mutex CmsStepMutex = new Mutex(true, "{689e76ce-b845-49f0-919c-c26491079fca}");
public static int MessageService { get; private set; }
public static void Main()
{
LogInfo("Application started");
//Check if is already running an instance of this application
if (!CmsStepMutex.WaitOne(TimeSpan.Zero, true))
ExceptionManager.Manage(ERROR_LEVEL.FATAL, "Only one istance of can be executed!");
ServerConfigController.ReadStartupConfig();
DatabaseContext.SetUpDbConnectionAndDbConfig();
// Start self host application
string configuredUri = "http://*:" + ServerStartupConfig.ServerPort.ToString();
// Register listener to "close application" messages
MessageServices.Current.Subscribe(SEND_STOP_SERVER, (a, b) =>
{
StopRequest.Set();
});
// Start server services
using (WebApp.Start<Step.App_Start.Startup>(url: configuredUri))
{
// Start WinForm
ServerControlWindow.Start();
// Start Threads
ThreadsHandler.Start();
// Start listeners
ListenersHandler.Start();
// Wait interrupt from client
StopRequest.WaitOne();
LogInfo("Application closed");
}
// Stop Threads
ThreadsHandler.Close();
// Stop messageservice listeners
ListenersHandler.Stop();
// Close WinForm
ServerControlWindow.Stop();
}
}
}