Example #1
0
        /// <summary>
        /// DataTable을 전달받아 XML 형태로 파일로 저장합니다.
        /// </summary>
        /// <param name="_oneDt">데이터테이블</param>
        /// <param name="_rootName">Root명</param>
        /// <param name="_savepath">저장경로</param>
        /// <param name="_savefile">저장파일명</param>
        public static void fnDtToXMLToFile(DataTable _oneDt, string _rootName, string _savepath, string _savefile)
        {
            // 저장/불러오기 경로 지정
            string savepath = _savepath + _savefile;

            try
            {
                // 문서를 읽는다.
                if (FileCls.chkFile(savepath))
                {
                    // 수정처리
                    fnUpdateXMLFile(_oneDt, savepath, savepath);
                }
                else
                {
                    // 신규이므로
                    fnMakeXMLFile(_oneDt, _rootName, _savepath, _savefile);
                }
            }
            catch (Exception e)
            {
                // 문서가 위치에 없다.
                LogCls.writeLog("", "MineError.log", "fnDtToXMLToFile Error" + e.Message);
            }
        }
Example #2
0
        /// <summary>
        /// 폴더자체를 이동합니다.
        /// </summary>
        /// <param name="_oripath">오리지널 경로</param>
        /// <param name="_targetpath">타겟 경로</param>
        /// <returns>
        /// 0 : 정상복사 완료
        /// -71 : 복사될경로가 없는경우
        /// -72 : 복사할경로가 없는경우
        /// -79 : Exception 발생시
        /// </returns>
        public static int moveFd(string _oripath, string _targetpath)
        {
            // 오리지널 경로가 있는지부터 판단
            DirectoryInfo di = new DirectoryInfo(_oripath);

            if (!di.Exists)
            {
                return(-71);
            }

            // 타겟 경로가 있는지부터 판단
            di = new DirectoryInfo(_targetpath);
            if (!di.Exists)
            {
                return(-72);
            }

            try
            {
                FileSystem.MoveDirectory(_oripath, _targetpath, UIOption.AllDialogs);

                return(0);
            }
            catch (Exception ex)
            {
                LogCls.writeLog("", "MineFrameworkLog.log", "Move Folder Error (" + ex.Message + ")");
                return(-79);
            }
        }
Example #3
0
        /// <summary>
        /// 파일을 삭제합니다.
        /// </summary>
        /// <param name="_path">삭제할 경로정보</param>
        /// <param name="_filename">삭제할 파일명</param>
        /// <returns>-99 : 폴더경로없음</returns>
        /// <returns>-98 : 파일생성오류</returns>
        /// <returns>0 : 파일생성완료</returns>
        public static int removeFile(string _path, string _filename)
        {
            string filestr = _path + "/" + _filename;

            // 경로가 있는지부터 판단
            DirectoryInfo di = new DirectoryInfo(_path);

            if (!di.Exists)
            {
                return(-99);
            }

            try
            {
                FileInfo fi = new FileInfo(filestr);
                fi.Delete();

                return(0);
            }
            catch (Exception fiex)
            {
                LogCls.writeLog("", "MineFrameworkLog.log", "File Remove Error (" + fiex.Message + ")");
                return(-98);
            }
        }
Example #4
0
        /// <summary>
        /// Json String을 전달받아 XML파일로 저장합니다.
        /// </summary>
        /// <param name="_jsonstr">Json String</param>
        /// <param name="_rootName">Root명</param>
        /// <param name="_savepath">저장경로</param>
        /// <param name="_savefile">저장파일명</param>
        public static void fnJsonToXMLToFile(string _jsonstr, string _rootName, string _savepath, string _savefile)
        {
            // 저장/불러오기 경로 지정
            string savepath = _savepath + _savefile;

            // Json을 DataTable형태로 변환
            DataTable jsonDt = JsonConvert.DeserializeObject <DataTable>(_jsonstr);

            try
            {
                // 문서를 읽는다.
                if (FileCls.chkFile(savepath))
                {
                    // 기존파일 추가처리
                    fnUpdateXMLFile(jsonDt, savepath, savepath);
                }
                else
                {
                    // 신규이므로
                    fnMakeXMLFile(jsonDt, _rootName, savepath, _savefile);
                }
            }
            catch (Exception e)
            {
                // 문서가 위치에 없다.
                LogCls.writeLog("", "MineError.log", "fnJsonToXMLToFile Error" + e.Message);
            }
        }
Example #5
0
        public static string decryptAES256(string plain)
        {
            try
            {
                RijndaelManaged rm = new RijndaelManaged();
                rm.KeySize   = 256;
                rm.BlockSize = 256;
                rm.Mode      = CipherMode.CBC;
                rm.Padding   = PaddingMode.PKCS7;
                rm.Key       = Encoding.UTF8.GetBytes(KEY_256);
                rm.IV        = Encoding.UTF8.GetBytes(KEY_256);

                var    decrypt = rm.CreateDecryptor();
                byte[] xBuff   = null;
                using (var ms = new MemoryStream())
                {
                    using (var cs = new CryptoStream(ms, decrypt, CryptoStreamMode.Write))
                    {
                        byte[] xXml = Convert.FromBase64String(plain);
                        cs.Write(xXml, 0, xXml.Length);
                    }

                    xBuff = ms.ToArray();
                }

                return(Encoding.UTF8.GetString(xBuff));
            }
            catch (Exception e)
            {
                LogCls.writeLog("", "PrcLog.log", "AES256 Decrypt Error : " + e.Message);
                return("");
            }
        }
Example #6
0
        /// <summary>
        /// Json String을 DataTable 형태로 변환합니다.
        /// </summary>
        /// <param name="jsonstr">json 형태의 string</param>
        /// <returns>DataTable Data</returns>
        public static DataTable ConvertJsonToDataTable(string jsonstr)
        {
            DataTable _makeDt = new DataTable();

            string[]      jsonstrArray = Regex.Split(jsonstr.Replace("[", "").Replace("]", ""), "},{");
            List <string> colName      = new List <string>();

            foreach (string js in jsonstrArray)
            {
                string[] jsonstrData = Regex.Split(js.Replace("{", "").Replace("}", ""), ",");
                foreach (string columsNameData in jsonstrData)
                {
                    try
                    {
                        int    idx    = columsNameData.IndexOf(":");
                        string colstr = columsNameData.Substring(0, idx - 1).Replace("\"", "");
                        if (!colName.Contains(colstr))
                        {
                            colName.Add(colstr);
                        }
                    }catch (Exception ex)
                    {
                        LogCls.writeLog("", "MineError.log", "ConvertJsonToDataTable Error Column : " + columsNameData + " (" + ex.Message + ")");
                    }
                }
                break;
            }

            // DataTable Column 정보 추가
            foreach (string addColName in colName)
            {
                _makeDt.Columns.Add(addColName);
            }

            // DataTable Data 입력
            foreach (string js in jsonstrArray)
            {
                string[] rowData = Regex.Split(js.Replace("{", "").Replace("}", ""), ",");
                DataRow  dr      = _makeDt.NewRow();
                foreach (string rd in rowData)
                {
                    try
                    {
                        int    idx           = rd.IndexOf(":");
                        string rowcolums     = rd.Substring(0, idx - 1).Replace("\"", "");
                        string rowdatastring = rd.Substring(idx + 1).Replace("\"", "");
                        dr[rowcolums] = rowdatastring;
                    }
                    catch (Exception ex)
                    {
                        LogCls.writeLog("", "MineError.log", "ConvertJsonToDataTable Error Data (" + ex.Message + ")");
                        continue;
                    }
                }
                _makeDt.Rows.Add(dr);
            }

            return(_makeDt);
        }
Example #7
0
        /// <summary>
        /// 폴더자체를 복사합니다.
        /// </summary>
        /// <param name="_oripath">오리지널 경로</param>
        /// <param name="_targetpath">타겟 경로</param>
        /// <returns>
        /// 0 : 정상복사 완료
        /// -71 : 복사될경로가 없는경우
        /// -72 : 복사할경로가 없는경우
        /// -79 : Exception 발생시
        /// </returns>
        public static int copyFd(string _oripath, string _targetpath)
        {
            // 오리지널 경로가 있는지부터 판단
            DirectoryInfo di = new DirectoryInfo(_oripath);

            if (!di.Exists)
            {
                return(-71);
            }

            // 타겟 경로가 있는지부터 판단
            di = new DirectoryInfo(_targetpath);
            if (!di.Exists)
            {
                return(-72);
            }

            try
            {
                FileSystem.CopyDirectory(_oripath, _targetpath, UIOption.AllDialogs);

                return(0);
            }
            catch (Exception ex)
            {
                LogCls.writeLog("", "MineFrameworkLog.log", "Copy Folder Error (" + ex.Message + ")");
                return(-79);
            }

            //string[] files = Directory.GetFiles(_oripath);
            //string[] folders = Directory.GetDirectories(_oripath);

            //string filename = string.Empty;
            //string destname = string.Empty;

            //// 파일부터 복사
            //foreach (string file in files)
            //{
            //    filename = Path.GetFileName(file);
            //    destname = Path.Combine(_targetpath, filename);
            //    File.Copy(filename, destname);
            //}

            //string orifolder = string.Empty;
            //string tarfolder = string.Empty;

            //// 폴더 복사
            //foreach (string folder in folders)
            //{
            //    orifolder = Path.GetFileName(folder);
            //    tarfolder = Path.Combine(_targetpath, orifolder);

            //}
        }
Example #8
0
        /// <summary>
        /// Database에 접속합니다. (Timeout 10초)
        /// </summary>
        /// <param name="constr">DB연결 String</param>
        /// <returns></returns>
        public static int Connect(string constr)
        {
            try
            {
                if (_dbType == DatabaseType.MSSQL)
                {
                    _conn = (SqlConnection) new SqlConnection();
                    if (string.IsNullOrEmpty(constr))
                    {
                        _conn.ConnectionString = "Data Source=" + dbipaddr + "," + dbport + ";Database=" + dbname + ";UID=" + dbid + ";PWD=" + dbpw + ";Connection Timeout=10";
                    }
                    else
                    {
                        _conn.ConnectionString = constr;
                    }
                    _conn.StateChange += _conn_StateChange;
                    _conn.Open();
                }
                else if (_dbType == DatabaseType.SQLITE)
                {
                    //_connlite = new SQLiteConnection("Data Source=" + sqlitepath + ";Version=3;");
                    //_connlite.StateChange += _connlite_StateChange;
                    //_connlite.Open();
                }
                else if (_dbType == DatabaseType.ORACLE)
                {
                    //_oraconn = new OracleConnection($"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={dbipaddr})(PORT={dbport})))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME={dbname})));User ID={dbid};Password={dbpw};Connection Timeout=30;");
                    //_oraconn.Open();
                }

                LogCls.writeLog("", "ConnLog.log", "DatabaseType : " + _dbType + " | DatabaseIp : " + dbipaddr + " | Connection Complete(" + DateTime.Now.ToString() + ")");

                return(0);
            }
            catch (Exception ex)
            {
                LogCls.writeLog("", "ConnLog.log", "DatabaseType : " + _dbType + " | DatabaseIp : " + dbipaddr + " | Connection Fail(" + DateTime.Now.ToString() + ") | Reason : " + ex.Message);

                if (_conn.State == System.Data.ConnectionState.Open)
                {
                    // Connection 객체연결 닫기
                    _conn.Close();

                    // Connection 객체연결 삭제
                    _conn.Dispose();
                }

                return(99);
            }
            finally
            {
            }
        }
Example #9
0
        /// <summary>
        /// 파일을 삭제합니다.
        /// </summary>
        /// <param name="_targetpath">삭제할 파일경로</param>
        /// <param name="_filename">삭제할파일명</param>
        /// <returns></returns>
        public static int delFile(string _targetpath, string _filename)
        {
            try
            {
                // 삭제할경로 및 파일명셋팅
                string delpath = _targetpath + _filename;

                // 파일삭제
                File.Delete(delpath);

                return(0);
            }
            catch (Exception ex)
            {
                LogCls.writeLog("", "MineFrameworkLog.log", "File Delete Error (" + ex.Message + ")");
                return(-98);
            }
        }
Example #10
0
        /// <summary>
        /// 폴더를 컴퓨터내에 생성합니다.
        /// </summary>
        public static void makeFd(string _path)
        {
            DirectoryInfo di = new DirectoryInfo(_path);

            try
            {
                if (!di.Exists)
                {
                    di.Create();
                }
            }
            catch (Exception ex)
            {
                LogCls.writeLog("", "MineFrameworkLog.log", "폴더생성중 오류발생 : " + ex.Message);
            }
            finally
            {
            }
        }
Example #11
0
        /// <summary>
        /// PostgresSQL에 접속합니다.
        /// </summary>
        /// <returns>
        /// 0 : 성공
        /// -99 : 접속실패(C:\Mines\log 내에 접속로그 출력됨)
        /// </returns>
        public static int connect()
        {
            npgconn = new NpgsqlConnection(connectionString);

            try
            {
                npgconn.Open();

                LogCls.writeLog("", "ConnLog.log", "DatabaseType : postgresql | DatabaseIp : " + dbipaddr + " | Connection Complete(" + DateTime.Now.ToString() + ")");

                return(0);
            }
            catch (NpgsqlException npg)
            {
                LogCls.writeLog("", "ConnLog.log", "DatabaseType : postgresql | DatabaseIp : " + dbipaddr + " | Connection Fail(" + DateTime.Now.ToString() + ") " + npg.Message);

                return(-99);
            }
        }
Example #12
0
        public static int executeNonQuery(string _query)
        {
            try
            {
                NpgsqlCommand npcmd = new NpgsqlCommand();
                npcmd.CommandType = System.Data.CommandType.Text;
                npcmd.Connection  = npgconn;
                npcmd.CommandText = _query;

                npcmd.ExecuteNonQuery();

                return(0);
            }
            catch (Exception e)
            {
                LogCls.writeLog("", "ConnLog.log", "executeNonQuery 오류발생 : " + _query);
                return(-99);
            }
        }
Example #13
0
        /// <summary>
        /// 파일을 대상경로로 이동합니다.
        /// </summary>
        /// <param name="_oripath"></param>
        /// <param name="_targetpath"></param>
        /// <param name="_filename"></param>
        /// <param name="_overwrite"></param>
        /// <returns></returns>
        public static int moveFile(string _oripath, string _targetpath, string _filename)
        {
            try
            {
                // 원래경로 셋팅
                string oripath = Path.Combine(_oripath + _filename);

                // 대상경로 셋팅
                string tarpath = Path.Combine(_targetpath + _filename);

                // 파일이동
                File.Move(oripath, tarpath);

                return(0);
            }
            catch (Exception ex)
            {
                LogCls.writeLog("", "MineFrameworkLog.log", "File Move Error (" + ex.Message + ")");
                return(-98);
            }
        }
Example #14
0
        /// <summary>
        /// 파일을 대상경로로 복사합니다.
        /// </summary>
        /// <param name="_oripath">원래경로(ex:@"C:\Users\Public\TestFolder")</param>
        /// <param name="_targetpath">대상경로</param>
        /// <param name="_filename">파일명</param>
        /// <param name="_overwrite">덮어쓰기여부</param>
        /// <returns></returns>
        public static int copyFile(string _oripath, string _targetpath, string _filename, bool _overwrite)
        {
            try
            {
                // 원래경로 셋팅
                string oripath = Path.Combine(_oripath + _filename);

                // 대상경로 셋팅
                string tarpath = Path.Combine(_targetpath + _filename);

                // 파일복사
                File.Copy(oripath, tarpath, _overwrite);

                return(0);
            }
            catch (Exception ex)
            {
                LogCls.writeLog("", "MineFrameworkLog.log", "File Copy Error (" + ex.Message + ")");
                return(-98);
            }
        }
Example #15
0
        public static SqlConnection MultiConnect(string constr)
        {
            if (string.IsNullOrEmpty(constr))
            {
                return(null);
            }

            SqlConnection mConn = (SqlConnection) new SqlConnection();

            try
            {
                if (_dbType == DatabaseType.MSSQL)
                {
                    mConn.ConnectionString = constr;
                    mConn.StateChange     += mConn_StateChange;
                    mConn.Open();

                    return(mConn);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                LogCls.writeLog("", "ConnLog.log", "DatabaseType : " + _dbType + " | DatabaseIp : " + dbipaddr + " | Connection Fail(" + DateTime.Now.ToString() + ") | Reason : " + ex.Message);

                if (mConn.State == System.Data.ConnectionState.Open)
                {
                    // Connection 객체연결 닫기
                    mConn.Close();

                    // Connection 객체연결 삭제
                    mConn.Dispose();
                }

                return(null);
            }
        }
Example #16
0
        /// <summary>
        /// 128 비트 방식으로 암호화 합니다.
        /// </summary>
        /// <param name="plain">암호화할 문자열</param>
        /// <returns></returns>
        public static string encryptAES128(string plain)
        {
            try
            {
                // byte로 변환
                byte[] plainBytes = Encoding.UTF8.GetBytes(plain);

                // 레인달 알고리즘
                RijndaelManaged rm = new RijndaelManaged();
                rm.Mode    = CipherMode.CBC;
                rm.Padding = PaddingMode.PKCS7;
                rm.KeySize = 128;

                // 메모리스트림 생성
                MemoryStream memoryStream = new MemoryStream();
                // Key값, iv값 정의
                ICryptoTransform encryptor = rm.CreateEncryptor(Encoding.UTF8.GetBytes(KEY_128), Encoding.UTF8.GetBytes(KEY_128));
                // 크립트스트림을 key와 iv값으로 메모리 스트림을 이용하여 생성
                CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write);
                // 크립트스트림에 바이트배열을 쓰고 플러쉬
                cryptoStream.Write(plainBytes, 0, plainBytes.Length);
                cryptoStream.FlushFinalBlock();
                // 메모리스트림에 담겨있는 암호화된 바이트배열을 닫음
                byte[] encryptBytes = memoryStream.ToArray();
                // 베이스64로 변환
                string encryptString = Convert.ToBase64String(encryptBytes);
                // 스트림닫기
                cryptoStream.Close();
                memoryStream.Close();

                return(encryptString);
            }
            catch (Exception e)
            {
                LogCls.writeLog("", "PrcLog.log", "AES128 Encrypt Error : " + e.Message);
                return(null);
            }
        }
Example #17
0
        public static DataTable queryExec(string _query)
        {
            try
            {
                NpgsqlCommand npcmd = new NpgsqlCommand();
                npcmd.CommandType = System.Data.CommandType.Text;
                npcmd.Connection  = npgconn;
                npcmd.CommandText = _query;

                NpgsqlDataReader reader  = npcmd.ExecuteReader();
                DataTable        queryDt = new DataTable();

                queryDt.Load(reader);

                return(queryDt);
            }
            catch (Exception ex)
            {
                LogCls.writeLog("", "ConnLog.log", "queryExec 오류발생 : " + _query);

                return(null);
            }
        }
Example #18
0
        public static string decryptAES128(string encrypt)
        {
            try
            {
                // base64를 바이트로 변환
                byte[] encryptBytes = Convert.FromBase64String(encrypt);

                // 레인달 알고리즘
                RijndaelManaged rm = new RijndaelManaged();
                rm.Mode    = CipherMode.CBC;
                rm.Padding = PaddingMode.PKCS7;
                rm.KeySize = 128;

                // 메모리스트림 생성
                MemoryStream memoryStream = new MemoryStream(encryptBytes);
                // Key값, iv값 정의
                ICryptoTransform decryptor = rm.CreateDecryptor(Encoding.UTF8.GetBytes(KEY_128), Encoding.UTF8.GetBytes(KEY_128));
                // 크립트스트림을 key와 iv값으로 메모리 스트림을 이용하여 생성
                CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read);
                // 복호화된 데이터를 담을 바이트 배열을 선언한다.
                byte[] plainBytes = new byte[encryptBytes.Length];
                int    plainCount = cryptoStream.Read(plainBytes, 0, plainBytes.Length);
                // 복호화된 바이트배열을 string으로 변환
                string plainString = Encoding.UTF8.GetString(plainBytes, 0, plainCount);
                // 스트림닫기
                cryptoStream.Close();
                memoryStream.Close();

                return(plainString);
            }
            catch (Exception e)
            {
                LogCls.writeLog("", "PrcLog.log", "AES128 Decrypt Error : " + e.Message);
                return(null);
            }
        }