Projekt

Obecné

Profil

Stáhnout (3.69 KB) Statistiky
| Větev: | Tag: | Revize:
1 7a998d66 Eliška Mourycová
using ServerApp.Connection;
2
using ServerApp.DataDownload;
3 57a75f60 Roman Kalivoda
using ServerApp.Parser.Parsers;
4 9fc5fa93 Roman Kalivoda
using ServerApp.Predictor;
5 4a417b8b Eliška Mourycová
using ServerApp.User;
6 3811845f Alex Konig
using System;
7
using System.Collections.Generic;
8 7a998d66 Eliška Mourycová
using System.IO;
9 4a417b8b Eliška Mourycová
using System.Threading;
10 3811845f Alex Konig
11
namespace ServerApp
12
{
13 7a998d66 Eliška Mourycová
14
	class Config // TBD where this should go
15
	{
16
		public string DataWebsite { get; set; }
17
		public string DownloadedFilesNaming { get; set; }
18
		public string DataRootDir { get; set; }
19
		public string Port { get; set; }
20
	}
21
22 4a417b8b Eliška Mourycová
    public class Program
23 3811845f Alex Konig
    {
24 7a998d66 Eliška Mourycová
25 4a417b8b Eliška Mourycová
		public static void NotifyUserMessage(string message)
26
		{
27
			Console.WriteLine("Received user message: " + message);
28
		}
29 7a998d66 Eliška Mourycová
30 3811845f Alex Konig
        static void Main(string[] args)
31
        {
32
33 c9eed50c A-Konig
			JsonParser p = new JsonParser(null);
34
			p.ParsePrediction();
35
36
			/*
37
38 3aba3c34 Eliška Mourycová
			Config config = FillConfigInfo(args);
39
			if (config == null)
40
			{
41
				Console.ReadLine();
42
				return;
43
			}
44 7a998d66 Eliška Mourycová
45 3aba3c34 Eliška Mourycová
			//create a thread for commands accepting:
46
			Thread inputThread = new Thread(CommandsAcceptor.AcceptCommand);
47
			inputThread.Start();
48 4a417b8b Eliška Mourycová
49 7a998d66 Eliška Mourycová
50
51
			//DataParser p = new DataParser("data/");
52
			//p.Parse();
53
54
55 3aba3c34 Eliška Mourycová
			//test scenario -data download:
56
			DataDownloader dd = new DataDownloader(config.DataRootDir, config.DataWebsite, config.DownloadedFilesNaming);
57
			dd.OverwriteExisting = false;
58
			List<string> savedFiles = new List<string>();
59
			savedFiles.AddRange(dd.DownloadData(DataType.JIS, DataFormat.CSV, new Date(1, 2019), new Date(12, 2020)));
60
			savedFiles.AddRange(dd.DownloadData(DataType.STROJE, DataFormat.CSV, new Date(1, 2017), new Date(12, 2020)));
61
			savedFiles.AddRange(dd.DownloadData(DataType.POCASI, DataFormat.CSV, new Date(1, 2017), new Date(12, 2020)));
62 085453be Eliška Mourycová
63
64
65 3aba3c34 Eliška Mourycová
			Console.WriteLine("Saved files: ");
66
			foreach (string s in savedFiles)
67
			{
68
				Console.WriteLine(s);
69
			}
70 d2d1c86a Eliška Mourycová
71 3aba3c34 Eliška Mourycová
			Console.WriteLine("subdirectories: ");
72
			foreach (KeyValuePair<DataType, string> kvp in dd.DataSubDirectories)
73
			{
74
				Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
75
			}
76 36c0667f Eliška Mourycová
77 3aba3c34 Eliška Mourycová
			List<string> retrievedData = dd.GetData(dd.DataSubDirectories[DataType.JIS], new Date(10, 2019), new Date(12, 2020));
78
			Console.WriteLine("Retrieved data: ");
79
			foreach (string s in retrievedData)
80
			{
81
				Console.WriteLine(s);
82
			}
83 c9eed50c A-Konig
			*/
84 36c0667f Eliška Mourycová
85 7a998d66 Eliška Mourycová
			// test - connection:
86 3aba3c34 Eliška Mourycová
			//ConnectionListener cl = new ConnectionListener(int.Parse(args[0])/*8000*//*int.Parse(config.Port)*/);
87
			//cl.StartListening();
88 7a998d66 Eliška Mourycová
89 3dc0ae76 A-Konig
			Console.ReadLine();
90 3811845f Alex Konig
        }
91 7a998d66 Eliška Mourycová
92
93
        private static Config FillConfigInfo(string[] args)
94
		{
95
96
			Config extractedConfigInfo = new Config();
97
98
			Console.WriteLine(Directory.GetCurrentDirectory());
99
			
100
			if (args.Length != 1)
101
				Console.WriteLine("Wrong usage of parameters, pass the path to a config file."); // todo better explanation?
102
103
			string fullPathConfig = Path.GetFullPath(args[0]);
104
			string[] lines = null;
105
			try {
106
				lines = File.ReadAllLines(fullPathConfig);
107
			}
108
			catch(Exception ex)
109
			{
110
				Console.WriteLine("Could not open " + fullPathConfig);
111
				return null;
112
			}
113
			
114
			for (var i = 0; i < lines.Length; i += 1)
115
			{
116
				string line = lines[i];
117
				Console.WriteLine(line);
118
				if (line.Length == 0 || line == null || line.StartsWith("#"))
119
					continue;
120
121
				switch (line)
122
				{
123
					case "!site!":
124
						extractedConfigInfo.DataWebsite = lines[++i].Trim();
125
						break;
126
					case "!naming_convention!":
127
						extractedConfigInfo.DownloadedFilesNaming = lines[++i].Trim();
128
						break;
129
					case "!data_root_dir!":
130
						string dirWithConfig = Path.GetDirectoryName(fullPathConfig);
131
						string rootPath = dirWithConfig + Path.DirectorySeparatorChar + lines[++i].Trim();
132
						extractedConfigInfo.DataRootDir = rootPath;
133
						
134
						break;
135
					case "!port!":
136
						extractedConfigInfo.Port = lines[++i].Trim();
137
						break;
138
					default: break;
139
				}
140
			}
141
142
			return extractedConfigInfo;
143
		}
144 3811845f Alex Konig
    }
145
}