-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainForm.cs
More file actions
107 lines (91 loc) · 3.29 KB
/
Copy pathMainForm.cs
File metadata and controls
107 lines (91 loc) · 3.29 KB
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
using System;
using System.IO;
using System.Windows.Forms;
using static CompileJava.Utils;
namespace CompileJava
{
public partial class MainForm : Form
{
private IniFile iniFileConfig;
public string ContainerName
{
get => txtContainerName.Text;
set => txtContainerName.Text = value;
}
public string DataPath
{
get => txtDataPath.Text;
set => txtDataPath.Text = value;
}
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
string filePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
filePath = filePath.Substring(0, filePath.LastIndexOf("\\")) + "\\Config.ini";
iniFileConfig = new IniFile(filePath, "Setting");
ContainerName = iniFileConfig.Read(nameof(ContainerName));
DataPath = iniFileConfig.Read(nameof(DataPath));
}
private void btnStartContainer_Click(object sender, EventArgs e)
{
mainTbLayoutPnl.Enabled = false;
if (btnStartContainer.Text == "Start")
{
btnStartContainer.Text = "Stop";
txtContainerName.ReadOnly = true;
txtResult.Text = Utils.ExecuteCommandSync("docker start " + ContainerName).Replace("\n", "");
}
else
{
btnStartContainer.Text = "Start";
txtContainerName.ReadOnly = false;
txtResult.Text = Utils.ExecuteCommandSync("docker stop " + ContainerName).Replace("\n", "");
}
iniFileConfig.Write(nameof(ContainerName), ContainerName);
mainTbLayoutPnl.Enabled = true;
}
private void btnCompile_Click(object sender, EventArgs e)
{
mainTbLayoutPnl.Enabled = false;
string javaClassName = Utils.GetClassName(txtJavaCode.Text);
if (!Directory.Exists(DataPath))
{
MessageBox.Show($"Can not find data directory '{DataPath}'", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
btnBrowseDataPath.PerformClick();
}
else
{
if (string.IsNullOrEmpty(javaClassName))
{
MessageBox.Show("Can not find class name in Java code", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtJavaCode.Focus();
}
else
{
Utils.SaveJavaCode(Path.Combine(DataPath, javaClassName + ".java"), txtJavaCode.Text);
Utils.GenerateBashFile(javaClassName, DataPath);
string command = $"docker exec {ContainerName} bash /data/compile.sh {@txtParameter.Text}";
txtResult.Text = Utils.ExecuteCommandSync(command);
}
}
iniFileConfig.Write(nameof(ContainerName), ContainerName);
iniFileConfig.Write(nameof(DataPath), DataPath);
mainTbLayoutPnl.Enabled = true;
}
private void btnBrowseDataPath_Click(object sender, EventArgs e)
{
using (var dialog = new FolderBrowserDialog())
{
dialog.SelectedPath = DataPath;
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK)
{
DataPath = dialog.SelectedPath;
}
}
}
}
}