From 3e747183d06c7e1cd6b1d5051a8eee5f79b7018b Mon Sep 17 00:00:00 2001 From: BrianTee Date: Mon, 30 Dec 2024 23:40:48 -0700 Subject: [PATCH 1/3] change to static log class --- SourceCode/AgIO/Source/AgIO.csproj | 4 +- SourceCode/AgIO/Source/Classes/CLog.cs | 21 +++ SourceCode/GPS/AgOpenGPS.csproj | 1 + SourceCode/GPS/Classes/CABCurve.cs | 12 +- SourceCode/GPS/Classes/CLog.cs | 66 ++++++++ SourceCode/GPS/Classes/CNMEA.cs | 2 - SourceCode/GPS/Forms/Controls.Designer.cs | 40 ++--- SourceCode/GPS/Forms/Field/FormBoundary.cs | 6 +- .../GPS/Forms/Field/FormBoundaryPlayer.cs | 2 +- SourceCode/GPS/Forms/Field/FormFieldDir.cs | 2 +- .../GPS/Forms/Field/FormFieldExisting.cs | 16 +- SourceCode/GPS/Forms/Field/FormFieldISOXML.cs | 17 +-- SourceCode/GPS/Forms/Field/FormFieldKML.cs | 10 +- SourceCode/GPS/Forms/Field/FormJob.cs | 2 +- SourceCode/GPS/Forms/FormEventViewer.cs | 8 +- SourceCode/GPS/Forms/FormGPS.cs | 77 +++------- SourceCode/GPS/Forms/FormMap.cs | 4 +- SourceCode/GPS/Forms/GUI.Designer.cs | 24 +-- .../GPS/Forms/Guidance/FormBuildTracks.cs | 4 +- SourceCode/GPS/Forms/Guidance/FormHeadAche.cs | 4 +- SourceCode/GPS/Forms/Guidance/FormHeadLine.cs | 4 +- SourceCode/GPS/Forms/Guidance/FormQuickAB.cs | 4 +- SourceCode/GPS/Forms/OpenGL.Designer.cs | 4 +- .../GPS/Forms/Pickers/FormFilePicker.cs | 14 +- .../GPS/Forms/Pickers/FormRecordPicker.cs | 2 +- SourceCode/GPS/Forms/Position.designer.cs | 12 +- SourceCode/GPS/Forms/SaveOpen.Designer.cs | 143 +++--------------- .../GPS/Forms/Settings/ConfigData.Designer.cs | 4 +- .../GPS/Forms/Settings/ConfigTool.Designer.cs | 8 +- .../Forms/Settings/ConfigVehicle.Designer.cs | 7 +- .../GPS/Forms/Settings/FormAllSettings.cs | 4 +- .../Forms/Settings/FormButtonsRightPanel.cs | 2 +- SourceCode/GPS/Forms/Settings/FormConfig.cs | 5 +- SourceCode/GPS/Forms/Settings/FormSteer.cs | 10 +- SourceCode/GPS/Forms/Settings/FormSteerWiz.cs | 4 +- SourceCode/GPS/Forms/UDPComm.Designer.cs | 37 ++--- SourceCode/GPS/Program.cs | 7 +- 37 files changed, 259 insertions(+), 334 deletions(-) create mode 100644 SourceCode/AgIO/Source/Classes/CLog.cs create mode 100644 SourceCode/GPS/Classes/CLog.cs diff --git a/SourceCode/AgIO/Source/AgIO.csproj b/SourceCode/AgIO/Source/AgIO.csproj index c5e4032e9..92b1e2720 100644 --- a/SourceCode/AgIO/Source/AgIO.csproj +++ b/SourceCode/AgIO/Source/AgIO.csproj @@ -27,7 +27,8 @@ false false true - false + false + AnyCPU @@ -70,6 +71,7 @@ + diff --git a/SourceCode/AgIO/Source/Classes/CLog.cs b/SourceCode/AgIO/Source/Classes/CLog.cs new file mode 100644 index 000000000..958364cbe --- /dev/null +++ b/SourceCode/AgIO/Source/Classes/CLog.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgIO +{ + public static class Log + { + public static StringBuilder sbEvent = new StringBuilder(); + + public static void EventWriter(string message) + { + sbEvent.Append(DateTime.Now.ToString("T")); + sbEvent.Append("-> "); + sbEvent.Append(message); + sbEvent.Append("\r"); + } + } +} diff --git a/SourceCode/GPS/AgOpenGPS.csproj b/SourceCode/GPS/AgOpenGPS.csproj index 4386946da..43c691600 100644 --- a/SourceCode/GPS/AgOpenGPS.csproj +++ b/SourceCode/GPS/AgOpenGPS.csproj @@ -134,6 +134,7 @@ + diff --git a/SourceCode/GPS/Classes/CABCurve.cs b/SourceCode/GPS/Classes/CABCurve.cs index 0423c95c7..465849d40 100644 --- a/SourceCode/GPS/Classes/CABCurve.cs +++ b/SourceCode/GPS/Classes/CABCurve.cs @@ -472,7 +472,7 @@ public List BuildNewOffsetList(double distAway, CTrk track) } catch (Exception e) { - mf.LogEventWriter("Exception Build new offset curve" + e.ToString()); + Log.EventWriter("Exception Build new offset curve" + e.ToString()); } return newCurList; @@ -516,14 +516,14 @@ public void GetCurrentCurveLine(vec3 pivot, vec3 steer) else// Pure Pursuit ------------------------------------------ { - double minDistA = double.MaxValue; - double minDistB = double.MaxValue; + double minDistA; + double minDistB; //close call hit //If is a curve if (mf.trk.gArr[mf.trk.idx].mode <= TrackMode.Curve) { - minDistA = minDistB = double.MaxValue; + minDistB = double.MaxValue; //close call hit int cc, dd; @@ -728,7 +728,7 @@ public void GetCurrentCurveLine(vec3 pivot, vec3 steer) { mf.btnAutoSteer.PerformClick(); mf.TimedMessageBox(2000, gStr.gsGuidanceStopped, gStr.gsPastEndOfCurve); - mf.LogEventWriter("Autosteer Stop, Past End of Curve"); + Log.EventWriter("Autosteer Stop, Past End of Curve"); } } @@ -738,7 +738,7 @@ public void GetCurrentCurveLine(vec3 pivot, vec3 steer) { mf.btnAutoSteer.PerformClick(); mf.TimedMessageBox(2000, gStr.gsGuidanceStopped, gStr.gsPastEndOfCurve); - mf.LogEventWriter("Autosteer Stop, Past End of Curve"); + Log.EventWriter("Autosteer Stop, Past End of Curve"); } } } diff --git a/SourceCode/GPS/Classes/CLog.cs b/SourceCode/GPS/Classes/CLog.cs new file mode 100644 index 000000000..f2ea4aab1 --- /dev/null +++ b/SourceCode/GPS/Classes/CLog.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgOpenGPS +{ + public static class Log + { + public static StringBuilder sbEvents = new StringBuilder(); + + public static void EventWriter(string message) + { + sbEvents.Append(DateTime.Now.ToString("T")); + sbEvents.Append("-> "); + sbEvents.Append(message); + sbEvents.Append("\r"); + } + + public static void CheckLogSize(string logFile, int sizeLimit) + { + //system event log file + FileInfo txtfile = new FileInfo(logFile); + if (txtfile.Exists) + { + if (txtfile.Length > (sizeLimit)) // ## NOTE: 0.5MB max file size + { + StringBuilder sbF = new StringBuilder(); + long bytes = txtfile.Length - sizeLimit; + bytes = (sizeLimit *2)/10 + bytes; + Log.sbEvents.Append("Log File Reduced by: " + bytes.ToString()); + + //create some extra space + int bytesSoFar = 0; + + using (StreamReader reader = new StreamReader(logFile)) + { + try + { + //Date time line + while (!reader.EndOfStream) + { + bytesSoFar += reader.ReadLine().Length; + if (bytesSoFar > bytes) + break; + } + + while (!reader.EndOfStream) + { + sbF.AppendLine(reader.ReadLine()); + } + } + catch { } + } + + using (StreamWriter writer = new StreamWriter(logFile)) + { + writer.WriteLine(sbF); + } + } + } + } + } +} diff --git a/SourceCode/GPS/Classes/CNMEA.cs b/SourceCode/GPS/Classes/CNMEA.cs index 504962a1c..e4fb12b24 100644 --- a/SourceCode/GPS/Classes/CNMEA.cs +++ b/SourceCode/GPS/Classes/CNMEA.cs @@ -32,8 +32,6 @@ public class CNMEA public int fixQuality, ageAlarm; public int satellitesTracked; - public StringBuilder logNMEASentence = new StringBuilder(); - private readonly FormGPS mf; public CNMEA(FormGPS f) diff --git a/SourceCode/GPS/Forms/Controls.Designer.cs b/SourceCode/GPS/Forms/Controls.Designer.cs index cb63517db..371b878d8 100644 --- a/SourceCode/GPS/Forms/Controls.Designer.cs +++ b/SourceCode/GPS/Forms/Controls.Designer.cs @@ -287,7 +287,7 @@ private void btnAutoSteer_Click(object sender, EventArgs e) if (sounds.isSteerSoundOn) sounds.sndAutoSteerOff.Play(); } - LogEventWriter("Steer Off, Above Max Safe Speed for Autosteer"); + Log.EventWriter("Steer Off, Above Max Safe Speed for Autosteer"); if (isMetric) TimedMessageBox(3000, "AutoSteer Disabled", "Above Maximum Safe Steering Speed: " + vehicle.maxSteerSpeed.ToString("N0") + " Kmh"); @@ -333,7 +333,7 @@ private void btnAutoYouTurn_Click(object sender, EventArgs e) if (bnd.bndList.Count == 0) { TimedMessageBox(2000, gStr.gsNoBoundary, gStr.gsCreateABoundaryFirst); - LogEventWriter("Uturn attempted without boundary"); + Log.EventWriter("Uturn attempted without boundary"); return; } @@ -620,7 +620,7 @@ private void btnJobMenu_Click(object sender, EventArgs e) TimedMessageBox(2500, "No GPS", "No GPS Position Found"); } - LogEventWriter("No GPS Position, Field Closed"); + Log.EventWriter("No GPS Position, Field Closed"); return; } @@ -726,11 +726,11 @@ private void btnJobMenu_Click(object sender, EventArgs e) TimedMessageBox(2500, "High Field Start Distance Warning", "Field Start is " + distance.ToString("N1") + " km From current position"); - LogEventWriter("High Field Start Distance Warning"); + Log.EventWriter("High Field Start Distance Warning"); } - LogEventWriter(" *Opened* " + currentFieldDirectory); - LogEventWriter(DateTime.Now.ToString("f", CultureInfo.CreateSpecificCulture(Settings.Default.setF_culture))); + Log.EventWriter(" *Opened* " + currentFieldDirectory); + Log.EventWriter(DateTime.Now.ToString("f", CultureInfo.CreateSpecificCulture(Settings.Default.setF_culture))); } } @@ -778,8 +778,8 @@ public void FileSaveEverythingBeforeClosingField() ExportFieldAs_ISOXMLv3(); ExportFieldAs_ISOXMLv4(); - LogEventWriter(currentFieldDirectory + " ** Closed **"); - LogEventWriter(DateTime.Now.ToString("f", CultureInfo.CreateSpecificCulture(Settings.Default.setF_culture))); + Log.EventWriter(currentFieldDirectory + " ** Closed **"); + Log.EventWriter(DateTime.Now.ToString("f", CultureInfo.CreateSpecificCulture(Settings.Default.setF_culture))); Settings.Default.setF_CurrentDir = currentFieldDirectory; Settings.Default.Save(); @@ -889,7 +889,7 @@ private void btnPathGoStop_Click(object sender, EventArgs e) { btnAutoSteer.PerformClick(); TimedMessageBox(2000, gStr.gsGuidanceStopped, "Paths Enabled"); - LogEventWriter("Autosteer On While Enable Paths"); + Log.EventWriter("Autosteer On While Enable Paths"); } DisableYouTurnButtons(); @@ -1123,7 +1123,7 @@ private void btnNavigationSettings_Click(object sender, EventArgs e) } private void btnStartAgIO_Click(object sender, EventArgs e) { - LogEventWriter("AgIO Manually Started"); + Log.EventWriter("AgIO Manually Started"); Process[] processName = Process.GetProcessesByName("AgIO"); if (processName.Length == 0) @@ -1144,7 +1144,7 @@ private void btnStartAgIO_Click(object sender, EventArgs e) catch { TimedMessageBox(2000, "No File Found", "Can't Find AgIO"); - LogEventWriter("AgIO Not Found"); + Log.EventWriter("AgIO Not Found"); } } @@ -1474,7 +1474,7 @@ private void nozzleAppToolStripMenuItem_Click(object sender, EventArgs e) if (isJobStarted) { TimedMessageBox(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - LogEventWriter("Turning Nozzle on or off while open field"); + Log.EventWriter("Turning Nozzle on or off while open field"); return; } @@ -1483,12 +1483,12 @@ private void nozzleAppToolStripMenuItem_Click(object sender, EventArgs e) if (isNozzleApp) { TimedMessageBox(2000, "", "Nozzle App On"); - LogEventWriter("Turning Nozzle App On"); + Log.EventWriter("Turning Nozzle App On"); } else { TimedMessageBox(2000, "", "Nozzle App Off"); - LogEventWriter("Turning Nozzle App Off"); + Log.EventWriter("Turning Nozzle App Off"); } @@ -1567,7 +1567,7 @@ private void resetALLToolStripMenuItem_Click(object sender, EventArgs e) Settings.Default.Save(); //save event - LogEventWriter("Reset ALL event occured" ); + Log.EventWriter("Reset ALL event occured" ); FileSaveSystemEvents(); MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); @@ -1870,9 +1870,9 @@ private void SetLanguage(string lang, bool Restart) private void systemLogViewerToolStripMenuItem_Click(object sender, EventArgs e) { FileSaveSystemEvents(); - sbSystemEvents.Clear(); + Log.sbEvents.Clear(); - FileInfo txtfile = new FileInfo(Path.Combine(logsDirectory, "zSystemEventsLog_log.txt")); + FileInfo txtfile = new FileInfo(Path.Combine(logsDirectory, "AgOpenGPS_Events_Log.txt")); if (txtfile.Exists) { Process.Start("notepad.exe", txtfile.FullName); @@ -2165,7 +2165,7 @@ private void toolStripAreYouSure_Click(object sender, EventArgs e) FileCreateContour(); FileCreateSections(); - LogEventWriter("All Section Mapping Deleted"); + Log.EventWriter("All Section Mapping Deleted"); } else { @@ -2225,7 +2225,7 @@ private void xTEChartToolStripMenuItem_Click(object sender, EventArgs e) } private void eventViewerToolStripMenuItem_Click(object sender, EventArgs e) { - Form form = new FormEventViewer(this); + Form form = new FormEventViewer(); form.Show(this); this.Activate(); } @@ -2451,7 +2451,7 @@ private void btnSimReverseDirection_Click(object sender, EventArgs e) { btnAutoSteer.PerformClick(); TimedMessageBox(2000, gStr.gsGuidanceStopped, "Sim Reverse Touched"); - LogEventWriter("Steer Off, Sim Reverse Activated"); + Log.EventWriter("Steer Off, Sim Reverse Activated"); } } private void hsbarSteerAngle_Scroll(object sender, ScrollEventArgs e) diff --git a/SourceCode/GPS/Forms/Field/FormBoundary.cs b/SourceCode/GPS/Forms/Field/FormBoundary.cs index fe8eef724..b0d00d3cd 100644 --- a/SourceCode/GPS/Forms/Field/FormBoundary.cs +++ b/SourceCode/GPS/Forms/Field/FormBoundary.cs @@ -294,7 +294,7 @@ private void btnAdd_Click(object sender, EventArgs e) if (mf.tool.width < 0.2) { mf.TimedMessageBox(2000, "Tool Error", "Your tool is too small"); - mf.LogEventWriter("Boundary, Tool is too narrow"); + Log.EventWriter("Boundary, Tool is too narrow"); return; } @@ -399,7 +399,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) else { mf.TimedMessageBox(2000, gStr.gsErrorreadingKML, gStr.gsChooseBuildDifferentone); - mf.LogEventWriter("KML Read Error to make new field"); + Log.EventWriter("KML Read Error to make new field"); } if (button.Name == "btnLoadBoundaryFromGE") @@ -415,7 +415,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) } catch (Exception ed) { - mf.LogEventWriter("Load Boundary from GE " + ed.ToString()); + Log.EventWriter("Load Boundary from GE " + ed.ToString()); return; } } diff --git a/SourceCode/GPS/Forms/Field/FormBoundaryPlayer.cs b/SourceCode/GPS/Forms/Field/FormBoundaryPlayer.cs index dee2ac834..184126426 100644 --- a/SourceCode/GPS/Forms/Field/FormBoundaryPlayer.cs +++ b/SourceCode/GPS/Forms/Field/FormBoundaryPlayer.cs @@ -138,7 +138,7 @@ private void btnStop_Click(object sender, EventArgs e) //mf.hd.BuildSingleSpaceHeadLines(); mf.btnABDraw.Visible = true; - mf.LogEventWriter("Driven Boundary Created, Area: " + lblArea.Text); + Log.EventWriter("Driven Boundary Created, Area: " + lblArea.Text); } //stop it all for adding diff --git a/SourceCode/GPS/Forms/Field/FormFieldDir.cs b/SourceCode/GPS/Forms/Field/FormFieldDir.cs index 9ef53aad9..95a0cf332 100644 --- a/SourceCode/GPS/Forms/Field/FormFieldDir.cs +++ b/SourceCode/GPS/Forms/Field/FormFieldDir.cs @@ -121,7 +121,7 @@ private void btnSave_Click(object sender, EventArgs e) } catch (Exception ex) { - mf.LogEventWriter("Creating new field " + ex); + Log.EventWriter("Creating new field " + ex); MessageBox.Show(gStr.gsError, ex.ToString()); mf.currentFieldDirectory = ""; diff --git a/SourceCode/GPS/Forms/Field/FormFieldExisting.cs b/SourceCode/GPS/Forms/Field/FormFieldExisting.cs index 4e625f0a3..6ddac79b7 100644 --- a/SourceCode/GPS/Forms/Field/FormFieldExisting.cs +++ b/SourceCode/GPS/Forms/Field/FormFieldExisting.cs @@ -43,7 +43,7 @@ private void FormFieldExisting_Load(object sender, EventArgs e) if (dirs == null || dirs.Length < 1) { mf.TimedMessageBox(2000, gStr.gsCreateNewField, gStr.gsFileError); - mf.LogEventWriter("File Error Load Existing Field"); + Log.EventWriter("File Error Load Existing Field"); Close(); return; @@ -100,7 +100,7 @@ private void FormFieldExisting_Load(object sender, EventArgs e) { MessageBox.Show(fieldDirectory + " is Damaged, Please Delete, Field.txt is Broken", gStr.gsFileError, MessageBoxButtons.OK, MessageBoxIcon.Error); - mf.LogEventWriter(fieldDirectory + " is Damaged, Please Delete,Field.txt is Broken" + ex.ToString()); + Log.EventWriter(fieldDirectory + " is Damaged, Please Delete,Field.txt is Broken" + ex.ToString()); fileList.Add(fieldDirectory); fileList.Add("Error"); } @@ -181,13 +181,13 @@ private void FormFieldExisting_Load(object sender, EventArgs e) catch (Exception ef) { area = 0; - mf.LogEventWriter(fieldDirectory + " Boundary.Txt error " + ef.ToString()); + Log.EventWriter(fieldDirectory + " Boundary.Txt error " + ef.ToString()); } } if (area == 0) { fileList.Add("No Bndry"); - mf.LogEventWriter("Boundary is Broken, no Area"); + Log.EventWriter("Boundary is Broken, no Area"); } else fileList.Add(Math.Round(area, 1).ToString("N1").PadLeft(10)); } @@ -197,7 +197,7 @@ private void FormFieldExisting_Load(object sender, EventArgs e) MessageBox.Show(fieldDirectory + " is Damaged, Missing Boundary.Txt " + " \r\n Delete Field or Fix ", gStr.gsFileError, MessageBoxButtons.OK, MessageBoxIcon.Error); - mf.LogEventWriter(fieldDirectory + " is Damaged, Missing Boundary.Txt "); + Log.EventWriter(fieldDirectory + " is Damaged, Missing Boundary.Txt "); } filename = Path.Combine(dir, "Field.txt"); @@ -206,7 +206,7 @@ private void FormFieldExisting_Load(object sender, EventArgs e) if (fileList == null || fileList.Count < 1) { mf.TimedMessageBox(2000, gStr.gsNoFieldsFound, gStr.gsCreateNewField); - mf.LogEventWriter("Create New Field, No Fields Found"); + Log.EventWriter("Create New Field, No Fields Found"); Close(); return; @@ -234,7 +234,7 @@ private void FormFieldExisting_Load(object sender, EventArgs e) else { mf.TimedMessageBox(2000, gStr.gsNoFieldsFound, gStr.gsCreateNewField); - mf.LogEventWriter("Field Existing, No Fields to List"); + Log.EventWriter("Field Existing, No Fields to List"); Close(); return; @@ -327,7 +327,7 @@ private void btnSave_Click(object sender, EventArgs e) } catch (Exception ex) { - mf.LogEventWriter("While Opening Field" + ex); + Log.EventWriter("While Opening Field" + ex); mf.TimedMessageBox(2000, gStr.gsFieldFileIsCorrupt, gStr.gsChooseADifferentField); mf.JobClose(); diff --git a/SourceCode/GPS/Forms/Field/FormFieldISOXML.cs b/SourceCode/GPS/Forms/Field/FormFieldISOXML.cs index 833a7fc09..704eea850 100644 --- a/SourceCode/GPS/Forms/Field/FormFieldISOXML.cs +++ b/SourceCode/GPS/Forms/Field/FormFieldISOXML.cs @@ -35,7 +35,6 @@ private void FormFieldISOXML_Load(object sender, EventArgs e) { tboxFieldName.Text = ""; btnBuildFields.Enabled = false; - string newFieldDir; label1.Text = gStr.gsEditFieldName; @@ -149,7 +148,7 @@ private void FormFieldISOXML_Load(object sender, EventArgs e) } catch (Exception ex) { - mf.LogEventWriter("Creating new iso field " + ex.ToString()); + Log.EventWriter("Creating new iso field " + ex.ToString()); MessageBox.Show(gStr.gsError, ex.ToString()); return; } @@ -263,7 +262,7 @@ private void btnBuildFields_Click(object sender, EventArgs e) catch (Exception ei) { mf.TimedMessageBox(2000, "Exception", "Catch Exception"); - mf.LogEventWriter("ISOXML Exception Loading " + ei.ToString()); + Log.EventWriter("ISOXML Exception Loading " + ei.ToString()); return; } @@ -356,7 +355,7 @@ private void btnBuildFields_Click(object sender, EventArgs e) } catch (Exception ex) { - mf.LogEventWriter("Creating new iso field " + ex.ToString()); + Log.EventWriter("Creating new iso field " + ex.ToString()); MessageBox.Show(gStr.gsError, ex.ToString()); mf.currentFieldDirectory = ""; @@ -412,7 +411,7 @@ private void btnBuildFields_Click(object sender, EventArgs e) } catch (Exception ew) { - mf.LogEventWriter("Creating new iso field " + ew.ToString()); + Log.EventWriter("Creating new iso field " + ew.ToString()); MessageBox.Show(gStr.gsError, ew.ToString()); } @@ -461,7 +460,7 @@ private void btnBuildFields_Click(object sender, EventArgs e) } catch (Exception ed) { - mf.LogEventWriter("Creating new iso field " + ed.ToString()); + Log.EventWriter("Creating new iso field " + ed.ToString()); MessageBox.Show(gStr.gsError, ed.ToString()); } @@ -512,7 +511,7 @@ private void btnBuildFields_Click(object sender, EventArgs e) } catch (Exception ex) { - mf.LogEventWriter("Creating new iso field " + ex.ToString()); + Log.EventWriter("Creating new iso field " + ex.ToString()); MessageBox.Show(gStr.gsError, ex.ToString()); } } @@ -679,7 +678,7 @@ private void btnBuildFields_Click(object sender, EventArgs e) } catch (Exception ex) { - mf.LogEventWriter("Creating new iso field " + ex.ToString()); + Log.EventWriter("Creating new iso field " + ex.ToString()); MessageBox.Show(gStr.gsError, ex.ToString()); } @@ -825,7 +824,7 @@ private void btnBuildFields_Click(object sender, EventArgs e) } catch (Exception ex) { - mf.LogEventWriter("Creating new iso field " + ex.ToString()); + Log.EventWriter("Creating new iso field " + ex.ToString()); MessageBox.Show(gStr.gsError, ex.ToString()); } diff --git a/SourceCode/GPS/Forms/Field/FormFieldKML.cs b/SourceCode/GPS/Forms/Field/FormFieldKML.cs index 0ec466a2c..0631f8179 100644 --- a/SourceCode/GPS/Forms/Field/FormFieldKML.cs +++ b/SourceCode/GPS/Forms/Field/FormFieldKML.cs @@ -187,7 +187,7 @@ private void LoadKMLBoundary(string filename) else { mf.TimedMessageBox(2000, gStr.gsErrorreadingKML, gStr.gsChooseBuildDifferentone); - mf.LogEventWriter("New Field, Error Reading KML"); + Log.EventWriter("New Field, Error Reading KML"); } break; } @@ -205,7 +205,7 @@ private void LoadKMLBoundary(string filename) btnSave.Enabled = false; btnLoadKML.Enabled = false; mf.TimedMessageBox(2000, gStr.gsErrorreadingKML, gStr.gsChooseBuildDifferentone); - mf.LogEventWriter("New Field, Error Reading KML" + ee.ToString()); + Log.EventWriter("New Field, Error Reading KML" + ee.ToString()); return; } } @@ -280,7 +280,7 @@ private void FindLatLon(string filename) else { mf.TimedMessageBox(2000, gStr.gsErrorreadingKML, gStr.gsChooseBuildDifferentone); - mf.LogEventWriter("New Field, Error Reading KML "); + Log.EventWriter("New Field, Error Reading KML "); } //if (button.Name == "btnLoadBoundaryFromGE") @@ -293,7 +293,7 @@ private void FindLatLon(string filename) catch (Exception et) { mf.TimedMessageBox(2000, "Exception", "Error Finding Lat Lon"); - mf.LogEventWriter("Lat Lon Exception Reading KML " + et.ToString()); + Log.EventWriter("Lat Lon Exception Reading KML " + et.ToString()); return; } } @@ -400,7 +400,7 @@ private void CreateNewField() } catch (Exception ex) { - mf.LogEventWriter("Creating new kml field " + ex.ToString()); + Log.EventWriter("Creating new kml field " + ex.ToString()); MessageBox.Show(gStr.gsError, ex.ToString()); mf.currentFieldDirectory = ""; diff --git a/SourceCode/GPS/Forms/Field/FormJob.cs b/SourceCode/GPS/Forms/Field/FormJob.cs index 64a67b818..cf95f69c9 100644 --- a/SourceCode/GPS/Forms/Field/FormJob.cs +++ b/SourceCode/GPS/Forms/Field/FormJob.cs @@ -90,7 +90,7 @@ private void btnJobResume_Click(object sender, EventArgs e) //open the Resume.txt and continue from last exit mf.FileOpenField("Resume"); - mf.LogEventWriter("Job Form, Field Resume"); + Log.EventWriter("Job Form, Field Resume"); //back to FormGPS DialogResult = DialogResult.OK; diff --git a/SourceCode/GPS/Forms/FormEventViewer.cs b/SourceCode/GPS/Forms/FormEventViewer.cs index 77003bdf1..781483ab6 100644 --- a/SourceCode/GPS/Forms/FormEventViewer.cs +++ b/SourceCode/GPS/Forms/FormEventViewer.cs @@ -6,12 +6,10 @@ namespace AgOpenGPS public partial class FormEventViewer : Form { //class variables - private readonly FormGPS mf = null; - public FormEventViewer(Form callingForm) + public FormEventViewer() { //get copy of the calling main form - mf = callingForm as FormGPS; InitializeComponent(); } @@ -27,10 +25,10 @@ private void FormEventViewer_Load(object sender, EventArgs e) private void timer1_Tick(object sender, EventArgs e) { - if (rtbAutoSteerStopEvents.TextLength != mf.sbSystemEvents.Length) + if (rtbAutoSteerStopEvents.TextLength != Log.sbEvents.Length) { rtbAutoSteerStopEvents.Clear(); - rtbAutoSteerStopEvents.AppendText(mf.sbSystemEvents.ToString()); + rtbAutoSteerStopEvents.AppendText(Log.sbEvents.ToString()); } } } diff --git a/SourceCode/GPS/Forms/FormGPS.cs b/SourceCode/GPS/Forms/FormGPS.cs index 6107ce1ed..5ff129e46 100644 --- a/SourceCode/GPS/Forms/FormGPS.cs +++ b/SourceCode/GPS/Forms/FormGPS.cs @@ -61,7 +61,7 @@ public partial class FormGPS : Form public bool isJobStarted = false, isBtnAutoSteerOn, isLidarBtnOn = true; //if we are saving a file - public bool isSavingFile = false, isLogNMEA = false; + public bool isSavingFile = false; //texture holders public uint[] texture; @@ -253,7 +253,7 @@ private void SystemEvents_PowerModeChanged(object sender, Microsoft.Win32.PowerM { PowerLineStatus powerLineStatus = SystemInformation.PowerStatus.PowerLineStatus; - LogEventWriter($"Power Line Status Change to: {powerLineStatus}"); + Log.EventWriter($"Power Line Status Change to: {powerLineStatus}"); if (powerLineStatus == PowerLineStatus.Online) { @@ -379,11 +379,11 @@ private void FormGPS_Load(object sender, EventArgs e) this.MouseWheel += ZoomByMouseWheel; - sbSystemEvents.Append("\r"); - sbSystemEvents.Append("Program Started: " + DateTime.Now.ToString("f", CultureInfo.CreateSpecificCulture(Settings.Default.setF_culture)) + "\r"); - sbSystemEvents.Append("AOG Version: "); - sbSystemEvents.Append(Application.ProductVersion.ToString(CultureInfo.InvariantCulture)); - sbSystemEvents.Append("\r"); + Log.sbEvents.Append("\r"); + Log.sbEvents.Append("Program Started: " + DateTime.Now.ToString("f", CultureInfo.CreateSpecificCulture(Settings.Default.setF_culture)) + "\r"); + Log.sbEvents.Append("AOG Version: "); + Log.sbEvents.Append(Application.ProductVersion.ToString(CultureInfo.InvariantCulture)); + Log.sbEvents.Append("\r"); //The way we subscribe to the System Event to check when Power Mode has changed. Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; @@ -415,62 +415,23 @@ private void FormGPS_Load(object sender, EventArgs e) //get the fields directory, if not exist, create fieldsDirectory = Path.Combine(baseDirectory, "Fields"); if (!string.IsNullOrEmpty(fieldsDirectory) && !Directory.Exists(fieldsDirectory)) { Directory.CreateDirectory(fieldsDirectory); - sbSystemEvents.Append("Fields Dir Created\r"); + Log.sbEvents.Append("Fields Dir Created\r"); } //get the fields directory, if not exist, create vehiclesDirectory = Path.Combine(baseDirectory, "Vehicles"); if (!string.IsNullOrEmpty(vehiclesDirectory) && !Directory.Exists(vehiclesDirectory)) { Directory.CreateDirectory(vehiclesDirectory); - sbSystemEvents.Append("Vehicles Dir Created\r"); + Log.sbEvents.Append("Vehicles Dir Created\r"); } //get the fields directory, if not exist, create logsDirectory = Path.Combine(baseDirectory, "Logs"); if (!string.IsNullOrEmpty(logsDirectory) && !Directory.Exists(logsDirectory)) { Directory.CreateDirectory(logsDirectory); - sbSystemEvents.Append("Logs Dir Created\r"); + Log.sbEvents.Append("Logs Dir Created\r"); } - //system event log file - FileInfo txtfile = new FileInfo(Path.Combine(logsDirectory, "zSystemEventsLog_log.txt")); - if (txtfile.Exists) - { - if (txtfile.Length > (500000)) // ## NOTE: 0.5MB max file size - { - sbSystemEvents.Append("Log File Reduced by 100Kb\r"); - StringBuilder sbF = new StringBuilder(); - long lines = txtfile.Length - 450000; - - //create some extra space - lines /= 30; - - using (StreamReader reader = new StreamReader(Path.Combine(logsDirectory, "zSystemEventsLog_log.txt"))) - { - try - { - //Date time line - for (long i = 0; i < lines; i++) - { - reader.ReadLine(); - } - - while (!reader.EndOfStream) - { - sbF.AppendLine(reader.ReadLine()); - } - } - catch { } - } - - using (StreamWriter writer = new StreamWriter(Path.Combine(logsDirectory, "zSystemEventsLog_log.txt"))) - { - writer.WriteLine(sbF); - } - } - } - else - { - sbSystemEvents.Append("Events Log File Created\r"); - } + //keep below 500 kb + Log.CheckLogSize(Path.Combine(logsDirectory, "AgOpenGPS_Events_Log.txt"), 500000); //make sure current field directory exists, null if not currentFieldDirectory = Settings.Default.setF_CurrentDir; @@ -483,13 +444,12 @@ private void FormGPS_Load(object sender, EventArgs e) currentFieldDirectory = ""; Settings.Default.setF_CurrentDir = ""; Settings.Default.Save(); - sbSystemEvents.Append("Field Directory is Empty or Missing\r"); + Log.sbEvents.Append("Field Directory is Empty or Missing\r"); } } - - sbSystemEvents.Append("Program Directory: " + (baseDirectory) + "\r"); - sbSystemEvents.Append("Fields Directory: " + (fieldsDirectory) + "\r"); + Log.sbEvents.Append("Program Directory: " + Application.StartupPath + "\r"); + Log.sbEvents.Append("Fields Directory: " + (fieldsDirectory) + "\r"); if (isBrightnessOn) { @@ -551,8 +511,7 @@ private void FormGPS_Load(object sender, EventArgs e) catch { TimedMessageBox(2000, "No File Found", "Can't Find AgIO"); - LogEventWriter("Can't Find AgIO"); - + Log.EventWriter("Can't Find AgIO"); } } } @@ -621,7 +580,7 @@ private void FormGPS_Load(object sender, EventArgs e) if (vehicleFileName == "Default Vehicle") { - LogEventWriter("Using Default Vehicle At Start Warning"); + Log.EventWriter("Using Default Vehicle At Start Warning"); YesMessageBox("Using Default Vehicle" + "\r\n\r\n" + "Load Existing Vehicle or Save As a New One !!!" + "\r\n\r\n" + "Changes will NOT be Saved for Default Vehicle"); @@ -704,7 +663,7 @@ private void FormGPS_FormClosing(object sender, FormClosingEventArgs e) SaveFormGPSWindowSettings(); - sbSystemEvents.Append("Program Exit: " + DateTime.Now.ToString("f", CultureInfo.CreateSpecificCulture(Settings.Default.setF_culture)) + "\r"); + Log.sbEvents.Append("Program Exit: " + DateTime.Now.ToString("f", CultureInfo.CreateSpecificCulture(Settings.Default.setF_culture)) + "\r"); //write the log file FileSaveSystemEvents(); diff --git a/SourceCode/GPS/Forms/FormMap.cs b/SourceCode/GPS/Forms/FormMap.cs index 966e257ea..6ba167a9d 100644 --- a/SourceCode/GPS/Forms/FormMap.cs +++ b/SourceCode/GPS/Forms/FormMap.cs @@ -444,7 +444,7 @@ private void SaveBackgroundImage() if (!mf.worldGrid.isGeoMap) { mf.TimedMessageBox(2000, "Map Error", "Map Too Large"); - mf.LogEventWriter("GeoMap, Map Too Large"); + Log.EventWriter("GeoMap, Map Too Large"); ResetMapGrid(); return; } @@ -476,7 +476,7 @@ private void SaveBackgroundImage() catch { mf.TimedMessageBox(2000, "File in Use", "Try loading again"); - mf.LogEventWriter("GeoMap File in Use, Try Reload"); + Log.EventWriter("GeoMap File in Use, Try Reload"); return; } diff --git a/SourceCode/GPS/Forms/GUI.Designer.cs b/SourceCode/GPS/Forms/GUI.Designer.cs index ab6dbd1ca..9e4715dc7 100644 --- a/SourceCode/GPS/Forms/GUI.Designer.cs +++ b/SourceCode/GPS/Forms/GUI.Designer.cs @@ -95,23 +95,13 @@ public partial class FormGPS public List buttonOrder = new List(); - public StringBuilder sbSystemEvents = new StringBuilder(); //Timer triggers at 125 msec - - public void LogEventWriter(string message) - { - sbSystemEvents.Append(DateTime.Now.ToString("T")); - sbSystemEvents.Append("-> "); - sbSystemEvents.Append(message); - sbSystemEvents.Append("\r"); - } - private void tmrWatchdog_tick(object sender, EventArgs e) { if (sentenceCounter == 19) { - LogEventWriter("No GPS Warning - Lost GPS"); + Log.EventWriter("No GPS Warning - Lost GPS"); } //Check for a newline char, if none then just return @@ -324,10 +314,6 @@ private void tmrWatchdog_tick(object sender, EventArgs e) if (navPanelCounter-- <= 0) panelNavigation.Visible = false; lblHz.Text = gpsHz.ToString("N1") + " ~ " + (frameTime.ToString("N1")) + " " + FixQuality; } - - //save nmea log file - if (isLogNMEA) FileSaveNMEA(); - }//end every 2 seconds //every second update all status /////////////////////////// 1 1 1 1 1 1 //////////////////////////// @@ -415,7 +401,7 @@ private void tmrWatchdog_tick(object sender, EventArgs e) { btnAutoSteer.PerformClick(); TimedMessageBox(2000, gStr.gsGuidanceStopped, gStr.gsNoGuidanceLines); - LogEventWriter("Steer Safe Off, No Tracks, Idx -1"); + Log.EventWriter("Steer Safe Off, No Tracks, Idx -1"); } @@ -963,7 +949,7 @@ public void PanelUpdateRightAndBottom() { btnAutoSteer.PerformClick(); TimedMessageBox(2000, gStr.gsGuidanceStopped, gStr.gsNoGuidanceLines); - LogEventWriter("Steer Safe Off, No Tracks, Idx -1"); + Log.EventWriter("Steer Safe Off, No Tracks, Idx -1"); } btnAutoSteer.Enabled = false; } @@ -1588,7 +1574,7 @@ private void oglMain_MouseDown(object sender, MouseEventArgs e) isFirstHeadingSet = false; isReverse = false; TimedMessageBox(2000, "Reset Direction", "Drive Forward > 1.5 kmh"); - LogEventWriter("Direction Reset, Drive Forward"); + Log.EventWriter("Direction Reset, Drive Forward"); return; } @@ -1620,7 +1606,7 @@ private void SpeedLimitExceeded() + (vehicle.functionSpeedLimit * 0.621371).ToString("N1") + " " + gStr.gsMPH); } - LogEventWriter("UTurn or Lateral Speed exceeded"); + Log.EventWriter("UTurn or Lateral Speed exceeded"); } diff --git a/SourceCode/GPS/Forms/Guidance/FormBuildTracks.cs b/SourceCode/GPS/Forms/Guidance/FormBuildTracks.cs index 0f7d66372..6745f9472 100644 --- a/SourceCode/GPS/Forms/Guidance/FormBuildTracks.cs +++ b/SourceCode/GPS/Forms/Guidance/FormBuildTracks.cs @@ -201,7 +201,7 @@ private void btnListUse_Click(object sender, EventArgs e) { mf.btnAutoSteer.PerformClick(); mf.TimedMessageBox(2000, gStr.gsGuidanceStopped, gStr.gsNoGuidanceLines); - mf.LogEventWriter("Autosteer Stop, No Tracks Available"); + Log.EventWriter("Autosteer Stop, No Tracks Available"); } Close(); @@ -1134,7 +1134,7 @@ private void btnLoadABFromKML_Click(object sender, EventArgs e) } catch (Exception ed) { - mf.LogEventWriter("Tracks from KML " + ed.ToString()); + Log.EventWriter("Tracks from KML " + ed.ToString()); return; } diff --git a/SourceCode/GPS/Forms/Guidance/FormHeadAche.cs b/SourceCode/GPS/Forms/Guidance/FormHeadAche.cs index 9256c9385..95516e602 100644 --- a/SourceCode/GPS/Forms/Guidance/FormHeadAche.cs +++ b/SourceCode/GPS/Forms/Guidance/FormHeadAche.cs @@ -742,7 +742,7 @@ private void btnBndLoop_Click(object sender, EventArgs e) if (nextLine == lineNum) { mf.TimedMessageBox(2000, "Create Error", "Is there maybe only 1 line?"); - mf.LogEventWriter("Headache, Only 1 Line"); + Log.EventWriter("Headache, Only 1 Line"); return; } @@ -782,7 +782,7 @@ private void btnBndLoop_Click(object sender, EventArgs e) if (crossings.Count != mf.hdl.tracksArr.Count * 2) { mf.TimedMessageBox(2000, "Crosings Error", "Make sure all ends cross and only once"); - mf.LogEventWriter("Headache, All ends cross and only once"); + Log.EventWriter("Headache, All ends cross and only once"); mf.bnd.bndList[0].hdLine?.Clear(); return; } diff --git a/SourceCode/GPS/Forms/Guidance/FormHeadLine.cs b/SourceCode/GPS/Forms/Guidance/FormHeadLine.cs index c824e8182..9483eff20 100644 --- a/SourceCode/GPS/Forms/Guidance/FormHeadLine.cs +++ b/SourceCode/GPS/Forms/Guidance/FormHeadLine.cs @@ -144,7 +144,7 @@ private void oglSelf_MouseDown(object sender, MouseEventArgs e) if (nudSetDistance.Value == 0 && rbtnCurve.Checked) { mf.TimedMessageBox(3000, "Distance Error", "Distance Set to 0, Nothing to Move"); - mf.LogEventWriter("Headland, Distance=0, Can't Move"); + Log.EventWriter("Headland, Distance=0, Can't Move"); return; } sliceArr?.Clear(); @@ -841,7 +841,7 @@ private void btnSlice_Click(object sender, EventArgs e) if (isStart < 2) { mf.TimedMessageBox(2000, "Error", "Crossings not Found"); - mf.LogEventWriter("Headland, Crossings Not Found"); + Log.EventWriter("Headland, Crossings Not Found"); return; } diff --git a/SourceCode/GPS/Forms/Guidance/FormQuickAB.cs b/SourceCode/GPS/Forms/Guidance/FormQuickAB.cs index 81395f71c..3502ea7d4 100644 --- a/SourceCode/GPS/Forms/Guidance/FormQuickAB.cs +++ b/SourceCode/GPS/Forms/Guidance/FormQuickAB.cs @@ -14,13 +14,11 @@ public partial class FormQuickAB : Form private double aveLineHeading; public List gTemp = new List(); - private bool isRefRightSide = true, isMakingOnlyAB = false; //left side 0 middle 1 right 2 + private bool isRefRightSide = true; //left side 0 middle 1 right 2 //used throughout to acces the master Track list private int idx; - private vec3 clickA, clickB; - public FormQuickAB(Form _mf) { mf = _mf as FormGPS; diff --git a/SourceCode/GPS/Forms/OpenGL.Designer.cs b/SourceCode/GPS/Forms/OpenGL.Designer.cs index 946202b59..476e1bb4d 100644 --- a/SourceCode/GPS/Forms/OpenGL.Designer.cs +++ b/SourceCode/GPS/Forms/OpenGL.Designer.cs @@ -496,10 +496,10 @@ private void oglMain_Paint(object sender, PaintEventArgs e) { btnAutoSteer.PerformClick(); TimedMessageBox(2000, "Autosteer Turned Off", "RTK Fix Alarm"); - LogEventWriter("Autosteer Off, RTK Fix Alarm"); + Log.EventWriter("Autosteer Off, RTK Fix Alarm"); } - LogEventWriter("RTK Alarm Fix is Lost"); + Log.EventWriter("RTK Alarm Fix is Lost"); sounds.sndRTKAlarm.Play(); } sounds.isRTKAlarming = true; diff --git a/SourceCode/GPS/Forms/Pickers/FormFilePicker.cs b/SourceCode/GPS/Forms/Pickers/FormFilePicker.cs index 997cf01ef..e1dee0ae7 100644 --- a/SourceCode/GPS/Forms/Pickers/FormFilePicker.cs +++ b/SourceCode/GPS/Forms/Pickers/FormFilePicker.cs @@ -38,7 +38,7 @@ private void FormFilePicker_Load(object sender, EventArgs e) if (dirs == null || dirs.Length < 1) { mf.TimedMessageBox(2000, gStr.gsCreateNewField, gStr.gsFileError); - mf.LogEventWriter("File Picker, No Fields"); + Log.EventWriter("File Picker, No Fields"); Close(); return; } @@ -94,7 +94,7 @@ private void FormFilePicker_Load(object sender, EventArgs e) { MessageBox.Show(fieldDirectory + " is Damaged, Please Delete, Field.txt is Broken", gStr.gsFileError, MessageBoxButtons.OK, MessageBoxIcon.Error); - mf.LogEventWriter("Field.txt is Broken" + eg.ToString()); + Log.EventWriter("Field.txt is Broken" + eg.ToString()); fileList.Add(fieldDirectory); fileList.Add("Error"); } @@ -175,7 +175,7 @@ private void FormFilePicker_Load(object sender, EventArgs e) catch (Exception) { area = 0; - mf.LogEventWriter("Field.txt is Broken" + e.ToString()); + Log.EventWriter("Field.txt is Broken" + e.ToString()); } } if (area == 0) fileList.Add("No Bndry"); @@ -195,7 +195,7 @@ private void FormFilePicker_Load(object sender, EventArgs e) if (fileList == null || fileList.Count < 1) { mf.TimedMessageBox(2000, gStr.gsNoFieldsFound, gStr.gsCreateNewField); - mf.LogEventWriter("File Picker, No fields Sorted"); + Log.EventWriter("File Picker, No fields Sorted"); Close(); return; } @@ -222,7 +222,7 @@ private void FormFilePicker_Load(object sender, EventArgs e) else { mf.TimedMessageBox(2000, gStr.gsNoFieldsFound, gStr.gsCreateNewField); - mf.LogEventWriter("File Picker, No Line items"); + Log.EventWriter("File Picker, No Line items"); Close(); return; } @@ -405,7 +405,7 @@ private void btnDeleteField_Click(object sender, EventArgs e) { MessageBox.Show(fieldDirectory + " is Damaged, Please Delete, Field.txt is Broken", gStr.gsFileError, MessageBoxButtons.OK, MessageBoxIcon.Error); - mf.LogEventWriter("Field.txt is Broken" + e.ToString()); + Log.EventWriter("Field.txt is Broken" + e.ToString()); fileList.Add(fieldDirectory); fileList.Add("Error"); } @@ -484,7 +484,7 @@ private void btnDeleteField_Click(object sender, EventArgs e) catch (Exception) { area = 0; - mf.LogEventWriter("Field.txt is Broken" + e.ToString()); + Log.EventWriter("Field.txt is Broken" + e.ToString()); } } if (area == 0) fileList.Add("No Bndry"); diff --git a/SourceCode/GPS/Forms/Pickers/FormRecordPicker.cs b/SourceCode/GPS/Forms/Pickers/FormRecordPicker.cs index f93d0567c..0b18652d6 100644 --- a/SourceCode/GPS/Forms/Pickers/FormRecordPicker.cs +++ b/SourceCode/GPS/Forms/Pickers/FormRecordPicker.cs @@ -104,7 +104,7 @@ private void btnOpenExistingLv_Click(object sender, EventArgs e) catch (Exception ex) { mf.TimedMessageBox(2000, gStr.gsRecordedPathFileIsCorrupt, gStr.gsButFieldIsLoaded); - mf.LogEventWriter("Load Recorded Path" + ex.ToString()); + Log.EventWriter("Load Recorded Path" + ex.ToString()); } } } diff --git a/SourceCode/GPS/Forms/Position.designer.cs b/SourceCode/GPS/Forms/Position.designer.cs index 509a734ad..d05761271 100644 --- a/SourceCode/GPS/Forms/Position.designer.cs +++ b/SourceCode/GPS/Forms/Position.designer.cs @@ -274,7 +274,7 @@ public void UpdateFixPosition() isFirstHeadingSet = true; TimedMessageBox(2000, "Direction Reset", "Forward is Set"); - LogEventWriter("Forward Is Set"); + Log.EventWriter("Forward Is Set"); lastGPS = pn.fix; @@ -778,13 +778,13 @@ public void UpdateFixPosition() //if (isFirstHeadingSet && jumpDistanceAlarm > 0 && jumpDistance > jumpDistanceAlarm) //{ - // LogEventWriter(": " + jumpDistance.ToString("N0") + " cm"); + // Log.EventWriter(": " + jumpDistance.ToString("N0") + " cm"); // if (isBtnAutoSteerOn) // { // btnAutoSteer.PerformClick(); // TimedMessageBox(3000, gStr.gsAutoSteer, "Big Jump in GPS position:" + jumpDistance.ToString("N0") + " cm"); - // LogEventWriter("Autosteer Off, Jump in GPS position: " + jumpDistance.ToString("N0") + " cm"); + // Log.EventWriter("Autosteer Off, Jump in GPS position: " + jumpDistance.ToString("N0") + " cm"); // } //} @@ -917,7 +917,7 @@ public void UpdateFixPosition() else TimedMessageBox(3000, "AutoSteer Disabled", "Below Minimum Safe Steering Speed: " + (vehicle.minSteerSpeed * 0.621371).ToString("N1") + " MPH"); - LogEventWriter("Steer Off, Below Min Steering Speed"); + Log.EventWriter("Steer Off, Below Min Steering Speed"); } } else @@ -1058,7 +1058,7 @@ public void UpdateFixPosition() if (sounds.isTurnSoundOn) { sounds.sndUTurnTooClose.Play(); - LogEventWriter("U Turn Creation Failure"); + Log.EventWriter("U Turn Creation Failure"); } } } @@ -1202,7 +1202,7 @@ private void TheRest() // { // btnAutoSteer.PerformClick(); // TimedMessageBox(2000, gStr.gsGuidanceStopped, "Panic Stop"); - // LogEventWriter("Steer Off, Panic Stop Exceeded"); + // Log.EventWriter("Steer Off, Panic Stop Exceeded"); // } //} diff --git a/SourceCode/GPS/Forms/SaveOpen.Designer.cs b/SourceCode/GPS/Forms/SaveOpen.Designer.cs index 757e6bd34..be8e7c43b 100644 --- a/SourceCode/GPS/Forms/SaveOpen.Designer.cs +++ b/SourceCode/GPS/Forms/SaveOpen.Designer.cs @@ -213,7 +213,7 @@ public void ExportFieldAs_ISOXMLv3() catch (Exception e) { TimedMessageBox(2000, "ISOXML Exception ", e.ToString()); - LogEventWriter("Export field as ISOXML Exception" + e); + Log.EventWriter("Export field as ISOXML Exception" + e); } } @@ -450,7 +450,7 @@ public void ExportFieldAs_ISOXMLv4() } catch (Exception e) { - LogEventWriter("Export Field as ISOXML: " + e.Message); + Log.EventWriter("Export Field as ISOXML: " + e.Message); } /* @@ -522,7 +522,7 @@ public void FileSaveHeadLines() } catch (Exception er) { - LogEventWriter("Saving Head Lines" + er.ToString()); + Log.EventWriter("Saving Head Lines" + er.ToString()); return; } @@ -556,7 +556,7 @@ public void FileLoadHeadLines() if (!File.Exists(filename)) { TimedMessageBox(2000, gStr.gsFileError, "Missing Headlines File"); - LogEventWriter("Load Field, Missing Headlines File"); + Log.EventWriter("Load Field, Missing Headlines File"); } else { @@ -637,7 +637,7 @@ public void FileLoadHeadLines() } catch { } } - LogEventWriter("Load Head Lines" + er.ToString()); + Log.EventWriter("Load Head Lines" + er.ToString()); } } } @@ -708,7 +708,7 @@ public void FileSaveTracks() } catch (Exception er) { - LogEventWriter("Saving Curve Line" + er.ToString()); + Log.EventWriter("Saving Curve Line" + er.ToString()); return; } @@ -747,7 +747,7 @@ public void FileLoadTracks() if (!File.Exists(filename)) { TimedMessageBox(2000, gStr.gsFileError, "Missing Tracks File"); - LogEventWriter("Load Field, Missing Tracks File"); + Log.EventWriter("Load Field, Missing Tracks File"); } else { @@ -815,7 +815,7 @@ public void FileLoadTracks() catch (Exception er) { TimedMessageBox(2000, gStr.gsCurveLineFileIsCorrupt, gStr.gsButFieldIsLoaded); - LogEventWriter("Load Curve Line" + er.ToString()); + Log.EventWriter("Load Curve Line" + er.ToString()); } } } @@ -872,7 +872,7 @@ public void FileSaveCurveLines() } catch (Exception er) { - LogEventWriter("Saving Curve Line" + er.ToString()); + Log.EventWriter("Saving Curve Line" + er.ToString()); return; } @@ -904,7 +904,7 @@ public void FileLoadCurveLines() if (!File.Exists(filename)) { TimedMessageBox(2000, gStr.gsFileError, "Missing Curve File"); - LogEventWriter("Load Field, Missing Curve File"); + Log.EventWriter("Load Field, Missing Curve File"); } else { @@ -980,7 +980,7 @@ public void FileLoadCurveLines() { TimedMessageBox(2000, gStr.gsCurveLineFileIsCorrupt, gStr.gsButFieldIsLoaded); - LogEventWriter("Load Curve Line" + er.ToString()); + Log.EventWriter("Load Curve Line" + er.ToString()); } } } @@ -1080,7 +1080,7 @@ public void FileLoadABLines() { TimedMessageBox(2000, "AB Line Corrupt", "Please delete it!!!"); - LogEventWriter("FieldOpen, Loading ABLine, Corrupt ABLine File" + er); + Log.EventWriter("FieldOpen, Loading ABLine, Corrupt ABLine File" + er); } } } @@ -1205,7 +1205,7 @@ public void FileOpenField(string _openType) catch (Exception e) { - LogEventWriter("While Opening Field" + e.ToString()); + Log.EventWriter("While Opening Field" + e.ToString()); TimedMessageBox(2000, gStr.gsFieldFileIsCorrupt, gStr.gsChooseADifferentField); @@ -1286,7 +1286,7 @@ public void FileOpenField(string _openType) } catch (Exception e) { - LogEventWriter("Section file" + e.ToString()); + Log.EventWriter("Section file" + e.ToString()); TimedMessageBox(2000, "Section File is Corrupt", gStr.gsButFieldIsLoaded); @@ -1349,7 +1349,7 @@ public void FileOpenField(string _openType) } catch (Exception e) { - LogEventWriter("Loading Contour file" + e.ToString()); + Log.EventWriter("Loading Contour file" + e.ToString()); TimedMessageBox(2000, gStr.gsContourFileIsCorrupt, gStr.gsButFieldIsLoaded); @@ -1430,7 +1430,7 @@ public void FileOpenField(string _openType) { TimedMessageBox(2000, gStr.gsFlagFileIsCorrupt, gStr.gsButFieldIsLoaded); - LogEventWriter("FieldOpen, Loading Flags, Corrupt Flag File" + e.ToString()); + Log.EventWriter("FieldOpen, Loading Flags, Corrupt Flag File" + e.ToString()); } } } @@ -1525,7 +1525,7 @@ public void FileOpenField(string _openType) { TimedMessageBox(2000, gStr.gsBoundaryLineFilesAreCorrupt, gStr.gsButFieldIsLoaded); - LogEventWriter("Load Boundary Line" + e.ToString()); + Log.EventWriter("Load Boundary Line" + e.ToString()); } } } @@ -1576,7 +1576,7 @@ public void FileOpenField(string _openType) { TimedMessageBox(2000, "Headland File is Corrupt", "But Field is Loaded"); - LogEventWriter("Load Headland Loop" + e.ToString()); + Log.EventWriter("Load Headland Loop" + e.ToString()); } } } @@ -1691,7 +1691,7 @@ public void FileOpenField(string _openType) { TimedMessageBox(2000, "Tram is corrupt", gStr.gsButFieldIsLoaded); - LogEventWriter("Load Boundary Line" + e.ToString()); + Log.EventWriter("Load Boundary Line" + e.ToString()); } } } @@ -1744,7 +1744,7 @@ public void FileOpenField(string _openType) { TimedMessageBox(2000, gStr.gsRecordedPathFileIsCorrupt, gStr.gsButFieldIsLoaded); - LogEventWriter("Load Recorded Path" + e.ToString()); + Log.EventWriter("Load Recorded Path" + e.ToString()); } } } @@ -2294,7 +2294,7 @@ public void FileLoadRecPath() { TimedMessageBox(2000, gStr.gsRecordedPathFileIsCorrupt, gStr.gsButFieldIsLoaded); - LogEventWriter("Load Recorded Path" + e.ToString()); + Log.EventWriter("Load Recorded Path" + e.ToString()); } } } @@ -2342,112 +2342,17 @@ public void FileSaveFlags() catch (Exception e) { TimedMessageBox(2000, "Error",e.Message + "\n Cannot write to file."); - LogEventWriter("Saving Flags" + e.ToString()); + Log.EventWriter("Saving Flags" + e.ToString()); return; } } } - //save all the flag markers - //public void FileSaveABLine() - //{ - // //Saturday, February 11, 2017 --> 7:26:52 AM - - // //get the directory and make sure it exists, create if not - // string dirField = fieldsDirectory + currentFieldDirectory + "\\"; - - // string directoryName = Path.GetDirectoryName(dirField); - // if ((directoryName.Length > 0) && (!Directory.Exists(directoryName))) - // { Directory.CreateDirectory(directoryName); } - - // //use Streamwriter to create and overwrite existing ABLine file - // using (StreamWriter writer = new StreamWriter(dirField + "ABLine.txt")) - // { - // try - // { - // //write out the ABLine - // writer.WriteLine("$ABLine"); - - // //true or false if ABLine is set - // if (ABLine.isABLineSet) writer.WriteLine(true); - // else writer.WriteLine(false); - - // writer.WriteLine(ABLine.abHeading.ToString(CultureInfo.InvariantCulture)); - // writer.WriteLine(ABLine.refPtA.easting.ToString(CultureInfo.InvariantCulture) + "," + ABLine.refPtA.northing.ToString(CultureInfo.InvariantCulture)); - // writer.WriteLine(ABLine.refPtB.easting.ToString(CultureInfo.InvariantCulture) + "," + ABLine.refPtB.northing.ToString(CultureInfo.InvariantCulture)); - // writer.WriteLine(ABLine.tramPassEvery.ToString(CultureInfo.InvariantCulture) + "," + ABLine.passBasedOn.ToString(CultureInfo.InvariantCulture)); - // } - - // catch (Exception e) - // { - // Console.WriteLine(e.Message + "\n Cannot write to file."); - // WriteErrorLog("Saving AB Line" + e.ToString()); - - // return; - // } - - // } - //} - - //save all the flag markers - //public void FileSaveCurveLine() - //{ - // //Saturday, February 11, 2017 --> 7:26:52 AM - - // //get the directory and make sure it exists, create if not - // string dirField = fieldsDirectory + currentFieldDirectory + "\\"; - - // string directoryName = Path.GetDirectoryName(dirField); - // if ((directoryName.Length > 0) && (!Directory.Exists(directoryName))) - // { Directory.CreateDirectory(directoryName); } - - // //use Streamwriter to create and overwrite existing ABLine file - // using (StreamWriter writer = new StreamWriter(dirField + "CurveLine.txt")) - // { - // try - // { - // //write out the ABLine - // writer.WriteLine("$CurveLine"); - - // //write out the heading - // writer.WriteLine(curve.refCurve.heading.ToString(CultureInfo.InvariantCulture)); - - // //write out the points of ref line - // writer.WriteLine(curve.refCurve.curvePts.Count.ToString(CultureInfo.InvariantCulture)); - // if (curve.refCurve.curvePts.Count > 0) - // { - // for (int j = 0; j < curve.refCurve.curvePts.Count; j++) - // writer.WriteLine(Math.Round(curve.refCurve.curvePts[j].easting, 3).ToString(CultureInfo.InvariantCulture) + "," + - // Math.Round(curve.refCurve.curvePts[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + - // Math.Round(curve.refCurve.curvePts[j].heading, 5).ToString(CultureInfo.InvariantCulture)); - // } - // } - - // catch (Exception e) - // { - // WriteErrorLog("Saving Curve Line" + e.ToString()); - - // return; - // } - - // } - //} - - //save nmea sentences - public void FileSaveNMEA() - { - using (StreamWriter writer = new StreamWriter("zAOG_log.txt", true)) - { - writer.Write(pn.logNMEASentence.ToString()); - } - pn.logNMEASentence.Clear(); - } - public void FileSaveSystemEvents() { - using (StreamWriter writer = new StreamWriter(Path.Combine(logsDirectory, "zSystemEventsLog_log.txt"), true)) + using (StreamWriter writer = new StreamWriter(Path.Combine(logsDirectory, "AgOpenGPS_Events_Log.txt"), true)) { - writer.Write(sbSystemEvents); + writer.Write(Log.sbEvents); } } diff --git a/SourceCode/GPS/Forms/Settings/ConfigData.Designer.cs b/SourceCode/GPS/Forms/Settings/ConfigData.Designer.cs index a53320d3d..bc7e299ce 100644 --- a/SourceCode/GPS/Forms/Settings/ConfigData.Designer.cs +++ b/SourceCode/GPS/Forms/Settings/ConfigData.Designer.cs @@ -264,7 +264,7 @@ private void btnZeroRoll_Click(object sender, EventArgs e) mf.ahrs.imuRoll += mf.ahrs.rollZero; mf.ahrs.rollZero = mf.ahrs.imuRoll; lblRollZeroOffset.Text = (mf.ahrs.rollZero).ToString("N2"); - mf.LogEventWriter("Roll Zeroed with " + mf.ahrs.rollZero.ToString()); + Log.EventWriter("Roll Zeroed with " + mf.ahrs.rollZero.ToString()); } else { @@ -276,7 +276,7 @@ private void btnRemoveZeroOffset_Click(object sender, EventArgs e) { mf.ahrs.rollZero = 0; lblRollZeroOffset.Text = "0.00"; - mf.LogEventWriter("Roll Zero Offset Removed"); + Log.EventWriter("Roll Zero Offset Removed"); } private void btnResetIMU_Click(object sender, EventArgs e) diff --git a/SourceCode/GPS/Forms/Settings/ConfigTool.Designer.cs b/SourceCode/GPS/Forms/Settings/ConfigTool.Designer.cs index 2abdbad04..c0e92294a 100644 --- a/SourceCode/GPS/Forms/Settings/ConfigTool.Designer.cs +++ b/SourceCode/GPS/Forms/Settings/ConfigTool.Designer.cs @@ -1153,7 +1153,7 @@ private void cboxNumSections_SelectedIndexChanged(object sender, EventArgs e) { wide = 99; mf.TimedMessageBox(3000, "Too Wide", "Max 50 Meters"); - mf.LogEventWriter("Sections, Tool Set Too Wide"); + Log.EventWriter("Sections, Tool Set Too Wide"); } } @@ -1163,7 +1163,7 @@ private void cboxNumSections_SelectedIndexChanged(object sender, EventArgs e) { wide = 19; mf.TimedMessageBox(3000, "Too Wide", "Max 164 Feet"); - mf.LogEventWriter("Sections, Tool Set Too Wide"); + Log.EventWriter("Sections, Tool Set Too Wide"); } } @@ -1250,7 +1250,7 @@ public void UpdateSpinners() if (toolWidth > 5000) { mf.TimedMessageBox(3000, "Too Wide", "Set to 99, Max 50 Meters"); - mf.LogEventWriter("Sections, Tool Set Too Wide"); + Log.EventWriter("Sections, Tool Set Too Wide"); toolWidth = 0; nudSection01.Value = 99; nudSection02.Value = 99; @@ -1275,7 +1275,7 @@ public void UpdateSpinners() if (toolWidth > 1900) { mf.TimedMessageBox(3000, "Too Wide", "Set to 99, Max 164 Feet"); - mf.LogEventWriter("Sections, Tool Set Too Wide"); + Log.EventWriter("Sections, Tool Set Too Wide"); toolWidth = 0; nudSection01.Value = 99; nudSection02.Value = 99; diff --git a/SourceCode/GPS/Forms/Settings/ConfigVehicle.Designer.cs b/SourceCode/GPS/Forms/Settings/ConfigVehicle.Designer.cs index 9425c72e0..11cda2a9d 100644 --- a/SourceCode/GPS/Forms/Settings/ConfigVehicle.Designer.cs +++ b/SourceCode/GPS/Forms/Settings/ConfigVehicle.Designer.cs @@ -153,7 +153,7 @@ private void btnVehicleLoad_Click(object sender, EventArgs e) ///Remind the user mf.TimedMessageBox(2500, "Steer and Machine Settings Sent", "Were Modules Connected?"); - mf.LogEventWriter("Vehicle Loaded: " + mf.vehicleFileName + ".XML"); + Log.EventWriter("Vehicle Loaded: " + mf.vehicleFileName + ".XML"); } UpdateVehicleListView(); @@ -197,7 +197,7 @@ private void btnVehicleDelete_Click(object sender, EventArgs e) } else { - mf.LogEventWriter("Attempted to Delete Default Vehicle, Denied"); + Log.EventWriter("Attempted to Delete Default Vehicle, Denied"); mf.TimedMessageBox(2500, "Default Vehicle Delete Denied", "Choose Another Vehicle"); } @@ -373,7 +373,7 @@ private void btnVehicleNewSave_Click(object sender, EventArgs e) ///Remind the user mf.TimedMessageBox(2500, "Steer and Machine Settings Sent", "Were Modules Connected?"); - mf.LogEventWriter("New Vehicle Loaded: " + mf.vehicleFileName + ".XML"); + Log.EventWriter("New Vehicle Loaded: " + mf.vehicleFileName + ".XML"); SettingsIO.ExportAll(Path.Combine(mf.vehiclesDirectory, mf.vehicleFileName + ".XML")); @@ -421,7 +421,6 @@ private void SaveDisplaySettings() mf.isSpeedoOn = chkDisplaySpeedo.Checked; mf.isSideGuideLines = chkDisplayExtraGuides.Checked; - mf.isLogNMEA = chkDisplayLogNMEA.Checked; mf.isDrawPolygons = chkDisplayPolygons.Checked; mf.isKeyboardOn = chkDisplayKeyboard.Checked; diff --git a/SourceCode/GPS/Forms/Settings/FormAllSettings.cs b/SourceCode/GPS/Forms/Settings/FormAllSettings.cs index e746082ca..1be4c05bb 100644 --- a/SourceCode/GPS/Forms/Settings/FormAllSettings.cs +++ b/SourceCode/GPS/Forms/Settings/FormAllSettings.cs @@ -160,7 +160,7 @@ private void btnScreenShot_Click(object sender, EventArgs e) this.DrawToBitmap(bm, new Rectangle(0, 0, this.Width, this.Height)); Clipboard.SetImage(bm); mf.TimedMessageBox(2000, "Captured", "Copied to Clipboard, Paste (CTRL-V) in Telegram"); - mf.LogEventWriter("View All Settings to Clipboard"); + Log.EventWriter("View All Settings to Clipboard"); } private void btnCreatePNG_Click(object sender, EventArgs e) @@ -169,7 +169,7 @@ private void btnCreatePNG_Click(object sender, EventArgs e) this.DrawToBitmap(bm, new Rectangle(0, 0, this.Width, this.Height)); bm.Save(Path.Combine(mf.baseDirectory, "AllSet.PNG"), ImageFormat.Png); System.Diagnostics.Process.Start("explorer.exe", mf.baseDirectory); - mf.LogEventWriter("View All Settings to PNG"); + Log.EventWriter("View All Settings to PNG"); Close(); } diff --git a/SourceCode/GPS/Forms/Settings/FormButtonsRightPanel.cs b/SourceCode/GPS/Forms/Settings/FormButtonsRightPanel.cs index fc0aae4d5..6062f5aad 100644 --- a/SourceCode/GPS/Forms/Settings/FormButtonsRightPanel.cs +++ b/SourceCode/GPS/Forms/Settings/FormButtonsRightPanel.cs @@ -158,7 +158,7 @@ private void btnOk_Click(object sender, EventArgs e) if (mf.buttonOrder.Count < 2) { mf.TimedMessageBox(2000, "Button Error", "Not Enough Buttons Added"); - mf.LogEventWriter("Button Picker, Not Enough Buttons"); + Log.EventWriter("Button Picker, Not Enough Buttons"); return; } else diff --git a/SourceCode/GPS/Forms/Settings/FormConfig.cs b/SourceCode/GPS/Forms/Settings/FormConfig.cs index 8758ad6bf..d27b738ee 100644 --- a/SourceCode/GPS/Forms/Settings/FormConfig.cs +++ b/SourceCode/GPS/Forms/Settings/FormConfig.cs @@ -260,7 +260,6 @@ private void tabDisplay_Enter(object sender, EventArgs e) chkDisplayStartFullScreen.Checked = Properties.Settings.Default.setDisplay_isStartFullScreen; chkSvennArrow.Checked = mf.isSvennArrowOn; chkDisplayExtraGuides.Checked = mf.isSideGuideLines; - chkDisplayLogNMEA.Checked = mf.isLogNMEA; chkDisplayPolygons.Checked = mf.isDrawPolygons; chkDisplayKeyboard.Checked = mf.isKeyboardOn; chkDisplayLogElevation.Checked = mf.isLogElevation; @@ -282,7 +281,7 @@ private void tabDisplay_Leave(object sender, EventArgs e) private void rbtnDisplayImperial_Click(object sender, EventArgs e) { mf.TimedMessageBox(2000, "Units Set", "Imperial"); - mf.LogEventWriter("Units To Imperial"); + Log.EventWriter("Units To Imperial"); mf.isMetric = false; Properties.Settings.Default.setMenu_isMetric = mf.isMetric; @@ -294,7 +293,7 @@ private void rbtnDisplayImperial_Click(object sender, EventArgs e) private void rbtnDisplayMetric_Click(object sender, EventArgs e) { mf.TimedMessageBox(2000, "Units Set", "Metric"); - mf.LogEventWriter("Units to Metric"); + Log.EventWriter("Units to Metric"); mf.isMetric = true; Properties.Settings.Default.setMenu_isMetric = mf.isMetric; diff --git a/SourceCode/GPS/Forms/Settings/FormSteer.cs b/SourceCode/GPS/Forms/Settings/FormSteer.cs index 3f0b1c34a..0e9cd369b 100644 --- a/SourceCode/GPS/Forms/Settings/FormSteer.cs +++ b/SourceCode/GPS/Forms/Settings/FormSteer.cs @@ -553,12 +553,12 @@ private void btnStanleyPure_Click(object sender, EventArgs e) if (mf.isStanleyUsed) { btnStanleyPure.Image = Resources.ModeStanley; - mf.LogEventWriter("Stanley Steer Mode Selectede"); + Log.EventWriter("Stanley Steer Mode Selectede"); } else { btnStanleyPure.Image = Resources.ModePurePursuit; - mf.LogEventWriter("Pure Pursuit Steer Mode Selected"); + Log.EventWriter("Pure Pursuit Steer Mode Selected"); } tabControl1.TabPages.Remove(tabPP); @@ -821,7 +821,7 @@ private void btnZeroWAS_Click(object sender, EventArgs e) if (Math.Abs(offset) > 3900) { mf.TimedMessageBox(2000, "Exceeded Range", "Excessive Steer Angle - Cannot Zero"); - mf.LogEventWriter("Excessive Steer Angle, No Zero " + offset); + Log.EventWriter("Excessive Steer Angle, No Zero " + offset); } else { @@ -995,7 +995,7 @@ private void btnSendSteerConfigPGN_Click(object sender, EventArgs e) SaveSettings(); mf.SendPgnToLoop(mf.p_251.pgn); pboxSendSteer.Visible = false; - mf.LogEventWriter("Steer Form, Send and Save Pressed"); + Log.EventWriter("Steer Form, Send and Save Pressed"); mf.TimedMessageBox(2000, gStr.gsAutoSteerPort, "Settings Sent To Steer Module"); } @@ -1130,7 +1130,7 @@ private void btnVehicleReset_Click(object sender, EventArgs e) MessageBoxDefaultButton.Button2); if (result3 == DialogResult.Yes) { - mf.LogEventWriter("Steer Form - Steer Settings Set to Default"); + Log.EventWriter("Steer Form - Steer Settings Set to Default"); mf.TimedMessageBox(2000, "Reset To Default", "Values Set to Inital Default"); Properties.Settings.Default.setVehicle_maxSteerAngle = mf.vehicle.maxSteerAngle diff --git a/SourceCode/GPS/Forms/Settings/FormSteerWiz.cs b/SourceCode/GPS/Forms/Settings/FormSteerWiz.cs index ce33d37a0..0005aed17 100644 --- a/SourceCode/GPS/Forms/Settings/FormSteerWiz.cs +++ b/SourceCode/GPS/Forms/Settings/FormSteerWiz.cs @@ -284,7 +284,7 @@ private void Timer1_Tick(object sender, EventArgs e) { hsbarCountsPerDegree.Value = 100; lblCPDError.Text = "Error, CPD set to 100"; - mf.LogEventWriter("Error, CPD set to 100" + ed.ToString()); + Log.EventWriter("Error, CPD set to 100" + ed.ToString()); } } } @@ -319,7 +319,7 @@ private void Timer1_Tick(object sender, EventArgs e) { hsbarAckerman.Value = 100; lblAckermannError.Text = "Error, Ackermann set to 100"; - mf.LogEventWriter("Error, Ackermann set to 100"+ eh.ToString()); + Log.EventWriter("Error, Ackermann set to 100"+ eh.ToString()); } } } diff --git a/SourceCode/GPS/Forms/UDPComm.Designer.cs b/SourceCode/GPS/Forms/UDPComm.Designer.cs index 12898f8bc..fcde0b307 100644 --- a/SourceCode/GPS/Forms/UDPComm.Designer.cs +++ b/SourceCode/GPS/Forms/UDPComm.Designer.cs @@ -55,16 +55,16 @@ private void ReceiveFromAgIO(byte[] data) { case 0xD6: { - if (udpWatch.ElapsedMilliseconds < udpWatchLimit) - { - udpWatchCounts++; - if (isLogNMEA) pn.logNMEASentence.Append("*** " - + DateTime.UtcNow.ToString("ss.ff -> ", CultureInfo.InvariantCulture) - + udpWatch.ElapsedMilliseconds + "\r\n"); - return; - } - udpWatch.Reset(); - udpWatch.Start(); + //if (udpWatch.ElapsedMilliseconds < udpWatchLimit) + //{ + // udpWatchCounts++; + // pn.logNMEASentence.Append("*** " + // + DateTime.UtcNow.ToString("ss.ff -> ", CultureInfo.InvariantCulture) + // + udpWatch.ElapsedMilliseconds + "\r\n"); + // return; + //} + //udpWatch.Reset(); + //udpWatch.Start(); double Lon = BitConverter.ToDouble(data, 5); double Lat = BitConverter.ToDouble(data, 13); @@ -160,11 +160,6 @@ private void ReceiveFromAgIO(byte[] data) sentenceCounter = 0; - if (isLogNMEA) - pn.logNMEASentence.Append( - DateTime.UtcNow.ToString("mm:ss.ff",CultureInfo.InvariantCulture)+ " " + - Lat.ToString("N7") + " " + Lon.ToString("N7") ); - UpdateFixPosition(); } } @@ -241,12 +236,6 @@ private void ReceiveFromAgIO(byte[] data) //Actual PWM mc.pwmDisplay = data[12]; - if (isLogNMEA) - pn.logNMEASentence.Append( - DateTime.UtcNow.ToString("mm:ss.ff", CultureInfo.InvariantCulture) + " AS " + - mc.actualSteerAngleDegrees.ToString("N1") + "\r\n" - ); - break; } @@ -269,7 +258,7 @@ private void ReceiveFromAgIO(byte[] data) lblHardwareMessage.Visible = true; hardwareLineCounter = data[5] * 10; - LogEventWriter(lblHardwareMessage.Text); + Log.EventWriter(lblHardwareMessage.Text); //color based on byte 6 if (data[6] == 0) lblHardwareMessage.BackColor = Color.Salmon; @@ -336,7 +325,7 @@ public void StartLoopbackServer() catch (Exception ex) { MessageBox.Show("Load Error: " + ex.Message, "UDP Server", MessageBoxButtons.OK, MessageBoxIcon.Error); - LogEventWriter("Load UDP Server Error: " + ex.ToString()); + Log.EventWriter("Load UDP Server Error: " + ex.ToString()); } } @@ -394,7 +383,7 @@ public void SendPgnToLoop(byte[] byteData) } catch (Exception) { - //LogEventWriter("Sending UDP Message" + e.ToString()); + //Log.EventWriter("Sending UDP Message" + e.ToString()); //MessageBox.Show("Send Error: " + e.Message, "UDP Client", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/SourceCode/GPS/Program.cs b/SourceCode/GPS/Program.cs index 699c382ea..aa4c93fce 100644 --- a/SourceCode/GPS/Program.cs +++ b/SourceCode/GPS/Program.cs @@ -43,7 +43,7 @@ private static void Main() key.Close(); } string workingDirectory = regKey.GetValue("WorkingDirectory").ToString(); - string baseDirectory = workingDirectory; + string baseDirectory; if (workingDirectory == "Default") @@ -109,6 +109,11 @@ private static void Main() { SettingsIO.ImportAll(Path.Combine(vehiclesDirectory, vehicleFileName + ".XML")); } + else + { + vehicleFileName = "Default Vehicle"; + Log.EventWriter("Vehicle file does not exist, Default Vehicle selected"); + } Properties.Settings.Default.setF_culture = language; Properties.Settings.Default.setF_workingDirectory = workingDirectory; From 075983adea107eb46766f2aa67539a59c4393a10 Mon Sep 17 00:00:00 2001 From: FantasyTeddy Date: Tue, 31 Dec 2024 09:41:42 +0100 Subject: [PATCH 2/3] Update workflow to match release strategy --- .github/workflows/build.yml | 49 +++++++++++++++++++++ .github/workflows/{main.yml => release.yml} | 40 +++-------------- 2 files changed, 55 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/build.yml rename .github/workflows/{main.yml => release.yml} (63%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..5e7730a72 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,49 @@ +name: Build + +on: + push: + branches: + - develop + pull_request: + branches: + - master + - develop + - release/* + +env: + # Path to the solution file relative to the root of the project. + SOLUTION_FILE_PATH: ./SourceCode/AgOpenGPS.sln + + # Configuration type to build. + # You can convert this to a build matrix if you need coverage of multiple configuration types. + # https://docs.github.com/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + BUILD_CONFIGURATION: Release + +jobs: + build: + runs-on: windows-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Add MSBuild to PATH + uses: microsoft/setup-msbuild@v2 + + - name: Restore NuGet packages + run: nuget restore ${{env.SOLUTION_FILE_PATH}} -PackagesDirectory .\SourceCode\packages -source "https://api.nuget.org/v3/index.json" + + - name: Build + run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}} + + - name: Create AgOpenGPS.zip + shell: powershell + run: Compress-Archive -Path "AgOpenGPS" -Destination "AgOpenGPS.zip" + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: AgOpenGPS.zip + path: AgOpenGPS.zip diff --git a/.github/workflows/main.yml b/.github/workflows/release.yml similarity index 63% rename from .github/workflows/main.yml rename to .github/workflows/release.yml index f7d531410..dd0b8fb88 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/release.yml @@ -4,10 +4,8 @@ on: push: branches: - master - - develop - pull_request: - branches: - - develop + - release/* + workflow_dispatch: env: # Path to the solution file relative to the root of the project. @@ -19,11 +17,8 @@ env: BUILD_CONFIGURATION: Release jobs: - build: + build-and-release: runs-on: windows-latest - outputs: - version: ${{ steps.variables.outputs.VERSION }} - prerelease: ${{ steps.variables.outputs.PRERELEASE }} steps: - name: Checkout @@ -40,45 +35,22 @@ jobs: - name: Build run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}} - - name: Set variables - id: variables - run: | - echo "VERSION=${{env.GitVersion_SemVer}}" >> $env:GITHUB_OUTPUT - echo "PRERELEASE=${{env.GitVersion_PreReleaseTag != ''}}" >> $env:GITHUB_OUTPUT - - name: Create AgOpenGPS.zip shell: powershell run: Compress-Archive -Path "AgOpenGPS" -Destination "AgOpenGPS.zip" - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: AgOpenGPS.zip - path: AgOpenGPS.zip - - release: - needs: build - runs-on: windows-latest - if: github.event_name != 'pull_request' - - steps: - - name: Download artifact - uses: actions/download-artifact@v4 - with: - name: AgOpenGPS.zip - - name: Create Release id: create_release uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - tag_name: ${{ needs.build.outputs.version }} - release_name: Release ${{ needs.build.outputs.version }} + tag_name: ${{ env.GitVersion_SemVer }} + release_name: Release ${{ env.GitVersion_SemVer }} body: | Automated Release by GitHub Action CI draft: false - prerelease: ${{ needs.build.outputs.prerelease }} + prerelease: ${{ contains(github.ref_name, 'release/') }} - name: Upload Release Asset uses: actions/upload-release-asset@v1 From 346200628e86a1cb167a71598f10216b1e6d9fa9 Mon Sep 17 00:00:00 2001 From: BrianTee Date: Wed, 1 Jan 2025 00:38:09 -0700 Subject: [PATCH 3/3] Add registry settings to AgIO --- .../AgIO/Source/Forms/Controls.Designer.cs | 4 +- .../AgIO/Source/Forms/FormCommPicker.cs | 15 ++- SourceCode/AgIO/Source/Forms/FormCommSaver.cs | 34 ++++--- SourceCode/AgIO/Source/Forms/FormLoop.cs | 85 +++++----------- SourceCode/AgIO/Source/Program.cs | 98 +++++++++++++------ 5 files changed, 130 insertions(+), 106 deletions(-) diff --git a/SourceCode/AgIO/Source/Forms/Controls.Designer.cs b/SourceCode/AgIO/Source/Forms/Controls.Designer.cs index ee3dbc695..867438319 100644 --- a/SourceCode/AgIO/Source/Forms/Controls.Designer.cs +++ b/SourceCode/AgIO/Source/Forms/Controls.Designer.cs @@ -245,7 +245,7 @@ private void toolStripMenuItem1_Click(object sender, EventArgs e) { form.ShowDialog(this); } - this.Text = "AgIO Profile: " + profileFileName; + this.Text = "AgIO Profile: " + profileName; } @@ -262,7 +262,7 @@ private void toolStripMenuItem2_Click(object sender, EventArgs e) } } - this.Text = "AgIO Profile: " + profileFileName; + this.Text = "AgIO Profile: " + profileName; } private void modSimToolStrip_Click(object sender, EventArgs e) diff --git a/SourceCode/AgIO/Source/Forms/FormCommPicker.cs b/SourceCode/AgIO/Source/Forms/FormCommPicker.cs index db279f4a9..80db2c10d 100644 --- a/SourceCode/AgIO/Source/Forms/FormCommPicker.cs +++ b/SourceCode/AgIO/Source/Forms/FormCommPicker.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Win32; +using System; using System.IO; using System.Windows.Forms; @@ -59,11 +60,19 @@ private void cboxVeh_SelectedIndexChanged(object sender, EventArgs e) } else { + if (mf.profileName != "Default Profile") + SettingsIO.ExportSettings(Path.Combine(mf.profileDirectory, mf.profileName + ".xml")); + SettingsIO.ImportSettings(Path.Combine(mf.profileDirectory, cboxEnv.SelectedItem.ToString().Trim() + ".xml")); - mf.profileFileName = cboxEnv.SelectedItem.ToString().Trim(); - Properties.Settings.Default.setConfig_profileName = mf.profileFileName; + mf.profileName = cboxEnv.SelectedItem.ToString().Trim(); + Properties.Settings.Default.setConfig_profileName = mf.profileName; Properties.Settings.Default.Save(); + + RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\AgIO"); + key.SetValue("ProfileName", mf.profileName); + key.Close(); + DialogResult = DialogResult.OK; Close(); } diff --git a/SourceCode/AgIO/Source/Forms/FormCommSaver.cs b/SourceCode/AgIO/Source/Forms/FormCommSaver.cs index 2146e4945..106c7dd37 100644 --- a/SourceCode/AgIO/Source/Forms/FormCommSaver.cs +++ b/SourceCode/AgIO/Source/Forms/FormCommSaver.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Win32; +using System; using System.IO; using System.Text.RegularExpressions; using System.Windows.Forms; @@ -19,7 +20,7 @@ public FormCommSaver(Form callingForm) private void FormCommSaver_Load(object sender, EventArgs e) { - lblLast.Text = "Current " + mf.profileFileName; + lblLast.Text = "Current " + mf.profileName; DirectoryInfo dinfo = new DirectoryInfo(mf.profileDirectory); FileInfo[] Files = dinfo.GetFiles("*.xml"); @@ -47,14 +48,21 @@ private void cboxVeh_SelectedIndexChanged(object sender, EventArgs e) if (result3 == DialogResult.Yes) { - mf.profileFileName = cboxEnv.SelectedItem.ToString().Trim(); + if (mf.profileName != "Default Profile") + SettingsIO.ExportSettings(Path.Combine(mf.profileDirectory, mf.profileName + ".xml")); + + mf.profileName = cboxEnv.SelectedItem.ToString().Trim(); Properties.Settings.Default.setConfig_profileName = cboxEnv.SelectedItem.ToString().Trim(); Properties.Settings.Default.Save(); - if (mf.profileFileName != "Default Profile") - SettingsIO.ExportSettings(mf.profileDirectory + mf.profileFileName + ".xml"); + RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\AgIO"); + key.SetValue("ProfileName", mf.profileName); + key.Close(); + + if (mf.profileName != "Default Profile") + SettingsIO.ExportSettings(mf.profileDirectory + mf.profileName + ".xml"); else - mf.YesMessageBox("Default Profileuration, Changes will NOT be Saved"); + mf.YesMessageBox("Default Profile, Changes will NOT be Saved"); Close(); } } @@ -73,14 +81,18 @@ private void btnSave_Click(object sender, EventArgs e) if (tboxName.Text.Trim().Length > 0) { - mf.profileFileName = tboxName.Text.ToString().Trim(); - Properties.Settings.Default.setConfig_profileName = mf.profileFileName; + mf.profileName = tboxName.Text.ToString().Trim(); + Properties.Settings.Default.setConfig_profileName = mf.profileName; Properties.Settings.Default.Save(); - if (mf.profileFileName != "Default Profile") - SettingsIO.ExportSettings(mf.profileDirectory + mf.profileFileName + ".xml"); + RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\AgIO"); + key.SetValue("ProfileName", mf.profileName); + key.Close(); + + if (mf.profileName != "Default Profile") + SettingsIO.ExportSettings(Path.Combine(mf.profileDirectory, mf.profileName + ".xml")); else - mf.YesMessageBox("Default Profileuration, Changes will NOT be Saved"); + mf.YesMessageBox("Default Profile, Changes will NOT be Saved"); Close(); } else diff --git a/SourceCode/AgIO/Source/Forms/FormLoop.cs b/SourceCode/AgIO/Source/Forms/FormLoop.cs index f0c0b1489..3eea2b4d4 100644 --- a/SourceCode/AgIO/Source/Forms/FormLoop.cs +++ b/SourceCode/AgIO/Source/Forms/FormLoop.cs @@ -1,4 +1,5 @@ using AgIO.Properties; +using Microsoft.Win32; using System; using System.Diagnostics; using System.Drawing; @@ -74,7 +75,7 @@ public partial class FormLoop : Form public string baseDirectory; //current directory of Comm storage - public string profileDirectory, profileFileName; + public string profileDirectory, profileName; public FormLoop() { @@ -84,59 +85,11 @@ public FormLoop() //First run private void FormLoop_Load(object sender, EventArgs e) { - string workingDirectory = Settings.Default.setF_workingDirectory == "Default" - ? Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) - : Settings.Default.setF_workingDirectory; - - baseDirectory = Path.Combine(workingDirectory, "AgOpenGPS"); - //get the fields directory, if not exist, create - profileDirectory = Path.Combine(baseDirectory, "AgIO"); - DirectoryInfo profileDirectoryInfo = new DirectoryInfo(profileDirectory); - if (!profileDirectoryInfo.Exists) - profileDirectoryInfo.Create(); - - FileInfo[] profileFiles = profileDirectoryInfo.GetFiles("*.xml"); - - if (profileFiles.Length == 0) - { - SettingsIO.ExportSettings(Path.Combine(profileDirectory, "Default Profile.xml")); - - //get list of files again, because it just changed by exporting the default profile - profileFiles = profileDirectoryInfo.GetFiles("*.xml"); - } - - bool isDefault = false; - bool isProfileExist = false; - - profileFileName = Settings.Default.setConfig_profileName; - - foreach (FileInfo file in profileFiles) - { - string temp = Path.GetFileNameWithoutExtension(file.Name).Trim(); - if (temp == "Default Profile") - { - isDefault = true; - } - - if (temp == profileFileName) - { - isProfileExist = true; - } - } - - if (!isDefault) - SettingsIO.ExportSettings(Path.Combine(profileDirectory, "Default Profile.xml")); - - if (!isProfileExist) - { - profileFileName = "Default Profile"; - Settings.Default.setConfig_profileName = profileFileName; - Settings.Default.Save(); - } - - //grab the current vehicle filename - make sure it exists + profileDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), + "AgOpenGPS", "AgIO"); + profileName = Settings.Default.setConfig_profileName; if (Settings.Default.setUDP_isOn) { @@ -316,11 +269,23 @@ private void FormLoop_Load(object sender, EventArgs e) cboxAutoRunGPS_Out.Checked = Properties.Settings.Default.setDisplay_isAutoRunGPS_Out; if (Properties.Settings.Default.setDisplay_isAutoRunGPS_Out) StartGPS_Out(); - this.Text = "AgIO Profile: " + profileFileName; + this.Text = "AgIO Profile: " + profileName; + + if (profileName == "Default Profile") + { + Log.EventWriter("Using Default Profile At Start Warning"); + + if (profileName == "Default Profile") + YesMessageBox("AgIO is Using Default Profile" + "\r\n\r\n" + "Load Existing Profile or Save a New One !!!" + + "\r\n\r\n" + "Changes will NOT be Saved"); + + SettingsIO.ExportSettings(Path.Combine(profileDirectory, "Default Profile.xml")); + + RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\AgIO"); + key.SetValue("ProfileName", "Default Profile"); + key.Close(); + } - if (profileFileName == "Default Profile") - YesMessageBox("Using Default Profile" + "\r\n\r\n" + "Load Existing Profile or Save a New One !!!" - + "\r\n\r\n" + "Changes will NOT be Saved"); } public void SetModulesOnOff() @@ -381,10 +346,10 @@ private void FormLoop_FormClosing(object sender, FormClosingEventArgs e) Settings.Default.Save(); - //if (profileFileName != "Default Profile") - SettingsIO.ExportSettings(Path.Combine(profileDirectory, profileFileName + ".xml")); - //else - //YesMessageBox("Using Default Profile" + "\r\n\r\n" + "Changes will NOT be Saved"); + if (profileName != "Default Profile") + SettingsIO.ExportSettings(Path.Combine(profileDirectory, profileName + ".xml")); + else + YesMessageBox("Using Default Profile" + "\r\n\r\n" + "Changes will NOT be Saved"); if (loopBackSocket != null) diff --git a/SourceCode/AgIO/Source/Program.cs b/SourceCode/AgIO/Source/Program.cs index 995ee4105..ee4376f37 100644 --- a/SourceCode/AgIO/Source/Program.cs +++ b/SourceCode/AgIO/Source/Program.cs @@ -18,50 +18,77 @@ internal static class Program [STAThread] private static void Main() { - string configPath = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath; - if (!File.Exists(configPath)) - { - //Existing user config does not exist, so load settings from previous assembly - Settings.Default.Upgrade(); - Settings.Default.Reload(); - Settings.Default.Save(); - } - - ////opening the subkey - RegistryKey regKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\AgOpenGPS"); + //opening the subkey + RegistryKey regKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\AgIO"); ////create default keys if not existing if (regKey == null) { - RegistryKey Key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\AgOpenGPS"); + RegistryKey Key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\AgIO"); //storing the values Key.SetValue("Language", "en"); + Key.SetValue("ProfileName", "Default Profile"); Key.Close(); + } - Properties.Settings.Default.setF_culture = "en"; - Properties.Settings.Default.Save(); + //Profile File Name from Registry Key + if (regKey.GetValue("ProfileName") == null) + { + RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\AgIO"); + key.SetValue("ProfileName", "Default Profile"); + key.Close(); } - else + + string profileName = regKey.GetValue("ProfileName").ToString(); + regKey.Close(); + + //get the Documents directory, if not exist, create + string profileDirectory = + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "AgOpenGPS", "AgIO"); + + if (!string.IsNullOrEmpty(profileDirectory) && !Directory.Exists(profileDirectory)) { - try - { - Properties.Settings.Default.setF_culture = regKey.GetValue("Language").ToString(); - Properties.Settings.Default.Save(); - regKey.Close(); - } - catch (System.Configuration.ConfigurationErrorsException ex) + Directory.CreateDirectory(profileDirectory); + } + + //reset to default Vehicle and save + Settings.Default.Reset(); + Settings.Default.Save(); + + //what's in the vehicle directory + DirectoryInfo dinfo = new DirectoryInfo(profileDirectory); + FileInfo[] vehicleFiles = dinfo.GetFiles("*.xml"); + + bool isProfileExist = false; + + foreach (FileInfo file in vehicleFiles) + { + string temp = Path.GetFileNameWithoutExtension(file.Name).Trim(); + + if (temp == profileName) { - // Corrupted XML! Delete the file, the user can just reload when this fails to appear. No need to worry them - MessageBoxButtons btns = MessageBoxButtons.OK; - System.Windows.Forms.MessageBox.Show("Error detected in config file - fixing it now, please close this and restart app", "Problem!", btns); - string filename = ((ex.InnerException as System.Configuration.ConfigurationErrorsException)?.Filename) as string; - System.IO.File.Delete(filename); - Settings.Default.Reload(); - Application.Exit(); + isProfileExist = true; } } + //does current vehicle exist? + if (isProfileExist && profileName != "Default Profile") + { + SettingsIO.ImportSettings(Path.Combine(profileDirectory, profileName + ".XML")); + } + else + { + if (profileName == "Default Profile") + Log.EventWriter("Default Profile does not exist in Program.cs"); + else + Log.EventWriter(profileName + ".XML Profile does not exist. Called in Program.cs"); + } + + Properties.Settings.Default.setConfig_profileName = profileName; + Properties.Settings.Default.Save(); + + if (Mutex.WaitOne(TimeSpan.Zero, true)) { Application.EnableVisualStyles(); @@ -70,4 +97,15 @@ private static void Main() } } } -} \ No newline at end of file +} + +//catch (System.Configuration.ConfigurationErrorsException ex) +//{ +// // Corrupted XML! Delete the file, the user can just reload when this fails to appear. No need to worry them +// MessageBoxButtons btns = MessageBoxButtons.OK; +// System.Windows.Forms.MessageBox.Show("Error detected in config file - fixing it now, please close this and restart app", "Problem!", btns); +// string filename = ((ex.InnerException as System.Configuration.ConfigurationErrorsException)?.Filename) as string; +// System.IO.File.Delete(filename); +// Settings.Default.Reload(); +// Application.Exit(); +//} \ No newline at end of file