Commit 4df6fdfb authored by COLOMBO Benjamin's avatar COLOMBO Benjamin
Browse files

Implements exportation od data in backup file in case of failure

parent 31ffb722
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeeWeatherPollenTracker
{
......@@ -38,7 +35,7 @@ namespace BeeWeatherPollenTracker
public void WriteInFile(Exception e)
{
DateTime dt = DateTime.Now;
string res = dt.ToString() + " : "+ e.Message ;
string res = dt.ToString() + " : " + e.Message;
byte[] data = Encoding.UTF8.GetBytes(res);
fs.Write(data, 0, data.Length);
......

using MySql.Data.EntityFramework;
using MySql.Data.EntityFramework;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Entity;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading;
......@@ -16,33 +16,33 @@ namespace BeeWeatherPollenTracker
internal static class Program
{
#region Constantes
private const string POLLEN_FORECAST_URL = "https://opendata.dwd.de/climate_environment/health/alerts/s31fg.json";
#endregion
#endregion Constantes
private static LoggerManager logs = null;
private static void Main(string[] args)
{
string pollenJson = null;
// Set up the logger manager
logs = LoggerManager.GetInstance();
// Entity Framework setup
DbConfiguration.SetConfiguration(new MySqlEFConfiguration());
#region Weather
WeatherForecast weather = new WeatherForecast();
Thread t = new Thread(new ThreadStart(weather.Process));
t.Start();
#endregion
#endregion Weather
#region Pool
// TODO: Create new service to retreive poll info (like weather)
// TODO: Launch service with thread
// Set up the logger manager
logs = LoggerManager.GetInstance();
#region Pollen
// Retrieve poll forecast data
try
......@@ -53,7 +53,7 @@ namespace BeeWeatherPollenTracker
{
var pollenResults = pollenClient.GetAsync(POLLEN_FORECAST_URL).Result;
var pollenJson = pollenResults.Content.ReadAsStringAsync().Result;
pollenJson = pollenResults.Content.ReadAsStringAsync().Result;
pollenData = JsonConvert.DeserializeObject<ClimateEnvironment>(pollenJson);
}
......@@ -62,7 +62,7 @@ namespace BeeWeatherPollenTracker
.First(p => p.PartregionId.ToString() == ConfigurationManager.AppSettings["PartregionId"]);
// 2020-03-11 11:00 Uhr
beehive_poll_forecast poll_measure = new beehive_poll_forecast();
poll_measure.Last_update_on = DateTime.Parse(pollenData.LastUpdate.Substring(0,pollenData.LastUpdate.Length-3));
poll_measure.Last_update_on = DateTime.Parse(pollenData.LastUpdate.Substring(0, pollenData.LastUpdate.Length - 3));
poll_measure.Sender = pollenData.Sender;
poll_measure.Region_name = pollenRegionForecast.PartregionName;
//pollenRegionForecast.Pollen.Erle
......@@ -70,14 +70,27 @@ namespace BeeWeatherPollenTracker
poll_measure.Today = pollenRegionForecast.Pollen.Erle.Today;
poll_measure.Tomorrow = pollenRegionForecast.Pollen.Erle.Tomorrow;
poll_measure.Day_after_to = pollenRegionForecast.Pollen.Erle.DayafterTo;
poll_measure.
// poll_measure.
}
catch (Exception e)
{
logs.WriteInFile(e);
if (string.IsNullOrEmpty(pollenJson))
{
try
{
File.WriteAllText($"pollen_{DateTime.Now.ToString()}.json", pollenJson);
}
catch (Exception inner)
{
logs.WriteInFile(inner);
}
}
}
#endregion Pollen
#endregion
t.Join();
}
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment