Projekt

Obecné

Profil

« Předchozí | Další » 

Revize c4383c00

Přidáno uživatelem Eliška Mourycová před více než 3 roky(ů)

Re #8942. Started implementing admin commands.

Zobrazit rozdíly:

Server/ServerApp/User/CommandsAcceptor.cs
1
using System;
1
using ServerApp.DataDownload;
2
using ServerApp.Predictor;
3
using System;
2 4
using System.Collections.Generic;
3 5
using System.Linq;
4 6
using System.Text;
......
10 12

  
11 13
	public class CommandsAcceptor
12 14
	{
15
		private DataDownloader dd;
16
		private IPredictionController model;
13 17

  
14
		public static void AcceptCommand()
18
		public CommandsAcceptor(DataDownloader dd, IPredictionController controller)
19
		{
20
			this.dd = dd;
21
			this.model = controller;
22
		}
23

  
24
		public void AcceptCommand()
15 25
		{
16 26
			while (true) {
17 27
				string command = Console.ReadLine();
28
				Console.WriteLine("received admin command: " + command);
18 29
				Command c = ParseString(command);
19 30
				CheckCommand(c);
20
				Program.NotifyUserMessage(command);
31
				//Program.NotifyUserMessage(command);
21 32
			}
22 33
		}
23 34

  
24 35
		private static Command ParseString(string str)
25 36
		{
26
			string[] splits = str.Split(' ');
37

  
38
			string[] splits = str.Trim().Split(' ');
27 39
			Command command = new Command();
28 40

  
41
			command.WholeCommand = str.Trim();
29 42
			command.MainCommand = splits[0];
30 43

  
31 44
			for(int i = 1; i < splits.Length; i++)
......
45 58
			return command;
46 59
		}
47 60

  
48
		private static void CheckCommand(Command c)
61
		private void CheckCommand(Command c)
49 62
		{
50
			Console.WriteLine(c);
51 63

  
52 64
			switch (c.MainCommand)
53 65
			{
54
				case "data": break;
55
				case "model": break;
56
				case "help": break;
66
				case "data":
67
					HandleDataCommand(c);
68
					break;
69
				case "model":
70
					HandleModelCommand(c);
71
					break;
72
				case "help":
73
					HandleHelpCommand(c);
74
					break;
75
				default:
76
					PrintUnknown(c.MainCommand);
77
					break;
57 78
			}
58 79
		}
59 80

  
60
		private void PrintUsage()
81
		private void PrintUnknown(string command)
82
		{
83
			Console.WriteLine("Unknown command: " + command);
84
		}
85

  
86
		private void HandleDataCommand(Command c)
61 87
		{
88
			// data -list
89
			// data -dl 1-2019 12-2020
90

  
91
			if(c.WholeCommand.Equals("data -list"))
92
			{
93
				Console.WriteLine("Listing all downloaded data files...");
94
				
95
			}
96
			else if (c.FlagsAndData.ContainsKey("dl"))
97
			{
98
				List<string> dates = c.FlagsAndData["dl"];
99
				if (dates.Count != 2)
100
				{
101
					Console.WriteLine("2 date arguments needed!");
102
					return;
103
				}
104

  
105
				Date start = Date.ParseDate(dates[0]);
106
				Date end = Date.ParseDate(dates[1]);
62 107

  
108
				if (start == null || end == null)
109
				{
110
					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.");
111
					return;
112
				}
113

  
114
				Console.WriteLine("Downloading data from " + start.ToString() + " to " + end.ToString());
115
			}
116
		}
117

  
118
		private void HandleModelCommand(Command c)
119
		{
120
			// model -files
121
			// model -retrain
122
			// model -rollback
123
		}
124

  
125
		private void HandleHelpCommand(Command c)
126
		{
127
			Console.WriteLine("help.");
128
		}
129

  
130
		private void PrintUsage(Command c)
131
		{
132
			
63 133
		}
64 134
	}
65 135
}

Také k dispozici: Unified diff