-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainClass.cs
115 lines (98 loc) · 3.09 KB
/
MainClass.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
namespace AlpineChough.MultiplicationTableGenerator
{
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Threading;
using Xwt;
/// <summary>
/// The main class.
/// </summary>
public static class MainClass
{
#region Private Properties
/// <summary>
/// Gets the path of the application's temporary folder.
/// </summary>
/// <value>The temporary folder.</value>
private static string TemporaryFolder
{
get
{
return Path.Combine(Path.GetTempPath(), "AlpineChough.MultiplicationTableGenerator");
}
}
#endregion
#region Public Methods
/// <summary>
/// The entry point of the program, where the program control starts and ends.
/// </summary>
public static void Main()
{
Setup setup = new Setup();
if (!Directory.Exists(TemporaryFolder))
{
Directory.CreateDirectory(TemporaryFolder);
}
try
{
Application.Initialize();
using (MainWindow mainWindow = new MainWindow(setup))
{
mainWindow.ApplicationExitRequested += (object sender, EventArgs e) =>
{
Application.Exit();
};
mainWindow.GenerateWorksheetRequested += (object sender, EventArgs e) =>
{
CreatePdf(setup);
};
mainWindow.Show();
Application.Run();
}
}
finally
{
foreach (string file in Directory.GetFiles(TemporaryFolder))
{
try
{
File.Delete(file);
}
catch
{
}
}
try
{
Directory.Delete(TemporaryFolder);
}
catch
{
}
}
}
#endregion
#region Private Methods
/// <summary>
/// Creates the PDF document.
/// </summary>
/// <param name="setup">The setup.</param>
private static void CreatePdf(Setup setup)
{
setup.Path = Path.Combine(TemporaryFolder, "Worksheet_" + DateTime.Now.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture) + ".pdf");
setup.Identifier = Guid.NewGuid();
setup.Symbol = ".";
PdfCreator pdfCreator = new PdfCreator();
pdfCreator.Identifier = setup.Identifier;
pdfCreator.Multiplications = MultiplicationFactory.Create(setup);
pdfCreator.Symbol = setup.Symbol;
pdfCreator.Path = setup.Path;
pdfCreator.Write();
Process.Start(setup.Path);
}
#endregion
}
}