private static void HandleXMLFileAdded(object source, FileSystemEventArgs e) { MainWindow.LogMessage("New XML file added at " + e.FullPath); //File watcher will trigger multiple events. Sleep for a bit. XMLFileWatcher.EnableRaisingEvents = false; Thread.Sleep(1000); XMLFileWatcher.EnableRaisingEvents = true; Observation observation = new Observation(); bool save = true; try { observation = XMLParser.getObservationFromXML(e.FullPath); } catch (Exception ex) { MainWindow.LogError("Unable to parse observation.", ex); //Copy the XML file with a timestamp so we can look at it later try { string directory = Path.GetDirectoryName(e.FullPath) + @"\"; File.Copy(e.FullPath, directory + "Parse Error - " + DateTime.Now.ToString("yyyy-MM-dd HH-mm") + ".xml"); } catch (Exception ex2) { MainWindow.LogError("Unable to copy error XML file for review", ex2); } save = false; } if (save) { try { MainWindow.LogMessage("Sending current observation to server"); string results = WebManager.SendCurrentObservationToServer(observation); MainWindow.LogMessage(results); } catch (Exception ex) { MainWindow.LogError("Unable to send the observation to the server", ex); } if (observation.SaveToDatabase) { try { MainWindow.LogMessage("Saving observation to the database"); DatabaseManager.LogObservation(observation); MainWindow.LogMessage("Observation saved to the database"); } catch (Exception ex) { MainWindow.LogError("Unable to save the observation to the database", ex, false, false); } try { MainWindow.LogMessage("Uploading today's data to the server"); string results = WebManager.UploadTodayObservations(); MainWindow.LogMessage(results); } catch (Exception ex) { MainWindow.LogError("Unable to save the observation to the database", ex, false, false); } } try { CheckHighsAndLows(observation); } catch (Exception ex) { MainWindow.LogError("Unable to update highs and lows", ex); } CheckPeriodicUploads(observation.ObservationDate); } }