hytos / DTI_PID / ID2PSN / Program.cs @ d8b09f9f
이력 | 보기 | 이력해설 | 다운로드 (4.2 KB)
1 | 7b5ddbe5 | humkyung | using Newtonsoft.Json; |
---|---|---|---|
2 | using System; |
||
3 | 0dae5645 | gaqhf | using System.Collections.Generic; |
4 | 31d37d58 | LJIYEON | using System.Data; |
5 | 6b9e7a56 | gaqhf | using System.IO; |
6 | 0dae5645 | gaqhf | using System.Linq; |
7 | 7b5ddbe5 | humkyung | using System.Net.Sockets; |
8 | using System.Text; |
||
9 | 0dae5645 | gaqhf | using System.Threading.Tasks; |
10 | using System.Windows.Forms; |
||
11 | |||
12 | namespace ID2PSN |
||
13 | { |
||
14 | static class Program |
||
15 | { |
||
16 | /// <summary> |
||
17 | /// 해당 애플리케이션의 주 진입점입니다. |
||
18 | /// </summary> |
||
19 | [STAThread] |
||
20 | 6b9e7a56 | gaqhf | static void Main(string[] args) |
21 | 0dae5645 | gaqhf | { |
22 | 14ab89ec | esham21 | if (!SingleInstance.Start("ecf2ed2e-1a3f-4926-a561-512857785805")) |
23 | eb41cac4 | esham21 | { |
24 | return; |
||
25 | } |
||
26 | |||
27 | 721b754d | gaqhf | ID2Info info = ID2Info.GetInstance(); |
28 | 31d37d58 | LJIYEON | DataTable projectTable = null; |
29 | abee404a | LJIYEON | try |
30 | 673075e0 | LJIYEON | { |
31 | 7b5ddbe5 | humkyung | using (TcpClient tcpClient = new TcpClient()) |
32 | abee404a | LJIYEON | { |
33 | 7b5ddbe5 | humkyung | tcpClient.SendTimeout = 500; |
34 | tcpClient.Connect("localhost", 2549); |
||
35 | |||
36 | var _params = new Dictionary<string, string>() |
||
37 | 757ab2f2 | LJIYEON | { |
38 | c4a35107 | humkyung | {"request", "prjinfo" }, |
39 | 7b5ddbe5 | humkyung | }; |
40 | var json = JsonConvert.SerializeObject(_params, Formatting.Indented); |
||
41 | byte[] message = Encoding.UTF8.GetBytes(json); |
||
42 | 757ab2f2 | LJIYEON | |
43 | 7b5ddbe5 | humkyung | using (NetworkStream networkStream = tcpClient.GetStream()) |
44 | 757ab2f2 | LJIYEON | { |
45 | d4b1ab29 | LJIYEON | try |
46 | { |
||
47 | networkStream.Write(message, 0, message.Length); |
||
48 | 7b5ddbe5 | humkyung | |
49 | d4b1ab29 | LJIYEON | byte[] outbuf = new byte[1024]; |
50 | int nbytes = networkStream.Read(outbuf, 0, outbuf.Length); |
||
51 | string output = Encoding.UTF8.GetString(outbuf, 4, nbytes - 5); |
||
52 | var result = JsonConvert.DeserializeObject<Dictionary<string, string>>(output); |
||
53 | 2c46461b | LJIYEON | |
54 | d4b1ab29 | LJIYEON | if (result["db_type"] == "SQLite") |
55 | { |
||
56 | info.ID2DBType = ID2DB_Type.SQLite; |
||
57 | var parent = Directory.GetParent(Path.GetDirectoryName(result["db_name"])); |
||
58 | info.DefaultPath = parent.ToString(); |
||
59 | ///DataRow dr = projectTable.Select(string.Format("DBTypes_UID = 2 AND Name = '{0}'", result["db_name"])).FirstOrDefault(); |
||
60 | ///info.DefaultPath = dr.Field<string>("Path"); |
||
61 | } |
||
62 | else if (result["db_type"] == "MSSQL") |
||
63 | { |
||
64 | 8d4723aa | 이지연 | |
65 | d4b1ab29 | LJIYEON | info.ID2DBType = ID2DB_Type.MSSQL; |
66 | info.ServerIP = result["host"]; |
||
67 | //info.Port = "3389"; |
||
68 | info.DBUser = result["user"]; |
||
69 | info.DBPassword = result["password"]; |
||
70 | info.Database = result["db_name"]; |
||
71 | info.DefaultPath = result["path"]; |
||
72 | ///DataRow dr = projectTable.Select(string.Format("DBTypes_UID = 2 AND Name = '{0}'", result["db_name"])).FirstOrDefault(); |
||
73 | ///info.DefaultPath = dr.Field<string>("Path"); |
||
74 | /// |
||
75 | 2c46461b | LJIYEON | |
76 | d4b1ab29 | LJIYEON | } |
77 | |||
78 | 19aff7f9 | 이지연 | MessageBox.Show(info.ID2DBType + "\n" + info.ServerIP + "\n" + info.Database + "\n" + info.DefaultPath, "ID2PSN", MessageBoxButtons.OK, MessageBoxIcon.Information); |
79 | 7b5ddbe5 | humkyung | } |
80 | d4b1ab29 | LJIYEON | catch(Exception ex) |
81 | 7b5ddbe5 | humkyung | { |
82 | d4b1ab29 | LJIYEON | MessageBox.Show(ex.StackTrace, "ID2PSN", MessageBoxButtons.OK, MessageBoxIcon.Error); |
83 | 7b5ddbe5 | humkyung | } |
84 | 757ab2f2 | LJIYEON | } |
85 | 7b5ddbe5 | humkyung | tcpClient.Close(); |
86 | abee404a | LJIYEON | } |
87 | 7bc1e1db | gaqhf | |
88 | abee404a | LJIYEON | if (DB.ConnTestAndCreateTable()) |
89 | { |
||
90 | Application.EnableVisualStyles(); |
||
91 | Application.SetCompatibleTextRenderingDefault(false); |
||
92 | 7b5ddbe5 | humkyung | Application.Run(new MainForm()); |
93 | abee404a | LJIYEON | } |
94 | else |
||
95 | MessageBox.Show("fail"); |
||
96 | } |
||
97 | 7b5ddbe5 | humkyung | catch (Exception ex) |
98 | 6b9e7a56 | gaqhf | { |
99 | d4b1ab29 | LJIYEON | MessageBox.Show(ex.StackTrace, "ID2PSN", MessageBoxButtons.OK, MessageBoxIcon.Error); |
100 | 6b9e7a56 | gaqhf | } |
101 | 0dae5645 | gaqhf | } |
102 | } |
||
103 | } |