diff --git a/Post/Post/ConfigConn.cs b/Post/Post/ConfigConn.cs new file mode 100644 index 0000000000000000000000000000000000000000..a9d237b3d328ee4cd4d3d50f88d2ee4f369eb887 --- /dev/null +++ b/Post/Post/ConfigConn.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using System.IO; // File +using System.Text.RegularExpressions; // Regex + +namespace Post +{ + public class ConfigConn + { + public string IP { get; set; } + public int PORT { get; set; } + public string DBNAME { get; set; } + public string USERNAME { get; set; } + public string PASSWORD { get; set; } + + public ConfigConn() + { + IP = ""; + PORT = 0; + DBNAME = ""; + USERNAME = ""; + PASSWORD = ""; + } + + public ConfigConn LoadConn(string alias) + { + ConfigConn configConn = new ConfigConn(); + ConstFunc constFunc = new ConstFunc(); + ConstValues constValues = new ConstValues(); + ConstValuesConfig constValuesConfig = new ConstValuesConfig(); + + try + { + string path = constFunc.GetDirectoryPath(constValues.CONST_CONFIG_CONN) + alias + ".conn"; Console.WriteLine("path : " + path); + bool isExist = File.Exists(path); + if (!isExist) + { + Console.WriteLine("connection file not found"); + return null; + } + + StreamReader reader = new StreamReader(path); + string rowData = reader.ReadToEnd(); + string[] arrData = Regex.Split(rowData, "\r\n"); + + for(int i = 0; i < arrData.Length; i++) + { + arrData[i] = arrData[i].Replace('"', ' ').Replace(';', ' '); + Console.WriteLine(">> " + arrData[i]); + string[] arr = Regex.Split(arrData[i], "="); + string[] arrTemp = new string[2]; + + if (arr.Length > 1) + { + arrTemp[0] = arr[0]; + arrTemp[1] = arr[1].Trim(); + } + else + { + arrTemp[0] = arr[0]; + arrTemp[1] = ""; + } + + if (arrTemp[0].Length > 0 && !arrTemp[0].Substring(0, 1).Equals("#")) + { + if (arrTemp[0].Equals(constValuesConfig.CONST_CONN_IP, StringComparison.OrdinalIgnoreCase)) + configConn.IP = arrTemp[1]; + else if (arrTemp[0].Equals(constValuesConfig.CONST_CONN_PORT, StringComparison.OrdinalIgnoreCase)) + configConn.PORT = Int32.Parse(arrTemp[1]); + else if (arrTemp[0].Equals(constValuesConfig.CONST_CONN_DBNAME, StringComparison.OrdinalIgnoreCase)) + { + if (arrTemp[1].Length == 0) + { + Console.WriteLine(arrTemp[0] + " 값 누락"); + return null; + } + configConn.DBNAME = arrTemp[1]; + } + else if (arrTemp[0].Equals(constValuesConfig.CONST_CONN_USERNAME, StringComparison.OrdinalIgnoreCase)) + { + + if (arrTemp[1].Length == 0) + { + Console.WriteLine(arrTemp[0] + " 값 누락"); + return null; + } + configConn.USERNAME = arrTemp[1]; + } + else if (arrTemp[0].Equals(constValuesConfig.CONST_CONN_PASSWORD, StringComparison.OrdinalIgnoreCase)) + { + + if (arrTemp[1].Length == 0) + { + Console.WriteLine(arrTemp[0] + " 값 누락"); + return null; + } + configConn.PASSWORD = arrTemp[1]; + } + } + } + Console.WriteLine("--------------------------"); + + reader.Close(); + + } catch(Exception e) + { + Console.WriteLine("LoadConn : " + e.ToString()); + return null; + } + + return configConn; + } + } +}