프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / KCOM / Common / TempFile.cs @ ea6f99ec

이력 | 보기 | 이력해설 | 다운로드 (23.9 KB)

1
using KCOM.Common;
2
using KCOM.Controls;
3
using KCOM.Views;
4
using MarkupToPDF.Common;
5
using MarkupToPDF.Controls.Parsing;
6
using Newtonsoft.Json;
7
using Newtonsoft.Json.Converters;
8
using Newtonsoft.Json.Linq;
9
using Newtonsoft.Json.Serialization;
10
using System;
11
using System.Collections;
12
using System.Collections.Generic;
13
using System.ComponentModel;
14
using System.Data;
15
using System.IO;
16
using System.Linq;
17
using System.Reflection;
18
using System.Runtime.Serialization.Formatters;
19
using System.Runtime.Serialization.Formatters.Binary;
20
using System.Runtime.Serialization.Json;
21
using System.Text;
22
using System.Windows;
23
using System.Windows.Media;
24
using System.Windows.Threading;
25
using System.Xml;
26
using System.Xml.Serialization;
27

    
28
namespace KCOM
29
{
30
    public class TempFile
31
    {
32
        //public static string PathString = AppDomain.CurrentDomain.BaseDirectory + "Temp";      
33
        public static string PathString = Path.GetTempPath() + "\\MARKUS";
34
        public static string FilePath = PathString + "\\" + App.ViewInfo.DocumentItemID + ".tmp";
35

    
36
        internal static void WriteTemp(List<TempDt> tempDtList)
37
        {
38
            if (tempDtList.Count > 0)
39
            {
40
                XmlDocument xmlDoc;
41
                XmlElement xmlEle1, xmlEle2, xmlEle3, xmlEle4, xmlEle5, xmlEle6;
42
                XmlNode newNode;
43
                xmlDoc = new XmlDocument();
44

    
45
                if ((System.IO.File.Exists(FilePath)) == false)
46
                {
47
                    if (!File.Exists(PathString))
48
                    {
49
                        Directory.CreateDirectory(PathString);
50
                    }
51

    
52
                    XmlWriterSettings settings = new XmlWriterSettings();
53
                    settings.Indent = true;
54
                    settings.NewLineOnAttributes = true;
55

    
56
                    XmlWriter xmlWriter = XmlWriter.Create(FilePath);
57
                    xmlWriter.WriteStartDocument();
58
                    xmlWriter.WriteStartElement("Root");
59

    
60
                    xmlWriter.WriteEndDocument();
61

    
62
                    xmlWriter.Flush();
63
                    xmlWriter.Close();
64
                }
65

    
66
                xmlDoc.Load(FilePath); // XML문서 로딩
67
                var nodes = xmlDoc.SelectNodes("/Root/CommentID");
68
                for (int i = 0; i < tempDtList.Count; i++)
69
                {
70
                    bool check = true;
71

    
72
                    foreach (XmlNode e in xmlDoc.GetElementsByTagName("CommentID"))
73
                    {
74
                        if (e.Attributes["Value"].Value.Equals(tempDtList[i].CommentID)) //CommentID가 같은경우
75
                        {
76
                            //데이터 수정
77
                            e.SelectSingleNode("ConvertData").InnerText = tempDtList[i].ConvertData;
78
                            e.SelectSingleNode("DATA_TYPE").InnerText = tempDtList[i].DATA_TYPE.ToString();
79
                            e.SelectSingleNode("MarkupInfoID").InnerText = tempDtList[i].MarkupInfoID;
80
                            e.SelectSingleNode("PageNumber").InnerText = tempDtList[i].PageNumber.ToString();
81
                            e.SelectSingleNode("IsUpdate").InnerText = tempDtList[i].IsUpdate.ToString();
82

    
83
                            xmlDoc.Save(FilePath); // XML문서 저장                
84

    
85
                            check = false;
86
                            break;
87
                        }
88
                    }
89

    
90
                    if (check == true)
91
                    {
92
                        newNode = xmlDoc.SelectSingleNode("Root"); // 추가할 부모 Node 찾기
93
                        xmlEle1 = xmlDoc.CreateElement("CommentID");
94
                        xmlEle1.SetAttribute("Value", tempDtList[i].CommentID);
95
                        newNode.AppendChild(xmlEle1);
96

    
97
                        xmlEle2 = xmlDoc.CreateElement("ConvertData"); // 추가할 Node 생성
98
                        xmlEle2.InnerText = tempDtList[i].ConvertData;
99
                        xmlEle1.AppendChild(xmlEle2);
100

    
101
                        xmlEle3 = xmlDoc.CreateElement("DATA_TYPE"); // 추가할 Node 생성
102
                        xmlEle3.InnerText = tempDtList[i].DATA_TYPE.ToString();
103
                        xmlEle1.AppendChild(xmlEle3);
104

    
105
                        xmlEle4 = xmlDoc.CreateElement("MarkupInfoID"); // 추가할 Node 생성
106
                        xmlEle4.InnerText = tempDtList[i].MarkupInfoID;
107
                        xmlEle1.AppendChild(xmlEle4);
108

    
109
                        xmlEle5 = xmlDoc.CreateElement("PageNumber"); // 추가할 Node 생성
110
                        xmlEle5.InnerText = tempDtList[i].PageNumber.ToString();
111
                        xmlEle1.AppendChild(xmlEle5);
112

    
113
                        xmlEle6 = xmlDoc.CreateElement("IsUpdate");
114
                        xmlEle6.InnerText = tempDtList[i].IsUpdate.ToString();
115
                        xmlEle1.AppendChild(xmlEle6);
116

    
117
                        xmlDoc.Save(FilePath); // XML문서 저장..
118
                    }
119
                }
120
                xmlDoc = null;
121
            }
122
        }
123
        
124
        public void AddTemp(MarkupToPDF.Common.Undo_data undoDataList, int PageNumber, double x, double y)
125
        {
126
            XmlDocument xmlDoc;
127
            XmlElement xmlEle1, xmlEle2, xmlEle3, xmlEle4, xmlEle5, xmlEle6;
128
            XmlNode newNode;
129
            xmlDoc = new XmlDocument();
130

    
131
            if ((System.IO.File.Exists(FilePath)) == false)
132
            {
133
                if (!File.Exists(PathString))
134
                {
135
                    Directory.CreateDirectory(PathString);
136
                }
137

    
138
                XmlWriterSettings settings = new XmlWriterSettings();
139
                settings.Indent = true;
140
                settings.NewLineOnAttributes = true;
141

    
142
                XmlWriter xmlWriter = XmlWriter.Create(FilePath);
143
                xmlWriter.WriteStartDocument();
144
                xmlWriter.WriteStartElement("Root");
145

    
146
                xmlWriter.WriteEndDocument();
147

    
148
                xmlWriter.Flush();
149
                xmlWriter.Close();
150
            }
151

    
152
            xmlDoc.Load(FilePath); // XML문서 로딩
153
            var nodes = xmlDoc.SelectNodes("/Root/CommentID");
154
            for (int i = 0; i < undoDataList.Markup_List.Count; i++)
155
            {
156
                var root = MarkupParser.MarkupToString(undoDataList.Markup_List[i].Markup, App.ViewInfo.UserID);
157
                bool check = true;
158
                                
159
                foreach (XmlNode e in xmlDoc.GetElementsByTagName("CommentID"))
160
                {
161
                    if (e.Attributes["Value"].Value.Equals(root.CommentID)) //CommentID가 같은경우
162
                    {
163
                        //데이터 수정
164
                        e.SelectSingleNode("ConvertData").InnerText = root.ConvertData;
165
                        e.SelectSingleNode("DATA_TYPE").InnerText = root.DATA_TYPE.ToString();
166
                        e.SelectSingleNode("MarkupInfoID").InnerText = undoDataList.Markup_List[i].Markup.MarkupInfoID;
167
                        e.SelectSingleNode("PageNumber").InnerText = PageNumber.ToString();
168
                        e.SelectSingleNode("IsUpdate").InnerText = 1.ToString();
169

    
170
                        xmlDoc.Save(FilePath); // XML문서 저장                
171

    
172
                        check = false;
173
                        break;
174
                    }
175
                }                
176

    
177
                if (check == true)
178
                {
179
                    newNode = xmlDoc.SelectSingleNode("Root"); 
180
                    xmlEle1 = xmlDoc.CreateElement("CommentID");
181
                    xmlEle1.SetAttribute("Value", root.CommentID);
182
                    newNode.AppendChild(xmlEle1);
183

    
184
                    xmlEle2 = xmlDoc.CreateElement("ConvertData"); 
185
                    xmlEle2.InnerText = root.ConvertData;
186
                    xmlEle1.AppendChild(xmlEle2);
187

    
188
                    xmlEle3 = xmlDoc.CreateElement("DATA_TYPE"); 
189
                    xmlEle3.InnerText = root.DATA_TYPE.ToString();
190
                    xmlEle1.AppendChild(xmlEle3);
191

    
192
                    xmlEle4 = xmlDoc.CreateElement("MarkupInfoID"); 
193
                    xmlEle4.InnerText = undoDataList.Markup_List[i].Markup.MarkupInfoID;
194
                    xmlEle1.AppendChild(xmlEle4);
195

    
196
                    xmlEle5 = xmlDoc.CreateElement("PageNumber");
197
                    xmlEle5.InnerText = PageNumber.ToString();
198
                    xmlEle1.AppendChild(xmlEle5);
199

    
200
                    xmlEle6 = xmlDoc.CreateElement("IsUpdate");
201
                    xmlEle6.InnerText = 1.ToString();
202
                    xmlEle1.AppendChild(xmlEle6);
203

    
204
                    xmlDoc.Save(FilePath); 
205
                }
206
            }
207
            xmlDoc = null;
208
        }
209

    
210
        public static void Remove() 
211
        {
212
            FileInfo fileDel = new FileInfo(FilePath);
213
            if (fileDel.Exists) 
214
            {
215
                fileDel.Delete(); 
216
            }
217
        }
218

    
219
        internal static void DelTemp(string CommentID, string PageNumber) //Control 삭제시
220
        {
221
            if ((System.IO.File.Exists(FilePath)) == false)
222
            {
223
                if (!File.Exists(PathString))
224
                {
225
                    Directory.CreateDirectory(PathString);
226
                }
227

    
228
                XmlWriterSettings settings = new XmlWriterSettings();
229
                settings.Indent = true;
230
                settings.NewLineOnAttributes = true;
231

    
232
                XmlWriter xmlWriter = XmlWriter.Create(FilePath);
233
                xmlWriter.WriteStartDocument();
234
                xmlWriter.WriteStartElement("Root");
235

    
236
                xmlWriter.WriteEndDocument();
237

    
238
                xmlWriter.Flush();
239
                xmlWriter.Close();
240
            }
241

    
242
            XmlDocument xmlDoc;
243
            xmlDoc = new XmlDocument();
244
            xmlDoc.Load(FilePath);
245

    
246
            var nodes = xmlDoc.SelectNodes("/Root/CommentID");
247
            XmlElement root = xmlDoc.DocumentElement;
248

    
249
            bool check = true;
250

    
251
            /*
252
            foreach (XmlNode node in nodes)
253
            {
254
                string sCommentID = node.Attributes["Value"].Value;
255

    
256
                if (sCommentID == CommentID)
257
                {
258
                    root.RemoveChild(xmlDoc.SelectNodes("//CommentID[@Value='" + CommentID + "']")[0]);
259
                    check = false;
260
                }
261
            }*/
262

    
263
            if (check == true)
264
            {
265
                XmlElement xmlEle1, xmlEle2, xmlEle3, xmlEle4, xmlEle5, xmlEle6;
266
                XmlNode newNode;
267
                newNode = xmlDoc.SelectSingleNode("Root");
268
                xmlEle1 = xmlDoc.CreateElement("CommentID");
269
                xmlEle1.SetAttribute("Value", CommentID);
270
                newNode.AppendChild(xmlEle1);
271

    
272
                xmlEle2 = xmlDoc.CreateElement("ConvertData");
273
                xmlEle2.InnerText = "";
274
                xmlEle1.AppendChild(xmlEle2);
275

    
276
                xmlEle3 = xmlDoc.CreateElement("DATA_TYPE"); 
277
                xmlEle3.InnerText = "";
278
                xmlEle1.AppendChild(xmlEle3);
279

    
280
                xmlEle4 = xmlDoc.CreateElement("MarkupInfoID");
281
                xmlEle4.InnerText = "";
282
                xmlEle1.AppendChild(xmlEle4);
283

    
284
                xmlEle5 = xmlDoc.CreateElement("PageNumber");
285
                xmlEle5.InnerText = PageNumber;
286
                xmlEle1.AppendChild(xmlEle5);
287

    
288
                xmlEle6 = xmlDoc.CreateElement("IsUpdate");
289
                xmlEle6.InnerText = 2.ToString();
290
                xmlEle1.AppendChild(xmlEle6);
291
            }
292

    
293
            xmlDoc.Save(FilePath);           
294
            xmlDoc = null;
295
        }
296

    
297
        public class TempLoadData
298
        {
299
            public int PageNumber { get; set; }
300
            public string CommentID { get; set; }
301
            public string ConvertData { get; set; }
302
            public string DATA_TYPE { get; set; }
303
            public string MarkupInfoID { get; set; }
304
            public int IsUpdate { get; set; }
305
        }
306

    
307
        static List<TempLoadData> tempLoadData = new List<TempLoadData>();
308

    
309

    
310
        public static Undo_data UndoData { get; set; }
311

    
312
        public class TempDt
313
        {
314
            public int PageNumber { get; set; }
315
            public string CommentID { get; set; }
316
            public string ConvertData { get; set; }
317
            public int DATA_TYPE { get; set; }
318
            public string MarkupInfoID { get; set; }
319
            public int IsUpdate { get; set; }
320
        }
321

    
322
        public static List<TempDt> tempDtList = new List<TempDt>();
323

    
324
        public static void TempLoad()
325
        {
326
            if ((System.IO.File.Exists(FilePath)) == true)
327
            {
328
                XmlDocument xdoc = new XmlDocument();
329
                xdoc.Load(FilePath);
330
                XmlNodeList nodes = xdoc.SelectNodes("/Root/CommentID");
331
                int PageNumber = 0;
332
                if (nodes.Count > 0)
333
                {
334
                    if (MessageBox.Show("저장하지 못한 데이터가 있습니다. 불러오시겠습니까?", "MARKUS", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
335
                    {
336
                        foreach (XmlNode node in nodes)
337
                        {
338
                            string CommentID = node.Attributes["Value"].Value;
339
                            string ConvertData = node.SelectSingleNode("ConvertData").InnerText;
340
                            string DATA_TYPE = node.SelectSingleNode("DATA_TYPE").InnerText;
341
                            string MarkupInfoID = node.SelectSingleNode("MarkupInfoID").InnerText;
342
                            int IsUpdate = Convert.ToInt32(node.SelectSingleNode("IsUpdate").InnerText);
343
                            PageNumber = Convert.ToInt32(node.SelectSingleNode("PageNumber").InnerText);
344

    
345
                            tempLoadData.Add(new TempLoadData()
346
                            {
347
                                PageNumber = PageNumber,
348
                                CommentID = CommentID,
349
                                ConvertData = ConvertData,
350
                                DATA_TYPE = DATA_TYPE,
351
                                MarkupInfoID = MarkupInfoID,
352
                                IsUpdate = IsUpdate
353
                            });
354
                        }
355

    
356
                        if (PageNumber > 0)
357
                        {
358
                            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.GotoPage(PageNumber);
359
                        }
360

    
361
                        // Temp Object add               
362
                        if (Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.CurrentPage.PageNumber == PageNumber)
363
                        {
364
                            TempControlLoad();
365
                        }
366
                        tempLoadData.Clear();
367
                    }
368
                }
369
                else //파일 삭제
370
                {
371
                    TempFile.Remove();
372
                }
373
            }
374
        }
375

    
376

    
377
        //Temp Control Load
378
        public static void TempControlLoad()
379
        {
380
            List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>();
381

    
382
            for (int k = 0; k < tempLoadData.Count; k++)
383
            {
384
                System.Windows.Controls.Control item = null;
385
                Multi_Undo_data multi_Undo_Data;
386

    
387

    
388
                switch (tempLoadData[k].IsUpdate)
389
                {
390
                    case 0://추가
391
                        var control = ViewerDataModel.Instance.MarkupControls_USER.Where(data => data.CommentID == tempLoadData[k].CommentID).FirstOrDefault();
392
                        if (control != null)
393
                        {
394
                            ViewerDataModel.Instance.MarkupControls_USER.Remove(control);
395
                            var Item_ = ViewerDataModel.Instance.MarkupList_USER.Where(d => d.ID == (control as MarkupToPDF.Common.CommentUserInfo).CommentID).FirstOrDefault();
396
                            ViewerDataModel.Instance.MarkupList_USER.Remove(Item_);
397
                        }
398

    
399
                        //Control                   
400
                        item = MarkupParser.ParseEx(App.ViewInfo.ProjectNO, tempLoadData[k].ConvertData, Common.ViewerDataModel.Instance.MarkupControls_USER, "#FFFF0000", "", tempLoadData[k].MarkupInfoID, tempLoadData[k].CommentID);
401

    
402
                        UndoData = new Undo_data()
403
                        {
404
                            IsUndo = false,
405
                            Event = Event_Type.Create,
406
                            EventTime = DateTime.Now,
407
                            Opacity = ViewerDataModel.Instance.ControlOpacity,
408
                            Markup_List = new List<Multi_Undo_data>()
409
                        };
410

    
411
                        multi_Undo_Data = new Multi_Undo_data();
412
                        multi_Undo_Data = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.Control_Style(item as MarkupToPDF.Common.CommentUserInfo);
413
                        UndoData.Markup_List.Add(multi_Undo_Data);
414
                        ViewerDataModel.Instance.UndoDataList.Add(UndoData);
415
                        break;
416
                    case 1://수정
417
                        control = ViewerDataModel.Instance.MarkupControls_USER.Where(data => data.CommentID == tempLoadData[k].CommentID).FirstOrDefault();
418
                        if (control != null)
419
                        {
420
                            ViewerDataModel.Instance.MarkupControls_USER.Remove(control);
421
                            var Item_ = ViewerDataModel.Instance.MarkupList_USER.Where(d => d.ID == (control as MarkupToPDF.Common.CommentUserInfo).CommentID).FirstOrDefault();
422
                            ViewerDataModel.Instance.MarkupList_USER.Remove(Item_);
423
                        }
424

    
425
                        //Control                   
426
                        item = MarkupParser.ParseEx(App.ViewInfo.ProjectNO, tempLoadData[k].ConvertData, Common.ViewerDataModel.Instance.MarkupControls_USER, "#FFFF0000", "", tempLoadData[k].MarkupInfoID, tempLoadData[k].CommentID);
427

    
428
                        UndoData = new Undo_data()
429
                        {
430
                            IsUndo = false,
431
                            Event = Event_Type.Thumb,
432
                            EventTime = DateTime.Now,
433
                            Opacity = ViewerDataModel.Instance.ControlOpacity,
434
                            Markup_List = new List<Multi_Undo_data>()
435
                        };
436

    
437
                        multi_Undo_Data = new Multi_Undo_data();
438
                        multi_Undo_Data = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.Control_Style(item as MarkupToPDF.Common.CommentUserInfo);
439
                        UndoData.Markup_List.Add(multi_Undo_Data);
440
                        ViewerDataModel.Instance.UndoDataList.Add(UndoData);
441
                        break;
442
                    case 2://삭제
443

    
444
                        control = ViewerDataModel.Instance.MarkupControls_USER.Where(data => data.CommentID == tempLoadData[k].CommentID).FirstOrDefault();
445
                        if (control != null)
446
                        {
447
                            ViewerDataModel.Instance.MarkupControls_USER.Remove(control);
448
                            var Item_ = ViewerDataModel.Instance.MarkupList_USER.Where(d => d.ID == (control as MarkupToPDF.Common.CommentUserInfo).CommentID).FirstOrDefault();
449
                            ViewerDataModel.Instance.MarkupList_USER.Remove(Item_);
450
                        }
451
                        break;
452
                }
453
            }
454
        }
455
       // public static Dispatcher Dispatcher { get; }
456
        public static void TempFileAdd()
457
        {
458
            System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate
459
            {
460
                if (ViewerDataModel.Instance.UndoDataList.Count > 0)
461
                {
462
                    DateTime undoTime = ViewerDataModel.Instance.UndoDataList.OrderByDescending(order => order.EventTime).FirstOrDefault().EventTime;
463
                    DateTime updatetime = DateTime.Now.AddDays(-1);
464
                    if (ViewerDataModel.Instance._markupInfoList.Count > 0)
465
                    {
466
                        updatetime = ViewerDataModel.Instance._markupInfoList.OrderByDescending(order => order.UpdateTime).FirstOrDefault().UpdateTime;
467
                    }
468

    
469
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.EmptyControlCheck();
470

    
471
                    if (undoTime > updatetime)
472
                    {
473
                        if (ViewerDataModel.Instance.MarkupControls_USER.Count > 0)
474
                        {
475
                            foreach (var control in ViewerDataModel.Instance.MarkupControls_USER)
476
                            {
477
                                var root = MarkupParser.MarkupToString(control, App.ViewInfo.UserID);
478

    
479
                                var existItem = ViewerDataModel.Instance.MarkupList_USER.Where(data => data.ID == root.CommentID).FirstOrDefault();
480
                                if (existItem != null)
481
                                {
482
                                    if (existItem.Data != root.ConvertData)
483
                                    {
484
                                        tempDtList.Add(new TempDt()
485
                                        {
486
                                            CommentID = control.CommentID,
487
                                            ConvertData = root.ConvertData,
488
                                            DATA_TYPE = root.DATA_TYPE,
489
                                            MarkupInfoID = App.Custom_ViewInfoId,
490
                                            PageNumber = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.CurrentPage.PageNumber,
491
                                            IsUpdate = 1
492
                                        });
493
                                    }
494
                                }
495
                                else //신규 추가 된 코멘트
496
                                {
497
                                    if (root.CommentID != null)
498
                                    {
499
                                        var currentCommentCheck = ViewerDataModel.Instance.MarkupList_USER.Where(dt => dt.ID == control.CommentID).FirstOrDefault();
500
                                        if (currentCommentCheck != null)
501
                                        {
502
                                            tempDtList.Add(new TempDt()
503
                                            {
504
                                                CommentID = control.CommentID,
505
                                                ConvertData = root.ConvertData,
506
                                                DATA_TYPE = root.DATA_TYPE,
507
                                                MarkupInfoID = App.Custom_ViewInfoId,
508
                                                PageNumber = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.CurrentPage.PageNumber,
509
                                                IsUpdate = 1
510
                                            });
511
                                        }
512
                                        else
513
                                        {
514
                                            tempDtList.Add(new TempDt()
515
                                            {
516
                                                CommentID = control.CommentID,
517
                                                ConvertData = root.ConvertData,
518
                                                DATA_TYPE = root.DATA_TYPE,
519
                                                MarkupInfoID = App.Custom_ViewInfoId,
520
                                                PageNumber = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.CurrentPage.PageNumber,
521
                                                IsUpdate = 0
522
                                            });
523
                                        }
524
                                    }
525
                                }
526
                            }
527
                        }
528

    
529
                        WriteTemp(tempDtList);
530
                        tempDtList.Clear();
531
                    }
532
                }
533
            }));
534

    
535
        }
536

    
537
        //public static string PathString = System.IO.Path.GetTempPath() + "\\MARKUS\\" + App.ViewInfo.DocumentItemID + ".tmp";
538

    
539
    }    
540
}
541

    
클립보드 이미지 추가 (최대 크기: 500 MB)