Revize 9cc42e60
Přidáno uživatelem Eliška Mourycová před téměř 4 roky(ů)
Server/ServerApp/Connection/ConnectionListener.cs | ||
---|---|---|
154 | 154 |
logger.Debug("At the end of HandleRequest"); |
155 | 155 |
} |
156 | 156 |
|
157 |
|
|
157 |
/// <summary> |
|
158 |
/// The callnack method triggered when client request received |
|
159 |
/// </summary> |
|
160 |
/// <param name="result"></param> |
|
158 | 161 |
private void ListenerCallback(IAsyncResult result) |
159 | 162 |
{ |
160 | 163 |
logger.Debug("in ListenerCallback"); |
... | ... | |
239 | 242 |
|
240 | 243 |
} |
241 | 244 |
|
242 |
|
|
245 |
/// <summary> |
|
246 |
/// Constructs the response for GET requests |
|
247 |
/// </summary> |
|
248 |
/// <param name="requestString">The whole string received with the GET request</param> |
|
249 |
/// <returns>The response string, empty if client's request doesn't follow protocol</returns> |
|
243 | 250 |
private string ConstructGETResponse(string requestString) |
244 | 251 |
{ |
245 | 252 |
//Console.WriteLine("Constructiing a response for GET request."); |
... | ... | |
291 | 298 |
|
292 | 299 |
} |
293 | 300 |
|
301 |
/// <summary> |
|
302 |
/// Constructs the response for POST requests |
|
303 |
/// </summary> |
|
304 |
/// <param name="requestString">The whole string received with the POST request</param> |
|
305 |
/// <returns>The response string, empty if client's request doesn't follow protocol</returns> |
|
294 | 306 |
private string ConstructPOSTResponse(string requestString) |
295 | 307 |
{ |
296 | 308 |
logger.Info("Constructing a response for POST request."); |
... | ... | |
333 | 345 |
|
334 | 346 |
} |
335 | 347 |
|
336 |
|
|
348 |
/// <summary> |
|
349 |
/// Gets the IPv4 IP of the machine |
|
350 |
/// </summary> |
|
351 |
/// <returns>The IP as a string</returns> |
|
337 | 352 |
private string GetLocalIPAddress() |
338 | 353 |
{ |
339 | 354 |
var host = Dns.GetHostEntry(Dns.GetHostName()); |
Server/ServerApp/Program.cs | ||
---|---|---|
16 | 16 |
namespace ServerApp |
17 | 17 |
{ |
18 | 18 |
|
19 |
class Config // TBD where this should go
|
|
19 |
class Config |
|
20 | 20 |
{ |
21 | 21 |
public string DataWebsite { get; set; } |
22 | 22 |
public string DownloadedFilesNaming { get; set; } |
... | ... | |
28 | 28 |
public class Program |
29 | 29 |
{ |
30 | 30 |
|
31 |
//public void NotifyUserMessage(string message) |
|
32 |
//{ |
|
33 |
// Console.WriteLine("Received user message: " + message); |
|
34 |
//} |
|
35 |
|
|
36 | 31 |
static void Main(string[] args) |
37 | 32 |
{ |
38 | 33 |
// setup logging service |
... | ... | |
42 | 37 |
Config config = FillConfigInfo(args); |
43 | 38 |
if (config == null) |
44 | 39 |
{ |
40 |
Console.WriteLine("Configuration file parsing failed. Abort."); |
|
45 | 41 |
Console.ReadLine(); |
46 | 42 |
return; |
47 | 43 |
} |
... | ... | |
49 | 45 |
// data download test |
50 | 46 |
DataDownloader dd = DataDownloadAndRetrievalTest(config); |
51 | 47 |
|
52 |
WeatherAsStringTest(dd); |
|
53 |
Console.ReadLine(); |
|
48 |
//WeatherAsStringTest(dd);
|
|
49 |
//Console.ReadLine();
|
|
54 | 50 |
|
55 | 51 |
// xml building test |
56 | 52 |
//XMLTest(); |
... | ... | |
73 | 69 |
Thread inputThread = new Thread(ca.AcceptCommand); |
74 | 70 |
inputThread.Start(); |
75 | 71 |
|
72 |
|
|
76 | 73 |
// connection test |
77 | 74 |
ConnectionTest(controller, config); |
78 | 75 |
|
79 |
Console.ReadLine(); |
|
76 |
//Console.ReadLine();
|
|
80 | 77 |
} |
81 | 78 |
|
82 | 79 |
|
... | ... | |
202 | 199 |
Console.WriteLine("Parsing configuration file..."); |
203 | 200 |
|
204 | 201 |
if (args.Length != 1) |
205 |
Console.WriteLine("Wrong usage of parameters, pass the path to a config file."); // todo better explanation?
|
|
202 |
Console.WriteLine("Wrong usage of parameters, pass only the path to a config file.");
|
|
206 | 203 |
|
207 | 204 |
string fullPathConfig = Path.GetFullPath(args[0]); |
208 | 205 |
string[] lines = null; |
... | ... | |
248 | 245 |
} |
249 | 246 |
} |
250 | 247 |
|
248 |
int parsedPort; |
|
249 |
|
|
250 |
bool success = int.TryParse(extractedConfigInfo.Port, out parsedPort); |
|
251 |
if (!success) |
|
252 |
{ |
|
253 |
Console.WriteLine("Configured port " + extractedConfigInfo.Port + " is not an integer number! Abort."); |
|
254 |
return null; |
|
255 |
} |
|
256 |
|
|
257 |
|
|
251 | 258 |
return extractedConfigInfo; |
252 | 259 |
} |
253 | 260 |
} |
Server/ServerApp/Properties/launchSettings.json | ||
---|---|---|
2 | 2 |
"profiles": { |
3 | 3 |
"ServerApp": { |
4 | 4 |
"commandName": "Project", |
5 |
"commandLineArgs": ".\\server_config"
|
|
5 |
"commandLineArgs": "C:\\Users\\elisk\\Documents\\aswi2021tri-musketyri\\Server\\ServerApp\\server_config"
|
|
6 | 6 |
} |
7 | 7 |
} |
8 | 8 |
} |
Server/ServerApp/User/Command.cs | ||
---|---|---|
1 |
using System; |
|
1 |
// |
|
2 |
// Author: Eliska Mourycova |
|
3 |
// |
|
4 |
|
|
5 |
using System; |
|
2 | 6 |
using System.Collections.Generic; |
3 | 7 |
using System.Linq; |
4 | 8 |
using System.Text; |
... | ... | |
6 | 10 |
|
7 | 11 |
namespace ServerApp.User |
8 | 12 |
{ |
9 |
|
|
13 |
/// <summary> |
|
14 |
/// This class represents a command input by the admin |
|
15 |
/// </summary> |
|
10 | 16 |
public class Command |
11 | 17 |
{ |
18 |
/// <summary> |
|
19 |
/// The whole string input |
|
20 |
/// </summary> |
|
12 | 21 |
public string WholeCommand { get; set; } |
22 |
|
|
23 |
/// <summary> |
|
24 |
/// The main part of the command |
|
25 |
/// </summary> |
|
13 | 26 |
public string MainCommand { get; set; } |
27 |
|
|
28 |
/// <summary> |
|
29 |
/// The flags and data associated with the command |
|
30 |
/// </summary> |
|
14 | 31 |
public Dictionary<string, List<string>> FlagsAndData { get; } |
32 |
|
|
33 |
// the last flag used |
|
15 | 34 |
private string lastFlag; |
16 | 35 |
|
17 | 36 |
public Command() |
... | ... | |
21 | 40 |
lastFlag = ""; |
22 | 41 |
} |
23 | 42 |
|
43 |
/// <summary> |
|
44 |
/// Adds a flag to the dictionary |
|
45 |
/// </summary> |
|
46 |
/// <param name="flag">The flag to add</param> |
|
24 | 47 |
public void AddFlag(string flag) |
25 | 48 |
{ |
26 | 49 |
FlagsAndData.Add(flag, new List<string>()); |
27 | 50 |
lastFlag = flag; |
28 | 51 |
} |
29 | 52 |
|
53 |
/// <summary> |
|
54 |
/// Adds data after a flag |
|
55 |
/// </summary> |
|
56 |
/// <param name="data">The data to add</param> |
|
30 | 57 |
public void AddData(string data) |
31 | 58 |
{ |
32 |
FlagsAndData[lastFlag].Add(data); |
|
59 |
if(FlagsAndData.ContainsKey(lastFlag)) |
|
60 |
FlagsAndData[lastFlag].Add(data); |
|
33 | 61 |
} |
34 | 62 |
} |
35 | 63 |
} |
Server/ServerApp/User/CommandsAcceptor.cs | ||
---|---|---|
13 | 13 |
namespace ServerApp.User |
14 | 14 |
{ |
15 | 15 |
|
16 |
|
|
16 |
/// <summary> |
|
17 |
/// This class tkes care of parsing and executing admin commands |
|
18 |
/// </summary> |
|
17 | 19 |
public class CommandsAcceptor |
18 | 20 |
{ |
21 |
// the DataDownloader instance |
|
19 | 22 |
private DataDownloader dd; |
23 |
|
|
24 |
// the predictor instance |
|
20 | 25 |
private IPredictionController model; |
21 | 26 |
|
22 | 27 |
public CommandsAcceptor(DataDownloader dd, IPredictionController controller) |
... | ... | |
25 | 30 |
this.model = controller; |
26 | 31 |
} |
27 | 32 |
|
33 |
/// <summary> |
|
34 |
/// Prints a prompt and waits for input |
|
35 |
/// </summary> |
|
28 | 36 |
public void AcceptCommand() |
29 | 37 |
{ |
30 | 38 |
while (true) { |
... | ... | |
35 | 43 |
Console.WriteLine("received admin command: " + command); |
36 | 44 |
Command c = ParseString(command); |
37 | 45 |
CheckCommand(c); |
38 |
//Program.NotifyUserMessage(command); |
|
39 | 46 |
} |
40 | 47 |
|
41 | 48 |
} |
42 | 49 |
} |
43 | 50 |
|
51 |
/// <summary> |
|
52 |
/// Parses the input string |
|
53 |
/// </summary> |
|
54 |
/// <param name="str">The whole string typed in by the user</param> |
|
55 |
/// <returns>A new instance of the Command class</returns> |
|
44 | 56 |
private Command ParseString(string str) |
45 | 57 |
{ |
46 | 58 |
|
... | ... | |
67 | 79 |
return command; |
68 | 80 |
} |
69 | 81 |
|
82 |
/// <summary> |
|
83 |
/// Checks the comamnd and decides what to do according to the main command |
|
84 |
/// </summary> |
|
85 |
/// <param name="c">The command</param> |
|
70 | 86 |
private void CheckCommand(Command c) |
71 | 87 |
{ |
72 | 88 |
|
... | ... | |
87 | 103 |
} |
88 | 104 |
} |
89 | 105 |
|
106 |
/// <summary> |
|
107 |
/// Prints to the console, that the given command is unknown |
|
108 |
/// </summary> |
|
109 |
/// <param name="command">The input command</param> |
|
90 | 110 |
private void PrintUnknown(string command) |
91 | 111 |
{ |
92 | 112 |
Console.WriteLine("Unknown command: " + command); |
93 | 113 |
} |
94 | 114 |
|
115 |
/// <summary> |
|
116 |
/// Handles the command linked to data listing and downloading |
|
117 |
/// </summary> |
|
118 |
/// <param name="c">The command</param> |
|
95 | 119 |
private void HandleDataCommand(Command c) |
96 | 120 |
{ |
97 | 121 |
// data -list |
... | ... | |
151 | 175 |
|
152 | 176 |
|
153 | 177 |
} |
178 |
else |
|
179 |
{ |
|
180 |
PrintUnknown(c.WholeCommand); |
|
181 |
HandleHelpCommand(c); |
|
182 |
} |
|
154 | 183 |
} |
155 | 184 |
|
185 |
/// <summary> |
|
186 |
/// Handles the command linked to predictor training, rollback and files listing |
|
187 |
/// </summary> |
|
188 |
/// <param name="c">The command</param> |
|
156 | 189 |
private void HandleModelCommand(Command c) |
157 | 190 |
{ |
158 | 191 |
// TODO: |
... | ... | |
193 | 226 |
break; |
194 | 227 |
} |
195 | 228 |
} |
229 |
else |
|
230 |
{ |
|
231 |
PrintUnknown(c.WholeCommand); |
|
232 |
HandleHelpCommand(c); |
|
233 |
} |
|
196 | 234 |
|
197 | 235 |
|
198 | 236 |
//model.Rollback() // 0 -ok, 1 nejde, 2 - error (kdyz nekdo smaze soubor config) |
199 | 237 |
//model.GetDataFileNames(); |
200 | 238 |
} |
201 | 239 |
|
240 |
/// <summary> |
|
241 |
/// Prints help to the console |
|
242 |
/// </summary> |
|
243 |
/// <param name="c"></param> |
|
202 | 244 |
private void HandleHelpCommand(Command c) |
203 | 245 |
{ |
204 | 246 |
Console.WriteLine("List of available commands and their description: "); |
... | ... | |
223 | 265 |
Console.WriteLine(" Example: model -rollback"); |
224 | 266 |
} |
225 | 267 |
|
226 |
private void PrintUsage(Command c) |
|
227 |
{ |
|
228 |
|
|
229 |
} |
|
230 | 268 |
} |
231 | 269 |
} |
Také k dispozici: Unified diff
Re #9055. Fixed admin commands related bug + refactor + documentation comments