-
Notifications
You must be signed in to change notification settings - Fork 0
/
EntryPoint.cs
executable file
·161 lines (150 loc) · 7.43 KB
/
EntryPoint.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension="log4net", Watch=true)]
namespace Talaran.Ldg {
public class EntryPoint {
private static readonly log4net.ILog log =
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public static void Main(string[] args) {
var options = new Options();
CommandLine.ICommandLineParser cmdParser =
new CommandLine.CommandLineParser(new CommandLine.CommandLineParserSettings(System.Console.Error));
if (cmdParser.ParseArguments(args, options)) {
string connectionString = string.Format("URI=file:{0}", options.Database);
#if (NET)
var connection = new System.Data.SQLite.SQLiteConnection(connectionString);
#else
var connection = new Mono.Data.Sqlite.SqliteConnection(connectionString);
#endif
connection.Open();
var command = connection.CreateCommand();
command.CommandText =
"CREATE TABLE IF NOT EXISTS at (id INTEGER PRIMARY KEY NOT NULL,name VARCHAR,surname VARCHAR,year INTEGER,gender CHAR,time VARCHAR)";
command.ExecuteNonQuery();
var repo = new AthleteRepository(command);
switch (options.Action) {
case Action.Module: {
// 10mm d=> 28pt
// 15mm => 42pt
//float marginLeft, float marginRight, float marginTop, float marginBottom
var document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 10, 10, 36, 36);
iTextSharp.text.pdf.PdfWriter.GetInstance(document,
new System.IO.FileStream("./module.pdf", System.IO.FileMode.Create));
document.Open();
var builder = new ModuleBuilder(document, options.YearEdition, 10);
for (int page = 0; page < 10; page++) {
builder.AddPage();
}
document.Close();
break;
}
case Action.Insert: {
System.Console.WriteLine("Drop all results?[y/N]?");
string yes = System.Console.ReadLine();
if (yes == "y") {
FileHelpers.FileHelperEngine<Athlete> engine = new FileHelpers.FileHelperEngine<Athlete>();
Athlete[] athletes = engine.ReadFile(options.Input);
repo.DeleteAll();
foreach (var a in athletes) {
System.Console.WriteLine(a.Name);
repo.Insert(a);
}
}
break;
}
case Action.CreateList:
case Action.CreateResult: {
string catFileName = GetCatFileName(options);
string reportFileName = GetReportFileName(options);
var document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 10, 10, 36, 36);
iTextSharp.text.pdf.PdfWriter.GetInstance(document,
new System.IO.FileStream(reportFileName, System.IO.FileMode.Create));
document.Open();
IBuilder builder = null;
if (options.Action == Action.CreateList) {
builder = new ListBuilder(document);
} else {
builder = new PdfBuilder(document);
}
Category[] cats = GetCategories(catFileName);
foreach (Category cat in cats) {
if (log.IsDebugEnabled) log.Debug("parse" + cat.Id);
builder.BeginReport(cat.Title, options.YearEdition);
var athletes = repo.Query(string.Format (cat.Sql, options.YearEdition));
foreach (Athlete athlete in athletes) {
builder.Add(athlete);
}
builder.EndReport();
}
document.Close();
break;
}
case Action.Interactive: {
Category[] cats = GetCategories(GetCatFileName(options));
var parser = new TimeParser();
foreach (Category cat in cats) {
System.Console.WriteLine("========{0}=========", cat.Id);
var athletes = repo.Query(string.Format (cat.Sql, options.YearEdition));
foreach (Athlete athlete in athletes) {
System.Console.Write("{0:00} {1}\t{2}({3}):", athlete.Id, athlete.Surname, athlete.Name, athlete.Gender);
string time = string.Empty;
string fmt = string.Empty;
do {
time = System.Console.ReadLine();
fmt = parser.Parse(time);
if (!string.IsNullOrEmpty(fmt) ) {
System.Console.WriteLine(fmt);
repo.UpdateTime(athlete.Id, fmt);
} else {
if (time != "s") {
System.Console.WriteLine("invalid..");
}
}
} while (string.IsNullOrEmpty(fmt) && time != "s");
}
}
break;
}
}
connection.Close();
}
}
private static Category[] GetCategories(string filename) {
FileHelpers.FileHelperEngine<Category> engineCat = new FileHelpers.FileHelperEngine<Category>();
return engineCat.ReadFile(filename);
}
private static string GetCatFileName(Options options) {
string catFileName = string.Empty;
switch (options.Action) {
case Action.Interactive:
case Action.CreateList: {
catFileName = "../../doc/list.csv";
break;
}
case Action.CreateResult: {
catFileName = "../../doc/cat.csv";
break;
}
default: {
throw new System.ArgumentException("invalid");
}
}
if (!string.IsNullOrEmpty(options.Categories)) {
catFileName = options.Categories;
}
if (log.IsDebugEnabled) log.Debug("use category: " + catFileName);
return catFileName;
}
private static string GetReportFileName(Options options) {
string reportFileName = string.Empty;
if (options.Action == Action.CreateList) {
reportFileName = string.Format("../../doc/list{0}.pdf", options.YearEdition);
} else {
reportFileName = string.Format("../../doc/class{0}.pdf", options.YearEdition);
}
if (!string.IsNullOrEmpty(options.Output)) {
reportFileName = options.Output;
}
if (log.IsDebugEnabled) log.Debug("report: " + reportFileName);
return reportFileName;
}
}
}