markus / FinalServiceV3 / KCOM_FinalService / FinalPDFClient / MainWindow.xaml.cs @ faf998c6
이력 | 보기 | 이력해설 | 다운로드 (4.23 KB)
1 |
using MarkupToPDF; |
---|---|
2 |
using Microsoft.Win32; |
3 |
using System; |
4 |
using System.Collections.Generic; |
5 |
using System.IO; |
6 |
using System.Linq; |
7 |
using System.Text; |
8 |
using System.Threading.Tasks; |
9 |
using System.Windows; |
10 |
using System.Windows.Controls; |
11 |
using System.Windows.Data; |
12 |
using System.Windows.Documents; |
13 |
using System.Windows.Input; |
14 |
using System.Windows.Media; |
15 |
using System.Windows.Media.Imaging; |
16 |
using System.Windows.Navigation; |
17 |
using System.Windows.Shapes; |
18 |
|
19 |
namespace FinalPDFClient |
20 |
{ |
21 |
/// <summary> |
22 |
/// MainWindow.xaml에 대한 상호 작용 논리 |
23 |
/// </summary> |
24 |
public partial class MainWindow : Window |
25 |
{ |
26 |
public MainWindow() |
27 |
{ |
28 |
InitializeComponent(); |
29 |
} |
30 |
|
31 |
public void MergedPDF() |
32 |
{ |
33 |
|
34 |
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); |
35 |
stopwatch.Start(); |
36 |
|
37 |
MarkupToPDF.MarkupToPDF markupToPDF = new MarkupToPDF.MarkupToPDF(); |
38 |
|
39 |
EventHandler<MakeFinalErrorArgs> errorEventHandler = null; |
40 |
EventHandler<EndFinalEventArgs> endFinalEventHandler = null; |
41 |
EventHandler<StatusChangedEventArgs> StatusChangedEventHandler = null; |
42 |
|
43 |
errorEventHandler = async (snd, evt) => |
44 |
{ |
45 |
await this.Dispatcher.InvokeAsync(() => |
46 |
{ |
47 |
txtOutput.Text += evt.Message; |
48 |
|
49 |
markupToPDF.FinalMakeError -= errorEventHandler; |
50 |
markupToPDF.EndFinal -= endFinalEventHandler; |
51 |
markupToPDF.StatusChanged -= StatusChangedEventHandler; |
52 |
}); |
53 |
}; |
54 |
|
55 |
endFinalEventHandler = async (snd, evt) => |
56 |
{ |
57 |
await this.Dispatcher.InvokeAsync(() => |
58 |
{ |
59 |
txtOutput.Text += evt.FinalPDFPath + " " + evt.Error; |
60 |
System.Diagnostics.Debug.WriteLine(evt.Message); |
61 |
|
62 |
var sb = new StringBuilder(); |
63 |
sb.AppendLine(txtOutput.Text); |
64 |
sb.AppendLine(new TimeSpan(stopwatch.ElapsedMilliseconds).ToString()); |
65 |
txtOutput.Text = sb.ToString(); |
66 |
|
67 |
markupToPDF.FinalMakeError -= errorEventHandler; |
68 |
markupToPDF.EndFinal -= endFinalEventHandler; |
69 |
markupToPDF.StatusChanged -= StatusChangedEventHandler; |
70 |
}); |
71 |
}; |
72 |
|
73 |
StatusChangedEventHandler = async (snd, evt) => |
74 |
{ |
75 |
await this.Dispatcher.InvokeAsync(() => { |
76 |
txtOutput.Text += evt.Message + " " + evt.CurrentPage + " " + evt.Error; |
77 |
}); |
78 |
}; |
79 |
|
80 |
markupToPDF.FinalMakeError += errorEventHandler; |
81 |
markupToPDF.EndFinal += endFinalEventHandler; |
82 |
markupToPDF.StatusChanged += StatusChangedEventHandler; |
83 |
try |
84 |
{ |
85 |
var addResult = markupToPDF.AddFinalPDF(txtProject.Text, txtDocId.Text, txtUserId.Text); |
86 |
|
87 |
if (addResult.Success) |
88 |
{ |
89 |
markupToPDF.MakeFinalPDF((object)addResult.FinalPDF); |
90 |
|
91 |
} |
92 |
} |
93 |
catch (Exception ex) |
94 |
{ |
95 |
txtOutput.Text = ex.ToString(); |
96 |
} |
97 |
} |
98 |
|
99 |
private void Button_Click(object sender, RoutedEventArgs e) |
100 |
{ |
101 |
MergedPDF(); |
102 |
} |
103 |
|
104 |
private void btXamlToString_Click(object sender, RoutedEventArgs e) |
105 |
{ |
106 |
OpenFileDialog openFileDialog = new OpenFileDialog(); |
107 |
|
108 |
openFileDialog.InitialDirectory = "c:\\"; |
109 |
openFileDialog.Filter = "xaml files (*.xaml)|*.txt|All files (*.*)|*.*"; |
110 |
openFileDialog.FilterIndex = 2; |
111 |
openFileDialog.RestoreDirectory = true; |
112 |
|
113 |
if (openFileDialog.ShowDialog() == true) |
114 |
{ |
115 |
//Read the contents of the file into a stream |
116 |
var fileStream = openFileDialog.OpenFile(); |
117 |
|
118 |
using (StreamReader reader = new StreamReader(fileStream)) |
119 |
{ |
120 |
string fileContent = reader.ReadToEnd(); |
121 |
|
122 |
MarkupToPDF.MarkupToPDF markupToPDF = new MarkupToPDF.MarkupToPDF(); |
123 |
|
124 |
markupToPDF.AddStamp(fileContent); |
125 |
} |
126 |
} |
127 |
|
128 |
} |
129 |
} |
130 |
} |