-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmMain.cs
4666 lines (3939 loc) · 180 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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.IO.Compression;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Collections.Specialized;
using System.Web;
using System.Timers;
//using System.IO.Compression;
using System.Diagnostics;
//using System.Linq;
using Renci.SshNet;
using IqaController.entity;
using IqaController.service;
/* Filesystemwatcher
* https://msdn.microsoft.com/ko-kr/library/system.io.filesystemwatcher(v=vs.110).aspx
*
* rest APi Call example
* https://stackoverflow.com/questions/9620278/how-do-i-make-calls-to-a-rest-api-using-c
*
* // 오라클 클라이언트 접속
* http://kin33.tistory.com/60
*
* //Visual studio 자주쓰는 팁
* https://msdn.microsoft.com/ko-kr/library/dn600331.aspx
*
* //circle loading bar
* https://github.com/falahati/CircularProgressBar
* https://www.youtube.com/watch?v=o7MGaf8YW6s
* */
namespace IqaController
{
public partial class frmMain : Form
{
private Queue<FileProcess> m_QueueZipfileParsing = new Queue<FileProcess>(); //시작 ~ 알집해제까지
private Queue<FileProcess> m_QueueZipfileParsing_2 = new Queue<FileProcess>(); //컨버터 실행 ~ FTP 전송 이후까지(컨버터 처리가 오래걸려서 작업큐 나눈다)
private Dictionary<string, FileProcess> m_dicFileProcess = new Dictionary<string, FileProcess>(); //
private Dictionary<string, FileProcess> m_dicFileProcessErr = new Dictionary<string, FileProcess>(); //Error 파일 따로 관리(로딩시 디렉토리에서도 읽어와야함)
private FileSystemWatcher m_zipFileWatcher = null;
private string m_ftpId = "14";
private Boolean m_formClose = false;
private Boolean m_bServiceOnOffButton = false; //서비스 On Off 버튼 토글
private Boolean m_ServiceOnIng = false; //서비스 처리 프로세스 진행중 여부 (true:진행중 , false:완료)
private System.Timers.Timer timer = new System.Timers.Timer();
private Dictionary<string, ControllerServerEntity> m_dicFtpInfo = new Dictionary<string, ControllerServerEntity>();
private List<ControllerServerEntity> m_lstServer = null; //환경설정 수집서버
private List<ControllerFileKeepEntity> m_lstFile = null; //환경설정 파일 보관주기
private List<ControllerEnvEntity> m_lstEnv = new List<ControllerEnvEntity>();
private int m_eventOrifileLoopCnt = 0;
private Boolean m_debug = true;
private string m_checkedkDay = ""; //일단위 체크날짜
private const string m_version = "1.0.7.7";
/* version Log
* 1.0.1 : 2018-12-11 : 파일명 규칙 사업자는 제외한다
* 1.0.2 : 2018-12-12 : 파일명 규칙 서비스타입 추가처리
* 1.0.3 : 2018-12-13 : 모두 중복 drm일시 처리 보완처리(중복 drml삭제해도 나머지 파일이 있어서 파일사이즈로 기존 처리하는부분 보완처리함)
* 1.0.4 : 2018-12-13 : 화면 및 zipfile key값 orgZipfileName -> zipfileName로 변경 FTP04같은경우 분단위로 같은 파일을 보내서 꼬일경우 발생 ㅠㅠ
* 1.0.5 : 2018-12-17 : DB 컬럼 UPLOAD_DATE MAIN 과 DETAIL 동일하게 처리요청
* 1.0.6 : 2018-12-21 : 컨버터 비정상에 인한 파일 복사시 문제 버그 수정
* 1.0.7 : 2018-12-26 : 취소기능 추가 - 서버 작업 완료되면 배포예정
2018-12-28 : zip 파일 Access Denied 발생(파일 자체를 제어할수 없음) 따라 해당 로그테이블에 이력 남기기 기능 추가 이전버전은 예외발생함에 따라 멈춤 발생
2019-01-02 : 비정상 종료 처리에 따른 수동 처리 자동화 기능 추가(DB 삭제후 해당 Zip파일 찾아서(backup , FTP루트폴더,WORK 폴더) FTP 루트 폴더로 옮기기 및 DB처리)
2019-01-03 : Event DRM 정보 처리시 그시점에 가져오는 방식으로 변경처리(기존은 컨트롤로 로딩시 한번 가져온다.)
* 1.0.7.1 : : 비정상 종료 체크 안되는 버그 수정
* 1.0.7.2 : 2019-01-17 : 비정상 종료 Zip파일명으로 찾기 기능 추가처리
* 1.0.7.3 : 2019-01-17 : 비정상 종료 컨버터 에러처리 기능 보이게 추가 처리
* 1.0.7.4 : 2019-01-18 : 작업완료 저장시 DB오류 오류값 로그에 남긴다. (iqaService.updateZipFileAllInfo)
* 1.0.7.5 : 2019-01-19 : 강제로 웹서비스 IQA 바라볼수있는 기능 추가(배포시 필요)
* 1.0.7.6 : 2019-01-22 : zip파일명 검사 single quote , double quote 추가 오류처리(서버에서 오류난다고 함)
* 1.0.7.7 : 2019-04-09 : 이노 컨버터 Windows 시스템 파일 경로 문자열 길이 문제 건 에러 처리 방안 추가
D:\INNOWHB\Check_List\file path check_날짜.txt 파일을 파일명 변경(file path check_날짜_시분초.txt)하여 이동 처리
-> D:\00_file_path_check\해당 파일 처리 진행 pass 후 다음 파일 진행
ZipfileBackupProc : 추후 안정화 되면 BACKUP 처리 젤 마지막에 처리하자
*/
delegate void TimerEventFiredDelegate();
public frmMain()
{
InitializeComponent();
}
private void StartTmrServiceBtn()
{
//tmrServiceBtn.Change(0, 2000);
if (timer != null)
{
if (!timer.Enabled)
{
timer.Enabled = true;
timer.Start();
}
}
}
private void EndTimerServiceBtn()
{
//tmrServiceBtn.Change(Timeout.Infinite, Timeout.Infinite);
if (timer != null)
{
timer.Enabled = false;
timer.Stop();
}
}
private void KillConvertor(Boolean bSti)
{
string findProcessName = "";
if (bSti)
{
findProcessName = "QMS Export.exe";
}
else
{
findProcessName = "QMS-W";
}
Process[] allProc = Process.GetProcesses();
foreach (Process p in allProc)
{
if (p.ProcessName.IndexOf(findProcessName) >= 0)
{
p.Kill();
break;
}
}
}
private void TestProc()
{
/*
runServyceType2RunConvertor("CSFB", @"D:\FTP16\WORK\본사_도로2조_CSFB_SKT_AUTO_청주시서원십_20180829", false);
Thread.Sleep(2000);
runServyceType2RunConvertor("LTED", @"D:\FTP16\WORK\본사_도로501조_LTED_SKT_AUTO_테스트_20180602", false);
Thread.Sleep(2000);
runServyceType2RunConvertor("LTED", @"D:\FTP16\WORK\인천본부_인빌딩46조_LTED_SKT_AUTO_소래포구 종합어시장_20180827", false);
//FileProcess row = GetFilePath2FileProcessInfo(@"D:\FTP16\WORK\충북본부_도로49조_HSDPA__KT_청주대2일차_20181210.zip");
//FileProcess row = GetFilePath2FileProcessInfo(@"D:\FTP16\WORK\경남본부_도로41조_HDV_LGU_부산지하철2호선aaa_20181210.zip");
string extractDir = @"D:\FTP14\test2";
string zipFilefullPath = @"D:\FTP14\7ziptest.zip";
SevenZipCall("x -o\"" + extractDir + "\" -r -y \"" + zipFilefullPath + "\"");
return;
*/
//FileProcess row = GetFilePath2FileProcessInfo(@"D:\FTP16\WORK\강북본부_도로47조_LTEV_SKT_AUTO_동대문구청 보건소_20181214.zip");
//ZipFileNamingParsing(row);
/*
FileInfo file = new FileInfo(@"D:\FTP16\WORK\본사_도로2조_LTED_SKT_L5_고양시 일산동구_20181115_20181207134958.zip");
if (file.Exists)
{
MessageBox.Show("존재");
}
else
{
MessageBox.Show("미존재");
}
*/
//FileProcess row = GetFilePath2FileProcessInfo(@"D:\FTP16\WORK\강북본부_도로407조_LTEV_SKT_AUTO_롯데_20181205.zip");
//DeleteWorkZipFile(@"D:\FTP16\WORK\강북본부_도로407조_LTEV_SKT_AUTO_롯데_20181205");
//Boolean bAccessible = util.Wait2FileAccessible(@"D:\FTP16\WORK\본사_도로2조_LTED_SKT_L5_고양시 일산동구_20181115_20181207134958.zip", 9999);
/*
string zipFileName = "강북본부_도로407조_LTEV_SKT_AUTO_롯데_20181201_20181205132239.zip";
string[] arFileInfo = zipFileName.Split('_');
var fileWorkDate = arFileInfo[arFileInfo.Length - 1];
fileWorkDate = Path.GetFileNameWithoutExtension(fileWorkDate);
fileWorkDate = fileWorkDate = fileWorkDate.Substring(0, 8);
DateTime dtFileWirkDate = new DateTime();
Boolean isDate = util.ParseDate(fileWorkDate, ref dtFileWirkDate);
if (!isDate)
{
Console.WriteLine("1");
}
else
{
Console.WriteLine("0");
}
*/
var zipFileName = "본사_도로2조_LTED_SKT_L5_고양시 일산동구_20181115_20181207134958.zip";
//string zipFileName = $@"<div>""{title}""</div>"
if (zipFileName.IndexOf("\"") >= 0)
{
Console.WriteLine("1");
}
}
private void frmMain_Load(object sender, EventArgs e)
{
this.Text = String.Format("IQA 컨트롤러 ver : [{0}]", m_version); ;
//최소 윈도우 사이즈
this.MinimumSize = new Size(800, 600);
iqaService.mainForm = this;
//TestProc();
//return;
#if DEBUG
m_debug = true;
#else
m_debug = false;
#endif
if (!DBContollerSetInfo(false))
{
MessageBox.Show("컨트롤러 실행에 필요한 데이타를 가져오는데 실패하였습니다.\n관리자에게 문의하십시요.");
this.Close();
Application.Exit();
return;
}
SetControl();
UpdateRowEnv();
//findDirErrorInfo(Define.con_DIR_ZIPDUP); zip파일 중복체크 안하기로 함
FindDirErrorInfo(Define.con_DIR_NAMING);
FindDirErrorInfo(Define.con_DIR_UPLOAD);
FindDirErrorInfo(Define.con_DIR_CONVERT);
CreateFolderWatching();
m_bServiceOnOffButton = false;
ServiceOnOff();
}
/* 작업중 비정상 종료된 Zip파일 리스트를 가져온다.
*/
private void GetAbnormalZipfileList2Grid()
{
string startDate = dtpStartDate.Value.Date.ToString("yyyyMMdd");
string endDate = dtpEndDate.Value.Date.ToString("yyyyMMdd");
string procServer = GetFtpName(m_ftpId);
dgvAbnormalZipfile.Rows.Clear();
List<ZipfileInfoEntity> abNormalZipfiles = iqaService.getAbnormalZipfileList(startDate, endDate, procServer);
if (abNormalZipfiles == null || abNormalZipfiles.Count <=0)
{
return;
}
string fullPath = "";
string findZipfileNm = "";
string defaultPath = GetDefaultFtpPath();
string backupDir = defaultPath + "\\" + Define.con_DIR_BACK;
string wokrDir = defaultPath + "\\" + Define.con_DIR_WORK;
Boolean bFine = false;
string findDirFlag = "";
foreach(ZipfileInfoEntity zipfileInfo in abNormalZipfiles)
{
//기본 FTP 폴더에서 찾는다
findZipfileNm = GetSystemZipfileNm2OrgFIleName(zipfileInfo.Zipfile_nm);
bFine = util.FindDir2File(defaultPath, findZipfileNm, ref fullPath);
if (!bFine)
{
//BACKUP 폴더에서 찾는다.
findZipfileNm = zipfileInfo.Zipfile_nm;
bFine = util.FindDir2File(backupDir, findZipfileNm, ref fullPath);
if (bFine)
{
findDirFlag = "backup";
}
else
{
//WORK 폴더에서 찾는다.
bFine = util.FindDir2File(wokrDir, findZipfileNm, ref fullPath);
if (bFine)
{
findDirFlag = "work";
}
}
}
else
{
findDirFlag = "root";
}
dgvAbnormalZipfile.RowCount = dgvAbnormalZipfile.RowCount + 1;
int nRow = dgvAbnormalZipfile.RowCount - 1;
DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)dgvAbnormalZipfile.Rows[nRow].Cells[0];
chk.Value = true;
dgvAbnormalZipfile.Rows[nRow].Cells[1].Value = zipfileInfo.Zipfile_nm;
dgvAbnormalZipfile.Rows[nRow].Cells[2].Value = zipfileInfo.Cur_state;
if (bFine)
{
dgvAbnormalZipfile.Rows[nRow].Cells[3].Value = "발견";
dgvAbnormalZipfile.Rows[nRow].Cells[4].Value = fullPath;
dgvAbnormalZipfile.Rows[nRow].Cells[5].Value = findDirFlag;
}
else
{
dgvAbnormalZipfile.Rows[nRow].Cells[3].Value = "미발견";
dgvAbnormalZipfile.Rows[nRow].Cells[4].Value = "";
dgvAbnormalZipfile.Rows[nRow].Cells[5].Value = "";
}
}
//전체 선택 해제시 체크 선택되있을시 안그려지는 갱신 안되는 문제 때문(화면상에만)
if (dgvAbnormalZipfile.Rows.Count > 0)
{
dgvAbnormalZipfile.CurrentCell = dgvAbnormalZipfile.Rows[0].Cells[1];
}
}
/* 이벤트 DRM 파일 요청건 FTP 전송 및 DB 처리
*/
private void EventOrifileSendProc()
{
//그떄그떄 가져온다.
CommonResultEntity resServer = iqaService.getControllerServer(true);
if (resServer.Flag == Define.con_FAIL)
{
util.Log("ERR:eventOrifileSendProc", "이벤트 DRM FTP 서버 정보 가져오기 실패");
return;
}
m_lstServer = (List<ControllerServerEntity>)resServer.Result;
//ControllerServerEntity freeFtpServer = m_dicFtpInfo[Define.con_FTP_DRM];
ControllerServerEntity freeFtpServer = m_lstServer[0];
if (freeFtpServer == null)
{
util.LogDrm("ERR:eventOrifileSendProc", "이벤트 DRM FTP 서버 정보 가져오기 실패");
return;
}
//util.Log("INFO", "Drm 요청파일 가져오기");
string procServer = GetFtpName(m_ftpId);
CommonResultEntity res = iqaService.getEventOrifileList(procServer);
if (res.Flag == Define.con_FAIL)
{
util.LogDrm("ERR", "Drm 요청파일 가져오기 실패");
return;
}
List<EventOriFileEntity> sendFileInfos = (List<EventOriFileEntity>)res.Result;
if (sendFileInfos == null || sendFileInfos.Count <=0)
{
util.LogDrm("INFO", "Drm 요청건수 0");
return;
}
util.LogDrm("INFO", "EVENT DRM 요청 발생 처리 시작 ##################################START");
//sendFileInfos 발견여부도 추후 DB에 남기자
EventOriFileProcResult eventOriFileResult = new EventOriFileProcResult();
eventOriFileResult.ProcServer = procServer;
eventOriFileResult.FtpServer = freeFtpServer.Name;
//BACKUP 폴도에서 해당 ZIP파일 찾아서 FTP로 전송한다.
string findZipFileName = sendFileInfos[0].Zipfile_nm;
eventOriFileResult.ZipfileNm = findZipFileName;
updateRowEventDrmFileSend(eventOriFileResult);
//추후 테스트후 적용하자
//iqaService.updateEventOrifileSendResult(eventOriFileResult, sendFileInfos);
string defaultPath = GetDefaultFtpPath();
string backupDir = defaultPath + "\\" + Define.con_DIR_BACK;
string[] filePaths = Directory.GetFiles(backupDir);
string orgZipFilePath = "";
int nfindPos = 0;
Boolean bFindZipFile = false;
eventOriFileResult.CurState = Define.con_EVENT_DRM_STATE_DRM;
foreach (string filePath in filePaths)
{
nfindPos = filePath.LastIndexOf('_');
if (nfindPos >= 0)
{
//orgZipFilePath = filePath.Substring(0, nfindPos); //DB에 Zip파일 원본이름 줄경우
orgZipFilePath = filePath; //DB에 해당날짜까지 시스템날짜까지 들어있는 ZIPfileName 정보를 줄경우
if (Path.GetFileNameWithoutExtension(findZipFileName) == Path.GetFileNameWithoutExtension(orgZipFilePath))
{
util.LogDrm("INFO", "ZIP파일 발견 및 복사: "+ Path.GetFileNameWithoutExtension(findZipFileName));
//폴더이동후 필요한 drm파일만 남기고 삭제한후 다시 압축후 전송한다.
if (!util.FileSave("copy", filePath, defaultPath + '\\' + Define.con_DIR_EVENT_ORIFILE+'\\'+ findZipFileName))
{
return;
}
string zipPath = defaultPath + "\\" + Define.con_DIR_EVENT_ORIFILE +"\\"+ findZipFileName;
string extractPath = defaultPath + "\\" + Define.con_DIR_EVENT_ORIFILE + "\\" + Path.GetFileNameWithoutExtension(findZipFileName);
string eventZipFileName = getEventCompressName();
try
{
//ZipFile.ExtractToDirectory(zipPath, extractPath); //압축 해제
string extractDir = extractPath + @"\";
SevenZipCall("x -o\"" + extractDir + "\" -r -y \"" + zipPath + "\"");
string[] extractFilePaths = Directory.GetFiles(extractPath);
string sendFilePath = defaultPath + @"\" + Define.con_DIR_EVENT_ORIFILE + @"\" + eventZipFileName;
//FTP 전송 요청한 파일만 담는 작업 폴더 만든다.
DirectoryInfo diChk = new DirectoryInfo(sendFilePath);
if (diChk.Exists == false)
{
diChk.Create();
}
Boolean bMatch = false;
int nOriFileCnt = 0;
foreach (string extractFilePath in extractFilePaths)
{
//string extractFileName = Path.GetFileName(extractFilePath);
string extractFileName = Path.GetFileNameWithoutExtension(extractFilePath);
string extenstion = Path.GetExtension(extractFilePath);
if (!(extenstion.ToUpper() == ".DRM" || extenstion.ToUpper() == ".DRMMP" || extenstion.ToUpper() == ".DML"))
{
continue;
}
//string remQmsFileNm = "";
foreach (EventOriFileEntity sendFileInfo in sendFileInfos)
{
//Event 요청 파일명과 같을경우 작업 폴더에 복사한다.
//확장자 drm , drmmp 같이 복사한다
string sendFileName = Path.GetFileNameWithoutExtension(sendFileInfo.Qmsfile_nm);
if (sendFileName == extractFileName)
{
util.LogDrm("INFO", "DRM 파일 발견 및 복사: " + sendFileName);
bFindZipFile = true;
bMatch = true;
//DRM , DRMMP 같은 이름 유지하기위해 실제 DRMMP는 DB쪽 요청정보에는 없기떄문에 같은이름으로 파일을 관리해야한다
if (sendFileInfo.Qmsfile_nmChg.Length <= 0)
{
//if (remQmsFileNm != sendFileInfo.Qmsfile_nmChg)
//{
nOriFileCnt++;
// remQmsFileNm = sendFileInfo.Qmsfile_nmChg;
//}
sendFileInfo.Qmsfile_nmChg = eventZipFileName + "_" + nOriFileCnt;
}
//util.FileSave("copy", extractFilePath, sendFilePath + "\\" + extractFileName + extenstion);
util.FileSave("copy", extractFilePath, sendFilePath + "\\" + sendFileInfo.Qmsfile_nmChg + extenstion);
util.LogDrm("INFO", "DRM 파일 발견 및 복사 완료: " + sendFileName);
sendFileInfo.FlagFind = "1";
}
}
}
if (!bMatch)
{
break;
}
//요청한 파일 압축한다. ㅠㅠ 실제 FTP서버에서 같은 닷넷프레임워크 버전인데 특정파일에 대해 ZipFIle 처리 안됨
//ZipFile.CreateFromDirectory(sendFilePath, defaultPath + "\\" + Define.con_DIR_EVENT_ORIFILE + "\\" + eventZipFileName + ".zip", CompressionLevel.Fastest, false, Encoding.Default);
util.LogDrm("INFO", "DRM 요청파일 압축");
string compressZipFile = defaultPath + "\\" + Define.con_DIR_EVENT_ORIFILE + "\\" + eventZipFileName + ".zip";
SevenZipCall("a \"" + compressZipFile + "\" \"" + sendFilePath + "\"" + @"\*"); //압축시 해당 파일만 압축하기위해 \* 을 추가함
eventOriFileResult.FlagUnzip = Define.con_SUCCESS;
}
catch (Exception ex)
{
eventOriFileResult.FlagUnzip = Define.con_FAIL;
eventOriFileResult.UnzipErrLog = ex.Message.ToString();
util.LogDrm("ERR", ex.Message.ToString());
}
if (eventOriFileResult.FlagUnzip == Define.con_SUCCESS)
{
eventOriFileResult.CurState = Define.con_EVENT_DRM_STATE_FTP;
updateRowEventDrmFileSend(eventOriFileResult);
//FTP로 전송한다.
//bool bSuccess = sendFtpEventOrifile(freeFtpServer, defaultPath + "\\" + Define.con_DIR_EVENT_ORIFILE + "\\" + eventZipFileName + ".zip");
util.LogDrm("INFO", "DRM파일요청 FTP 전송");
bool bSuccess = sendSftpEventOrifile(defaultPath + "\\" + Define.con_DIR_EVENT_ORIFILE + "\\" + eventZipFileName + ".zip", freeFtpServer);
if (bSuccess)
{
util.LogDrm("INFO", "DRM파일요청 FTP 전송 성공");
eventOriFileResult.FlagSendFtp = Define.con_SUCCESS;
eventOriFileResult.ChgCompressFileNm = eventZipFileName + ".zip";
}
else
{
util.LogDrm("ERR", "DRM파일요청 FTP 전송 실패");
eventOriFileResult.FlagSendFtp = Define.con_FAIL;
}
updateRowEventDrmFileSend(eventOriFileResult);
}
//작업파일 모두 삭제 한다.
util.AllDeleteInDirectory(defaultPath + "\\" + Define.con_DIR_EVENT_ORIFILE);
break;
}
}
}
eventOriFileResult.CurState = Define.con_EVENT_DRM_STATE_END;
if (bFindZipFile)
{
eventOriFileResult.IsDrmFind = "1";
}
else
{
eventOriFileResult.IsDrmFind = "0";
}
iqaService.updateEventOrifileSendResult(eventOriFileResult, sendFileInfos);
updateRowEventDrmFileSend(eventOriFileResult);
util.Log("INFO", "EVENT DRM 요청 발생 처리 완료 #####################################END");
}
private void compressTest()
{
// 참조 소스
// https://docs.microsoft.com/ko-kr/dotnet/api/system.io.compression.zipfile?view=netframework-4.7.2
try
{
//압축 하기
string startPath = @"D:\FTP14\TEST\본사_도로501조_LTED_SKT_AUTO_압축테스트_20180602";
string zipPath = @"D:\FTP14\TEST\test.zip";
ZipFile.CreateFromDirectory(startPath, zipPath ,CompressionLevel.Fastest,false,Encoding.Default);
/*압축해제 예제
string zipPath = @"D:\FTP14\TEST\본사_도로2조_CSFB_SKT_AUTO_청주시서원구_20180829.zip";
string extractPath = @"D:\FTP14\TEST\본사_도로2조_CSFB_SKT_AUTO_청주시서원구_20180829";
ZipFile.ExtractToDirectory(zipPath, extractPath);
*/
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
return;
//ZipFile.ExtractToDirectory(zipPath, extractPath);
}
/* 환경설정 파일 보관주기에 따른 삭제 처리
*
*/
private void FilePeriodChk2Proc()
{
string path = GetDefaultFtpPath();
if (!(m_lstFile != null && m_lstFile.Count > 0))
{
return;
}
string ftpName = GetFtpName(m_ftpId);
foreach (ControllerFileKeepEntity filePeriodInfo in m_lstFile)
{
string dirPath = filePeriodInfo.DirPath;
if (dirPath.Length <= 0)
{
continue;
}
//해당 FTP서버 속하면 삭제 처리한다.
if (dirPath.IndexOf(ftpName) <= 0)
{
continue;
}
if (!Directory.Exists(dirPath)){
continue;
}
//해당 디렉토리내 파일 삭제
string[] files = Directory.GetFiles(dirPath);
int period = Convert.ToInt16(filePeriodInfo.Period);
foreach (string file in files)
{
FileInfo fi = new FileInfo(file);
/*
string fileName = Path.GetFileName(fi.Name);
if (fileName == "인천본부_도로54조_HSDPA_SKT_AUTO_덕적도_20181109_20181107162054.zip")
{
Console.WriteLine("dd");
}
*/
DateTime dtDate = fi.LastWriteTime;
dtDate = dtDate.AddDays(period); //보관 기간
int nCompare = DateTime.Compare(dtDate, DateTime.Now);
if (nCompare < 0)
{
fi.Delete();
}
}
//해당 폴더내 서브 디렉토리 삭제 처리
string[] dirs = Directory.GetDirectories(dirPath);
foreach (string dir in dirs)
{
DirectoryInfo dirInfo = new DirectoryInfo(dir);
DateTime dtDate = dirInfo.LastWriteTime;
dtDate = dtDate.AddDays(period); //보관 기간
int nCompare = DateTime.Compare(dtDate, DateTime.Now);
if (nCompare < 0)
{
dirInfo.Delete(true);
}
}
}
}
/* 서비스 감시 버튼 깜빡깜빡 처리
*/
void serviceBtnBlinkProc()
{
if (m_bServiceOnOffButton)
{
if (btnService.BackColor == Color.Silver)
btnService.BackColor = Color.Red;
else
btnService.BackColor = Color.Silver;
}
else
{
if (!m_ServiceOnIng)
btnService.BackColor = Color.Silver;
}
}
void tmr_ServiceBtnBlink(object sender, ElapsedEventArgs e)
{
if (this.IsHandleCreated)
{
BeginInvoke(new TimerEventFiredDelegate(serviceBtnBlinkProc));
}
}
private void SetControlServiceBtnOnOff()
{
if (m_bServiceOnOffButton)
{
cboFtpServer.Enabled = false;
btnService.Text = "서비스 On 상태";
StartTmrServiceBtn();
}
else
{
cboFtpServer.Enabled = true;
if (m_ServiceOnIng)
{
btnService.Text = "서비스 Off 처리중...";
btnService.Enabled = false;
}
else
{
EndTimerServiceBtn();
btnService.Text = "서비스 Off 상태";
btnService.Enabled = true;
btnService.BackColor = Color.Silver;
}
}
}
/*
private void setControlServiceOnOff()
{
if (m_bServiceOnOffButton)
{
cboFtpServer.Enabled = false;
btnService.Text = "서비스 On 상태";
serviceOnMainProc();
}
else
{
cboFtpServer.Enabled = true;
if (m_ServiceOnIng)
{
btnService.Text = "서비스 Off 처리중...";
btnService.Enabled = false;
}
else
{
EndTimerServiceBtn();
btnService.Text = "서비스 Off 상태";
btnService.Enabled = true;
btnService.BackColor = Color.Silver;
}
}
}
*/
private void SetLog(FileProcess row, string flag , string message)
{
AddLogFile(row, flag, message);
this.Invoke(new Action(delegate ()
{
dgvProcessLog.RowCount = dgvProcessLog.RowCount + 1;
int nRow = dgvProcessLog.RowCount - 1;
dgvProcessLog.Rows[nRow].Cells[0].Value = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); ;
if (row != null)
{
dgvProcessLog.Rows[nRow].Cells[1].Value = row.MeasuBranch;
dgvProcessLog.Rows[nRow].Cells[2].Value = row.MeasuGroup;
dgvProcessLog.Rows[nRow].Cells[3].Value = row.ZipFileName;
//dgvProcessLog.Rows[nRow].Cells[Define.con_KEY_PROCESSLOG_COLIDX].Value = row.OrgZipFileName;
dgvProcessLog.Rows[nRow].Cells[Define.con_KEY_PROCESSLOG_COLIDX].Value = row.ZipFileName;
}
else
{
dgvProcessLog.Rows[nRow].Cells[3].Value = "Global";
}
dgvProcessLog.Rows[nRow].Cells[4].Value = message;
}));
//Console.WriteLine(message);
}
private void UpdateRowEnv()
{
m_lstEnv.Clear();
if (m_lstServer == null || m_lstServer.Count <= 0)
{
util.Log("ERR:DBContollerSetInfo", "기본설정정보 없음");
return;
}
foreach (ControllerServerEntity server in m_lstServer)
{
ControllerEnvEntity env = new ControllerEnvEntity();
env.Flag = "server";
env.Item = server.Name;
env.Info1 = "IP : " + server.Ip;
env.Info2 = "ID : " + server.Id;
env.Info3 = "PW : " + server.Password;
m_lstEnv.Add(env);
#if DEBUG
if (server.Name == "TEST_APP")
{
m_dicFtpInfo[Define.con_FTP_WAV] = server;
//m_dicFtpInfo[Define.con_FTP_DRM] = server;
m_dicFtpInfo[Define.con_FTP_QMS] = server;
}
#else
if (server.Name == "QMS3_WAV")
{
m_dicFtpInfo[Define.con_FTP_WAV] = server;
}
else if (server.Name == "QM3_DRM")
{
//m_dicFtpInfo[Define.con_FTP_DRM] = server; 처리시점에 가져오는방법으로 추가 요청
}
else if (server.Name == "APP02")
{
m_dicFtpInfo[Define.con_FTP_QMS] = server;
}
#endif
}
foreach (ControllerFileKeepEntity file in m_lstFile)
{
ControllerEnvEntity env = new ControllerEnvEntity();
env.Flag = "file";
env.Item = file.Item;
env.Info1 = "IP : " + file.DirPath;
env.Info2 = "ID : " + file.Period.ToString() + "일";
env.Info3 = "";
m_lstEnv.Add(env);
}
int nRow = 0;
this.Invoke(new Action(delegate ()
{
dgvEnv.Rows.Clear();
//dgvEnv.RowCount = 0;
foreach (ControllerEnvEntity env in m_lstEnv)
{
dgvEnv.RowCount = dgvEnv.RowCount + 1;
nRow = dgvEnv.RowCount - 1;
dgvEnv.Rows[nRow].Cells[1].Value = env.Item;
dgvEnv.Rows[nRow].Cells[2].Value = env.Info1;
dgvEnv.Rows[nRow].Cells[3].Value = env.Info2;
dgvEnv.Rows[nRow].Cells[4].Value = env.Info3;
}
}));
}
/* 디렉토리 탐색후 Error 파일정보를 가져온다.
*/
private void FindDirErrorInfo(string flagErr)
{
string defaultPath = GetDefaultFtpPath();
string[] dirs = Directory.GetDirectories(defaultPath + "\\" + flagErr);
string findExtention = "";
if (flagErr == Define.con_DIR_UPLOAD)
{
findExtention = "qms";
}
else
{
findExtention = "zip";
}
foreach (string dir in dirs)
{
string zipfileFullPath = "";
string[] files = Directory.GetFiles(dir, "*."+ findExtention);
string zipfileNm = Path.GetFileName(dir+".zip"); //즉 폴더이름에 확장자 zip을 붙인다 - 오류 발생시 zip파일 이름 유지하기 위해
if (files.Length > 0)
{
zipfileFullPath = Path.GetDirectoryName(files[0]);
//zipfileNm = Path.GetFileName(files[0]);
FileProcess row = new FileProcess();
row.ZipFileName = zipfileNm; //zipfile 명 즉 폴더 이름
row.OrgZipFileName = files[0]; //zip파일명 시스템 날짜 붙이기전 원래 이름
row.ProcessServer = GetFtpName(m_ftpId); //process서버 명
row.ZipfileFullPath = zipfileFullPath;
//파일명 규칙 오류
if (flagErr == Define.con_DIR_NAMING)
{
row.FileNameRule = Define.CON_MSG_ERROR;
}
else if (flagErr == Define.con_DIR_CONVERT)
{
row.ConversionFlag = Define.CON_MSG_ERROR;
}
else if (flagErr == Define.con_DIR_UPLOAD)
{
row.FtpSendFlag = Define.CON_MSG_COMPLETE;
row.FtpSuccessFlag = Define.con_FAIL;
string qmsFileNm = "";
//string qmsFileNmChg = "";
int nIdx = 0;
foreach(string filePath in files)
{
//FileInfo file = new FileInfo(filePath);
nIdx++;
qmsFileNm = Path.GetFileName(filePath);
ZipFileDetailEntity detail = new ZipFileDetailEntity();
detail.QmsfileNm = qmsFileNm;
detail.QmsfileNmChg = GetQmsNameChange(Convert.ToString(nIdx));
row.ZipfileDetailList.Add(detail); ;
}
}
else if (flagErr == Define.con_DIR_ZIPDUP)
{
row.ZipDupFlag = Define.CON_MSG_ERROR;
}
UpdateRowErrorFile(row);
}
}
}
//서버쪽 파일명 꺠지는 현상으로 qms파일 변경 처리 한다.
private string GetQmsNameChange(string seq)
{
DateTime curDate = DateTime.Now;
string qmsNmChg = GetFtpName(m_ftpId) + "_" + seq + "_" + curDate.ToString("yyyyMMddHHmmss.ffff") + ".qms";
return qmsNmChg;
}
private string getEventCompressName()
{
DateTime curDate = DateTime.Now;
string eventZipName = GetFtpName(m_ftpId) + "_" + "Event" + "_" + curDate.ToString("yyyyMMddHHmmss");
return eventZipName;
}
private void UpdateRowErrorFile(FileProcess row)
{
//string sFileNm = row.OrgZipFileName;
string sFileNm = row.ZipFileName;
this.Invoke(new Action(delegate ()
{
if (m_dicFileProcessErr.ContainsKey(sFileNm))
{
m_dicFileProcessErr[sFileNm] = row;
}
else
{
m_dicFileProcessErr.Add(sFileNm, row);
}
dgvErrorFile.RowCount = dgvErrorFile.RowCount + 1;
int nRow = dgvErrorFile.RowCount - 1;
dgvErrorFile.Rows[nRow].Cells[1].Value = row.ProcessServer;
dgvErrorFile.Rows[nRow].Cells[3].Value = row.ZipfileFullPath;
dgvErrorFile.Rows[nRow].Cells[4].Value = row.ZipFileName;
if (row.FileNameRule == Define.CON_MSG_ERROR)
{
dgvErrorFile.Rows[nRow].Cells[2].Value = "파일명규칙 Error";
dgvErrorFile.setCellButton("수정/파일이동", 5, nRow);
}
else if (row.FtpSendFlag == Define.CON_MSG_COMPLETE && row.FtpSuccessFlag == Define.con_FAIL)
{
dgvErrorFile.Rows[nRow].Cells[2].Value = "FTP 전송 Error";
dgvErrorFile.setCellButton("FTP 전송", 5, nRow);
}
else if (row.ZipDupFlag == Define.CON_MSG_ERROR)