commit 4a417b8bfbc57a59cc6c705ffafbb10754818f95
Author: Eliška Mourycová <eliska.mourycova@seznam.cz>
Date:   Mon Apr 26 14:58:09 2021 +0200

    Re #8691. Url config improvements + thread for commands accepting prepared.

diff --git a/Server/ServerApp/DataDownload/DataDownloader.cs b/Server/ServerApp/DataDownload/DataDownloader.cs
index 1433193..ff8b08e 100644
--- a/Server/ServerApp/DataDownload/DataDownloader.cs
+++ b/Server/ServerApp/DataDownload/DataDownloader.cs
@@ -28,11 +28,6 @@ namespace ServerApp.DataDownload
 		XML, JSON, CSV
 	}
 
-	public enum TimeSpan
-	{
-
-	}
-
 	/// <summary>
 	/// This class takes care of downloading of data. Download happens from http://openstore.zcu.cz/.
 	/// </summary>
@@ -65,14 +60,20 @@ namespace ServerApp.DataDownload
 		// a shortcut to writing Path.DirectorySeparatorChar
 		private char sep = Path.DirectorySeparatorChar;
 
-		public DataDownloader(string rootDataDir, string website, string namingConvention) // todo take naming conventons specifiaction into account
+		private List<string> separatedFileName;
+		private List<string> variablesInsertions;
+		private List<char> nameTurns;
+
+		public DataDownloader(string rootDataDir, string website, string namingConvention) // todo: take naming conventons specifiaction into account
 		{
 			// initialize all needed variables:
 
 			DataSubDirectories = new Dictionary<DataType, string>();
-
-			Console.WriteLine(Directory.GetCurrentDirectory());
+			
+			//Console.WriteLine(Directory.GetCurrentDirectory());
 			site = website;//"http://openstore.zcu.cz/";
+
+			ParseNaming(namingConvention);
 			dataStr = "OD_ZCU_";
 
 			RootDataDirectory = rootDataDir;//$"..{sep}..{sep}..{sep}data{sep}auto";
@@ -81,6 +82,109 @@ namespace ServerApp.DataDownload
 			webClient = new WebClient();
 		}
 
+		private void ParseNaming(string namingConvention)
+		{
+			separatedFileName = new List<string>();
+			variablesInsertions = new List<string>();
+			nameTurns = new List<char>();
+
+			string currPart = "";
+			string currVar = "";
+			bool readingNormal = true;
+			foreach (char c in namingConvention)
+			{
+				if (c == '{')
+				{
+					AddToNameParts(currPart);
+					readingNormal = false;
+					currPart = "";
+				}
+				else if (c == '}')
+				{
+					AddToVariables(currVar);
+					readingNormal = true;
+					currVar = "";
+				}
+				else
+				{
+					// normal char
+					if (readingNormal)
+						currPart += c;
+					else
+						currVar += c;
+				}
+			}
+
+			// add the rest if there is any:
+			if (readingNormal)
+				AddToNameParts(currPart);
+			else
+				AddToVariables(currVar);
+
+			Console.WriteLine();
+		}
+
+		private void AddToNameParts(string s)
+		{
+			if (s.Length > 0)
+			{
+				separatedFileName.Add(s);
+				nameTurns.Add('n');
+			}
+				
+		}
+
+		private void AddToVariables(string s)
+		{
+			if (s.Length > 0)
+			{
+				variablesInsertions.Add(s);
+				nameTurns.Add('v');
+			}
+				
+		}
+
+
+		private string BuildDownloadedName(DataType type, DataFormat format, int year, int month)
+		{
+			string nameZip = "";
+
+			int partInd = 0;
+			int varInd = 0;
+			for(int i = 0; i < nameTurns.Count; i++)
+			{
+				if (nameTurns[i] == 'n')
+				{
+					nameZip += separatedFileName[partInd];
+					partInd++;
+				}
+				else if(nameTurns[i] == 'v')
+				{
+					string add = "";
+					switch (variablesInsertions[varInd])
+					{
+						case "type":
+							add = "" + type;
+							break;
+						case "month": 
+							add = month < 10 ? "0" + month : "" + month;
+							break;
+						case "year":
+							add = "" + year;
+							break;
+						case "format":
+							add = "" + format;
+							break;
+						default: throw new Exception("Config file error - naming conventions can only contain variables with following names: type, month, year, format");
+					}
+					nameZip += add;
+					varInd++;
+				}
+			}
+
+			return nameZip;
+		}
+
 		/// <summary>
 		/// Downloads a specific archive.
 		/// </summary>
@@ -97,10 +201,12 @@ namespace ServerApp.DataDownload
 			// Prepare the url string to be downloaded from:
 			string monthStr = month < 10 ? "0" + month : "" + month;
 			string yearStr = "" + year;
-
 			string monthYr = monthStr + "_" + yearStr;
-			string url = site + "/" + dataStr + monthYr + "/" + dataStr + type + "_" + monthYr + "_" + format + ".zip";
-			string nameZip = dataStr + type + "_" + monthYr + "_" + format + ".zip";
+
+
+			string nameZip = BuildDownloadedName(type, format, year, month);//dataStr + type + "_" + monthYr + "_" + format + ".zip";
+			string url = site + "/" + dataStr + monthYr + "/" + nameZip;//+ dataStr + type + "_" + monthYr + "_" + format + ".zip";
+			
 			string nameFolder = RootDataDirectory + sep + type + sep; //+ dataStr + type + "_" + monthYr + "_" + format;
 
 			try
@@ -208,7 +314,7 @@ namespace ServerApp.DataDownload
 				currentDate = nextDate;
 
 
-			} while (currentDate != endDate);
+			} while (currentDate <= endDate);
 
 
 			
@@ -229,8 +335,14 @@ namespace ServerApp.DataDownload
 			throw new NotImplementedException();
 		}
 
-		public List<string> GetData(string subDirectory, int startYear, int endYear, int startMonth, int endMonth)
+		public List<string> GetData(string subDirectory, Date startDate, Date endDate)
 		{
+			string[] files = Directory.GetFiles(subDirectory);
+			for(int i = 0; i < files.Length; i++)
+			{
+
+			}
+
 			throw new NotImplementedException();
 		}
 
diff --git a/Server/ServerApp/Program.cs b/Server/ServerApp/Program.cs
index 8bf79fc..59d641b 100644
--- a/Server/ServerApp/Program.cs
+++ b/Server/ServerApp/Program.cs
@@ -2,9 +2,11 @@
 using ServerApp.DataDownload;
 using ServerApp.Parser.Parsers;
 using ServerApp.Predictor;
+using ServerApp.User;
 using System;
 using System.Collections.Generic;
 using System.IO;
+using System.Threading;
 
 namespace ServerApp
 {
@@ -17,10 +19,13 @@ namespace ServerApp
 		public string Port { get; set; }
 	}
 
-    class Program
+    public class Program
     {
 
-
+		public static void NotifyUserMessage(string message)
+		{
+			Console.WriteLine("Received user message: " + message);
+		}
 
         static void Main(string[] args)
         {
@@ -32,6 +37,10 @@ namespace ServerApp
 				return;
 			}
 
+			// create a thread for commands accepting:
+			//Thread inputThread = new Thread(CommandsAcceptor.AcceptCommand);
+			//inputThread.Start();
+
 
 
 			//DataParser p = new DataParser("data/");
@@ -80,7 +89,7 @@ namespace ServerApp
 
 			// test - connection:
 			//AsynchronousSocketListener asl = new AsynchronousSocketListener();
-			//         asl.StartListening();
+			//asl.StartListening();
 
 
 			//NaiveBayesClassifier naiveBayesClassifier = new NaiveBayesClassifier();
diff --git a/Server/ServerApp/ServerApp.csproj b/Server/ServerApp/ServerApp.csproj
index 0d57fb5..3d8a32b 100644
--- a/Server/ServerApp/ServerApp.csproj
+++ b/Server/ServerApp/ServerApp.csproj
@@ -158,6 +158,7 @@
     <Compile Include="Predictor\NaiveBayesClassifier.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="User\CommandsAcceptor.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="App.config" />
diff --git a/Server/ServerApp/User/CommandsAcceptor.cs b/Server/ServerApp/User/CommandsAcceptor.cs
new file mode 100644
index 0000000..49c81fb
--- /dev/null
+++ b/Server/ServerApp/User/CommandsAcceptor.cs
@@ -0,0 +1,20 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ServerApp.User
+{
+	public class CommandsAcceptor
+	{
+
+		public static void AcceptCommand()
+		{
+			while (true) {
+				string command = Console.ReadLine();
+				Program.NotifyUserMessage(command);
+			}
+		}
+	}
+}
diff --git a/Server/ServerApp/server_config b/Server/ServerApp/server_config
index bfd79a6..ef70b07 100644
--- a/Server/ServerApp/server_config
+++ b/Server/ServerApp/server_config
@@ -1,5 +1,5 @@
-
 #
+# Tri Musketyri, ASWI 2021
 # This is the server configuration file. See [wiki_site] for detailed information about its structure.
 # Pass this file as an argument to the server program when launching it.
 #
@@ -11,6 +11,8 @@
 http://openstore.zcu.cz/
 
 # the naming convention for files stored at the site to download from:
+# variables in this string must keep their name, cannot be excluded and others cannot be added. They must be enclosed in {} brackets
+# {} characters are treated as special characters and cannot be used as a part of the name
 !naming_convention!
 OD_ZCU_{type}_{month}_{year}_{format}.zip
 
