public static void EnableLogging(bool val) { lock (lockObject) { if (s_tl != null && s_tl.Enabled != val) { if (!val) { s_tl.LogMessage("Server", "Logging disabled"); } s_tl.Enabled = val; if (val) { s_tl.LogMessage("Server", "Logging enabled"); } } } using (Settings settings = new Settings()) { settings.Set("traceOn", val.ToString()); } }
public static void Write(string logMsg) { if (enabled) { // the original logger required a newline, but the ASCOM logging // doesn't need newlines. Remove trailing newlines if (logMsg[logMsg.Length - 1] == '\n') { logMsg = logMsg.Remove(logMsg.Length - 1); } lock (m_logger) { DateTime currentTime = DateTime.Now; TimeSpan elapsed = currentTime - m_startTime; TimeSpan delta = currentTime - m_lastWriteTime; m_logger.LogMessage(String.Format("{0,12:####0.000000} {1,10:##0.000000}", elapsed.TotalSeconds, delta.TotalSeconds), logMsg); m_lastWriteTime = currentTime; } } }
public string Move(int mov) { tl.LogMessage("Transmitting", ""); SendCommand command = new SendCommand((int)Command.Move, (int)Command.Acknowledge, 2000); command.AddArgument(mov); rcmd = _cmdMessenger.SendCommand(command); if (rcmd.Ok) { tl.LogMessage("Transmit", "true"); System.Threading.Thread.Sleep(mov); } else { tl.LogMessage("Transmit", "false"); } return(status); }
/// <summary> /// Runs custom wizard logic at the beginning of a template wizard run. /// </summary> /// <param name="automationObject"></param> /// <param name="replacementsDictionary"></param> /// <param name="runKind"></param> /// <param name="customParams"></param> public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams) { TL.LogMessage("RunStarted", $"Started wizard"); myDTE = (DTE2)automationObject; DialogResult dialogResult = DialogResult.Cancel; try { // Display a form to the user. The form collects // input for the custom message. inputForm = new DeviceDriverForm(TL); // Pass our trace logger into the form so all Wizard trace goes into one file dialogResult = inputForm.ShowDialog(); } catch (Exception ex) { TL.LogMessageCrLf("RunStarted", "Form Exception: " + ex.ToString()); MessageBox.Show("Form Exception: " + ex.ToString()); } if (dialogResult != DialogResult.OK) { throw new WizardCancelledException("The wizard has been cancelled"); } try { // Save user inputs. DeviceId = inputForm.DeviceId; DeviceName = inputForm.DeviceName; DeviceClass = inputForm.DeviceClass; DeviceInterface = inputForm.DeviceInterface; InterfaceVersion = inputForm.InterfaceVersion; Namespace = inputForm.Namespace; TL.Enabled = true; TL.LogMessage("DeviceId", DeviceId); TL.LogMessage("DeviceName", DeviceName); TL.LogMessage("DeviceClass", DeviceClass); TL.LogMessage("DeviceInterface", DeviceInterface); TL.LogMessage("InterfaceVersion", InterfaceVersion.ToString()); TL.LogMessage("Namespace", Namespace); inputForm.Dispose(); inputForm = null; // Add custom parameters. replacementsDictionary.Add("$deviceid$", DeviceId); replacementsDictionary.Add("$deviceclass$", DeviceClass); replacementsDictionary.Add("$devicename$", DeviceName); replacementsDictionary.Add("$namespace$", Namespace); replacementsDictionary["$projectname$"] = DeviceId; replacementsDictionary["$safeprojectname$"] = DeviceId; replacementsDictionary.Add("TEMPLATEDEVICENAME", DeviceName); if (DeviceClass == "VideoUsingBaseClass") // Special handling for "VideoWithBaseClass" template because its file name is not the same as the device type "Video" { replacementsDictionary.Add("TEMPLATEDEVICECLASS", "Video"); // This ensures that the class is named Video and not VideoWithBaseClass } else // ALl other templates process normally because the selected device name exatly matches the device type e.g. Telescope, Rotator etc. { replacementsDictionary.Add("TEMPLATEDEVICECLASS", DeviceClass); } replacementsDictionary.Add("ITEMPLATEDEVICEINTERFACE", DeviceInterface); replacementsDictionary.Add("TEMPLATENAMESPACE", Namespace); replacementsDictionary.Add("TEMPLATEINTERFACEVERSION", InterfaceVersion.ToString()); // create and replace guids replacementsDictionary.Add(csTemplateAssemblyGuid, Guid.NewGuid().ToString()); replacementsDictionary.Add(csTemplateInterfaceGuid, Guid.NewGuid().ToString()); replacementsDictionary.Add(csTemplateRateGuid, Guid.NewGuid().ToString()); replacementsDictionary.Add(csTemplateAxisRatesGuid, Guid.NewGuid().ToString()); replacementsDictionary.Add(csTemplateTrackingRatesGuid, Guid.NewGuid().ToString()); } catch (Exception ex) { TL.LogMessageCrLf("RunStarted", "Result Exception: " + ex.ToString()); MessageBox.Show("Form result setup exception: " + ex.ToString()); } }
private void setupMount_Click(object sender, EventArgs e) { try { SharedResources.SetupMount(); } catch (Exception ex) { m_tl.LogMessage("MainForm", ex.ToString()); string msg = String.Format("Could not open telescope setup:\n\n{0}\n\nPlease resolve the problem and try again.", ex.Message); MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }