Projekt

Obecné

Profil

Stáhnout (4.5 KB) Statistiky
| Větev: | Tag: | Revize:
1
using ServerApp.Connection;
2
using ServerApp.Connection.XMLProtocolHandler;
3
using ServerApp.DataDownload;
4
using ServerApp.Parser.Parsers;
5
using ServerApp.Predictor;
6
using ServerApp.User;
7
using System;
8
using System.Collections.Generic;
9
using System.IO;
10
using System.Threading;
11

    
12
namespace ServerApp
13
{
14

    
15
	class Config // TBD where this should go
16
	{
17
		public string DataWebsite { get; set; }
18
		public string DownloadedFilesNaming { get; set; }
19
		public string DataRootDir { get; set; }
20
		public string Port { get; set; }
21
	}
22

    
23
    public class Program
24
    {
25

    
26
		public static void NotifyUserMessage(string message)
27
		{
28
			Console.WriteLine("Received user message: " + message);
29
		}
30

    
31
        static void Main(string[] args)
32
        {
33

    
34
			Config config = FillConfigInfo(args);
35
			if (config == null)
36
			{
37
				Console.ReadLine();
38
				return;
39
			}
40

    
41
			//create a thread for commands accepting:
42
			Thread inputThread = new Thread(CommandsAcceptor.AcceptCommand);
43
			inputThread.Start();
44

    
45

    
46

    
47
			//DataParser p = new DataParser("data/");
48
			//p.Parse();
49

    
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
			//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();
88
			#endregion
89

    
90
			#region XML_TEST
91
			//Response response = Response.Randomize();
92
			//var xml = XmlCommunication.Serialize(response);
93
			//Console.WriteLine(xml);
94
			//Response responseDeserialized = XmlCommunication.Deserialize(response, xml);
95

    
96
			//Console.WriteLine("------");
97

    
98

    
99
			//Request request = Request.Randomize();
100
			//xml = XmlCommunication.Serialize(request);
101
			//Console.WriteLine(xml);
102
			//Request requestDeserialized = XmlCommunication.Deserialize(request, xml);
103
			#endregion
104

    
105

    
106

    
107

    
108
			Console.ReadLine();
109
        }
110

    
111

    
112
        private static Config FillConfigInfo(string[] args)
113
		{
114

    
115
			Config extractedConfigInfo = new Config();
116

    
117
			Console.WriteLine(Directory.GetCurrentDirectory());
118
			
119
			if (args.Length != 1)
120
				Console.WriteLine("Wrong usage of parameters, pass the path to a config file."); // todo better explanation?
121

    
122
			string fullPathConfig = Path.GetFullPath(args[0]);
123
			string[] lines = null;
124
			try {
125
				lines = File.ReadAllLines(fullPathConfig);
126
			}
127
			catch(Exception ex)
128
			{
129
				Console.WriteLine("Could not open " + fullPathConfig);
130
				return null;
131
			}
132
			
133
			for (var i = 0; i < lines.Length; i += 1)
134
			{
135
				string line = lines[i];
136
				Console.WriteLine(line);
137
				if (line.Length == 0 || line == null || line.StartsWith("#"))
138
					continue;
139

    
140
				switch (line)
141
				{
142
					case "!site!":
143
						extractedConfigInfo.DataWebsite = lines[++i].Trim();
144
						break;
145
					case "!naming_convention!":
146
						extractedConfigInfo.DownloadedFilesNaming = lines[++i].Trim();
147
						break;
148
					case "!data_root_dir!":
149
						string dirWithConfig = Path.GetDirectoryName(fullPathConfig);
150
						string rootPath = dirWithConfig + Path.DirectorySeparatorChar + lines[++i].Trim();
151
						extractedConfigInfo.DataRootDir = rootPath;
152
						
153
						break;
154
					case "!port!":
155
						extractedConfigInfo.Port = lines[++i].Trim();
156
						break;
157
					default: break;
158
				}
159
			}
160

    
161
			return extractedConfigInfo;
162
		}
163
    }
164
}
(2-2/5)