public UlConnectViewModel(LanguageDatabase languageDatabase) { this.languageDatabase = languageDatabase; ConnectionInfoDatabase = new ConnectionInfoDatabase(); //Websocket variables validWebsocketAddress = String.Format(@"ws://{0}.{0}.{0}.{0}:8266", @"(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])"); //regex for valid IP rg = new Regex(validWebsocketAddress); webSockets = new SortedList <int, WebsocketWithTimer>(); //Database configuration SelectedIndex = 0; ConnectionInfoDatabase.ImportDatabaseFromFile("data"); if (ConnectionInfoDatabase.Database.Count != 0) { ConnectionInfoDatabase.IsDatabaseEmpty = false; languageDatabase.SetLanguageForConnDatabaseElements(this.ConnectionInfoDatabase.Database); } //Intialize ReactiveCommands DisconnectButtonCommand = ReactiveCommand.Create(() => { ThreadPool.QueueUserWorkItem(Disconnect); }); ConnectButtonCommand = ReactiveCommand.Create(() => { ThreadPool.QueueUserWorkItem(Connect); }); AddItemButtonCommand = ReactiveCommand.Create(() => { var connItem = new ConnectionInfoItem(); languageDatabase.SetLanguageForConnection(connItem.PageVariables); ConnectionInfoDatabase.AddItem(connItem, "data"); }); RemoveItemButtonCommand = ReactiveCommand.Create(() => { if (ConnectionInfoDatabase.Database.Count != 0) { ConnectionInfoDatabase.RemoveItem(SelectedIndex, "data"); if (webSockets.Keys.Contains(SelectedIndex)) //Checking if tab has runned WebSocket { CloseWebSocket(SelectedIndex, true); } } }); SaveInfoButtonCommand = ReactiveCommand.Create(() => { ConnectionInfoDatabase.SaveInfo(SelectedIndex, "data"); }); SendSignalButtonCommand = ReactiveCommand.Create(() => SendSignal()); }