Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Ilka Kistinger
bee-weather
Commits
4df6fdfb
Commit
4df6fdfb
authored
Mar 12, 2020
by
COLOMBO Benjamin
Browse files
Implements exportation od data in backup file in case of failure
parent
31ffb722
Changes
2
Hide whitespace changes
Inline
Side-by-side
BeeWeatherPollenTracker/LoggerManager.cs
View file @
4df6fdfb
using
System
;
using
System.IO
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
BeeWeatherPollenTracker
{
...
...
@@ -38,10 +35,10 @@ 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
);
}
}
}
}
\ No newline at end of file
BeeWeatherPollenTracker/Program.cs
View file @
4df6fdfb
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,44 +16,44 @@ 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
#
region
Pollen
// Set up the logger manager
logs
=
LoggerManager
.
GetInstance
();
// Retrieve poll forecast data
// Retrieve poll forecast data
try
{
{
// Get Pollen Data
ClimateEnvironment
pollenData
;
using
(
HttpClient
pollenClient
=
new
HttpClient
())
{
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
#
endregion
Pollen
t
.
Join
();
}
}
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment