/// <summary> /// Posts and returns the updated DeviceServerObjects as echo. /// </summary> /// <param name="dso"></param> /// <returns></returns> private DeviceServerObjects PostServerObjects(DeviceServerObjects dso) { SQLServerRequests requests = new SQLServerRequests(); dso = requests.PostDeviceServerObjects(dso, DeviceServerObjectAction.insert); return(dso); }
/// <summary> /// /// </summary> /// <returns></returns> private DeviceServerObjects RequestDeviceServerObjects() { SQLServerRequests serverRequests = new SQLServerRequests(); DeviceServerObjects serverObjects = serverRequests.PostDeviceServerObjects(new DeviceServerObjects { DeviceID = GetDeviceID() }, DeviceServerObjectAction.select); new MattimonAgentLibrary.Tools.DebugTools.TextLogging().LogToFile(serverObjects, mWriteLogToInstallDirectory, out Exception exception); if (exception != null) { new System.Threading.Thread(() => { Invoke((MethodInvoker) delegate() { GUI.BitscoreForms.BitscoreMessageBox.Show("An error occurred while attempted to read or write to local log file.\nYou may simply ignore this error." + "\n\nError details:\n" + exception.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); }); }); } return(serverObjects); }
/// <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(); }