commit c4383c00c625cf9cc46d82dfbde67ef8bbf92b38
Author: Eliška Mourycová <eliska.mourycova@seznam.cz>
Date:   Fri May 21 14:29:30 2021 +0200

    Re #8942. Started implementing admin commands.

diff --git a/Server/ServerApp/DataDownload/Date.cs b/Server/ServerApp/DataDownload/Date.cs
index 4fef619..3191bf9 100644
--- a/Server/ServerApp/DataDownload/Date.cs
+++ b/Server/ServerApp/DataDownload/Date.cs
@@ -38,6 +38,49 @@ namespace ServerApp.DataDownload
 			return new Date(newMonth, newYear);
 		}
 
+		/// <summary>
+		/// Parses the date given in format: 1-2020
+		/// </summary>
+		/// <param name="str">The string to parse</param>
+		/// <returns>A new date</returns>
+		public static Date ParseDate(string str)
+		{
+
+			uint month, year;
+
+			string ds = str.Trim();
+			string[] splits = ds.Split('-');
+
+			if(splits.Length != 2)
+			{
+				Console.WriteLine("Unknown date format. Must be e.g. 1-2020.");
+				return null;
+			}
+
+			bool monthOk = uint.TryParse(splits[0], out month);
+			bool yearOk = uint.TryParse(splits[1], out year);
+
+			if(!monthOk || !yearOk)
+			{
+				Console.WriteLine("Unknown date format. Must be e.g. 1-2020.");
+				return null;
+			}
+
+
+			try
+			{
+				Date d = new Date(month, year);
+				return d;
+			}
+			catch (Exception ex)
+			{
+				return null;
+			}
+			
+
+			return null;
+		}
+
 
 		#region OVERRIDEN METHODS FOR OF THE OBJECT CLASS
 		public override bool Equals(object obj)
diff --git a/Server/ServerApp/Program.cs b/Server/ServerApp/Program.cs
index 148f525..7db41a9 100644
--- a/Server/ServerApp/Program.cs
+++ b/Server/ServerApp/Program.cs
@@ -25,7 +25,7 @@ namespace ServerApp
     public class Program
     {
 
-		public static void NotifyUserMessage(string message)
+		public void NotifyUserMessage(string message)
 		{
 			Console.WriteLine("Received user message: " + message);
 		}
@@ -42,10 +42,7 @@ namespace ServerApp
 				return;
 			}
 
-			// commands accepting test
-			//create a thread for commands accepting:
-			//Thread inputThread = new Thread(CommandsAcceptor.AcceptCommand);
-			//inputThread.Start();
+			
 
 
 			// is this obsolete?
@@ -78,8 +75,16 @@ namespace ServerApp
 			//parse(new DateTime(2019, 10, 5), , interval = 1, wholeDay = true)
 
 
+			// commands accepting test
+			// create a thread for commands accepting:
+			CommandsAcceptor ca = new CommandsAcceptor(dd, controller);
+			Thread inputThread = new Thread(ca.AcceptCommand);
+			inputThread.Start();
+
 			// connection test
 			ConnectionTest(controller, config);
+
+
 			
 
 			Console.ReadLine();
diff --git a/Server/ServerApp/User/Command.cs b/Server/ServerApp/User/Command.cs
index e5ad907..67e5577 100644
--- a/Server/ServerApp/User/Command.cs
+++ b/Server/ServerApp/User/Command.cs
@@ -6,13 +6,10 @@ using System.Threading.Tasks;
 
 namespace ServerApp.User
 {
-	public enum Commands
-	{
-		RETRAIN, ROLLBACK, DATA_LIST, NEW_DATA, HELP
-	}
 
 	public class Command
 	{
+		public string WholeCommand { get; set; }
 		public string MainCommand { get; set; }
 		public Dictionary<string, List<string>> FlagsAndData { get; }
 		private string lastFlag;
diff --git a/Server/ServerApp/User/CommandsAcceptor.cs b/Server/ServerApp/User/CommandsAcceptor.cs
index 0d70551..1bbea20 100644
--- a/Server/ServerApp/User/CommandsAcceptor.cs
+++ b/Server/ServerApp/User/CommandsAcceptor.cs
@@ -1,4 +1,6 @@
-﻿using System;
+﻿using ServerApp.DataDownload;
+using ServerApp.Predictor;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -10,22 +12,33 @@ namespace ServerApp.User
 
 	public class CommandsAcceptor
 	{
+		private DataDownloader dd;
+		private IPredictionController model;
 
-		public static void AcceptCommand()
+		public CommandsAcceptor(DataDownloader dd, IPredictionController controller)
+		{
+			this.dd = dd;
+			this.model = controller;
+		}
+
+		public void AcceptCommand()
 		{
 			while (true) {
 				string command = Console.ReadLine();
+				Console.WriteLine("received admin command: " + command);
 				Command c = ParseString(command);
 				CheckCommand(c);
-				Program.NotifyUserMessage(command);
+				//Program.NotifyUserMessage(command);
 			}
 		}
 
 		private static Command ParseString(string str)
 		{
-			string[] splits = str.Split(' ');
+
+			string[] splits = str.Trim().Split(' ');
 			Command command = new Command();
 
+			command.WholeCommand = str.Trim();
 			command.MainCommand = splits[0];
 
 			for(int i = 1; i < splits.Length; i++)
@@ -45,21 +58,78 @@ namespace ServerApp.User
 			return command;
 		}
 
-		private static void CheckCommand(Command c)
+		private void CheckCommand(Command c)
 		{
-			Console.WriteLine(c);
 
 			switch (c.MainCommand)
 			{
-				case "data": break;
-				case "model": break;
-				case "help": break;
+				case "data":
+					HandleDataCommand(c);
+					break;
+				case "model":
+					HandleModelCommand(c);
+					break;
+				case "help":
+					HandleHelpCommand(c);
+					break;
+				default:
+					PrintUnknown(c.MainCommand);
+					break;
 			}
 		}
 
-		private void PrintUsage()
+		private void PrintUnknown(string command)
+		{
+			Console.WriteLine("Unknown command: " + command);
+		}
+
+		private void HandleDataCommand(Command c)
 		{
+			// data -list
+			// data -dl 1-2019 12-2020
+
+			if(c.WholeCommand.Equals("data -list"))
+			{
+				Console.WriteLine("Listing all downloaded data files...");
+				
+			}
+			else if (c.FlagsAndData.ContainsKey("dl"))
+			{
+				List<string> dates = c.FlagsAndData["dl"];
+				if (dates.Count != 2)
+				{
+					Console.WriteLine("2 date arguments needed!");
+					return;
+				}
+
+				Date start = Date.ParseDate(dates[0]);
+				Date end = Date.ParseDate(dates[1]);
 
+				if (start == null || end == null)
+				{
+					Console.WriteLine("Date parsing was not successful. Please ensure you enter the dates in the following format: 1-2020. Month must be greater than zero.");
+					return;
+				}
+
+				Console.WriteLine("Downloading data from " + start.ToString() + " to " + end.ToString());
+			}
+		}
+
+		private void HandleModelCommand(Command c)
+		{
+			// model -files
+			// model -retrain
+			// model -rollback
+		}
+
+		private void HandleHelpCommand(Command c)
+		{
+			Console.WriteLine("help.");
+		}
+
+		private void PrintUsage(Command c)
+		{
+			
 		}
 	}
 }
