public void Log(string text, LogBox listbox) { string timeStamp = DateTime.Now.ToString("T"); mainWindow.LogEvent($"{timeStamp} {text}", listbox); }
private void Log(string msg) { LogBox.AppendText($"{DateTime.Now:HH:mm:ss.fff}: {msg}\n"); LogBox.ScrollToEnd(); }
internal void AddLogEvent(LoggingEvent eve) { try { switch (eve.Level.Name) { case "DEBUG": totalDebug++; break; case "WARN": totalWarn++; break; case "INFO": totalInfo++; break; case "ERROR": totalError++; break; case "FATAL": totalFatal++; break; } EventCounts = String.Format( "DEBUG: {0} INFO: {1} WARN: {2} ERROR:{3} FATAL:{4}", totalDebug, totalInfo, totalWarn, totalError, totalFatal); LatestLogLines.Add(eve.RenderedMessage); while (LatestLogLines.Count > 300) { LatestLogLines.RemoveAt(0); } if (this.Visibility == Visibility.Visible) { Dispatcher.BeginInvoke( new Action( () => { LogBox.Document.Blocks.Add(new Paragraph(new Run(eve.RenderedMessage))); while (LogBox.Document.Blocks.Count > 300) { LogBox.Document.Blocks.Remove(LogBox.Document.Blocks.FirstBlock); } if (AutoScroll) { LogBox.ScrollToEnd(); } })); } } catch { // This comes from the logger, if we log here we could enter a recursive nightmare that we may never wake from. Imagine the horror of a thousand crying IO events, bleeding, tormented. The smell is enough to drive a made insane. Well we're on the subject I should mention that I never was a big fan of the first Freddy Kruger film. Wasn't really one of my favorites. Anyways, I suppose this comment is carrying on a little, so I'll wrap it up. Thanks for listening and stuff. Oh, and don't forget to break your while loops and dispose your objects, or the Garbage Man will come to get you! } }
private void PortListener() { while (true) { try { if (portUsed.IsOpen) { if (portUsed.BytesToRead > 0) { if (activeByte == 0x10) { byte[] buffer = new byte[portUsed.BytesToRead]; portUsed.Read(buffer, 0, portUsed.BytesToRead); bytesReceived += buffer.Count(); var str = Encoding.ASCII.GetString(buffer); Invoke((Action) delegate { LogBox.AppendText(str); }); Invoke((Action) delegate { label4.Text = bytesReceived.ToString(); }); if (!allowReceiving && str == "Setup end.\r\n") { Invoke((Action) delegate { allowReceiving = true; }); Invoke((Action) delegate { PortsList.Enabled = false; }); Invoke((Action) delegate { BaudRateList.Enabled = false; }); Invoke((Action) delegate { ResolutionList.Enabled = true; }); Invoke((Action) delegate { ExposureList.Enabled = true; }); Invoke((Action) delegate { CaptureBtn.Enabled = true; }); } } else if (JPEGformat == true) { if (portUsed.BytesToRead > 4 && imgStart) { /* Image comes in form of: 0x10FF01FF - 'Size of image' - 'Image with jpeg header 0xFFD8 */ /* We need to allocate more bytes than we excpect to receive because in the time * between allocating memory and reading from serial port, additional bytes might've * been sent and are unaccounted for, throwing exceptions */ byte[] buffer = new byte[30000]; int bytesRead = portUsed.Read(buffer, 0, portUsed.BytesToRead); bytesReceived += bytesRead; Array.Resize(ref buffer, bytesRead); var str = Encoding.ASCII.GetString(buffer); //Invoke((Action)delegate { LogBox.AppendText("str" + "\n"); }); tempBuffer.AddRange(buffer); if (tempBuffer[0] == 0x10 && tempBuffer[1] == 0xFF && tempBuffer [2] == 0x01 && tempBuffer[3] == 0xFF) // Check for starting bits { tempBuffer.RemoveRange(0, 4); imgStart = false; } int index = 0; while (tempBuffer[index] != 0xFF && tempBuffer[++index] != 0xD8) { ; } var imgSizeBuff = new List <byte>(index); imgSizeBuff.AddRange(tempBuffer.GetRange(0, index)); tempBuffer.RemoveRange(0, index); Invoke((Action) delegate { LogBox.AppendText("Size of image: " + Encoding.ASCII.GetString(imgSizeBuff.ToArray()) + " bytes\n"); }); Invoke((Action) delegate { label4.Text = bytesReceived.ToString(); }); Invoke((Action) delegate { dbgHexBox.AppendText(ByteArrToHexString(buffer) + "\n\n"); }); Invoke((Action) delegate { dbgStringBox.AppendText(str + "\n\n"); }); //Invoke((Action)delegate { LogBox.AppendText("Contents of temporary buffer:\n" + ByteArrToHexString(tempBuffer.ToArray())); }); } if (portUsed.BytesToRead > 0 && !imgStart) { /* We need to allocate more bytes than we excpect to receive because in the time * between allocating memory and reading from serial port, additional bytes might've * been sent and are unaccounted for, throwing exceptions */ byte[] buffer = new byte[30000]; int bytesRead = portUsed.Read(buffer, 0, portUsed.BytesToRead); bytesReceived += bytesRead; Array.Resize(ref buffer, bytesRead); tempBuffer.AddRange(buffer); var str = Encoding.ASCII.GetString(buffer); Invoke((Action) delegate { label4.Text = bytesReceived.ToString(); }); Invoke((Action) delegate { dbgHexBox.AppendText(ByteArrToHexString(buffer) + "\n\n"); }); Invoke((Action) delegate { dbgStringBox.AppendText(str + "\n\n"); }); if (tempBuffer.ElementAt(tempBuffer.Count - 2) == 0xFF && tempBuffer.ElementAt(tempBuffer.Count - 1) == 0xD9) { imgStart = true; activeByte = 0x10; ShowImageOnScreen(); } } } else if (!JPEGformat) { int totalBytes = portUsed.BytesToRead; if (totalBytes > 4) { byte[] buffer = new byte[totalBytes]; portUsed.Read(buffer, 0, totalBytes); bytesReceived += buffer.Count(); var str = Encoding.ASCII.GetString(buffer); tempBuffer.AddRange(buffer); Invoke((Action) delegate { dbgHexBox.AppendText(ByteArrToHexString(buffer) + "\n\n"); }); Invoke((Action) delegate { dbgStringBox.AppendText(str + "\n\n"); }); if (tempBuffer.Count >= 4 && tempBuffer[0] == 0x10 && tempBuffer[1] == 0xFF && tempBuffer[2] == 0x01 && tempBuffer[3] == 0xFF) // Check for starting bits { int index = 0; while (tempBuffer[index] != 0x0D && tempBuffer[++index] != 0x0A) { ; } tempBuffer.RemoveRange(0, index + 2); Invoke((Action) delegate { LogBox.AppendText("Contents of tempBuffer:\n" + ByteArrToHexString(tempBuffer.ToArray())); }); imgStart = false; } Invoke((Action) delegate { label4.Text = bytesReceived.ToString(); }); } if (tempBuffer.Count == imgSize) { string imageFolderPath = ""; string imageName = ""; string currExposure = "", currResolution = ""; Invoke((MethodInvoker) delegate() { currExposure = ExposureList.SelectedText.ToString(); }); Invoke((MethodInvoker) delegate() { currResolution = ResolutionList.SelectedText.ToString(); }); if (ImageNameBox.Text != "") { if (ImageNameBox.Text.EndsWith(".jpg")) { imageName = ImageNameBox.Text.Replace(".jpg", ""); } else { imageName = ImageNameBox.Text; } } else { imageName = "exposure_" + currExposure + "res_" + currResolution + ".jpg"; } if (FolderBox.Text == "") { string documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var di = Directory.CreateDirectory(documents + "/ArduCam"); imageFolderPath = di.FullName; } else { var di = Directory.CreateDirectory(FolderBox.Text); imageFolderPath = FolderBox.Text; } File.WriteAllBytes(imageFolderPath + "/" + imageName + "_" + photoNumber.ToString() + ".RAW", tempBuffer.ToArray()); tempBuffer.Clear(); imgStart = true; activeByte = 0x10; Invoke((MethodInvoker) delegate() { ResolutionList.Enabled = true; }); Invoke((MethodInvoker) delegate() { ExposureList.Enabled = true; }); Invoke((MethodInvoker) delegate() { CaptureBtn.Enabled = true; }); } } } } } catch (Exception ex) { Invoke((Action) delegate { LogBox.AppendText(ex.Message + "\n"); }); tempBuffer = new List <byte>(); } if (readStop) { break; } } }
private void ClearBtn_Click(object sender, EventArgs e) { dbgHexBox.Clear(); dbgStringBox.Clear(); LogBox.Clear(); }
private void Form1_ResizeEnd(object sender, EventArgs e) { LogBox.Refresh(); }
private void ClearLog_Click(object sender, EventArgs e) { LogBox.Clear(); }
void RAStepper_OnStatusChangedEvent(object sender, EventArgs e) { LogBox.AppendText("RA Status:" + fMounter.RAStepper.Status.ToString() + "\r\n"); }
void RTC_OnTemperatureChangedEvent(object sender, EventArgs e) { LogBox.AppendText("Mounter temperature:" + fMounter.RTC.DevTemperature.ToString("0.0") + "\r\n"); tbTemp.Text = fMounter.RTC.DevTemperature.ToString("0.0"); }
void RAStepper_OnPowerChangedEvent(object sender, EventArgs e) { LogBox.AppendText("RA Power:" + fMounter.RAStepper.Power.ToString() + "\r\n"); cbRAPower.Checked = fMounter.RAStepper.Power; }
void fMounter_OnReleaseTimeChangeEvent(object sender, EventArgs e) { LogBox.AppendText("Release time:" + fMounter.ReleaseTime.ToString() + "\r\n"); tbReleaseTime.Text = fMounter.ReleaseTime.ToString(); }
void fMounter_OnRATurningEvent(object sender, EventArgs e) { LogBox.AppendText("RA turning:" + fMounter.RATurning.ToString() + "\r\n"); cbRATurning.Checked = fMounter.RATurning; }
void fMounter_OnGotoEvent(object sender, EventArgs e) { LogBox.AppendText("Go to the new coordinates" + "\r\n"); }
void fMounter_OnNavMicrostepEvent(object sender, EventArgs e) { LogBox.AppendText("Nav microstep:" + fMounter.RAStepper.fModes[(byte)MODES.NAVIGATION].fMicrostep.ToString() + "\r\n"); cbMicroStepNav.SelectedIndex = fMounter.RAStepper.fModes[(byte)MODES.NAVIGATION].fMicrostep; }
void fMounter_OnNavSpeedEvent(object sender, EventArgs e) { LogBox.AppendText("Nav speed:" + fMounter.NavSpeed.ToString() + " (" + fMounter.RAStepper.fModes[(byte)MODES.NAVIGATION].fCurrentStepDelay.ToString() + ")\r\n"); tbNavSpeed.Text = fMounter.NavSpeed.ToString("0.#"); pgSpeed.Value = Convert.ToInt32((pgSpeed.Maximum - pgSpeed.Minimum) * (fMounter.NavSpeed - fMounter.NavSpeedMin) / (fMounter.NavSpeedMax - fMounter.NavSpeedMin)); }
void RTC_OnDateTimeChangedEvent(object sender, EventArgs e) { dateTimePicker.Value = fMounter.RTC.DeviceDateTime; LogBox.AppendText("Mounter datetime:" + fMounter.RTC.DateTimeToStrStd(fMounter.RTC.DeviceDateTime) + "\r\n"); }
void fMounter_OnDailyMicrostepEvent(object sender, EventArgs e) { LogBox.AppendText("Daily microstep:" + fMounter.RAStepper.fModes[(byte)MODES.DAILY].fMicrostep.ToString() + "\r\n"); cbMicroStepDaily.SelectedIndex = fMounter.RAStepper.fModes[(byte)MODES.DAILY].fMicrostep; }
void DEStepper_OnPositionChangedEvent(object sender, EventArgs e) { LogBox.AppendText("DE Pos: " + Convert.ToString(fMounter.PosDE_EQ) + " (" + Convert.ToString(fMounter.DEStepper.Position) + ")" + "\r\n"); tbDEPos.Text = Convert.ToString(fMounter.DEStepper.Position); tbDEPosEQ.Text = fMounter.PosDE_EQ.ToString("0.######"); }
void HandleFileWatch() { // setup a file watch FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(); var wh = new AutoResetEvent(false); DirectoryInfo dir = new DirectoryInfo(PathTxtBox.Text).Parent; fileSystemWatcher.Path = dir.FullName; fileSystemWatcher.EnableRaisingEvents = true; fileSystemWatcher.Changed += (s, ev) => wh.Set(); // open a read only stream to tail it. var msg = ""; while (doWork) { try { if (streamReader == null) { doWork = false; break; } if (streamReader.BaseStream.CanRead) // is the file still open? { msg = streamReader.ReadLine(); // note: this was opened when we picked a file. we assume its valid here. } else { doWork = false; break; } } catch (Exception) { msg = "<<<< UNABLE TO PARSE LINE >>>>"; } if (msg != null) { LogBox.Invoke(new MethodInvoker(delegate() { lock (locker) { TryFilterLogMsg(msg); } Application.DoEvents(); })); } else { UpdateLineLabel(); { // batch update now. if (WatchLogQueue.Count > 0) { this.BeginInvoke(new MethodInvoker(delegate() { lock (locker) { LogBox.BeginUpdate(); LogBox.Items.AddRange(WatchLogQueue.ToArray()); if (LogBox.Items.Count > logLineLimit) { long reduceby = LogBox.Items.Count - logLineLimit; for (int i = 0; i < reduceby; i++) { LogBox.Items.RemoveAt(0); } } GoToListBottom(); LogBox.EndUpdate(); WatchLogQueue.Clear(); } })); } } wh.WaitOne(250); } } fileSystemWatcher.EnableRaisingEvents = false; // shut it down first. wh.Close(); WatchLogQueue.Clear(); }
private void btnConnect_Click(object sender, EventArgs e) { try { fMounter.Connect(cbPort.Text, baudRate); } catch (System.IO.IOException ex) { LogBox.AppendText(ex.Message + "\r\n"); } catch (UnauthorizedAccessException ex) { LogBox.AppendText(ex.Message + "\r\n"); } catch (System.InvalidOperationException ex) { LogBox.AppendText(ex.Message + "\r\n"); } if (fMounter.IsConnected) { fMounter.fGearRatioRA = Convert.ToDouble(tbRAGear.Text); fMounter.fGearRatioDE = Convert.ToDouble(tbDEGear.Text); fMounter.IsTimeRunning = cbIsTimeRunning.Checked; btnConnect.Enabled = false; cbPort.Enabled = false; btnDisconnect.Enabled = true; btnGoTo.Enabled = true; btnPing.Enabled = true; // btnSetMinPos.Enabled = true; btnRollLeft.Enabled = true; btnRollRight.Enabled = true; btnRollUp.Enabled = true; btnRollDown.Enabled = true; btnSetReleaseTime.Enabled = true; btnSetSpeedRATurning.Enabled = true; btnStepLeft.Enabled = true; btnStepRight.Enabled = true; btnStepUp.Enabled = true; btnStepDown.Enabled = true; btnStop.Enabled = true; tbCmd.Enabled = true; cbObjectPos.Enabled = true; tbRAPosEQ.Enabled = true; tbReleaseTime.Enabled = true; tbSpeedRADaily.Enabled = true; cbDebug.Enabled = true; cbRAPower.Enabled = true; cbDEPower.Enabled = true; //cbRangeCheck.Enabled = true; cbRCP.Enabled = true; btnSend.Enabled = true; //pgPosition.Enabled = true; pgSpeed.Enabled = true; btnSetNavSpeed.Enabled = true; // btnSetMinPos.Enabled = true; btnSetPosRA.Enabled = true; btnSetPosDE.Enabled = true; btnSave.Enabled = true; btnDelete.Enabled = true; tbRANewPos.Enabled = true; tbDENewPos.Enabled = true; tbRAPos.Enabled = true; tbDEPos.Enabled = true; tbRAPosEQ.Enabled = true; tbDEPosEQ.Enabled = true; btnSetRAGear.Enabled = true; btnSetDEGear.Enabled = true; btnSetRAMaxMinPos.Enabled = true; btnSetDEMaxMinPos.Enabled = true; tbRAGear.Enabled = true; tbDEGear.Enabled = true; tbRAPosMin.Enabled = true; tbDEPosMin.Enabled = true; tbRAPosMax.Enabled = true; tbDEPosMax.Enabled = true; tbRAMinDailySpeed.Enabled = true; tbDEMinDailySpeed.Enabled = true; tbRAMaxDailySpeed.Enabled = true; tbDEMaxDailySpeed.Enabled = true; btnSetRADailySpeed.Enabled = true; btnSetDEDailySpeed.Enabled = true; cbMicroStepDaily.Enabled = true; tbMinNavSpeed.Enabled = true; tbMaxNavSpeed.Enabled = true; btnSetNavSpeed.Enabled = true; cbMicroStepNav.Enabled = true; btnTime.Enabled = true; rbDegrees.Enabled = true; rbHours.Enabled = true; cbRATurning.Enabled = true; cbDETurning.Enabled = true; tbSpeedRADaily.Enabled = true; tbSpeedDEDaily.Enabled = true; btnSetSpeedRATurning.Enabled = true; btnSetSpeedDETurning.Enabled = true; pgSpeed.Enabled = true; tbNavSpeed.Enabled = true; btnSetCurrentNavSpeed.Enabled = true; LoadCoordinates(); UpdatePosBtn(); ASCOM.FMounterV1.Properties.Settings.Default.ComPort = cbPort.Text; } }
public void Clear() { LogBox.Clear(); }
void fMounter_OnFirmwareEvent(object sender, EventArgs e) { LogBox.AppendText("Firmware version: " + fMounter.DeviceVersion + "\r\n"); }
private void ShowImageOnScreen() { string imageFolderPath = ""; string imageName = ""; string currExposure = "", currResolution = ""; Invoke((MethodInvoker) delegate() { currExposure = ExposureList.SelectedText.ToString(); }); Invoke((MethodInvoker) delegate() { currResolution = ResolutionList.SelectedText.ToString(); }); if (ImageNameBox.Text != "") { if (ImageNameBox.Text.EndsWith(".jpg")) { imageName = ImageNameBox.Text.Replace(".jpg", ""); } else { imageName = ImageNameBox.Text; } } else { imageName = "exposure_" + currExposure + "res_" + currResolution + ".jpg"; } if (FolderBox.Text == "") { string documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var di = Directory.CreateDirectory(documents + "/ArduCam"); imageFolderPath = di.FullName; } else { var di = Directory.CreateDirectory(FolderBox.Text); imageFolderPath = FolderBox.Text; } try { Invoke((Action) delegate { LogBox.AppendText("Image received\n"); }); receivedImage = (Bitmap)((new ImageConverter()).ConvertFrom(tempBuffer.ToArray())); pictureBox1.Image = receivedImage; pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; if (saturationCheckBtn.Checked) { bool saturated = CheckSaturation(receivedImage); if (saturated) { Invoke((Action) delegate { LogBox.AppendText("The picture is saturated!\n"); }); } else { Invoke((Action) delegate { LogBox.AppendText("Received picture is not saturated!\n"); }); } } Invoke((Action) delegate { ResolutionList.Enabled = true; }); Invoke((Action) delegate { ExposureList.Enabled = true; }); Invoke((Action) delegate { CaptureBtn.Enabled = true; }); } catch (Exception ex) { Invoke((Action) delegate { LogBox.AppendText(ex.Message); }); } finally { File.WriteAllBytes(imageFolderPath + "/" + imageName + "_" + photoNumber.ToString() + ".jpg", tempBuffer.ToArray()); tempBuffer.Clear(); } }
void fMounter_OnPingEvent(object sender, EventArgs e) { LogBox.AppendText("+ \r\n"); }
private void LogBox_TextChanged(object sender, EventArgs e) { LogBox.SelectionStart = LogBox.Text.Length; LogBox.ScrollToCaret(); }
void fMounter_OnNavSpeedMinEvent(object sender, EventArgs e) { LogBox.AppendText("Nav speed min:" + fMounter.NavSpeedMin.ToString() + " (" + fMounter.RAStepper.fModes[(byte)MODES.NAVIGATION].MaxStepDelay.ToString() + ")\r\n"); tbMinNavSpeed.Text = fMounter.NavSpeedMin.ToString("0.#"); }
public LogViewer(IApplication app) : this() { LogBox.Text = app.Log.ToString(); LogBox.ScrollToEnd(); }
void fMounter_OnDailySpeedRAEvent(object sender, EventArgs e) { LogBox.AppendText("Daily speed RA:" + fMounter.DailySpeedRA.ToString() + " (" + fMounter.RAStepper.fModes[(byte)MODES.DAILY].fCurrentStepDelay.ToString() + ")\r\n"); tbSpeedRADaily.Text = fMounter.DailySpeedRA.ToString("0.######"); }
public MainPage(Window w) { InitSettingBrowser(); InitializeComponent(); Directory.CreateDirectory(TempFolder); RequestObject.DataRecived += (o, args) => { if (args.IsError == RecivedDataType.Error) { Manager.Log(args.Data, LogMessageType.Error); } else { payloads[args.Id].TaskSource.SetResult(JArray.Parse(args.Data)); ForgeOfEmpires.Manager.ParseStringData(args.Data); } }; LoadConfig(); LoadOtherResourcesHtml(); InitBrowser(); w.Closed += (sender, args) => { Manager.SaveCache(); SaveConfig(); Config.Save(); Cef.Shutdown(); Environment.Exit(0); if (File.Exists(Path.Combine(TempFolder, "OtherResources.html"))) { File.Delete(Path.Combine(TempFolder, "OtherResources.html")); } }; var random = new Random(); Requests.PayloadSendRequest += async(requests, args) => { var delay = random.Next(50, 400); Manager.Log($"Request delay: {delay}ms", LogMessageType.Request); await Task.Delay(delay); SendRequest(args.Payload); }; Manager.LogMessageSend += (manager, args) => { Dispatcher.Invoke(() => { if ((ShowLogMessageType & args.Type) == args.Type) { LogBox.AppendText(args.Message + "\n"); LogBox.ScrollToEnd(); } }); //var tr = new TextRange(LogBox.Document.ContentEnd, LogBox.Document.ContentEnd) {Text = args.Message}; //tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red); }; Manager.Log("Logging..."); if (UserName.Text.Length == 0 || Password.Password.Length == 0) { Manager.Log("Login failed. User name or password is empty. Fill in login data and click on Relogin"); } ForgeOfEmpires.Manager.LogoutEvent += (manager, args) => { if (IsReloginRunning) { return; } IsReloginRunning = true; Relogin(); }; ForgeOfEmpires.Manager.ResourcesUpdate += (manager, args) => { try { foreach (var value in args.Values) { switch (value.Item1) { //case "tavern_silver": TavernSilver.Dispatcher.Invoke(() => TavernSilver.Text = value.Item2.ToString(CultureInfo.CurrentUICulture)); break; //case "premium": DiamondBox.Dispatcher.Invoke(() => DiamondBox.Text = value.Item2.ToString(CultureInfo.CurrentUICulture)); break; //case "money": MoneyBox.Dispatcher.Invoke(() => MoneyBox.Text = value.Item2.ToString(CultureInfo.CurrentUICulture)); break; //case "supplies": SupplyBox.Dispatcher.Invoke(() => SupplyBox.Text = value.Item2.ToString(CultureInfo.CurrentUICulture)); break; //case "strategy_points": ForgePointsBox.Dispatcher.Invoke(() => ForgePointsBox.Text = value.Item2.ToString(CultureInfo.CurrentUICulture)); break; //case "medals": Medals.Dispatcher.Invoke(() => Medals.Text = value.Item2.ToString(CultureInfo.CurrentUICulture)); break; default: otherBrowser.ExecuteScriptAsync("updateItem", value.Item1, value.Item2); break; } } } catch (Exception e) { Manager.Log("Resource update Exception: " + e.ToString(), LogMessageType.Exception); } }; }
private void Log(string message) { LogBox.AppendText($"{message}{Environment.NewLine}"); }