/// <summary> /// Shows service options dialog and restarts service if needed. /// </summary> private void ConfigureService() { // Check we are already configuring service. if (this.IsConfiguring) { return; } try { this.Timer.Stop(); this.Tray.Icon = this.ServiceConfiguredIcon; this.IsConfiguring = true; // Getting service options. APCServiceOptions remoteOptions = ((APCServiceOptions)(System.Activator.GetObject(typeof(APCServiceOptions), String.Format("tcp://{0}:{1}/APCService.rem", this.APCServiceController.MachineName, this.APCSrvOpt.MachinePort)))); // Copy all the values to a local class. APCServiceOptions localOptions = new APCServiceOptions(); remoteOptions.CopyTo(localOptions); // Creating window. this.ConfigForm = new ConfigureForm(this.APCServiceController.ServiceName, this.APCServiceController.MachineName, localOptions); ConfigForm.BringToFront(); ConfigForm.TopMost = true; ConfigForm.TopMost = false; DialogResult cfr = ConfigForm.ShowDialog(); // User wants settings to be applied. if ((cfr == DialogResult.OK) || (cfr == DialogResult.Yes)) { // Copy all values to remote class. localOptions.CopyTo(remoteOptions); localOptions.CopyTo(this.APCSrvOpt); // Restarting service. if (cfr.Equals(System.Windows.Forms.DialogResult.Yes)) { this.CMIRestartService_Click(null, null); } } } catch (System.Runtime.Remoting.RemotingException _x) { System.Diagnostics.Debug.WriteLine(_x.ToString()); ShowMessage(MessageType.ErrorTCPConnection, null, "Connection to " + this.APCSrvOpt.MachineName + " is established, but the service options and service provider status cannot be received"); } catch (System.Exception _x) { System.Diagnostics.Debug.WriteLine(_x.ToString()); ShowMessage(MessageType.ErrorConfiguring, null, "Unable to configure APCService now"); } finally { this.LastMessageShown = MessageType.None; this.LastKnownSPStatus = "UNKNOWN"; this.IsConfiguring = false; this.Timer.Start(); } }
/// <summary> /// Occurs when user clicks twice in icon. /// </summary> /// <param name="sender">Sender of event.</param> /// <param name="id">ID of message target.</param> private void OnDoubleClick(object sender, EventArgs id) { this.ValidateContextMenuItems(); if (this.CMIConfigureAPCService.Visible) { this.ConfigureService(); } else if (this.IsConfiguring == true) { ConfigForm.BringToFront(); ConfigForm.TopMost = true; ConfigForm.TopMost = false; } }