///<summary>Timer that runs every minute and queries the current database connection for the StopWebCamSnapshot preference. ///Updates _isStopWebCamSnapshot to reflect the current preference value. This is so that we do not have to process signals.</summary> private void TimerStopWebCamSnapshotPref_Tick(object sender, EventArgs e) { _timerStopWebCamSnapshotPref.Stop(); ODException.SwallowAnyException(() => { DataAction.RunCustomers(() => { _isStopWebCamSnapshot = Prefs.GetBoolNoCache(PrefName.StopWebCamSnapshot); }, useConnectionStore: false); }); _timerStopWebCamSnapshotPref.Start(); }
public void DataAction_RunCustomers_Default() { //Delete any sitelink entries so that there are no overrides in the database. SiteLinkT.ClearSiteLinkTable(); string databaseName = ""; DataAction.RunCustomers(() => { databaseName = DataConnection.GetDatabaseName(); }, useConnectionStore: false); Assert.AreEqual(_databaseNameCustomersHQ, databaseName); }
public void DataAction_RunCustomers_Override() { SiteT.ClearSiteTable(); SiteLinkT.ClearSiteLinkTable(); Site site = SiteT.CreateSite(MethodBase.GetCurrentMethod().Name); SiteLink siteLink = SiteLinkT.CreateSiteLink(site.SiteNum, octetStart: ODEnvironment.GetLocalIPAddress(), connectionSettingsHQOverrides: GetJsonSerializedConnectionOverride(ConnectionNames.CustomersHQ, "127.0.0.1", _databaseNameCustomersHQ, "root", "")); string serverName = ""; DataAction.RunCustomers(() => { serverName = DataConnection.GetServerName(); }, useConnectionStore: false); Assert.AreEqual("127.0.0.1", serverName); Assert.AreNotEqual(_dictConnectionDefaults[ConnectionNames.CustomersHQ].ServerName, serverName); }
///<summary>Returns true if db success; otherwise returns false.</summary> private bool SetProximity(bool isProximal) { try { if (Extension == 0) { return(false); //There is most likely a setup issue or db connection problem. } DataAction.RunCustomers(() => Phones.SetProximity(isProximal, Extension), useConnectionStore: false); //We got here so everything worked ok. return(true); } catch (Exception e) { e.DoNothing(); } //We got here so something failed. return(false); }
///<summary>Attempts to connect and get connection settings from the database that is used by DataAction.RunCustomers(). ///Returns true and sets text boxes to the corresponding connectino setting values if a successful connection was made. ///Otherwise; displays an error message to the user and returns false. Assumes a connection to a 'customers' db has already been made.</summary> private bool TryDatabaseConnectionSettings() { //Assume that we have a guaranteed connection to HQ's 'customers' database. //Look and see what connection settings this computer should use via DataAction.RunCustomers(). _timerDatabase.Stop(); try { //Clear out the currently cached HQ database connections and refresh both the preference and site link caches. DataAction.ClearDictHqCentralConnections(); Prefs.RefreshCache(); SiteLinks.RefreshCache(); string serverName = ""; string databaseName = ""; string mySqlUser = ""; string mySqlPassword = ""; Action action = () => { serverName = DataConnection.GetServerName(); databaseName = DataConnection.GetDatabaseName(); mySqlUser = DataConnection.GetMysqlUser(); mySqlPassword = DataConnection.GetMysqlPass(); }; DataAction.RunCustomers(action, useConnectionStore: false); //Display the settings to the user so that we can easily tell what database this instance is pointing to. textServerName.Text = serverName; textDatabaseName.Text = databaseName; textMySQLUser.Text = mySqlUser; textMySQLPassword.Text = mySqlPassword; } catch (Exception ex) { labelError.Visible = true; MessageBox.Show(this, "There was an error making a connection to the database.\r\n" + "Please correct the database connection settings then click Reconnect.\r\n\r\n" + ex.Message); return(false); } _timerDatabase.Start(); return(true); }
private void butDiagnostics_Click(object sender, EventArgs e) { BugSubmission.SubmissionInfo subInfo = new BugSubmission(new Exception()).Info; StringBuilder strBuilder = new StringBuilder(); foreach (FieldInfo field in subInfo.GetType().GetFields()) { object value = field.GetValue(subInfo); if (value.In(null, "")) { continue; } if (value is Dictionary <PrefName, string> ) //DictPrefValues { Dictionary <PrefName, string> dictPrefValues = value as Dictionary <PrefName, string>; if (dictPrefValues.Keys.Count > 0) { strBuilder.AppendLine(field.Name + ":"); dictPrefValues.ToList().ForEach(x => strBuilder.AppendLine(" " + x.Key.ToString() + ": " + x.Value)); strBuilder.AppendLine("-------------"); } } else if (value is List <string> ) //EnabledPlugins { List <string> enabledPlugins = value as List <string>; if (enabledPlugins.Count > 0) { strBuilder.AppendLine(field.Name + ":"); enabledPlugins.ForEach(x => strBuilder.AppendLine(" " + x)); strBuilder.AppendLine("-------------"); } } else if (value is bool) { strBuilder.AppendLine(field.Name + ": " + (((bool)value) == true?"true":"false")); } else { strBuilder.AppendLine(field.Name + ": " + value); } } //Display the current HQ connection information. if (PrefC.IsODHQ) { Action <ConnectionNames> action = (connName) => { strBuilder.AppendLine($"{connName.ToString()}:"); strBuilder.AppendLine($" Server Name: {DataConnection.GetServerName()}"); strBuilder.AppendLine($" Database Name: {DataConnection.GetDatabaseName()}"); strBuilder.AppendLine($" MySQL User: {DataConnection.GetMysqlUser()}"); strBuilder.AppendLine($" MySQL Password: {DataConnection.GetMysqlPass()}"); }; strBuilder.AppendLine("-------------"); strBuilder.AppendLine("HQ Connection Settings"); try { DataAction.RunBugsHQ(() => action(ConnectionNames.BugsHQ), useConnectionStore: false); DataAction.RunCustomers(() => action(ConnectionNames.CustomersHQ), useConnectionStore: false); DataAction.RunManualPublisherHQ(() => action(ConnectionNames.ManualPublisher)); DataAction.RunWebChat(() => action(ConnectionNames.WebChat)); } catch (Exception ex) { strBuilder.AppendLine($"ERROR: {ex.Message}"); } strBuilder.AppendLine("-------------"); } MsgBoxCopyPaste msgbox = new MsgBoxCopyPaste(strBuilder.ToString()); msgbox.Text = Lans.g(this, "Diagnostics"); msgbox.ShowDialog(); }