private static void HandleJPEGFileAdded(object source, FileSystemEventArgs e)
        {
            MainWindow.LogMessage("New JPEG file added at " + e.FullPath);

            //It takes a bit after creation before the file is sendable, sleep a few seconds
            XMLFileWatcher.EnableRaisingEvents = false;
            Thread.Sleep(5000);
            XMLFileWatcher.EnableRaisingEvents = true;
            try
            {
                MainWindow.LogMessage("Uploading JPEG image");
                string results = WebManager.uploadWebcamImage(e.FullPath);
                MainWindow.LogMessage(results);
            }
            catch (Exception ex)
            {
                MainWindow.LogError("Unable to upload JPEG image", ex);
            }

            try
            {
                File.Delete(e.FullPath);
            }
            catch (Exception ex)
            {
                MainWindow.LogError("Unable to delete the file after upload", ex);
            }
        }
Ejemplo n.º 2
0
        private void StartButtonClick(object sender, RoutedEventArgs e)
        {
            LogMessage("Setting up FTP Parameters");
            bool ready = false;

            try
            {
                int uploadFrequency = int.Parse(UploadFrequency.Text);
                XMLParser.SetUploadFrequency(uploadFrequency);
                WebManager.SetupFTP(Username.Text, Password.Password, FTPServer.Text + "/" + RemotePath.Text + "/");
                ready = true;
            }
            catch (Exception ex)
            {
                LogError("Unable to set up the FTP parameters", ex);
            }

            if (ready)
            {
                LogMessage("Starting directory monitor");
                try
                {
                    string jpegDirectory = "";
                    if (Directory.Exists(JPEGLabel.Text))
                    {
                        jpegDirectory = JPEGLabel.Text;
                    }
                    DirectoryMonitor.Start(XMLLabel.Text, jpegDirectory, this);
                }
                catch (Exception ex)
                {
                    LogError("Unable to start directory monitor", ex);
                }
            }
        }
Ejemplo n.º 3
0
 private void ForceUploadTodayClick(object sender, RoutedEventArgs e)
 {
     LogMessage("Force uploading today's observations");
     try
     {
         LogMessage(WebManager.UploadTodayObservations());
     }
     catch (Exception ex)
     {
         LogError("Unable to upload today's observations", ex);
     }
 }
Ejemplo n.º 4
0
        private void TestCreateJSONClick(object sender, RoutedEventArgs e)
        {
            Observation observation = GetObservation();

            if (null != observation)
            {
                try
                {
                    string json = WebManager.GenerateJSONCurrentConditions(observation);
                    LogMessage("JSON generated successfully");
                    System.Windows.MessageBox.Show(json, "Generated JSON");
                    System.Windows.Clipboard.SetText(json);
                }
                catch (Exception ex)
                {
                    LogError("Failed to generate JSON.", ex);
                }
            }
        }
        private static void CheckPeriodicUploads(DateTime observationDate)
        {
            DateTime thisObservationDate = DateTime.Parse(observationDate.ToString("yyyy-MM-dd"));

            if (thisObservationDate > LastDailyUpload)
            {
                bool uploadSuccess = true;
                try
                {
                    MainWindow.LogMessage("Sending yesterday's observations to server");
                    string results = WebManager.UploadYesterdayObservations();
                    MainWindow.LogMessage(results);
                }
                catch (Exception ex)
                {
                    MainWindow.LogError("Unable to upload yesterday's observations", ex);
                    uploadSuccess = false;
                }

                try
                {
                    MainWindow.LogMessage("Sending highs and lows to server");
                    string results = WebManager.UploadHighsAndLows();
                    MainWindow.LogMessage(results);
                }
                catch (Exception ex)
                {
                    MainWindow.LogError("Unable to upload highs and lows", ex);
                    uploadSuccess = false;
                }

                if (uploadSuccess)
                {
                    LastDailyUpload = thisObservationDate;
                }
            }
        }
Ejemplo n.º 6
0
        private void ForceUploadDailyFiles(object sender, RoutedEventArgs e)
        {
            try
            {
                LogMessage("Sending current observation to server");
                string results = WebManager.UploadYesterdayObservations();
                LogMessage(results);
            }
            catch (Exception ex)
            {
                LogError("Unable to upload yesterday's observations", ex);
            }

            try
            {
                LogMessage("Sending current observation to server");
                string results = WebManager.UploadHighsAndLows();
                LogMessage(results);
            }
            catch (Exception ex)
            {
                LogError("Unable to upload highs and lows", ex);
            }
        }
        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);
            }
        }