Skip to content

Commit

Permalink
Merge pull request #171 from mcrossley/master
Browse files Browse the repository at this point in the history
v3.24.2
  • Loading branch information
mcrossley authored Mar 15, 2023
2 parents a12b575 + 0821616 commit 2524ccd
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 66 deletions.
106 changes: 67 additions & 39 deletions CumulusMX/Cumulus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
using System.Web.Caching;
using System.Web.UI.WebControls;
using static System.Net.Mime.MediaTypeNames;
using System.Text.RegularExpressions;

namespace CumulusMX
{
Expand Down Expand Up @@ -722,7 +723,7 @@ public Cumulus(int HTTPport, bool DebugEnabled, string startParms)

LogMessage($"Current culture: {CultureInfo.CurrentCulture.DisplayName} [{CultureInfo.CurrentCulture.Name}]");

LogMessage($"Running as a {(IntPtr.Size == 4 ? "32" : "64")}bit process");
LogMessage($"Running as a {(IntPtr.Size == 4 ? "32" : "64")} bit process");

// Messy, but Windows and Linux use different mechanisms for loading DLLs, neither are very pretty
// Simplest method is to leave them searching the application directory, and copy the correct file there before it is loaded by the first SQlite connect()
Expand Down Expand Up @@ -1709,7 +1710,7 @@ internal void SetupPhpUploadClients()

internal async void TestPhpUploadCompression()
{
LogDebugMessage("Testing PHP upload compression");
LogDebugMessage($"Testing PHP upload compression: '{FtpOptions.PhpUrl}'");
using (var request = new HttpRequestMessage(HttpMethod.Get, FtpOptions.PhpUrl))
{
try
Expand Down Expand Up @@ -3239,7 +3240,7 @@ private async Task RealtimeUpload(byte cycle)
}
else
{
tasklist.Add(UploadFile(phpRealtimeUploadHttpClient, uploadfile, remotefile, cycle, ExtraFiles[idx].binary));
tasklist.Add(UploadFile(phpRealtimeUploadHttpClient, uploadfile, remotefile, cycle, ExtraFiles[idx].binary, ExtraFiles[idx].UTF8));
}
// no extra files are incremental for now, so no need to update LastDataTime

Expand Down Expand Up @@ -4039,6 +4040,12 @@ private void ReadIniFile()
}

ProgramOptions.TimeFormat = ini.GetValue("Program", "TimeFormat", "t");
if (ProgramOptions.TimeFormat == "t")
ProgramOptions.TimeFormatLong = "T";
else if (ProgramOptions.TimeFormat == "h:mm tt")
ProgramOptions.TimeFormatLong = "h:mm:ss tt";
else
ProgramOptions.TimeFormatLong = "HH:mm:ss";

ProgramOptions.WarnMultiple = ini.GetValue("Station", "WarnMultiple", true);
ProgramOptions.ListWebTags = ini.GetValue("Station", "ListWebTags", false);
Expand Down Expand Up @@ -9648,12 +9655,12 @@ public async Task DoIntervalUpload()
var uploadfile = ReportPath + NOAAconf.LatestMonthReport;
var remotefile = NOAAconf.FtpFolder + '/' + NOAAconf.LatestMonthReport;

tasklist.Add(UploadFile(phpUploadHttpClient, uploadfile, remotefile));
tasklist.Add(UploadFile(phpUploadHttpClient, uploadfile, remotefile, -1, false, NOAAconf.UseUtf8));

uploadfile = ReportPath + NOAAconf.LatestYearReport;
remotefile = NOAAconf.FtpFolder + '/' + NOAAconf.LatestYearReport;

tasklist.Add(UploadFile(phpUploadHttpClient, uploadfile, remotefile));
tasklist.Add(UploadFile(phpUploadHttpClient, uploadfile, remotefile, -1, false, NOAAconf.UseUtf8));
LogFtpDebugMessage("PHP[Int]: Upload of NOAA reports complete");
NOAAconf.NeedFtp = false;
}
Expand Down Expand Up @@ -9689,20 +9696,20 @@ public async Task DoIntervalUpload()
// all checks OK, file needs to be uploaded
try
{
var idx = i;

if (ExtraFiles[i].process)
{
var encoding = UTF8encode ? new UTF8Encoding(false) : Encoding.GetEncoding("iso-8859-1");
tokenParser.Encoding = encoding;

tasklist.Add(Task.Run(async () =>
{
var data = await ProcessTemplateFile2StringAsync(uploadfile, false);
_ = await UploadString(phpUploadHttpClient, false, string.Empty, data, remotefile);
var data = await ProcessTemplateFile2StringAsync(uploadfile, false, ExtraFiles[idx].UTF8);
_ = await UploadString(phpUploadHttpClient, false, string.Empty, data, remotefile, -1, false, ExtraFiles[idx].UTF8);
}));
}
else
{
tasklist.Add(UploadFile(phpUploadHttpClient, uploadfile, remotefile));
tasklist.Add(UploadFile(phpUploadHttpClient, uploadfile, remotefile, -1, false, ExtraFiles[idx].UTF8));
}
}
catch (Exception e)
Expand Down Expand Up @@ -10156,7 +10163,7 @@ private bool UploadStream(SftpClient conn, string remotefile, Stream dataStream,

// Return True if the upload worked
// Return False if the upload failed
private async Task<bool> UploadFile(HttpClient httpclient, string localfile, string remotefile, int cycle = -1, bool binary = false)
private async Task<bool> UploadFile(HttpClient httpclient, string localfile, string remotefile, int cycle = -1, bool binary = false, bool utf8=true)
{
string cycleStr = cycle >= 0 ? cycle.ToString() : "Int";

Expand All @@ -10170,7 +10177,7 @@ private async Task<bool> UploadFile(HttpClient httpclient, string localfile, str
return false;
}

var utf8 = new UTF8Encoding(false);
var encoding = utf8 ? new UTF8Encoding(false) : Encoding.GetEncoding("iso-8859-1");

string data;
if (binary)
Expand All @@ -10180,7 +10187,7 @@ private async Task<bool> UploadFile(HttpClient httpclient, string localfile, str
}
else
{
data = await Utils.ReadAllTextAsync(localfile, utf8);
data = await Utils.ReadAllTextAsync(localfile, encoding);
}

return await UploadString(httpclient, false, string.Empty, data, remotefile, cycle, binary);
Expand Down Expand Up @@ -11077,32 +11084,6 @@ public void DoExtraEndOfDayFiles()
{
remotefile = GetRemoteFileName(remotefile, logDay);

if (!ExtraFiles[i].FTP)
{
uploadfile += "tmp";
try
{
if (ExtraFiles[i].process)
{
LogDebugMessage("EOD: Processing extra file " + uploadfile);
// process the file
var output = ProcessTemplateFile2String(uploadfile, tokenParser, false, ExtraFiles[i].UTF8);
File.WriteAllText(remotefile, output);
}
else
{
LogDebugMessage("EOD: Copying extra file " + uploadfile);
File.Copy(uploadfile, remotefile);
}
}
catch (Exception ex)
{
LogDebugMessage("EOD: Error writing file " + uploadfile);
LogDebugMessage(ex.Message);
}
//LogDebugMessage("Finished processing extra file " + uploadfile);
}

if (ExtraFiles[i].FTP)
{
// FTP the file at the next interval
Expand Down Expand Up @@ -12055,6 +12036,29 @@ private string GetUploadFilename(string input, DateTime dat)
NOAAReports noaa = new NOAAReports(this, station);
return noaa.GetLastNoaaMonthReportFilename(dat, true);
}
else if (input.StartsWith("<custinterval"))
{
try
{
Match match = Regex.Match(input, @"<custinterval([0-9]{1,2})>");

if (match.Success)
{
var idx = int.Parse(match.Groups[1].Value) - 1; // we use a zero relative array

return GetCustomIntvlLogFileName(idx, dat);
}
else
{
LogMessage("GetUploadFilename: No match found for <custinterval[1-10]> in " + input);
return input;
}
}
catch (Exception ex)
{
LogMessage($"GetUploadFilename: Error processing <custinterval[1-10]>, value='{input}', error: {ex.Message}");
}
}

return input;
}
Expand Down Expand Up @@ -12083,6 +12087,29 @@ private string GetRemoteFileName(string input, DateTime dat)
NOAAReports noaa = new NOAAReports(this, station);
return input.Replace("<noaamonthfile>", Path.GetFileName(noaa.GetLastNoaaMonthReportFilename(dat, false)));
}
else if (input.Contains("<custinterval"))
{
try
{
Match match = Regex.Match(input, @"<custinterval([0-9]{1,2})>");

if (match.Success)
{
var idx = int.Parse(match.Groups[1].Value) - 1; // we use a zero relative array

return input.Replace(match.Groups[0].Value, Path.GetFileName(GetCustomIntvlLogFileName(idx, dat)));
}
else
{
LogMessage("GetRemoteFileName: No match found for <custinterval[1-10]> in " + input);
return input;
}
}
catch (Exception ex)
{
LogMessage($"GetRemoteFileName: Error processing <custinterval[1-10]>, input='{input}', error: {ex.Message}");
}
}

return input;
}
Expand Down Expand Up @@ -12261,6 +12288,7 @@ public class ProgramOptionsClass
public bool DataStoppedExit { get; set; }
public int DataStoppedMins { get; set; }
public string TimeFormat { get; set; }
public string TimeFormatLong { get; set; }
}

public class CultureConfig
Expand Down
1 change: 1 addition & 0 deletions CumulusMX/CumulusMX.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<WarningLevel>4</WarningLevel>
<AllowedReferenceRelatedFileExtensions>".pdb"=""</AllowedReferenceRelatedFileExtensions>
<DebugSymbols>false</DebugSymbols>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup />
<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion CumulusMX/DavisStation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2078,7 +2078,7 @@ private void GetArchiveData()
bool midnightraindone = luhour == 0;

// work out the next logger interval after the last CMX update
var nextLoggerTime = Utils.RoundTimeUpToInterval(cumulus.LastUpdateTime, TimeSpan.FromMinutes(loggerInterval));
var nextLoggerTime = Utils.RoundTimeUpToInterval(cumulus.LastUpdateTime.AddMinutes(-1), TimeSpan.FromMinutes(loggerInterval));

// check if the calculated logger time is later than now!
if (nextLoggerTime > DateTime.Now)
Expand Down
11 changes: 8 additions & 3 deletions CumulusMX/DavisWllStation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public override void Start()
// Create a current conditions thread to poll readings every 10 seconds as temperature updates every 10 seconds
GetWllCurrent(null, null);
tmrCurrent.Elapsed += GetWllCurrent;
tmrCurrent.Interval = 10 * 1000; // Every 10 seconds
tmrCurrent.Interval = 20 * 1000; // Every 10 seconds
tmrCurrent.AutoReset = true;
tmrCurrent.Start();

Expand Down Expand Up @@ -910,15 +910,20 @@ private void DecodeCurrent(string currentJson)
WindRecent[nextwind].Timestamp = dateTime;
nextwind = (nextwind + 1) % MaxWindRecent;

RecentMaxGust = gustCal;
if (broadcastStopped)
{
// if we are not receiving live broadcasts, then use current gust value)
RecentMaxGust = gustCal;
}
}
}
}
else if (!CalcRecentMaxGust)
{
// Check for spikes, and set highs
if (CheckHighGust(gustCal, gustDir, dateTime))
if (CheckHighGust(gustCal, gustDir, dateTime) && broadcastStopped)
{
// if we are not receiving live broadcasts, then use current gust value
RecentMaxGust = gustCal;
}
}
Expand Down
7 changes: 7 additions & 0 deletions CumulusMX/ProgramSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ public string UpdateConfig(IHttpContext context)
cumulus.ProgramOptions.TimeFormat = settings.culture.timeFormat;
cumulus.ProgramOptions.Culture.RemoveSpaceFromDateSeparator = settings.culture.removespacefromdateseparator;

if (cumulus.ProgramOptions.TimeFormat == "t")
cumulus.ProgramOptions.TimeFormatLong = "T";
else if (cumulus.ProgramOptions.TimeFormat == "h:mm tt")
cumulus.ProgramOptions.TimeFormatLong = "h:mm:ss tt";
else
cumulus.ProgramOptions.TimeFormatLong = "HH:mm:ss";


if (cumulus.ProgramOptions.Culture.RemoveSpaceFromDateSeparator && CultureInfo.CurrentCulture.DateTimeFormat.DateSeparator.Contains(" "))
{
Expand Down
6 changes: 3 additions & 3 deletions CumulusMX/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Cumulus MX")]
[assembly: AssemblyDescription("Version 3.24.1 - Build 3234")]
[assembly: AssemblyDescription("Version 3.24.2 - Build 3235")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Cumulus MX")]
Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.24.1.3234")]
[assembly: AssemblyFileVersion("3.24.1.3234")]
[assembly: AssemblyVersion("3.24.2.3235")]
[assembly: AssemblyFileVersion("3.24.2.3235")]
45 changes: 34 additions & 11 deletions CumulusMX/StationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using EmbedIO;
using System.Reflection;
using static Swan.Terminal;
using Swan.Formatters;
using ServiceStack;

namespace CumulusMX
{
Expand Down Expand Up @@ -1249,8 +1251,7 @@ internal string UploadNow(IHttpContext context)
var json = WebUtility.UrlDecode(data);
var now = DateTime.Now;

// Dead simple (dirty), there is only one setting at present!
var includeGraphs = json.Contains("true");
var options = json.FromJson<UploadNowData>();

if (!cumulus.FtpOptions.Enabled && !cumulus.FtpOptions.LocalCopyEnabled)
return "Upload/local copy is not enabled!";
Expand All @@ -1274,25 +1275,40 @@ internal string UploadNow(IHttpContext context)
}

// Graph configs may have changed, so force re-create and upload the json files - just flag everything!
cumulus.LogDebugMessage("Upload Now: Flagging the graph data files for full recreation, if required");
cumulus.LogDebugMessage("Upload Now: Flagging the graph data files for recreation and upload/copy");
if (options.graphs)
cumulus.LogDebugMessage("Upload Now: Flagging graph data files for full upload rather than incremental");

for (var i = 0; i < cumulus.GraphDataFiles.Length; i++)
{
cumulus.GraphDataFiles[i].CreateRequired = true;
cumulus.GraphDataFiles[i].FtpRequired = true;
cumulus.GraphDataFiles[i].CopyRequired = true;
cumulus.GraphDataFiles[i].Incremental = false;
if (options.graphs)
cumulus.GraphDataFiles[i].Incremental = false;
cumulus.GraphDataFiles[i].LastDataTime = DateTime.MinValue;
}

// (re)generate the daily graph data files, and upload if required
cumulus.LogDebugMessage("Upload Now: Flagging the daily graph data files for full recreation, if required");
for (var i = 0; i < cumulus.GraphDataEodFiles.Length; i++)
if (options.dailygraphs)
{
cumulus.GraphDataEodFiles[i].CreateRequired = true;
cumulus.GraphDataEodFiles[i].FtpRequired = true;
cumulus.GraphDataEodFiles[i].CopyRequired = true;
cumulus.GraphDataEodFiles[i].Incremental = false;
cumulus.GraphDataEodFiles[i].LastDataTime = DateTime.MinValue;
cumulus.LogDebugMessage("Upload Now: Flagging the daily graph data files for recreation and upload/copy");
for (var i = 0; i < cumulus.GraphDataEodFiles.Length; i++)
{
cumulus.GraphDataEodFiles[i].CreateRequired = true;
cumulus.GraphDataEodFiles[i].FtpRequired = true;
cumulus.GraphDataEodFiles[i].CopyRequired = true;
cumulus.GraphDataEodFiles[i].Incremental = false;
cumulus.GraphDataEodFiles[i].LastDataTime = DateTime.MinValue;
}
}

// flag the latest NOAA files for upload
if (options.noaa)
{
cumulus.LogDebugMessage("Upload Now: Flagging the latest NOAA report files for upload/copy");
cumulus.NOAAconf.NeedFtp = true;
cumulus.NOAAconf.NeedCopy = true;
}

cumulus.WebUpdating = 1;
Expand All @@ -1308,6 +1324,13 @@ internal string UploadNow(IHttpContext context)
}
}

private class UploadNowData
{
public bool dailygraphs { get; set; }
public bool noaa { get; set; }
public bool graphs { get; set; }
}

internal string SetSelectaChartOptions(IHttpContext context)
{
var errorMsg = "";
Expand Down
Loading

0 comments on commit 2524ccd

Please sign in to comment.