프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / ID2PSN / Program.cs @ abc4250b

이력 | 보기 | 이력해설 | 다운로드 (4.25 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
                using (TcpClient tcpClient = new TcpClient())
32
                {
33
                    tcpClient.SendTimeout = 500;
34
                    tcpClient.Connect("localhost", 2549);
35

    
36
                    var _params = new Dictionary<string, string>()
37
                    {
38
                        {"request", "prjinfo" },
39
                    };
40
                    var json = JsonConvert.SerializeObject(_params, Formatting.Indented);
41
                    byte[] message = Encoding.UTF8.GetBytes(json);
42

    
43
                    using (NetworkStream networkStream = tcpClient.GetStream())
44
                    {
45
                        try
46
                        {
47
                            networkStream.Write(message, 0, message.Length);
48

    
49
                            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

    
54
                            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
                                info.ID2DBType = ID2DB_Type.MSSQL;
65
                                info.ServerIP = result["host"];
66
                                //info.Port = "3389"; 
67
                                info.DBUser = result["user"];
68
                                info.DBPassword = result["password"];
69
                                info.Database = result["db_name"];
70
                                info.DefaultPath = result["path"];
71
                                ///DataRow dr = projectTable.Select(string.Format("DBTypes_UID = 2 AND Name = '{0}'", result["db_name"])).FirstOrDefault();
72
                                ///info.DefaultPath = dr.Field<string>("Path");
73
                                ///
74

    
75
                            }
76

    
77
                            MessageBox.Show(info.ID2DBType + "\n" + info.ServerIP + "\n" + info.DBUser + "\n" + info.DBPassword + "\n" + info.Database + "\n" + info.DefaultPath, "ID2PSN", MessageBoxButtons.OK, MessageBoxIcon.Information);
78
                        }
79
                        catch(Exception ex)
80
                        {
81
                            MessageBox.Show(ex.StackTrace, "ID2PSN", MessageBoxButtons.OK, MessageBoxIcon.Error);
82
                        }
83
                    }
84
                    tcpClient.Close();
85
                }
86

    
87
                if (DB.ConnTestAndCreateTable())
88
                {
89
                    Application.EnableVisualStyles();
90
                    Application.SetCompatibleTextRenderingDefault(false);
91
                    Application.Run(new MainForm());
92
                }
93
                else
94
                    MessageBox.Show("fail");
95
            }
96
            catch (Exception ex)
97
            {
98
                MessageBox.Show(ex.StackTrace, "ID2PSN", MessageBoxButtons.OK, MessageBoxIcon.Error);
99
            }
100
        }
101
    }
102
}
클립보드 이미지 추가 (최대 크기: 500 MB)