hytos / DTI_PID / ID2PSN / Program.cs @ 2c46461b
이력 | 보기 | 이력해설 | 다운로드 (3.58 KB)
1 |
using Newtonsoft.Json; |
---|---|
2 |
using System; |
3 |
using System.Collections.Generic; |
4 |
using System.Data; |
5 |
using System.IO; |
6 |
using System.Linq; |
7 |
using System.Net.Sockets; |
8 |
using System.Text; |
9 |
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 |
static void Main(string[] args) |
21 |
{ |
22 |
if (!SingleInstance.Start("ecf2ed2e-1a3f-4926-a561-512857785805")) |
23 |
{ |
24 |
return; |
25 |
} |
26 |
|
27 |
ID2Info info = ID2Info.GetInstance(); |
28 |
DataTable projectTable = null; |
29 |
try |
30 |
{ |
31 |
//DB Type 확인 |
32 |
projectTable = DB.GetProject(); |
33 |
|
34 |
|
35 |
using (TcpClient tcpClient = new TcpClient()) |
36 |
{ |
37 |
tcpClient.SendTimeout = 500; |
38 |
tcpClient.Connect("localhost", 2549); |
39 |
|
40 |
var _params = new Dictionary<string, string>() |
41 |
{ |
42 |
{"request", "database" }, |
43 |
}; |
44 |
var json = JsonConvert.SerializeObject(_params, Formatting.Indented); |
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 |
if (result["db_type"] == "SQLite") |
58 |
{ |
59 |
info.ID2DBType = ID2DB_Type.SQLite; |
60 |
var parent = Directory.GetParent(Path.GetDirectoryName(result["db_name"])); |
61 |
DataRow dr = projectTable.Select(string.Format("DBTypes_UID = 2 AND Name = '{0}'", result["db_name"])).FirstOrDefault(); |
62 |
info.DefaultPath = dr.Field<string>("Path"); |
63 |
} |
64 |
else if (result["db_type"] == "MSSQL") |
65 |
{ |
66 |
info.ID2DBType = ID2DB_Type.MSSQL; |
67 |
info.ServerIP = result["host"]; |
68 |
//info.Port = "3389"; |
69 |
info.DBUser = result["user"]; |
70 |
info.DBPassword = result["password"]; |
71 |
//info.DefaultPath = result["db_name"]; |
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 |
} |
76 |
tcpClient.Close(); |
77 |
} |
78 |
|
79 |
if (DB.ConnTestAndCreateTable()) |
80 |
{ |
81 |
Application.EnableVisualStyles(); |
82 |
Application.SetCompatibleTextRenderingDefault(false); |
83 |
Application.Run(new MainForm()); |
84 |
} |
85 |
else |
86 |
MessageBox.Show("fail"); |
87 |
} |
88 |
catch (Exception ex) |
89 |
{ |
90 |
MessageBox.Show("Failed to open ID2 drawing.", "ID2PSN", MessageBoxButtons.OK, MessageBoxIcon.Error); |
91 |
} |
92 |
} |
93 |
} |
94 |
} |