Revize 4129ce12
Přidáno uživatelem Eliška Mourycová před téměř 4 roky(ů)
Server/ServerApp/Connection/ConnectionListener.cs | ||
---|---|---|
4 | 4 |
|
5 | 5 |
using ServerApp.Connection.XMLProtocolHandler; |
6 | 6 |
using System; |
7 |
using System.Collections.Generic; |
|
7 | 8 |
using System.IO; |
8 | 9 |
using System.Net; |
9 | 10 |
using System.Net.Sockets; |
... | ... | |
291 | 292 |
// } |
292 | 293 |
|
293 | 294 |
|
294 |
class ClientRequest
|
|
295 |
class ClientService
|
|
295 | 296 |
{ |
296 |
HttpListenerContext context; |
|
297 |
string request; |
|
297 |
int id; |
|
298 |
Request request; |
|
299 |
Response response; |
|
298 | 300 |
} |
299 | 301 |
|
300 | 302 |
public class ConnectionListener |
301 | 303 |
{ |
302 | 304 |
private readonly int PORT; |
305 |
private Dictionary<int, ClientService> allRequests; |
|
306 |
private Queue<Request> waitingRequests; |
|
307 |
|
|
303 | 308 |
|
304 | 309 |
public ConnectionListener(int port) |
305 | 310 |
{ |
Server/ServerApp/DataDownload/DataDownloader.cs | ||
---|---|---|
385 | 385 |
/// <returns></returns> |
386 | 386 |
public List<string> GetData(string subDirectory, Date startDate, Date endDate) |
387 | 387 |
{ |
388 |
if (startDate == null || endDate == null) |
|
389 |
return GetData(subDirectory); |
|
390 |
|
|
391 |
|
|
388 | 392 |
string[] files = Directory.GetFiles(subDirectory); |
389 | 393 |
List<string> found00Files = new List<string>(); |
390 | 394 |
List<string> relevantFiles = new List<string>(); |
... | ... | |
455 | 459 |
return relevantFiles; |
456 | 460 |
} |
457 | 461 |
|
462 |
/// <summary> |
|
463 |
/// Returns all file paths in a given directory |
|
464 |
/// </summary> |
|
465 |
/// <param name="subDirectory"></param> |
|
466 |
/// <returns></returns> |
|
467 |
private List<string> GetData(string subDirectory) |
|
468 |
{ |
|
469 |
string[] files = Directory.GetFiles(subDirectory); |
|
470 |
List<string> relevantFiles = new List<string>(files.Length); |
|
471 |
|
|
472 |
for (int i = 0; i < files.Length; i++) |
|
473 |
relevantFiles.Add(files[i]); |
|
474 |
|
|
475 |
return relevantFiles; |
|
476 |
} |
|
477 |
|
|
458 | 478 |
|
459 | 479 |
#region UNUSED |
460 | 480 |
//public string GetDirectoryListingRegexForUrl(string url) |
Server/ServerApp/Program.cs | ||
---|---|---|
48 | 48 |
//p.Parse(); |
49 | 49 |
|
50 | 50 |
#region UNCOMMENT |
51 |
//test scenario -data download: |
|
52 |
DataDownloader dd = new DataDownloader(config.DataRootDir, config.DataWebsite, config.DownloadedFilesNaming); |
|
53 |
dd.OverwriteExisting = false; |
|
54 |
List<string> savedFiles = new List<string>(); |
|
55 |
savedFiles.AddRange(dd.DownloadData(DataType.JIS, DataFormat.CSV, new DataDownload.Date(1, 2019), new DataDownload.Date(12, 2020))); |
|
56 |
savedFiles.AddRange(dd.DownloadData(DataType.STROJE, DataFormat.CSV, new DataDownload.Date(1, 2017), new DataDownload.Date(12, 2020))); |
|
57 |
savedFiles.AddRange(dd.DownloadData(DataType.POCASI, DataFormat.CSV, new DataDownload.Date(1, 2017), new DataDownload.Date(12, 2020))); |
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
Console.WriteLine("Saved files: "); |
|
62 |
foreach (string s in savedFiles) |
|
63 |
{ |
|
64 |
Console.WriteLine(s); |
|
65 |
} |
|
66 |
|
|
67 |
Console.WriteLine("subdirectories: "); |
|
68 |
foreach (KeyValuePair<DataType, string> kvp in dd.DataSubDirectories) |
|
69 |
{ |
|
70 |
Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); |
|
71 |
} |
|
72 |
|
|
73 |
List<string> retrievedData = dd.GetData(dd.DataSubDirectories[DataType.JIS], new DataDownload.Date(10, 2019), new DataDownload.Date(12, 2020)); |
|
74 |
Console.WriteLine("Retrieved data: "); |
|
75 |
foreach (string s in retrievedData) |
|
76 |
{ |
|
77 |
Console.WriteLine(s); |
|
78 |
} |
|
79 |
|
|
80 |
// test - connection: |
|
81 |
ConnectionListener cl = new ConnectionListener(int.Parse(config.Port)); |
|
82 |
cl.StartListening(); |
|
51 |
////test scenario -data download: |
|
52 |
//DataDownloader dd = new DataDownloader(config.DataRootDir, config.DataWebsite, config.DownloadedFilesNaming); |
|
53 |
//dd.OverwriteExisting = false; |
|
54 |
//List<string> savedFiles = new List<string>(); |
|
55 |
//savedFiles.AddRange(dd.DownloadData(DataType.JIS, DataFormat.CSV, new DataDownload.Date(1, 2019), new DataDownload.Date(12, 2020))); |
|
56 |
//savedFiles.AddRange(dd.DownloadData(DataType.STROJE, DataFormat.CSV, new DataDownload.Date(1, 2017), new DataDownload.Date(12, 2020))); |
|
57 |
//savedFiles.AddRange(dd.DownloadData(DataType.POCASI, DataFormat.CSV, new DataDownload.Date(1, 2017), new DataDownload.Date(12, 2020))); |
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
//Console.WriteLine("Saved files: "); |
|
62 |
//foreach (string s in savedFiles) |
|
63 |
//{ |
|
64 |
// Console.WriteLine(s); |
|
65 |
//} |
|
66 |
|
|
67 |
//Console.WriteLine("subdirectories: "); |
|
68 |
//foreach (KeyValuePair<DataType, string> kvp in dd.DataSubDirectories) |
|
69 |
//{ |
|
70 |
// Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); |
|
71 |
//} |
|
72 |
|
|
73 |
//List<string> retrievedData = dd.GetData(dd.DataSubDirectories[DataType.JIS], new DataDownload.Date(10, 2019), new DataDownload.Date(12, 2020)); |
|
74 |
//Console.WriteLine("Retrieved data: "); |
|
75 |
//foreach (string s in retrievedData) |
|
76 |
//{ |
|
77 |
// Console.WriteLine(s); |
|
78 |
//} |
|
79 |
//Console.WriteLine("all from directory:"); |
|
80 |
//retrievedData = dd.GetData(dd.DataSubDirectories[DataType.JIS], null, null); |
|
81 |
//foreach (string s in retrievedData) |
|
82 |
//{ |
|
83 |
// Console.WriteLine(s); |
|
84 |
//} |
|
85 |
//// test - connection: |
|
86 |
////ConnectionListener cl = new ConnectionListener(int.Parse(config.Port)); |
|
87 |
////cl.StartListening(); |
|
83 | 88 |
#endregion |
84 | 89 |
|
85 | 90 |
#region XML_TEST |
Server/ServerApp/ServerApp.csproj | ||
---|---|---|
165 | 165 |
<Compile Include="Predictor\NaiveBayesClassifier.cs" /> |
166 | 166 |
<Compile Include="Program.cs" /> |
167 | 167 |
<Compile Include="Properties\AssemblyInfo.cs" /> |
168 |
<Compile Include="User\Command.cs" /> |
|
168 | 169 |
<Compile Include="User\CommandsAcceptor.cs" /> |
169 | 170 |
</ItemGroup> |
170 | 171 |
<ItemGroup> |
Server/ServerApp/User/Command.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 |
|
|
7 |
namespace ServerApp.User |
|
8 |
{ |
|
9 |
public enum Commands |
|
10 |
{ |
|
11 |
RETRAIN, ROLLBACK, DATA_LIST, NEW_DATA, HELP |
|
12 |
} |
|
13 |
|
|
14 |
public class Command |
|
15 |
{ |
|
16 |
public string MainCommand { get; set; } |
|
17 |
public Dictionary<string, List<string>> FlagsAndData { get; } |
|
18 |
private string lastFlag; |
|
19 |
|
|
20 |
public Command() |
|
21 |
{ |
|
22 |
MainCommand = ""; |
|
23 |
FlagsAndData = new Dictionary<string, List<string>>(); |
|
24 |
lastFlag = ""; |
|
25 |
} |
|
26 |
|
|
27 |
public void AddFlag(string flag) |
|
28 |
{ |
|
29 |
FlagsAndData.Add(flag, new List<string>()); |
|
30 |
lastFlag = flag; |
|
31 |
} |
|
32 |
|
|
33 |
public void AddData(string data) |
|
34 |
{ |
|
35 |
FlagsAndData[lastFlag].Add(data); |
|
36 |
} |
|
37 |
} |
|
38 |
} |
Server/ServerApp/User/CommandsAcceptor.cs | ||
---|---|---|
6 | 6 |
|
7 | 7 |
namespace ServerApp.User |
8 | 8 |
{ |
9 |
|
|
10 |
|
|
9 | 11 |
public class CommandsAcceptor |
10 | 12 |
{ |
11 | 13 |
|
... | ... | |
13 | 15 |
{ |
14 | 16 |
while (true) { |
15 | 17 |
string command = Console.ReadLine(); |
18 |
Command c = ParseString(command); |
|
19 |
CheckCommand(c); |
|
16 | 20 |
Program.NotifyUserMessage(command); |
17 | 21 |
} |
18 | 22 |
} |
23 |
|
|
24 |
private static Command ParseString(string str) |
|
25 |
{ |
|
26 |
string[] splits = str.Split(' '); |
|
27 |
Command command = new Command(); |
|
28 |
|
|
29 |
command.MainCommand = splits[0]; |
|
30 |
|
|
31 |
for(int i = 1; i < splits.Length; i++) |
|
32 |
{ |
|
33 |
|
|
34 |
string current = splits[i]; |
|
35 |
if (current.StartsWith("-")) |
|
36 |
{ |
|
37 |
command.AddFlag(current.Substring(1)); |
|
38 |
} |
|
39 |
else |
|
40 |
{ |
|
41 |
command.AddData(current); |
|
42 |
} |
|
43 |
} |
|
44 |
|
|
45 |
return command; |
|
46 |
} |
|
47 |
|
|
48 |
private static void CheckCommand(Command c) |
|
49 |
{ |
|
50 |
Console.WriteLine(c); |
|
51 |
|
|
52 |
switch (c.MainCommand) |
|
53 |
{ |
|
54 |
case "data": break; |
|
55 |
case "model": break; |
|
56 |
case "help": break; |
|
57 |
} |
|
58 |
} |
|
59 |
|
|
60 |
private void PrintUsage() |
|
61 |
{ |
|
62 |
|
|
63 |
} |
|
19 | 64 |
} |
20 | 65 |
} |
Také k dispozici: Unified diff
Re #8838. Started refining commands accepting + modified GetData in DataDownloader.