commit 26ecc7563c5dc55f811b5e1ff0887c207d73d336
Author: A-Konig <alex-nebulae@seznam.cz>
Date:   Tue May 25 21:45:17 2021 +0200

    re #8962 Adding reading of file to string to CsvDataLoader

diff --git a/Server/ServerApp/DataDownload/DataDownloader.cs b/Server/ServerApp/DataDownload/DataDownloader.cs
index 8bddaa4..24875c6 100644
--- a/Server/ServerApp/DataDownload/DataDownloader.cs
+++ b/Server/ServerApp/DataDownload/DataDownloader.cs
@@ -95,9 +95,9 @@ namespace ServerApp.DataDownload
 
 			DateTime now = DateTime.Now;
 			WebClient webClient = new WebClient();
-			string data = webClient.DownloadString(predictionSite);
+			webClient.DownloadFile(predictionSite, $"data/{now.Year}{now.Month}{now.Day}.json");
 
-			return data;
+			return $"data/{now.Year}{now.Month}{now.Day}.json";
 		}
 
 		/// <summary>
diff --git a/Server/ServerApp/Parser/InputData/CsvDataLoader.cs b/Server/ServerApp/Parser/InputData/CsvDataLoader.cs
index 1d36908..b66a942 100644
--- a/Server/ServerApp/Parser/InputData/CsvDataLoader.cs
+++ b/Server/ServerApp/Parser/InputData/CsvDataLoader.cs
@@ -18,6 +18,19 @@ namespace ServerApp.Parser.InputData
         /// <summary> Culture info for parsing numbers </summary>
         static CultureInfo cultureInfo = new CultureInfo("de-DE");
 
+        /// <summary>
+        /// Load file into string
+        /// </summary>
+        /// <param name="path">Paht to file</param>
+        /// <returns>Null if file does not exist, or file in string</returns>
+        public string LoadPredictionFile(string path)
+        {
+            if (path == null || !File.Exists(path))
+                return null;
+
+            return File.ReadAllText(path);
+        }
+
         /// <summary>
         /// Load csv file into array
         /// </summary>
diff --git a/Server/ServerApp/Parser/InputData/IDataLoader.cs b/Server/ServerApp/Parser/InputData/IDataLoader.cs
index cabdcd7..ea2337d 100644
--- a/Server/ServerApp/Parser/InputData/IDataLoader.cs
+++ b/Server/ServerApp/Parser/InputData/IDataLoader.cs
@@ -32,5 +32,13 @@ namespace ServerApp.Parser.InputData
         /// <returns></returns>
         List<WeatherInstance> LoadWeatherFile(string pathToFile);
 
+        /// <summary>
+        /// Load file into string
+        /// </summary>
+        /// <param name="path">Paht to file</param>
+        /// <returns>Null if file does not exist, or file in string</returns>
+        string LoadPredictionFile(string path);
+
+
     }
 }
diff --git a/Server/ServerApp/Program.cs b/Server/ServerApp/Program.cs
index 046ae4f..33ed43c 100644
--- a/Server/ServerApp/Program.cs
+++ b/Server/ServerApp/Program.cs
@@ -1,6 +1,7 @@
 ﻿using ServerApp.Connection;
 using ServerApp.Connection.XMLProtocolHandler;
 using ServerApp.DataDownload;
+using ServerApp.Parser.InputData;
 using ServerApp.Parser.OutputInfo;
 using ServerApp.Parser.Parsers;
 using ServerApp.Predictor;
@@ -131,7 +132,7 @@ namespace ServerApp
 
             // PARSE DATA
 
-            JsonParser jsonP = new JsonParser(dd);
+            JsonParser jsonP = new JsonParser(dd, new CsvDataLoader());
 			jsonP.ParsePrediction();
 
 			var res = jsonP.GetPredictionForTime(jsonP.Predictions[5].startTime, jsonP.Predictions[20].startTime);
diff --git a/Server/ServerApp/WeatherPredictionParser/JsonParser.cs b/Server/ServerApp/WeatherPredictionParser/JsonParser.cs
index 0c2bf7a..6ca29b9 100644
--- a/Server/ServerApp/WeatherPredictionParser/JsonParser.cs
+++ b/Server/ServerApp/WeatherPredictionParser/JsonParser.cs
@@ -3,6 +3,7 @@
 //
 
 using ServerApp.DataDownload;
+using ServerApp.Parser.InputData;
 using ServerApp.Parser.OutputInfo;
 using System;
 using System.Collections.Generic;
@@ -20,8 +21,10 @@ namespace ServerApp.WeatherPredictionParser
     /// <author>A. Konig</author>
     public class JsonParser : IJsonParser
     {
+        /// <summary> Data downloader </summary>
+        DataDownloader downloader;
         /// <summary> Data loader </summary>
-        DataDownloader loader;
+        IDataLoader loader;
         /// <summary> Currently parsed day </summary>
         DateTime currParsedDay;
         /// <summary> Sunrise time of currently parsed day </summary>
@@ -32,9 +35,10 @@ namespace ServerApp.WeatherPredictionParser
         /// <summary>
         /// Constructor
         /// </summary>
-        /// <param name="loader"></param>
-        public JsonParser(DataDownloader loader)
+        /// <param name="downloader"></param>
+        public JsonParser(DataDownloader downloader, IDataLoader loader)
         {
+            this.downloader = downloader;
             this.loader = loader;
         }
 
@@ -107,7 +111,12 @@ namespace ServerApp.WeatherPredictionParser
             sunsetTime = new List<DateTime>();
 
             // get file
-            string data = loader.DownloadWeatherPrediction();
+            string file = downloader.DownloadWeatherPrediction();
+            string data = loader.LoadPredictionFile(file);
+
+            if (data == null)
+                return;
+
             DateTime now = DateTime.Now;
 
             Current = new WeatherInfo();
diff --git a/Server/TestProject/ParserTests/TestingParser.cs b/Server/TestProject/ParserTests/TestingParser.cs
index 85b328f..6be3b61 100644
--- a/Server/TestProject/ParserTests/TestingParser.cs
+++ b/Server/TestProject/ParserTests/TestingParser.cs
@@ -1268,9 +1268,12 @@ namespace TestProject
             string data = SetBasicData();
 
             Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
-            dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
+            dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
 
-            JsonParser target = new JsonParser(dl.Object);
+            Mock<IDataLoader> l = new Mock<IDataLoader>();
+            l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
+
+            JsonParser target = new JsonParser(dl.Object, l.Object);
 
             target.ParsePrediction();
             WeatherInfo current = target.Current;
@@ -1284,9 +1287,12 @@ namespace TestProject
             string data = SetBasicData();
 
             Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
-            dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
+            dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
+
+            Mock<IDataLoader> l = new Mock<IDataLoader>();
+            l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
 
-            JsonParser target = new JsonParser(dl.Object);
+            JsonParser target = new JsonParser(dl.Object, l.Object);
 
             target.ParsePrediction();
             List<WeatherInfo> retVal = target.Predictions;
@@ -1306,9 +1312,12 @@ namespace TestProject
             string data = SetAstronomyData();
 
             Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
-            dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
+            dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
 
-            JsonParser target = new JsonParser(dl.Object);
+            Mock<IDataLoader> l = new Mock<IDataLoader>();
+            l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
+
+            JsonParser target = new JsonParser(dl.Object, l.Object);
 
             target.ParsePrediction();
             List<WeatherInfo> retVal = target.Predictions;
@@ -1333,9 +1342,12 @@ namespace TestProject
         {
             string data = "";
             Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
-            dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
+            dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
+
+            Mock<IDataLoader> l = new Mock<IDataLoader>();
+            l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
 
-            JsonParser target = new JsonParser(dl.Object);
+            JsonParser target = new JsonParser(dl.Object, l.Object);
 
             List<WeatherInfo> pred = new List<WeatherInfo>();
             pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
@@ -1367,9 +1379,12 @@ namespace TestProject
         {
             string data = "";
             Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
-            dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
+            dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
 
-            JsonParser target = new JsonParser(dl.Object);
+            Mock<IDataLoader> l = new Mock<IDataLoader>();
+            l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
+
+            JsonParser target = new JsonParser(dl.Object, l.Object);
 
             List<WeatherInfo> pred = new List<WeatherInfo>();
             pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
@@ -1394,9 +1409,12 @@ namespace TestProject
         {
             string data = "";
             Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
-            dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
+            dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
+
+            Mock<IDataLoader> l = new Mock<IDataLoader>();
+            l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
 
-            JsonParser target = new JsonParser(dl.Object);
+            JsonParser target = new JsonParser(dl.Object, l.Object);
 
             List<WeatherInfo> pred = new List<WeatherInfo>();
             pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
@@ -1426,9 +1444,12 @@ namespace TestProject
         {
             string data = "";
             Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
-            dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
+            dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
 
-            JsonParser target = new JsonParser(dl.Object);
+            Mock<IDataLoader> l = new Mock<IDataLoader>();
+            l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
+
+            JsonParser target = new JsonParser(dl.Object, l.Object);
 
             List<WeatherInfo> pred = new List<WeatherInfo>();
             pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
@@ -1455,9 +1476,12 @@ namespace TestProject
             // TODO make an input file
             string data = "";
             Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
-            dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
+            dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
+
+            Mock<IDataLoader> l = new Mock<IDataLoader>();
+            l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
 
-            JsonParser target = new JsonParser(dl.Object);
+            JsonParser target = new JsonParser(dl.Object, l.Object);
 
             List<WeatherInfo> pred = new List<WeatherInfo>();
             pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
