private void RestartServiceWorker(object param) { Thread worker = param as Thread; if ((worker != null) && workers.Contains(worker)) { workers.Remove(worker); } ServiceController service = services.Values[serviceView.SelectedIndices[0]].Controller; try { this.Invoke(new StringInvoker(delegate(string serviceName) { statusBox.Text = String.Format( translator.GetString("StoppingMsg"), serviceName ); }), service.ServiceName); service.Stop(); service.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 10)); this.Invoke(new StringInvoker(delegate(string serviceName) { statusBox.Text = String.Format( translator.GetString("StartingMsg"), serviceName ); }), service.ServiceName); service.Start(); service.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 10)); } catch (System.ServiceProcess.TimeoutException) { //MessageBox.Show( // translator.GetString("RestartTimeoutMsg"), // translator.GetString("TimeoutTitle"), // MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception exc) { ExceptionDialog.ShowException(exc); } if (refreshTimer != null) { DiscoverServices(); } this.Invoke(new MethodInvoker(delegate { statusBox.Text = String.Empty; })); }
private void StopServiceWorker(object param) { ThreadItem item = param as ThreadItem; if (workers.Contains(item.Worker)) { workers.Remove(item.Worker); } ServiceController service = item.Service; this.Invoke(new StringInvoker(delegate(string serviceName) { statusBox.Text = String.Format( translator.GetString("StoppingMsg"), serviceName ); }), service.ServiceName); service.Stop(); try { service.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 15)); } catch (System.ServiceProcess.TimeoutException) { //MessageBox.Show( // translator.GetString("StopTimeoutMsg"), // translator.GetString("TimeoutTitle"), // MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception exc) { ExceptionDialog.ShowException(exc); } if (refreshTimer != null) { DiscoverServices(); } this.Invoke(new MethodInvoker(delegate { statusBox.Text = String.Empty; })); }
//======================================================================================== // Connect() //======================================================================================== private bool Connect() { this.Cursor = Cursors.WaitCursor; this.Capture = true; EnableControls(false); var settings = new XElement("lastConnection"); string userID = userIDBox.Text.Trim(); string password = passwordBox.Text.Trim(); settings.Add(new XElement("userID", userID)); settings.Add(new XElement("mode", modeBox.Text)); if (modeBox.SelectedIndex > 0) { userID += ";DBA Privilege=" + modeBox.Text; //password += " as " + modeBox.Text; } if (localButton.Checked) { if (status != null) { status.Text = String.Format( translator.GetString("ConnectingToLocalMsg"), userID, password ); } connection = new DatabaseConnection(userID, password); settings.Add(new XElement("method", "local")); } else if (tnsButton.Checked) { string tns = tnsBox.Text.Trim(); if (status != null) { status.Text = String.Format( translator.GetString("ConnectingToTNSMsg"), tns ); } connection = new DatabaseConnection(userID, password, tns); settings.Add(new XElement("method", "tns")); settings.Add(new XElement("tns", tns)); } else { string host = hostBox.Text.Trim(); int port = int.Parse(portBox.Text.Trim()); string service = serviceBox.Text.Trim(); if (status != null) { status.Text = String.Format( translator.GetString("ConnectingToRemoteMsg"), host, port, service ); } connection = new DatabaseConnection(userID, password, host, port, service); settings.Add(new XElement("method", "remote")); settings.Add(new XElement("host", host)); settings.Add(new XElement("port", port)); settings.Add(new XElement("service", service)); } if (status != null) { status.Text = String.Empty; } if (connection != null) { try { object con = connection.OraConnection; } catch (Exception exc) { ExceptionDialog.ShowException(exc); connection = null; } } this.Capture = false; this.Cursor = Cursors.Default; if (connection != null) { UserOptions.SetValue("general/lastConnection", settings); UserOptions.Save(); return(true); } EnableControls(true); return(false); }
//======================================================================================== // ShowException() //======================================================================================== public static void ShowException(Exception exc) { ExceptionDialog dialog = new ExceptionDialog(exc); dialog.ShowDialog(); }