/// <summary> /// Rest Request /// </summary> /// <param name="deviceId"></param> /// <returns></returns> private static bool DeviceEntryExist(long deviceId) { DeviceRequests deviceRequests = new DeviceRequests(); Boolean deviceIdExisting = deviceRequests.DeviceEntryExist(deviceId); if (!deviceIdExisting) { DialogResult dr = GUI.BitscoreForms.BitscoreMessageBox.Show( String.Format("The program can't find the device (#{0}) entry on the server.\n", deviceId) + "Click \"OK\" to fix this issue by re-posting a new device entry on our server.\n\n" + "Note: previous history will not longer be available.", MattimonAgentApplicationAssemblyAttributes.AssemblyProduct, MessageBoxButtons.OKCancel, MessageBoxIcon.Error); if (dr != DialogResult.OK) { return(false); } else { FormBackgroundWorker worker = new FormBackgroundWorker(null, DoWork, "Re-posting device") { RunWorkerCompletedEventHandler = DoWorkCompleted }; worker.DoWork(); } return(false); } return(true); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FormDashboard_Load(object sender, EventArgs e) { FormBackgroundWorker = new FormBackgroundWorker(this, DoWork, "Gathering user settings") { RunWorkerCompletedEventHandler = DoWorkCompleted }; FormBackgroundWorker.DoWork(); MattimonSqlServerDataRequestWorker.RunWorkerAsync(mFromServerDeviceServerObjects); }
private void BackgroundWorkerFetchAll() { worker = new FormBackgroundWorker(this, DoWorkFetchDeviceOptions, "Fetching"); worker.DoWork(); }
private void WorkUpdateDeviceOptions() { worker = new FormBackgroundWorker(this, DoWorkUpdateDeviceOptions, "Posting options"); worker.DoWork(); }
/// <summary> /// /// </summary> /// <param name="instances"></param> private void DeleteSqlServerInstance(ServerInstance[] instances) { string svcPath = string.Empty, svcName = string.Empty; FormBackgroundWorker deleteInstances = new FormBackgroundWorker(this, new DoWorkEventHandler((s, e) => { SQLServerRequests requests = new SQLServerRequests(); DeviceServerObjects dso = new DeviceServerObjects(); dso.DeviceID = GetDeviceID(); dso.Instances = instances; try { svcPath = Path.Combine(RegistryTools.GetInstallLocationByDisplayName( MattimonAgentLibrary.Static.MattimonRegistrySubkeyNames.DisplayName), "MattimonSQLServerService.exe"); if (!File.Exists(svcPath)) { throw new IOException("Could not locate the service file: " + svcPath + ".\n" + "Re-installing the application might fix this issue."); } } catch (IOException ioe) { throw ioe; } catch (Exception ex) { throw ex; } svcName = new ProjectAssemblyAtrributes(svcPath).AssemblyTitle; SQLiteClientDatabase db = GetLocalDatabase(); foreach (ServerInstance si in dso.Instances) { string insname = si.InstanceName.ToLower().Equals("mssqlserver") ? "" : si.InstanceName; db.DeleteConnectionStringEntry(si.ServerName, insname); } e.Result = requests.PostDeviceServerObjects(dso, DeviceServerObjectAction.delete); }), "Deleting Instance(s)"); deleteInstances.RunWorkerCompletedEventHandler = new RunWorkerCompletedEventHandler((s, e) => { if (e.Error != null) { GUI.BitscoreForms.BitscoreMessageBox.Show(this, "An error occurred while attempting to delete SQL Server instances.\n\n" + "Error details:\n" + Tools.ExceptionHelper.GetFormatedExceptionMessage(e.Error), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (e.Result != null && e.Result is DeviceServerObjects dso) { if (dso.Exception != null || dso.HttpRequestException != null) { if (dso.Exception != null) { GUI.BitscoreForms.BitscoreMessageBox.Show(this, "An server-side error occurred.\n\n" + "Error details:\n" + Tools.ExceptionHelper.GetFormatedExceptionMessage(dso.Exception), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (dso.HttpRequestException != null) { GUI.BitscoreForms.BitscoreMessageBox.Show(this, "An server-side error occurred.\n\n" + "Error details:\n" + Tools.ExceptionHelper.GetFormatedExceptionMessage(dso.HttpRequestException), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } BtnSqlSrv_Refresh_Click(btn_sqlsrv_refresh, EventArgs.Empty); GUI.BitscoreForms.BitscoreMessageBox.Show(this, "Instance(s) have been deleted.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } }); deleteInstances.DoWork(); }