Projekt

Obecné

Profil

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

    
11
namespace ServerApp
12
{
13

    
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
    public class Program
23
    {
24

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

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

    
33
			JsonParser p = new JsonParser(null);
34
			p.ParsePrediction();
35

    
36
			/*
37

    
38
			Config config = FillConfigInfo(args);
39
			if (config == null)
40
			{
41
				Console.ReadLine();
42
				return;
43
			}
44

    
45
			//create a thread for commands accepting:
46
			Thread inputThread = new Thread(CommandsAcceptor.AcceptCommand);
47
			inputThread.Start();
48

    
49

    
50

    
51
			//DataParser p = new DataParser("data/");
52
			//p.Parse();
53

    
54

    
55
			//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

    
63

    
64

    
65
			Console.WriteLine("Saved files: ");
66
			foreach (string s in savedFiles)
67
			{
68
				Console.WriteLine(s);
69
			}
70

    
71
			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

    
77
			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
			*/
84

    
85
			// test - connection:
86
			//ConnectionListener cl = new ConnectionListener(int.Parse(args[0])/*8000*//*int.Parse(config.Port)*/);
87
			//cl.StartListening();
88

    
89
			Console.ReadLine();
90
        }
91

    
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
    }
145
}
(2-2/5)