hytos / ID2.Manager / ID2.Manager.Compare / Classes / ID2Helper.cs @ 4142eefa
이력 | 보기 | 이력해설 | 다운로드 (3.35 KB)
1 | 13a36357 | humkyung | using Newtonsoft.Json; |
---|---|---|---|
2 | using System; |
||
3 | using System.Collections.Generic; |
||
4 | using System.Diagnostics; |
||
5 | using System.Linq; |
||
6 | using System.Net.Sockets; |
||
7 | using System.Reflection; |
||
8 | using System.Runtime.InteropServices; |
||
9 | using System.Text; |
||
10 | using System.Threading.Tasks; |
||
11 | |||
12 | namespace ID2.Manager.Classes |
||
13 | { |
||
14 | public static class ID2Helper |
||
15 | { |
||
16 | [DllImport("kernel32")] |
||
17 | private static extern long WritePrivateProfileString(string section, string key, string val, string filePath); |
||
18 | [DllImport("kernel32")] |
||
19 | private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath); |
||
20 | [DllImport("kernel32.dll")] |
||
21 | private static extern int GetPrivateProfileSection(string lpAppName, byte[] lpszReturnBuffer, int nSize, string lpFileName); |
||
22 | |||
23 | /// <summary> |
||
24 | /// 주어진 DrawingName의 도면을 ID2에서 엽니다. |
||
25 | /// </summary> |
||
26 | /// <param name="DrawingName"></param> |
||
27 | /// <param name="uids"></param> |
||
28 | public static void OpenPID(string DrawingName, string uids, int port) |
||
29 | { |
||
30 | using (TcpClient tcpClient = new TcpClient()) |
||
31 | { |
||
32 | try |
||
33 | { |
||
34 | tcpClient.SendTimeout = 500; |
||
35 | tcpClient.Connect("localhost", port); |
||
36 | |||
37 | var _params = new Dictionary<string, string>() |
||
38 | { |
||
39 | { "request", "open drawing" }, |
||
40 | { "drawing", DrawingName }, |
||
41 | { "oid", uids } |
||
42 | }; |
||
43 | string json = JsonConvert.SerializeObject(_params, Formatting.Indented); |
||
44 | |||
45 | byte[] message = Encoding.UTF8.GetBytes(json); |
||
46 | |||
47 | using (NetworkStream networkStream = tcpClient.GetStream()) |
||
48 | { |
||
49 | networkStream.Write(message, 0, message.Length); |
||
50 | |||
51 | byte[] outbuf = new byte[1024]; |
||
52 | int nbytes = networkStream.Read(outbuf, 0, outbuf.Length); |
||
53 | string output = Encoding.UTF8.GetString(outbuf, 4, nbytes - 5); |
||
54 | var result = JsonConvert.DeserializeObject<Dictionary<string, string>>(output); |
||
55 | } |
||
56 | } |
||
57 | catch (Exception ex) |
||
58 | { |
||
59 | throw ex; |
||
60 | } |
||
61 | } |
||
62 | } |
||
63 | |||
64 | /// <summary> |
||
65 | /// Write Data to the INI File |
||
66 | /// </summary> |
||
67 | /// <PARAM name="Section"></PARAM> |
||
68 | /// Section name |
||
69 | /// <PARAM name="Key"></PARAM> |
||
70 | /// Key Name |
||
71 | /// <PARAM name="Value"></PARAM> |
||
72 | /// Value Name |
||
73 | public static void IniWriteValue(string sPath, string Section, string Key, string Value) |
||
74 | { |
||
75 | WritePrivateProfileString(Section, Key, Value, sPath); |
||
76 | } |
||
77 | |||
78 | /// <summary> |
||
79 | /// Read Data Value From the Ini File |
||
80 | /// </summary> |
||
81 | /// <PARAM name="Section"></PARAM> |
||
82 | /// <PARAM name="Key"></PARAM> |
||
83 | /// <PARAM name="Path"></PARAM> |
||
84 | /// <returns></returns> |
||
85 | public static string IniReadValue(string sPath, string Section, string Key) |
||
86 | { |
||
87 | StringBuilder temp = new StringBuilder(255); |
||
88 | int i = GetPrivateProfileString(Section, Key, string.Empty, temp, 255, sPath); |
||
89 | return temp.ToString(); |
||
90 | } |
||
91 | } |
||
92 | } |