public void DataAction_GetHqConnections_Defaults() { Dictionary <ConnectionNames, CentralConnection> dictHqConnections = DataAction.GetHqConnections(); Assert.IsNotNull(dictHqConnections); Assert.AreEqual(_dictConnectionDefaults.Count, dictHqConnections.Count); foreach (ConnectionNames connectionName in _dictConnectionDefaults.Keys) { Assert.IsTrue(AreConnsEqual(_dictConnectionDefaults[connectionName], dictHqConnections[connectionName])); } }
private void FillGridConnections() { Dictionary <ConnectionNames, CentralConnection> dictConnDefaults = null; ODException.SwallowAnyException(() => { dictConnDefaults = DataAction.GetHqConnections(); }); if (dictConnDefaults == null) { MsgBox.Show("Error loading default HQ connections. Please restart Open Dental or log off and log back in."); return; } Dictionary <ConnectionNames, CentralConnection> dictConnOverrides = _siteLink.DictConnectionSettingsHQOverrides; gridConnections.BeginUpdate(); if (gridConnections.ListGridColumns.Count < 1) { //The order of these columns matter. See GetConnectionOverrides() gridConnections.ListGridColumns.Add(new GridColumn("Conn Name", -1)); gridConnections.ListGridColumns.Add(new GridColumn("Server", -1, true)); gridConnections.ListGridColumns.Add(new GridColumn("Database", -1, true)); gridConnections.ListGridColumns.Add(new GridColumn("User", -1, true)); gridConnections.ListGridColumns.Add(new GridColumn("Password", -1, true)); } Action <ConnectionNames> actionAddConnection = (connName) => { GridRow row = new GridRow(); CentralConnection connection = dictConnDefaults[connName]; if (dictConnOverrides != null && dictConnOverrides.ContainsKey(connName)) { connection = dictConnOverrides[connName]; row.Bold = true; } row.Cells.Add(connName.ToString()); row.Cells.Add(connection.ServerName ?? ""); row.Cells.Add(connection.DatabaseName ?? ""); row.Cells.Add(connection.MySqlUser ?? ""); row.Cells.Add(connection.MySqlPassword ?? ""); row.Tag = connName; gridConnections.ListGridRows.Add(row); }; gridConnections.ListGridRows.Clear(); actionAddConnection(ConnectionNames.BugsHQ); actionAddConnection(ConnectionNames.CustomersHQ); actionAddConnection(ConnectionNames.ManualPublisher); actionAddConnection(ConnectionNames.WebChat); gridConnections.EndUpdate(); }
///<summary>Returns a JSON serialized version of a connection override dictionary based off of gridConnection. ///Users can edit cells of the grid to change the site overrides and this method returns what should be saved to the db.</summary> private string GetConnectionOverrides() { string retVal = ""; Dictionary <ConnectionNames, CentralConnection> dictConnDefaults = DataAction.GetHqConnections(); Dictionary <ConnectionNames, CentralConnection> dictConnOverrides = new Dictionary <ConnectionNames, CentralConnection>(); foreach (GridRow row in gridConnections.ListGridRows) { ConnectionNames connName = (ConnectionNames)row.Tag; if (!dictConnDefaults.ContainsKey(connName)) { continue; //Should never happen. } CentralConnection connectionDefault = dictConnDefaults[connName]; //Read in the cell text and create an override if any of the values differ from the default. string serverName = row.Cells[1].Text; string databaseName = row.Cells[2].Text; string mySqlUser = row.Cells[3].Text; string mySqlPassword = row.Cells[4].Text; if (serverName.IsNullOrEmpty() && databaseName.IsNullOrEmpty() && mySqlUser.IsNullOrEmpty() && mySqlPassword.IsNullOrEmpty()) { continue; //Do not add an override, this will cause the connection to go back to using the default. } if (serverName != connectionDefault.ServerName || databaseName != connectionDefault.DatabaseName || mySqlUser != connectionDefault.MySqlUser || mySqlPassword != connectionDefault.MySqlPassword) { dictConnOverrides[connName] = new CentralConnection() { ServerName = serverName, DatabaseName = databaseName, MySqlUser = mySqlUser, MySqlPassword = mySqlPassword }; } } if (dictConnOverrides.Count > 0) { retVal = GetOverridesSerialized(dictConnOverrides); } return(retVal); }