-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmMain.cs
281 lines (245 loc) · 9.31 KB
/
frmMain.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Net.NetworkInformation;
namespace FTP_Downloader
{
public partial class frmMain : Form
{
private int iFile = 1;
private int iMax = 0;
private int iCount = 0;
private bool m_bExit = false;
public frmMain()
{
InitializeComponent();
}
private DateTime m_DTStart = DateTime.Now;
public ProcessInfo m_sProcessInfo;
private void frmMain_Load(object sender, EventArgs e)
{
try
{
if (!getLoadIniData())
{
Application.Exit();
}
else
{
this.Text = m_sProcessInfo.strCompanyName + " FTP Downlader [Ver:" + Assembly.GetExecutingAssembly().GetName().Version.ToString() +"]";
Lbl_Logo.Text = m_sProcessInfo.strCompanyName + "-" + m_sProcessInfo.strPlantName;
timer1.Enabled = true;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private bool getLoadIniData()
{
//실행 파일 폴더 가져오기
string strFileName = @".\FTP_Downloader.ini";
//FTP
m_sProcessInfo.strServer_ip=IniControl.ReadString(strFileName, "FTP_SERVER", "SERVER_IP", "10.10.32.1");
m_sProcessInfo.strUser_id=IniControl.ReadString(strFileName, "FTP_SERVER", "USER_ID", "mes");
m_sProcessInfo.strPassword=IniControl.ReadString(strFileName, "FTP_SERVER", "PASSWORD", "mes");
m_sProcessInfo.strDownloadPath=IniControl.ReadString(strFileName, "FTP_SERVER", "DOWNLOAD_PATH", "MES_Process");
m_sProcessInfo.strProgram_name=IniControl.ReadString(strFileName, "FTP_SERVER", "PROGRAM_NAME", "LF_FPROOF.exe");
m_sProcessInfo.strWorkDir = IniControl.ReadString(strFileName, "FTP_SERVER", "WORK_PATH", @".\");
m_sProcessInfo.strBackUpPath = IniControl.ReadString(strFileName, "FTP_SERVER", "BACKUP_PATH", @".\BACKUP");
m_sProcessInfo.bBackupHist = IniControl.ReadBool(strFileName, "FTP_SERVER", "BACKUP_HISTORY");
//GENERAL
m_sProcessInfo.strBizcd = IniControl.ReadString(strFileName, "GENERAL", "BIZCD", "1002");
m_sProcessInfo.strCorcd = IniControl.ReadString(strFileName, "GENERAL", "CORCD", "1000");
m_sProcessInfo.strCompanyName = IniControl.ReadString(strFileName, "GENERAL", "COMPANY_NAME", "HanilEH");
m_sProcessInfo.strPlantName = IniControl.ReadString(strFileName, "GENERAL", "PLANT_NAME", "Plant");
return true;
}
private void setDownLoad()
{
try
{
FtpHelper helper = new FtpHelper
(
m_sProcessInfo.strServer_ip + ";" + m_sProcessInfo.strUser_id + ";" + m_sProcessInfo.strPassword
, m_sProcessInfo.strDownloadPath
, m_sProcessInfo.strWorkDir
);
helper.BackUpPath = m_sProcessInfo.strBackUpPath;
List<FtpHelper.ftpinfo> listFullSub = helper.GetFullFilesList();
string strErr = "";
iMax = listFullSub.Count;
iCount = Convert.ToInt16(Math.Round(Convert.ToDouble(100 / listFullSub.Count)));
if (progressBar1.InvokeRequired)
{
object obj = new object();
MethodInvoker del = delegate { setProgressBarSet(); };
this.Invoke(del);
}
else
{
progressBar1.Maximum = iCount * iMax;
}
foreach (FtpHelper.ftpinfo name in listFullSub)
{
if (label3.InvokeRequired)
{
object obj = new object();
MethodInvoker del = delegate { setFileNameSet(name.filename); };
this.Invoke(del);
}
else
{
label3.Text = name.filename;
}
if (progressBar1.InvokeRequired)
{
object obj = new object();
MethodInvoker del = delegate { setProgressBarValue(); };
this.Invoke(del);
}
else
{
setProgressBarValue();
}
if (label2.InvokeRequired)
{
object obj = new object();
MethodInvoker del = delegate { setFileView(); };
this.Invoke(del);
}
else
{
label2.Text = iFile + "/" + iMax;
}
helper.FileDownLoad(name, ref strErr);
iFile++;
}
if (!m_bExit)
{
Process pros = new Process();
string sPath = Application.StartupPath + "\\" + m_sProcessInfo.strProgram_name;
pros.StartInfo.CreateNoWindow = true;
pros.StartInfo.Arguments = GetArgstr();
pros.StartInfo.FileName = sPath;
pros.Start();
}
Application.Exit(new CancelEventArgs(false));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private string GetArgstr()
{
string[] args = Environment.GetCommandLineArgs();
string argSTR = "";
if (args.Length >= 2)
{
for (int i = 0; i < args.Length; i++)
{
if (i > 0)
{
argSTR += args[i];
if (i < args.Length - 1)
{
argSTR += " ";
}
}
}
}
return argSTR;
}
private void setFileNameSet(string name)
{
label3.Text = name;
}
private void setProgressBarValue()
{
progressBar1.Value += iCount;
}
private void setProgressBarSet()
{
progressBar1.Maximum = iCount * iMax;
}
private void setFileView()
{
label2.Text = iFile + "/" + iMax;
}
private void setStart()
{
System.Threading.Thread th = new System.Threading.Thread(new System.Threading.ThreadStart(setDownLoad));
th.Start();
}
private void button1_Click(object sender, EventArgs e)
{
m_bExit = true;
Application.Exit();
}
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
TimeSpan span = DateTime.Now - m_DTStart;
if (PingTest(m_sProcessInfo.strServer_ip))
{
Lbl_Network.BackColor = Color.Lime;
Lbl_Network.Text = "Network-OK";
setStart();
return;
}
else
{
Lbl_Network.BackColor = Color.Red;
Lbl_Network.Text = "Network-NG";
}
if (span.TotalSeconds > 30)
{
this.Hide();
if (MessageBox.Show("Server Connection is waiting..\nDo you want to keep trying?", "Question", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
{
this.Show();
m_DTStart = DateTime.Now;
}
else
{
Process pros = new Process();
string sPath = Application.StartupPath + "\\" + m_sProcessInfo.strProgram_name;
if (String.IsNullOrEmpty(m_sProcessInfo.strProgram_name) == false)
{
pros.StartInfo.CreateNoWindow = true;
pros.StartInfo.FileName = sPath;
pros.StartInfo.Arguments = GetArgstr();
pros.Start();
}
Application.Exit();
}
}
timer1.Enabled = true;
}
private bool PingTest(string serverIP)
{
bool pingable = false;
Ping pinger = new Ping();
try
{
PingReply reply = pinger.Send(serverIP);
pingable = reply.Status == IPStatus.Success;
}
catch (PingException)
{
// Discard PingExceptions and return false;
}
return pingable;
}
}
}