public SettingsViewModel(LanguageDatabase languageDatabase, SettingsDatabase settingsDatabase, ConnectionInfoDatabase connectionInfoDatabase) { UpdateSettingsVisual(languageDatabase); FileNames = FileOperations.GetFileNames("lang"); if (fileNames.Contains(settingsDatabase.Database["Language"])) { selectedIndex = FileNames.IndexOf(settingsDatabase.Database["Language"]); } SaveSettingsCommand = ReactiveCommand.Create(() => { settingsDatabase.ChangeParameter("Language", FileNames[selectedIndex]); languageDatabase.ImportLanguage(FileNames[selectedIndex]); UpdateSettingsVisual(languageDatabase); connectionInfoDatabase.CreateConnectionText = languageDatabase.Database["CreateConnectionText"]; languageDatabase.SetLanguageForAllElementsInDatabase(connectionInfoDatabase.Database); }); }
public UlConnectViewModel(LanguageDatabase languageDatabase) { this.languageDatabase = languageDatabase; ConnectionInfoDatabase = new ConnectionInfoDatabase(); //Websocket variables validWebsocketAddress = String.Format(@"ws://{0}.{0}.{0}.{0}:8266", @"(1\d{2}||25[012345]||2[01234]\d||[1-9]\d||\d)"); //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.SetLanguageForAllElementsInDatabase(ConnectionInfoDatabase.Database); } //Intialize ReactiveCommands DisconnectButtonCommand = ReactiveCommand.Create(() => { ThreadPool.QueueUserWorkItem(Disconnect); }); ConnectButtonCommand = ReactiveCommand.Create(() => { ThreadPool.QueueUserWorkItem(Connect); }); AddItemButtonCommand = ReactiveCommand.Create(() => { var connItem = new ConnectionInfoItem(); connItem.PageVariables.SetLanguage(languageDatabase.Database); 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()); }