Files
cms_thermo_active/Step.UI/ServerControlWindow.cs
T
CMS3762\carminatini 1e56f6e6d3 - Client Configuration on XML File
- Refactoring Projects in the solution
2017-12-05 14:26:27 +01:00

111 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using TeamDev.SDK.MVVM;
using static Step.Config.StartupConfig;
namespace Step.UI
{
public partial class ServerControlWindow : Form
{
String HomePageUI;
public ServerControlWindow()
{
InitializeComponent();
HomePageUI = "http://localhost:" + ServerConfig.ServerPort.ToString() + "/index.html";
}
private static ServerControlWindow ctrlwindow = null;
public static void Start()
{ // Open WinForm
Thread th = new Thread(() =>
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
ctrlwindow = new ServerControlWindow();
Application.Run(ctrlwindow);
});
th.SetApartmentState(ApartmentState.STA);
th.Start();
}
public static void Stop()
{ // Close WinForm
if (ctrlwindow != null)
{
ctrlwindow.Invoke((ThreadStart)delegate ()
{
ctrlwindow._closing = true;
ctrlwindow.Close();
ctrlwindow = null;
});
}
}
private bool _closing = false;
// Avoid closing the window
protected override void OnClosing(CancelEventArgs e)
{
if (!_closing)
{
e.Cancel = true;
this.Hide();
}
}
private void OpenUiButton_Click(object sender, EventArgs e)
{
//Open CMS Client
StartCMSClient();
}
private void StopServerButton_Click(object sender, EventArgs e)
{
// Send message to listeners and close server
MessageServices.Current.Publish("StopServer");
}
private void notifyIcon1_Click(object sender, EventArgs e)
{
this.Show();
this.TopMost = true;
this.TopMost = false;
}
private void StopServerItem_Click(object sender, EventArgs e)
{
MessageServices.Current.Publish("StopServer");
}
private void StartCMSClient()
{
//Setup the Path Variable
String CMSClientPath = "";
//Check if the system is 64/32 bit
if (Environment.Is64BitOperatingSystem && File.Exists(Environment.CurrentDirectory + @"\Client\x64\CMS_Client.exe"))
CMSClientPath = Environment.CurrentDirectory + @"\Client\x64\CMS_Client.exe";
else if (File.Exists(Environment.CurrentDirectory + @"\Client\x86\CMS_Client.exe"))
CMSClientPath = Environment.CurrentDirectory + @"\Client\x86\CMS_Client.exe";
if(!String.IsNullOrEmpty(CMSClientPath))
Process.Start(CMSClientPath, HomePageUI);
else
MessageBox.Show("CMS_Client.Exe not found");
}
}
}