//#################################################################### // // private function // //#################################################################### // // 日付関連 // private static clsResponse _日付チェック(string pDate) { clsResponse ret = new clsResponse(); string date = _StringToDate(pDate); try { DateTime d = Convert.ToDateTime(date); } catch (Exception ex) { ret.xSetError(ex.Message); return(ret); } return(ret); }
public static clsResponse xCreateMdb(string pFileName) { clsResponse ret = new clsResponse(); string inFileName = ""; string outFileName = ""; string msg = ""; try { inFileName = Assembly.GetExecutingAssembly().CodeBase; if (Environment.OSVersion.Platform.ToString().ToLower().StartsWith("win")) { inFileName = inFileName.Substring(8); } else { inFileName = inFileName.Substring(7); } inFileName = Path.GetFullPath( Path.GetDirectoryName(inFileName)); inFileName = Path.GetFullPath( Path.Combine(inFileName, "../Conf/MSAccess.conf")); outFileName = Path.GetFullPath(pFileName); File.Copy(inFileName, outFileName, true); msg = "mdbを生成しました。" + Environment.NewLine; msg += "(" + outFileName + ")"; ////////clsTextLogger.xWriteTextLog( //////// MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + //////// MethodBase.GetCurrentMethod().Name, msg); } catch (Exception ex) { msg = "mdbの生成に失敗しました!" + Environment.NewLine; msg += ex.Message + Environment.NewLine; msg += ex.StackTrace; ret.xSetError(msg); ////////clsTextLogger.xWriteTextLog( //////// MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + //////// MethodBase.GetCurrentMethod().Name, msg); } return(ret); }
public static clsResponse xDataTableToFile(DataTable pDataTable, string pFileName) { clsResponse ret = new clsResponse(); string msg = ""; StreamWriter sw = null; try { sw = new StreamWriter(pFileName, false, Encoding.Default); for (int i = 0; i < pDataTable.Rows.Count; i++) { StringBuilder sb = new StringBuilder(); for (int j = 0; j < pDataTable.Columns.Count; j++) { if (j > 0) { sb.Append(","); } sb.Append("\"" + pDataTable.Rows[i][j].ToString() + "\""); } sw.WriteLine(sb.ToString()); } } catch (Exception ex) { msg = "ファイルの書込みに失敗しました。"; msg += Environment.NewLine; msg += ex.Message; msg += ex.StackTrace; ret.xSetError(msg); return(ret); } finally { if (sw != null) { sw.Close(); sw = null; } } return(ret); }
private static void _WriteTextJobLog( string pLogFile, string pFrom, string pMessage, string pUserID, string pMachineName) { bool ret = true; clsResponse clsRet = new clsResponse(); string userID = ""; string machineName = ""; string fileName = ""; string dirName = ""; StringBuilder text = null; DateTime now = clsSystemInfo.xNow; try { userID = pUserID; if (userID.Length == 0) { userID = clsSystemInfo.xWindowsUser; } machineName = pMachineName; if (machineName.Length == 0) { machineName = clsSystemInfo.xMachineName; } if (pLogFile.Length > 0) { fileName = Path.GetFullPath(pLogFile); dirName = Path.GetDirectoryName(fileName); if (!Directory.Exists(dirName)) { Directory.CreateDirectory(dirName); } } else { // ▼ Win7対応 dirName = clsSystemInfo.xLogDirectory; if (!Directory.Exists(dirName)) { dirName = Assembly.GetAssembly(typeof(clsTextLogger)).CodeBase; if (Environment.OSVersion.Platform.ToString().ToLower().StartsWith("win")) { dirName = Path.GetDirectoryName(dirName.Substring(8)); } else { dirName = Path.GetDirectoryName(dirName.Substring(7)); } } fileName = Path.GetFullPath(Path.Combine(dirName, "Elpis.log")); // ▲ Win7対応 } // ▼ LogFileが1Mbを超えたらバックアップし、新規作成 if (File.Exists(fileName)) { FileInfo fi = null; try { fi = new FileInfo(fileName); if (fi.Length > 10000000) { string dir = Path.GetDirectoryName(fileName); string newFileName = Path.GetFileNameWithoutExtension(fileName) + "_" + now.ToString("yyyyMMddHHmmss") + ".log"; newFileName = Path.Combine(dir, newFileName); File.Move(fileName, newFileName); } } catch (Exception ex) { string hh = ""; return; } finally { if (fi != null) { fi = null; } } } // ▲ LogFileが1Mbを超えたらバックアップし、新規作成 // ▼ Log出力 // 初めて書き込む際は、権限を設定する。 if (!File.Exists(fileName)) { using (StreamWriter sw = new StreamWriter(fileName, true, Encoding.UTF8)) { text = new StringBuilder(); text.Append("## " + Environment.NewLine); text.Append("## Created " + now.ToString("yyyy/MM/dd HH:mm:ss") + Environment.NewLine); text.Append("## " + Environment.NewLine); sw.WriteLine(text.ToString()); text = null; sw.Close(); } // ▼ ファイルアクセス権変更(winのみ実行) if (Environment.OSVersion.Platform.ToString().ToLower().StartsWith("win")) { clsACL acl = null; try { acl = new clsACL(); clsRet = acl.xChengeFileSecurity(fileName); } catch (Exception ex) { clsRet.xSetError(ex.Message + Environment.NewLine + ex.StackTrace); } } // ▲ ファイルアクセス権変更 } using (StreamWriter sw = new StreamWriter(fileName, true, Encoding.UTF8)) { text = new StringBuilder(); text.Append(now.ToString("yyyy/MM/dd HH:mm:ss fff") + ","); text.Append(userID + ","); text.Append(machineName + ","); text.Append(pMessage.Replace(Environment.NewLine, " ") + ","); text.Append(pFrom); sw.WriteLine(text.ToString()); text = null; sw.Close(); } // ▲ Log出力 } catch (Exception ex) { ret = false; } }
private bool _Save() { bool ret = true; clsResponse response = new clsResponse(); // ▼ 設定データをバイト配列に変換する DataSet ds = new DataSet(); ds.Tables.Add(myData_.Copy()); MemoryStream ms = new MemoryStream(); ds.WriteXml(ms, XmlWriteMode.IgnoreSchema); byte[] bytesIn = ms.ToArray(); // ▲ 設定データをバイト配列に変換する // ▼ 暗号化する string key = clsCrypt.xGetPublicKey(); //DESCryptoServiceProviderオブジェクトの作成 DESCryptoServiceProvider des = new DESCryptoServiceProvider(); //共有キーと初期化ベクタを決定 //パスワードをバイト配列にする byte[] bytesKey = Encoding.UTF8.GetBytes(key); //共有キーと初期化ベクタを設定 des.Key = ResizeBytesArray(bytesKey, des.Key.Length); des.IV = ResizeBytesArray(bytesKey, des.IV.Length); //暗号化されたデータを書き出すためのMemoryStream MemoryStream msOut = new MemoryStream(); //DES暗号化オブジェクトの作成 ICryptoTransform desdecrypt = des.CreateEncryptor(); //書き込むためのCryptoStreamの作成 CryptoStream cryptStreem = new CryptoStream( msOut, desdecrypt, CryptoStreamMode.Write); //書き込む cryptStreem.Write(bytesIn, 0, bytesIn.Length); cryptStreem.FlushFinalBlock(); //暗号化されたデータを取得 byte[] bytesOut = msOut.ToArray(); //閉じる cryptStreem.Close(); msOut.Close(); // ▲ 暗号化する // ▼ ファイルに書き出す FileStream file = null; try { file = new FileStream( myFileName_, FileMode.Create, FileAccess.Write); file.Write(bytesOut, 0, bytesOut.Length); file.Flush(); } catch (Exception ex) { ret = false; string msg = ex.Message + ex.StackTrace; clsTextLogger.xWriteTextLog( MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + MethodBase.GetCurrentMethod().Name, msg); return(ret); } finally { if (file != null) { file.Close(); file.Dispose(); file = null; } } // ▲ ファイルに書き出す // ▼ アクセス権変更 clsACL acl = null; try { acl = new clsACL(); response = acl.xChengeFileSecurity(myFileName_); } catch (Exception ex) { ret = false; response.xSetError(ex.Message + Environment.NewLine + ex.StackTrace); } if (response.xHasError) { ret = false; clsTextLogger.xWriteTextLog( MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + MethodBase.GetCurrentMethod().Name, response.xMessage); } // ▲ アクセス権変更 return(ret); }
private clsResponse _ChengeFileSecurity(string pFileName) { clsResponse ret = new clsResponse(); string fileName = ""; string msg = ""; FileInfo fileInfo = null; FileSecurity fileSec = null; FileSystemAccessRule accessRule = null; // winのみ実行 if (Environment.OSVersion.Platform.ToString().ToLower().StartsWith("win")) { } else { return(ret); } try { fileName = Path.GetFullPath(pFileName); if (!File.Exists(fileName)) { msg = "ファイル未登録!" + "(" + fileName + ")"; ret.xSetError(msg); return(ret); } } catch (Exception ex) { msg = " 予期せぬエラーが発生しました。"; msg += Environment.NewLine + ex.Message; ret.xSetError(msg); msg += Environment.NewLine + ex.StackTrace; clsTextLogger.xWriteTextLog( MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + MethodBase.GetCurrentMethod().Name, msg); return(ret); } try { fileInfo = new FileInfo(fileName); fileSec = new FileSecurity(); fileSec = fileInfo.GetAccessControl(); // アクセス権限を指定 // Everyoneに対し、フルコントロールの許可 // (サブフォルダ、及び、ファイルにも適用) accessRule = new FileSystemAccessRule( "Everyone", FileSystemRights.FullControl, AccessControlType.Allow); fileSec.AddAccessRule(accessRule); fileInfo.SetAccessControl(fileSec); } catch (Exception ex) { msg = " 予期せぬエラーが発生しました。"; msg += Environment.NewLine + ex.Message; ret.xSetError(msg); msg += Environment.NewLine + ex.StackTrace; clsTextLogger.xWriteTextLog( MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + MethodBase.GetCurrentMethod().Name, msg); return(ret); } return(ret); }