|
|
|
|
@ -1,8 +1,10 @@ |
|
|
|
|
using System; |
|
|
|
|
using System.Net; |
|
|
|
|
using System.Threading; |
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
using System.Windows; |
|
|
|
|
using System.Windows.Media; |
|
|
|
|
using RobotClientWpf.Properties; |
|
|
|
|
using RobotClientWpf.Utilities; |
|
|
|
|
using RobotLib; |
|
|
|
|
|
|
|
|
|
@ -13,14 +15,38 @@ namespace RobotClientWpf |
|
|
|
|
/// </summary> |
|
|
|
|
public partial class MainWindow : Window |
|
|
|
|
{ |
|
|
|
|
private bool startupCanceled; |
|
|
|
|
private static Mutex? mutex; // mutex with unique key |
|
|
|
|
private static readonly string mutexName = "00489402-435c-426e-9d11-9a2b839b39b6"; // random guid |
|
|
|
|
|
|
|
|
|
private static readonly NLog.Logger log = NLog.LogManager.GetCurrentClassLogger(); |
|
|
|
|
private ChallengeFactory challenge; |
|
|
|
|
private ChallengeFactory? challenge; |
|
|
|
|
private bool manualDisconnect; |
|
|
|
|
|
|
|
|
|
public MainWindow() |
|
|
|
|
{ |
|
|
|
|
// Check if another instance is already running |
|
|
|
|
// There is already an instance running of this program |
|
|
|
|
if (Mutex.TryOpenExisting(mutexName, out mutex)) |
|
|
|
|
{ |
|
|
|
|
MessageBox.Show("Another instance of RobotClientWpf is already running!" + Environment.NewLine + |
|
|
|
|
"You cannot open multiple instances.", "Already running", MessageBoxButton.OK, MessageBoxImage.Exclamation); |
|
|
|
|
startupCanceled = true; |
|
|
|
|
Application.Current.Shutdown(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// new mutex and keep Alive |
|
|
|
|
mutex = new Mutex(false, mutexName); |
|
|
|
|
GC.KeepAlive(mutex); |
|
|
|
|
|
|
|
|
|
// start window |
|
|
|
|
InitializeComponent(); |
|
|
|
|
this.challenge = new ChallengeFactory(); |
|
|
|
|
// inform other views about challenge factory |
|
|
|
|
this.mainView.SetChallengeFactory(this.challenge); |
|
|
|
|
this.configView.SetChallengeFactory(this.challenge); |
|
|
|
|
// subscribe to events |
|
|
|
|
this.challenge.PublisherSubscriber.ConnectionStateChanged += PublisherSubscriber_ConnectionStateChanged; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -74,7 +100,7 @@ namespace RobotClientWpf |
|
|
|
|
string ipAddress = UIAccessHelpers.GetTextboxText(tbIp); |
|
|
|
|
if (IPAddress.TryParse(ipAddress, out _)) |
|
|
|
|
{ |
|
|
|
|
var connectionSuccess = this.challenge.PublisherSubscriber.Connect(ipAddress); |
|
|
|
|
var connectionSuccess = this.challenge.PublisherSubscriber.Connect(ipAddress, "ADIS", "TEST"); |
|
|
|
|
if (connectionSuccess) |
|
|
|
|
{ |
|
|
|
|
this.DisplayBottomMessage(MessageSeverity.Success, "Successfully connected to MQTT broker."); |
|
|
|
|
@ -132,5 +158,20 @@ namespace RobotClientWpf |
|
|
|
|
{ |
|
|
|
|
this.DisplayBottomMessage(MessageSeverity.Information, ""); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) |
|
|
|
|
{ |
|
|
|
|
if (!startupCanceled) |
|
|
|
|
{ |
|
|
|
|
// save settings |
|
|
|
|
Settings.Default.MqttBrokerIp = this.tbIp.Text; |
|
|
|
|
Settings.Default.Save(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
this.tbIp.Text = Settings.Default.MqttBrokerIp; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|