Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 34bf7aa2

Přidáno uživatelem Eliška Mourycová před téměř 4 roky(ů)

Refs #8620, #8619. Refactor + testing.

Zobrazit rozdíly:

Server/ServerApp/DataDownload/DataDownloader.cs
1
using System;
1
//
2
// Author: Eliska Mourycova
3
//
4

  
5
using System;
2 6
using System.Collections.Generic;
3 7
using System.IO;
4 8
using System.IO.Compression;
5
using System.Linq;
6 9
using System.Net;
7
using System.Text;
8
using System.Text.RegularExpressions;
9
using System.Threading.Tasks;
10
using static System.Net.Mime.MediaTypeNames;
11 10

  
12 11
namespace DataDownload
13 12
{
13
	/// <summary>
14
	/// Enum representing all of the available data types (not all will be used in this project)
15
	/// They are in Czech for easier handling file names.
16
	/// TBD: They might be translated to English later.
17
	/// </summary>
14 18
	public enum DataType
15 19
	{
16 20
		POCASI, ENERGO, STROJE, EMAIL, OBSAZENI_MISTNOSTI, JIS, KOLOBEZKY, WIFI
17 21
	}
22

  
23
	/// <summary>
24
	/// Represent all available data formats.
25
	/// </summary>
18 26
	public enum DataFormat
19 27
	{
20 28
		XML, JSON, CSV
21 29
	}
22 30

  
31
	/// <summary>
32
	/// This class takes care of downloading of data. Download happens from http://openstore.zcu.cz/.
33
	/// </summary>
23 34
	public class DataDownloader
24 35
	{
36
		/// <summary>
37
		/// The root directory containing all downloaded data
38
		/// </summary>
25 39
		public string DataDirectory { get; }
40

  
41
		/// <summary>
42
		/// Flag stating whether files which already exist should be overwritten when downloaded again
43
		/// </summary>
26 44
		public bool OverwriteExisting { get; set; }
27 45

  
46
		// the main site where the data can be downloaded from
28 47
		private string site;
48

  
49
		// the substring at the start of every file name
29 50
		private string dataStr;
51

  
52
		// WebClient instance used for the actual download
30 53
		private WebClient webClient;
54

  
55
		// a shortcut to writing Path.DirectorySeparatorChar
31 56
		private char sep = Path.DirectorySeparatorChar;
32 57

  
33 58
		public DataDownloader()
34 59
		{
60
			// initialize all needed variables:
61

  
35 62
			Console.WriteLine(Directory.GetCurrentDirectory());
36 63
			site = "http://openstore.zcu.cz/";
37 64
			dataStr = "OD_ZCU_";
......
42 69
			webClient = new WebClient();
43 70
		}
44 71

  
72
		/// <summary>
73
		/// Downloads a specific archive.
74
		/// </summary>
75
		/// <param name="type">The type of data</param>
76
		/// <param name="format">The format of the data</param>
77
		/// <param name="year">The year</param>
78
		/// <param name="month">The month</param>
79
		/// <returns>A list of all extracted file names (should be only one)</returns>
45 80
		private List<string> DownloadData(DataType type, DataFormat format, int year, int month)
46 81
		{
47 82
			// the list of all files potentially relevant to the caller

Také k dispozici: Unified diff