From 71eff8764ec62d97e14371e631d09e8fbf8d60e7 Mon Sep 17 00:00:00 2001 From: Mark Crossley Date: Tue, 20 Dec 2022 17:36:00 +0000 Subject: [PATCH] Now skips (with a warning in the diags log) blank lines in the monthly log files --- CreateMissing.csproj | 4 ++-- Program.cs | 25 +++++++++++++++++++++---- Updates.txt | 4 ++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/CreateMissing.csproj b/CreateMissing.csproj index 4658d7d..2bbc4e6 100644 --- a/CreateMissing.csproj +++ b/CreateMissing.csproj @@ -3,8 +3,8 @@ Exe v4.5.2 - 1.3.1.2 - 1.3.1.2 + 1.3.1.3 + 1.3.2.3 CreateMissing.Program net48 diff --git a/Program.cs b/Program.cs index 3a6562d..9e86be1 100644 --- a/Program.cs +++ b/Program.cs @@ -12,7 +12,8 @@ class Program { public static Cumulus cumulus; public static string location; - public static ConsoleColor defConsoleColour; + + private static ConsoleColor defConsoleColour; private static DayFile dayfile; private static readonly List CurrentLogLines = new List(); @@ -409,6 +410,14 @@ private static Dayfilerec GetDayRecFromMonthly(DateTime date) // we use idx 0 & 1 together (date/time), set the idx to 1 idx = 1; // process each record in the file + // first a sanity check for an empty line! + if (string.IsNullOrWhiteSpace(CurrentLogLines[CurrentLogLineNum])) + { + CurrentLogLineNum++; + LogMessage($"LogFile: Error at line {CurrentLogLineNum}, an empty line was detected!"); + continue; + } + //var st = new List(Regex.Split(line, CultureInfo.CurrentCulture.TextInfo.ListSeparator)); // Regex is very expensive, let's assume the separator is always a single character var st = new List(CurrentLogLines[CurrentLogLineNum++].Split(dayfile.FieldSep[0])); @@ -831,7 +840,7 @@ private static Dayfilerec GetDayRecFromMonthly(DateTime date) raintoday += (raincounter - lastentrycounter) * cumulus.CalibRainMult; } - // add last hours rain for this last record. + // add last hours rain for this last record. AddLastHoursRainEntry(entrydate, totalRainfall + raintoday, ref rain1hLog, ref rain24hLog); // rainfall in last hour @@ -858,8 +867,8 @@ private static Dayfilerec GetDayRecFromMonthly(DateTime date) finished = true; } } - - + + if (started && recCount >= 5) // need at least five records to create a day { // we were in the right day, now we aren't @@ -1014,6 +1023,14 @@ private static Dayfilerec GetSolarDayRecFromMonthly(DateTime date, Dayfilerec re while (CurrentSolarLogLineNum < CurrentSolarLogLines.Count) { // process each record in the file + // first a sanity check for an empty line! + if (string.IsNullOrWhiteSpace(CurrentLogLines[CurrentLogLineNum])) + { + CurrentLogLineNum++; + LogMessage($"Solar: Error at line {CurrentLogLineNum}, an empty line was detected!"); + continue; + } + // Regex is very expensive, let's assume the separator is always a single character var st = new List(CurrentSolarLogLines[CurrentSolarLogLineNum].Split(dayfile.FieldSep[0])); var entrydate = Utils.DdmmyyhhmmStrToDate(st[0], st[1]); diff --git a/Updates.txt b/Updates.txt index adfe7e8..0ff5b5b 100644 --- a/Updates.txt +++ b/Updates.txt @@ -1,3 +1,7 @@ +1.3.1 +————— +- Now skips (with a warning in the diags log) blank lines in the monthly log files + 1.3.0 ————— - Support for CMX v3.20.0 - adds 24 hour rainfall