public SettingsViewModel(LanguageDatabase languageDatabase, SettingsDatabase settingsDatabase, ConnectionInfoDatabase connectionInfoDatabase) { UpdateSettingsVisual(languageDatabase); FileNames = FileOperations.GetFileNames("lang", FileOperations.IsJsonChecker); if (FileNames.Count == 0) { FileOperations.AddUnsucessfullImportTask("Missing language files in \nlang folder"); FileOperations.UnsuccessImportTaskStack.Pop().Start(); } if (settingsDatabase.Database.ContainsKey("Language")) { if (fileNames.Contains(settingsDatabase.Database["Language"])) { selectedIndex = FileNames.IndexOf(settingsDatabase.Database["Language"]); } } else { selectedIndex = 0; } SaveSettingsCommand = ReactiveCommand.Create(() => { settingsDatabase.ChangeParameter("Language", FileNames[selectedIndex]); languageDatabase.ImportLanguage(FileNames[selectedIndex]); UpdateSettingsVisual(languageDatabase); connectionInfoDatabase.CreateConnectionText = languageDatabase.Database["CreateConnectionText"]; languageDatabase.SetLanguageForConnDatabaseElements(connectionInfoDatabase.Database); }); }
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()); }