internal string FtpNow(IHttpContext context) { try { var data = new StreamReader(context.Request.InputStream).ReadToEnd(); var json = WebUtility.UrlDecode(data); // Dead simple (dirty), there is only one setting at present! var includeGraphs = json.Contains("true"); if (string.IsNullOrEmpty(cumulus.FtpHostname)) { return("{\"result\":\"No FTP host defined\"}"); } if (cumulus.WebUpdating == 1) { cumulus.LogMessage("FTP Now: Warning, a previous web update is still in progress, first chance, skipping attempt"); return("{\"result\":\"A web update is already in progress\"}"); } if (cumulus.WebUpdating >= 2) { cumulus.LogMessage("FTP Now: Warning, a previous web update is still in progress, second chance, aborting connection"); if (cumulus.ftpThread.ThreadState == ThreadState.Running) { cumulus.ftpThread.Abort(); } // If enabled (re)generate the daily graph data files, and upload if (includeGraphs && cumulus.IncludeGraphDataFiles) { cumulus.LogDebugMessage("FTP Now: Generating the daily graph data files"); station.CreateEodGraphDataFiles(); cumulus.DailyGraphDataFilesNeedFTP = true; } cumulus.LogMessage("FTP Now: Trying new web update"); cumulus.WebUpdating = 1; cumulus.ftpThread = new Thread(cumulus.DoHTMLFiles) { IsBackground = true }; cumulus.ftpThread.Start(); return("{\"result\":\"An existing FTP process was aborted, and a new FTP process invoked\"}"); } // If enabled (re)generate the daily graph data files, and upload if (includeGraphs && cumulus.IncludeGraphDataFiles) { cumulus.LogDebugMessage("FTP Now: Generating the daily graph data files"); station.CreateEodGraphDataFiles(); cumulus.DailyGraphDataFilesNeedFTP = true; } cumulus.WebUpdating = 1; cumulus.ftpThread = new Thread(cumulus.DoHTMLFiles) { IsBackground = true }; cumulus.ftpThread.Start(); return("{\"result\":\"FTP process invoked\"}"); } catch (Exception ex) { cumulus.LogMessage($"FTP Now: {ex.Message}"); context.Response.StatusCode = 500; return($"{{\"result\":\"Error: {ex.Message}\"}}"); } }