hytos / DTI_PID / APIDConverter / Utils / AvevaThread.cs @ 87f22597
이력 | 보기 | 이력해설 | 다운로드 (8.29 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Runtime.InteropServices; |
5 |
using System.Text; |
6 |
using System.Threading.Tasks; |
7 |
using System.Threading; |
8 |
using System.Collections; |
9 |
using System.Configuration; |
10 |
using System.Data; |
11 |
using System.Data.Common; |
12 |
using System.Data.SqlClient; |
13 |
using System.IO; |
14 |
using System.Runtime.CompilerServices; |
15 |
using Microsoft.VisualBasic.CompilerServices; |
16 |
|
17 |
using Autodesk.AutoCAD.ApplicationServices; |
18 |
using Autodesk.AutoCAD.ApplicationServices.Core; |
19 |
using Autodesk.AutoCAD.DatabaseServices; |
20 |
using Autodesk.AutoCAD.EditorInput; |
21 |
using Autodesk.AutoCAD.Geometry; |
22 |
using Autodesk.AutoCAD.Interop; |
23 |
using Autodesk.AutoCAD.Interop.Common; |
24 |
using Autodesk.AutoCAD.Runtime; |
25 |
using Autodesk.AutoCAD.Windows; |
26 |
|
27 |
using AVEVA.PID.Components; |
28 |
using AVEVA.PID.GUI; |
29 |
using AVEVA.PID.Common; |
30 |
using AVEVA.PID.DWGSelector; |
31 |
using AVEVA.PID.Utilities; |
32 |
|
33 |
using AVEVA.PID.CustomizationUtility.DB; |
34 |
using AVEVA.PID.CustomizationUtility.Model; |
35 |
using AVEVA.PID.CustomizationUtility.Properties; |
36 |
|
37 |
namespace AVEVA.PID.CustomizationUtility |
38 |
{ |
39 |
[Flags] |
40 |
public enum ThreadType |
41 |
{ |
42 |
None = 0, |
43 |
LineNumberModeling = 1, |
44 |
AddProperty = 2, |
45 |
DuplicationWarning = 4 |
46 |
} |
47 |
|
48 |
class AvevaThread |
49 |
{ |
50 |
[DllImport("user32")] |
51 |
public static extern int FindWindow(string lpClassName, string lpWindowName); |
52 |
[DllImport("user32.dll")] |
53 |
public static extern int FindWindowEx(int hWnd1, int hWnd2, string lpsz1, string lpsz2); |
54 |
[DllImport("user32")] |
55 |
public static extern int SendMessage(IntPtr hWnd, int uMsg, IntPtr WParam, IntPtr LParam); |
56 |
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto)] |
57 |
static extern long GetClassName(IntPtr hwnd, StringBuilder lpClassName, long nMaxCount); |
58 |
static string GetClassNameOfWindow(IntPtr hwnd) |
59 |
{ |
60 |
string className = ""; |
61 |
StringBuilder classText = null; |
62 |
try |
63 |
{ |
64 |
int cls_max_length = 1000; |
65 |
classText = new StringBuilder("", cls_max_length + 5); |
66 |
GetClassName(hwnd, classText, cls_max_length + 2); |
67 |
|
68 |
if (!String.IsNullOrEmpty(classText.ToString()) && !String.IsNullOrWhiteSpace(classText.ToString())) |
69 |
className = classText.ToString(); |
70 |
} |
71 |
catch (System.Exception ex) |
72 |
{ |
73 |
className = ex.Message; |
74 |
} |
75 |
finally |
76 |
{ |
77 |
classText = null; |
78 |
} |
79 |
return className; |
80 |
} |
81 |
|
82 |
const int BM_CLICK = 0x00F5; |
83 |
const int LoopTime = 500; |
84 |
private static ThreadType Running; |
85 |
|
86 |
public static bool IsRunning(ThreadType type) |
87 |
{ |
88 |
if (Running.HasFlag(type)) |
89 |
return true; |
90 |
else |
91 |
return false; |
92 |
} |
93 |
|
94 |
public static void Run(ThreadType type, params object[] param) |
95 |
{ |
96 |
if ((type & (type - 1)) == 0) |
97 |
{ |
98 |
if (type.HasFlag(ThreadType.LineNumberModeling) && !Running.HasFlag(ThreadType.LineNumberModeling)) |
99 |
{ |
100 |
Thread thread = new Thread(LineNumberModeling); |
101 |
thread.IsBackground = true; |
102 |
thread.Start(); |
103 |
Running |= ThreadType.LineNumberModeling; |
104 |
} |
105 |
else if (type.HasFlag(ThreadType.AddProperty) && !Running.HasFlag(ThreadType.AddProperty)) |
106 |
{ |
107 |
Thread thread = new Thread(() => AddProperty(param[0] as List<Tuple<string, string>>)); |
108 |
thread.IsBackground = true; |
109 |
thread.Start(); |
110 |
Running |= ThreadType.AddProperty; |
111 |
} |
112 |
else if (type.HasFlag(ThreadType.DuplicationWarning) && !Running.HasFlag(ThreadType.DuplicationWarning)) |
113 |
{ |
114 |
Thread thread = new Thread(DuplicationWarningMessageBox); |
115 |
thread.IsBackground = true; |
116 |
thread.Start(); |
117 |
Running |= ThreadType.DuplicationWarning; |
118 |
} |
119 |
} |
120 |
} |
121 |
|
122 |
public static void Stop(ThreadType type) |
123 |
{ |
124 |
Running &= ~type; |
125 |
} |
126 |
|
127 |
public static void LineNumberModeling() |
128 |
{ |
129 |
try |
130 |
{ |
131 |
while (Running.HasFlag(ThreadType.LineNumberModeling)) |
132 |
{ |
133 |
int handle = FindPropertiesFormHandle(); |
134 |
if (handle > 0) |
135 |
{ |
136 |
string name = GetClassNameOfWindow((IntPtr)handle); |
137 |
|
138 |
System.Windows.Forms.Control control = System.Windows.Forms.Control.FromHandle((IntPtr)handle); |
139 |
if (control != null && control.GetType() == typeof(ComponentPropertiesUI)) |
140 |
{ |
141 |
ComponentPropertiesUI UI = control as ComponentPropertiesUI; |
142 |
Infragistics.Win.UltraWinGrid.UltraGridRow row = UI.GetGridRow("AddLabel"); |
143 |
if (row != null) |
144 |
row.Cells["Value"].Value = "Yes"; |
145 |
} |
146 |
|
147 |
int button = FindWindowEx(handle, 0, null, "Ok"); |
148 |
if (button > 0) |
149 |
{ |
150 |
SendMessage((IntPtr)button, BM_CLICK, (IntPtr)0, (IntPtr)0); |
151 |
Running &= ~ThreadType.LineNumberModeling; |
152 |
} |
153 |
} |
154 |
Thread.Sleep(LoopTime); |
155 |
} |
156 |
} |
157 |
catch (System.Exception ex) |
158 |
{ |
159 |
|
160 |
} |
161 |
} |
162 |
public static void AddProperty(List<Tuple<string, string>> datas) |
163 |
{ |
164 |
try |
165 |
{ |
166 |
while (Running.HasFlag(ThreadType.AddProperty)) |
167 |
{ |
168 |
int handle = FindPropertiesFormHandle(); |
169 |
if (handle > 0) |
170 |
{ |
171 |
System.Windows.Forms.Control control = System.Windows.Forms.Control.FromHandle((IntPtr)handle); |
172 |
if (control != null && control.GetType() == typeof(ComponentPropertiesUI)) |
173 |
{ |
174 |
ComponentPropertiesUI UI = control as ComponentPropertiesUI; |
175 |
foreach (var tuple in datas) |
176 |
{ |
177 |
Infragistics.Win.UltraWinGrid.UltraGridRow row = UI.GetGridRow(tuple.Item1); |
178 |
if (row != null) |
179 |
row.Cells["Value"].Value = tuple.Item2; |
180 |
} |
181 |
|
182 |
int button = FindWindowEx(handle, 0, null, "Ok"); |
183 |
if (button > 0) |
184 |
{ |
185 |
SendMessage((IntPtr)button, BM_CLICK, (IntPtr)0, (IntPtr)0); |
186 |
} |
187 |
} |
188 |
Running &= ~ThreadType.AddProperty; |
189 |
break; |
190 |
} |
191 |
Thread.Sleep(LoopTime); |
192 |
} |
193 |
} |
194 |
catch (System.Exception ex) |
195 |
{ |
196 |
|
197 |
} |
198 |
} |
199 |
public static void DuplicationWarningMessageBox() |
200 |
{ |
201 |
try |
202 |
{ |
203 |
while (Running.HasFlag(ThreadType.DuplicationWarning)) |
204 |
{ |
205 |
int handle = FindWindow(null, AvevaACAD18String.DuplicationWarningMessageBox); |
206 |
if (handle > 0) |
207 |
{ |
208 |
int button = FindWindowEx(handle, 0, null, "Ok"); |
209 |
if (button > 0) |
210 |
{ |
211 |
SendMessage((IntPtr)button, BM_CLICK, (IntPtr)0, (IntPtr)0); |
212 |
} |
213 |
} |
214 |
Thread.Sleep(LoopTime); |
215 |
} |
216 |
} |
217 |
catch (System.Exception ex) |
218 |
{ |
219 |
|
220 |
} |
221 |
} |
222 |
|
223 |
public static int FindPropertiesFormHandle() |
224 |
{ |
225 |
int result = 0; |
226 |
foreach (var item in AvevaACAD18String.PropertiesFormNames) |
227 |
{ |
228 |
result = FindWindow(null, item); |
229 |
if (result > 0) |
230 |
break; |
231 |
} |
232 |
|
233 |
return result; |
234 |
} |
235 |
public static void Test() |
236 |
{ |
237 |
|
238 |
} |
239 |
} |
240 |
} |