for Push.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.Commons.Conversion
|
||||
{
|
||||
public static class KanaConvertUxer
|
||||
{
|
||||
/// <summary>
|
||||
/// 半角カタカナを全角カタカナに変換します。
|
||||
/// 空文字やnullはそのまま返却します。
|
||||
/// </summary>
|
||||
// public static bool TryConvertHankakuToZenkaku(string input, out string result, out string resultMessage)
|
||||
// {
|
||||
// result = input;
|
||||
// resultMessage = string.Empty;
|
||||
|
||||
// if (string.IsNullOrEmpty(input))
|
||||
// return true;
|
||||
|
||||
// // 半角カタカナが含まれているかチェック
|
||||
// if (!Regex.IsMatch(input, @"[\uFF61-\uFF9F]"))
|
||||
// return true;
|
||||
|
||||
// // 変換処理
|
||||
// result = Microsoft.VisualBasic.Strings.StrConv(input, Microsoft.VisualBasic.VbStrConv.Katakana | Microsoft.VisualBasic.VbStrConv.Wide, 0);
|
||||
// return true;
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// 全角カタカナを半角カタカナに変換します。
|
||||
/// 空文字やnullはそのまま返却します。
|
||||
/// </summary>
|
||||
// public static bool TryConvertZenkakuToHankaku(string input, out string result, out string resultMessage)
|
||||
// {
|
||||
// result = input;
|
||||
// resultMessage = string.Empty;
|
||||
|
||||
// if (string.IsNullOrEmpty(input))
|
||||
// return true;
|
||||
|
||||
// // 全角カタカナが含まれているかチェック(ざっくり)
|
||||
// if (!Regex.IsMatch(input, @"[\u30A0-\u30FF]"))
|
||||
// return true;
|
||||
|
||||
// // 変換処理
|
||||
// result = Microsoft.VisualBasic.Strings.StrConv(input, Microsoft.VisualBasic.VbStrConv.Katakana | Microsoft.VisualBasic.VbStrConv.Narrow, 0);
|
||||
// return true;
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.Commons
|
||||
{
|
||||
public static class DateHelperUxer
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 指定した年と月の末日を返します。
|
||||
/// </summary>
|
||||
/// <param name="year">年(例: 2025)</param>
|
||||
/// <param name="month">月(1~12)</param>
|
||||
/// <returns>末日(28~31)</returns>
|
||||
public static bool TryGetLastDayOfMonth(int year, int month, out int matsubi,out string resultMessage)
|
||||
{
|
||||
matsubi = -1;
|
||||
resultMessage = string.Empty;
|
||||
|
||||
if (month < 1 || month > 12)
|
||||
{
|
||||
resultMessage = "月が1~12の範囲ではありません。";
|
||||
return false;
|
||||
}
|
||||
|
||||
// DateTime構造体を使って末日を取得
|
||||
matsubi = DateTime.DaysInMonth(year, month);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using KssSmaPlaLib.IO.File;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.Commons
|
||||
{
|
||||
public static class DictionaryUxer
|
||||
{
|
||||
// /// <summary>
|
||||
// /// 指定されたキーに対応する値(string)を取得します。キーが存在しない場合は 指定されたデフォルト値(未指定時はnull) を返します。
|
||||
// /// </summary>
|
||||
// public static TValue GetValueOrDefault<TKey, TValue>(
|
||||
// Dictionary<TKey, TValue> dict,
|
||||
// TKey key,
|
||||
// TValue defaultValue = default)
|
||||
// {
|
||||
// return dict.TryGetValue(key, out TValue value) ? value : defaultValue;
|
||||
// }
|
||||
|
||||
public static bool CreateNameToIdDic(string pcsv, out Dictionary<string,int> dic, out string resultMessage)
|
||||
{
|
||||
resultMessage = string.Empty;
|
||||
dic = new Dictionary<string,int>();
|
||||
|
||||
if (string.IsNullOrEmpty(pcsv)) return true;
|
||||
|
||||
var csvArray = pcsv.Split('|');
|
||||
foreach (var csv in csvArray)
|
||||
{
|
||||
var items = csv.Split(',');
|
||||
if (items.Length != 2)
|
||||
{
|
||||
resultMessage = $"要素数が{items.Length}個のCSVあり[CSV:{csv}]";
|
||||
return false;
|
||||
}
|
||||
|
||||
// IDの数値チェック
|
||||
if (!int.TryParse(items[1], out int id))
|
||||
{
|
||||
resultMessage = $"IDが数値でないCSVあり[CSV:{csv}]";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Nameのカンマ記号復元
|
||||
items[0] = items[0].Replace("@@@COMMA@@@", ",");
|
||||
|
||||
dic[items[0]] = id;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.Commons
|
||||
{
|
||||
public class EncodingUxer
|
||||
{
|
||||
#region 列挙体
|
||||
|
||||
public enum EncodingType
|
||||
{
|
||||
Utf8WithBom,
|
||||
Utf8WithoutBom,
|
||||
ShiftJIS
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static Encoding GetEncoding(EncodingType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case EncodingType.Utf8WithBom:
|
||||
return new UTF8Encoding(encoderShouldEmitUTF8Identifier: true); // BOMあり
|
||||
case EncodingType.Utf8WithoutBom:
|
||||
return new UTF8Encoding(encoderShouldEmitUTF8Identifier: false); // BOMなし
|
||||
case EncodingType.ShiftJIS:
|
||||
return Encoding.GetEncoding("shift_jis"); // ANSI(Windows-932)
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(type), "未対応のエンコーディングです");
|
||||
}
|
||||
}
|
||||
|
||||
public static EncodingType? GetEncodingType(string typeString)
|
||||
{
|
||||
typeString = typeString.ToLower();
|
||||
|
||||
if (StringUxer.WildcardMatch(typeString, "*utf*8*without*bom*"))
|
||||
return EncodingType.Utf8WithoutBom;
|
||||
if (StringUxer.WildcardMatch(typeString, "*utf*8*with*bom*"))
|
||||
return EncodingType.Utf8WithBom;
|
||||
if (StringUxer.WildcardMatch(typeString, "*utf*8*"))
|
||||
return EncodingType.Utf8WithoutBom;
|
||||
if (StringUxer.WildcardMatch(typeString, "*s*jis*"))
|
||||
return EncodingType.ShiftJIS;
|
||||
if (StringUxer.WildcardMatch(typeString, "*シ*jis*"))
|
||||
return EncodingType.ShiftJIS;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.Commons
|
||||
{
|
||||
public static class IntUxer
|
||||
{
|
||||
public static int StrToInt(string str, int defaultValue)
|
||||
{
|
||||
if (int.TryParse(str, out int intValue))
|
||||
{
|
||||
return intValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using KssSmaPlaLib.Ini;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace KssSmaPlaLib.Commons
|
||||
{
|
||||
/// <summary>
|
||||
/// ロガー
|
||||
/// </summary>
|
||||
public static class LoggerUxer
|
||||
{
|
||||
/// <summary>
|
||||
/// 初期化
|
||||
/// </summary>
|
||||
/// <param name="iniPath">ログINIファイルパス</param>
|
||||
public static void Initialize(string iniPath)
|
||||
{
|
||||
EnsureIniExists(iniPath);
|
||||
// var config = IniReferenceResolveUxer.ReadSectionWithReference(iniPath, "Logging");
|
||||
|
||||
var level = Enum.TryParse(
|
||||
//config["LogLevel"],
|
||||
IniHelper.ReadValue(iniPath, "Logging", "LogLevel"),
|
||||
out LogEventLevel parsedLevel)
|
||||
? parsedLevel
|
||||
: LogEventLevel.Information;
|
||||
|
||||
// var path = config["LogFilePath"];
|
||||
var path = IniHelper.ReadValue(iniPath, "Logging", "LogFilePath");
|
||||
var rolling = IniHelper.ReadValue(iniPath, "Logging", "RollingInterval");
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.MinimumLevel.Is(level)
|
||||
.WriteTo.Console()
|
||||
.WriteTo.File(path, rollingInterval: (RollingInterval)Enum.Parse(typeof(RollingInterval), rolling))
|
||||
.CreateLogger();
|
||||
}
|
||||
|
||||
public static void Info(string message) => Log.Information(message);
|
||||
public static void Warn(string message) => Log.Warning(message);
|
||||
public static void Error(string message) => Log.Error(message);
|
||||
public static void Close() => Log.CloseAndFlush();
|
||||
|
||||
public static void StartInfo()
|
||||
{
|
||||
// DLL(自身)のアセンブリ
|
||||
var dllAssembly = Assembly.GetExecutingAssembly();
|
||||
var dllVersion = dllAssembly.GetName().Version?.ToString();
|
||||
var dllProduct = dllAssembly.GetCustomAttribute<AssemblyProductAttribute>()?.Product ?? "不明";
|
||||
|
||||
// EXE(呼び出し元)のアセンブリ
|
||||
var exeAssembly = Assembly.GetEntryAssembly();
|
||||
var exeVersion = exeAssembly?.GetName().Version?.ToString();
|
||||
var exeProduct = exeAssembly?.GetCustomAttribute<AssemblyProductAttribute>()?.Product ?? "不明";
|
||||
|
||||
// ログ出力
|
||||
Info($"[EXE] 製品名: {exeProduct}, バージョン: {exeVersion}");
|
||||
Info($"[DLL] 製品名: {dllProduct}, バージョン: {dllVersion}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ログINI初期化(無ければ)
|
||||
/// </summary>
|
||||
/// <param name="path">ログINIファイルパス</param>
|
||||
private static void EnsureIniExists(string path)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
File.WriteAllLines(path, new[]
|
||||
{
|
||||
"[Logging]",
|
||||
"LogLevel=Information",
|
||||
"LogFilePath=log.txt",
|
||||
"RollingInterval=Day"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.Commons
|
||||
{
|
||||
public static class RetCodeUxer
|
||||
{
|
||||
/// <summary>
|
||||
/// 戻り値(プロセス終了値)
|
||||
/// </summary>
|
||||
public enum RetCode
|
||||
{
|
||||
/// <summary>
|
||||
/// 成功
|
||||
/// </summary>
|
||||
Success = 0,
|
||||
|
||||
/// <summary>
|
||||
/// ファイルバックアップ時エラー
|
||||
/// </summary>
|
||||
FileBackupError = -1,
|
||||
|
||||
/// <summary>
|
||||
/// ファイルクリーンナップエラー
|
||||
/// </summary>
|
||||
CleanupError = -2,
|
||||
|
||||
/// <summary>
|
||||
/// 開始日エラー
|
||||
/// </summary>
|
||||
StartDateError = -3,
|
||||
|
||||
/// <summary>
|
||||
/// DB接続エラー
|
||||
/// </summary>
|
||||
DbConnectError = -4,
|
||||
|
||||
/// <summary>
|
||||
/// SQLフォルダパス未設定
|
||||
/// </summary>
|
||||
SqlFolderPathNoSetting = -5,
|
||||
|
||||
/// <summary>
|
||||
/// SQLファイルロードエラー
|
||||
/// </summary>
|
||||
SqlFileLoadError = -6,
|
||||
|
||||
/// <summary>
|
||||
/// CSVファイル名パターン群が未設定
|
||||
/// </summary>
|
||||
CsvFileNamePatternsNotSetting = -7,
|
||||
|
||||
/// <summary>
|
||||
/// 設定ファイルの要素数エラー
|
||||
/// </summary>
|
||||
IniFileItemCountError = -8,
|
||||
|
||||
/// <summary>
|
||||
/// 挿入前の削除時に例外発生
|
||||
/// </summary>
|
||||
DeleteBeforeInsertException = -9,
|
||||
|
||||
/// <summary>
|
||||
/// CSVデータをDB登録時エラー
|
||||
/// </summary>
|
||||
InsertDbFromCsvFilesError = -10,
|
||||
|
||||
/// <summary>
|
||||
/// CSVからDB登録時に例外発生
|
||||
/// </summary>
|
||||
CsvToDbException = -11,
|
||||
|
||||
/// <summary>
|
||||
/// ファイル削除でフォルダパス未設定
|
||||
/// </summary>
|
||||
FileDeleteFolderPathNotSetting = -12,
|
||||
|
||||
/// <summary>
|
||||
/// ファイル削除でフォルダパス未存在
|
||||
/// </summary>
|
||||
FileDeleteFolderPathNotExist = -13,
|
||||
|
||||
/// <summary>
|
||||
/// ファイル削除でファイル名パターン未設定
|
||||
/// </summary>
|
||||
FileDeleteFileNamePatternNotSetting = -14,
|
||||
|
||||
/// <summary>
|
||||
/// ファイル削除でファイル名パターン削除エラー
|
||||
/// </summary>
|
||||
FileDeletePatternFilesError = -15,
|
||||
|
||||
/// <summary>
|
||||
/// SFTPオブジェクト生成エラー
|
||||
/// </summary>
|
||||
SftpObjectCreateError = -16,
|
||||
|
||||
/// <summary>
|
||||
/// SFTPアップロードエラー
|
||||
/// </summary>
|
||||
SftpUploadError = -17,
|
||||
|
||||
/// <summary>
|
||||
/// SFTPアップロードで入力フォルダ未存在
|
||||
/// </summary>
|
||||
SftpInFolderPathNotExist = -18,
|
||||
|
||||
/// <summary>
|
||||
/// SFTPでCSVファイル名パターンが未設定
|
||||
/// </summary>
|
||||
SftpCsvFileNamePatternsNotSetting = -19,
|
||||
|
||||
/// <summary>
|
||||
/// SFTPダウンロード時に例外発生
|
||||
/// </summary>
|
||||
SftpDownloadException = -20,
|
||||
|
||||
/// <summary>
|
||||
/// SFTPファイル削除エラー
|
||||
/// </summary>
|
||||
SftpDeleteMatchingFilesError = -21,
|
||||
|
||||
/// <summary>
|
||||
/// SFTPパターンマッチファイルダウンロード時エラー
|
||||
/// </summary>
|
||||
SftpMatchFilesDownloadError = -22,
|
||||
|
||||
/// <summary>
|
||||
/// SFTP共通:テスト接続エラー
|
||||
/// </summary>
|
||||
SftpTestConnectError = -23,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.Commons
|
||||
{
|
||||
public class StringUxer
|
||||
{
|
||||
public static bool WildcardMatch(string input, string pattern)
|
||||
{
|
||||
// "*" を ".*" に変換し、正規表現にする
|
||||
string regexPattern = "^" + Regex.Escape(pattern).Replace("\\*", ".*") + "$";
|
||||
return Regex.IsMatch(input, regexPattern, RegexOptions.IgnoreCase);
|
||||
}
|
||||
// public static bool TryParseIniSignature(string iniValue, out string functionName, out List<string> args)
|
||||
// {
|
||||
// functionName = null;
|
||||
// args = null;
|
||||
|
||||
// var pattern = @"^([a-zA-Z_][a-zA-Z0-9_]*)\((.*?)\)$";
|
||||
// var match = Regex.Match(iniValue.Trim(), pattern);
|
||||
|
||||
// if (!match.Success)
|
||||
// return false;
|
||||
|
||||
// functionName = match.Groups[1].Value;
|
||||
// var argsString = match.Groups[2].Value;
|
||||
|
||||
// args = string.IsNullOrEmpty(argsString)
|
||||
// ? new List<string>()
|
||||
// : argsString.Split(',').Select(arg => arg.Trim()).ToList();
|
||||
|
||||
// return true;
|
||||
// }
|
||||
|
||||
public static bool TryExtractYearFromString(string str, out int year)
|
||||
{
|
||||
// var match = Regex.Match(str, @"\b(20\d{2})\b"); // 条件厳しめ
|
||||
var match = Regex.Match(str, @"(20\d{2})"); // 条件緩め
|
||||
year = match.Success ? int.Parse(match.Groups[1].Value) : -1;
|
||||
return year != -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// CSVから文字列取得(インデックス指定:範囲外の時既定値)
|
||||
/// </summary>
|
||||
/// <param name="csv">CSV文字列(カンマ区切り)</param>
|
||||
/// <param name="index">インデックス</param>
|
||||
/// <param name="noString">範囲外の時の既定値</param>
|
||||
/// <returns>取得した文字列</returns>
|
||||
public static string GetStringByIndexFormCsv(string csv, int index, string noString = "(No name...)")
|
||||
{
|
||||
string[] strSplit = csv.Split(',');
|
||||
if (index < 0 || index > strSplit.Length - 1) return noString;
|
||||
return strSplit[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.Commons
|
||||
{
|
||||
public static class VariableUxer
|
||||
{
|
||||
private static List<string> _args = new List<string>();
|
||||
|
||||
public static List<string> Args { get => _args; }
|
||||
public static void SetArgs(string[] args) { _args = args.ToList(); }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user