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
fc2426c5
Commit
fc2426c5
authored
Mar 11, 2020
by
Charles Still
Browse files
Add init logger
parent
0e147fc0
Changes
3
Hide whitespace changes
Inline
Side-by-side
BeeWeatherPollenTracker/BeeWeatherPollenTracker.csproj
View file @
fc2426c5
...
...
@@ -60,6 +60,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"LoggerManager.cs"
/>
<Compile
Include=
"Program.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
</ItemGroup>
...
...
@@ -67,6 +68,7 @@
<None
Include=
"App.config"
/>
<None
Include=
"packages.config"
/>
</ItemGroup>
<ItemGroup
/>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<Target
Name=
"EnsureNuGetPackageBuildImports"
BeforeTargets=
"PrepareForBuild"
>
<PropertyGroup>
...
...
BeeWeatherPollenTracker/LoggerManager.cs
0 → 100644
View file @
fc2426c5
using
System
;
using
System.IO
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
BeeWeatherPollenTracker
{
public
class
LoggerManager
{
private
static
LoggerManager
Logger
=
null
;
private
String
Path
=
""
;
private
FileStream
fs
=
null
;
public
LoggerManager
()
{
Path
=
".\\logfile.txt"
;
if
(!
File
.
Exists
(
Path
))
// Check if the file is existing and create him if not.
{
fs
=
File
.
Create
(
Path
);
}
else
{
fs
=
File
.
OpenWrite
(
Path
);
}
}
public
static
LoggerManager
GetInstance
()
{
if
(
Logger
==
null
)
{
Logger
=
new
LoggerManager
();
}
return
Logger
;
}
public
void
WriteInFile
(
Exception
e
)
{
DateTime
dt
=
DateTime
.
Now
;
string
res
=
dt
.
ToString
()
+
" : "
+
e
.
Message
;
byte
[]
data
=
Encoding
.
UTF8
.
GetBytes
(
res
);
fs
.
Write
(
data
,
0
,
data
.
Length
);
}
}
}
BeeWeatherPollenTracker/Program.cs
View file @
fc2426c5
...
...
@@ -12,23 +12,34 @@ namespace BeeWeatherPollenTracker
private
const
string
OPEN_WEATHER_MAP_API_KEY
=
"3f80e65ed0609e7e52737e65d522aed8"
;
private
const
double
FORECAST_LENGTH
=
3.0
;
static
LoggerManager
logs
=
null
;
private
static
void
Main
(
string
[]
args
)
{
// Set up API KEY
ClientSettings
.
SetApiKey
(
OPEN_WEATHER_MAP_API_KEY
);
// Set up the logger manager
logs
=
LoggerManager
.
GetInstance
();
// Retrieve forecast data from from OWM API
var
cityId
=
int
.
Parse
(
ConfigurationManager
.
AppSettings
[
"CityId"
]);
var
apiResults
=
FiveDaysForecast
.
GetByCityId
(
cityId
);
if
(!
apiResults
.
Success
)
try
{
throw
new
ApplicationException
(
apiResults
.
Message
);
}
var
cityId
=
int
.
Parse
(
ConfigurationManager
.
AppSettings
[
"CityId"
]);
var
apiResults
=
FiveDaysForecast
.
GetByCityId
(
cityId
);
if
(!
apiResults
.
Success
)
{
throw
new
ApplicationException
(
apiResults
.
Message
);
}
// Filter: keep only 3 next days forecast
var
forecast
=
apiResults
.
Items
.
Where
(
x
=>
x
.
Date
<
DateTime
.
Now
.
AddDays
(
FORECAST_LENGTH
))
.
ToList
();
// Filter: keep only 3 next days forecast
var
forecast
=
apiResults
.
Items
.
Where
(
x
=>
x
.
Date
<
DateTime
.
Now
.
AddDays
(
FORECAST_LENGTH
))
.
ToList
();
}
catch
(
Exception
e
)
{
logs
.
WriteInFile
(
e
);
}
}
}
}
\ 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