97 lines
3.6 KiB
C#
97 lines
3.6 KiB
C#
using KssSmaPlaLib.Commons;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace KssSmaPlaLib.Batch.Commons
|
|
{
|
|
public static class CommonUxer
|
|
{
|
|
public const string DIC_KEY_TITLE = "Title";
|
|
public const string DIC_KEY_DAYS_TO_START_OFFSET = "DaysToStartOffset";
|
|
public const string DIC_KEY_DAYS_TO_END_OFFSET = "DaysToEndOffset";
|
|
|
|
public static bool TryGetStartDate(Dictionary<string, string> iniDic, out DateTime startDate, out string resultMessage)
|
|
{
|
|
startDate = DateTime.Today;
|
|
resultMessage = string.Empty;
|
|
|
|
// 開始日
|
|
DateTime? fromDate = null;
|
|
if (VariableUxer.Args.Count >= 2)
|
|
{
|
|
if (DateTime.TryParseExact(
|
|
VariableUxer.Args[1].Substring(1),
|
|
"yyyy/MM/dd",
|
|
CultureInfo.InvariantCulture,
|
|
DateTimeStyles.None,
|
|
out var d) == false)
|
|
{
|
|
resultMessage = $"起動時パラメータの開始日(第2引数)が不正です。[起動時パラメータ:{string.Join(",", VariableUxer.Args)}]";
|
|
return false;
|
|
}
|
|
fromDate = d;
|
|
}
|
|
|
|
// 起動時パラメータで開始日指定あり
|
|
if (fromDate != null)
|
|
{
|
|
startDate = (DateTime)fromDate;
|
|
return true;
|
|
}
|
|
|
|
// 起動時パラメータで開始日指定なし
|
|
|
|
// オフセット日数取得
|
|
var daysToStartOffset = DictionaryUxer.GetValueOrDefault(iniDic, DIC_KEY_DAYS_TO_START_OFFSET, "0");
|
|
|
|
if (int.TryParse(daysToStartOffset, out var days) == false)
|
|
{
|
|
// 加算日数エラー
|
|
resultMessage = $"設定ファイルの開始日オフセット(加算日数)の設定値が不正です。[{daysToStartOffset}]";
|
|
return false;
|
|
}
|
|
// システム日付(本日日)に加算日数を加算して開始日とする
|
|
startDate = DateTime.Today.AddDays(days);
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 終了日のオフセット指定があるときだけ、終了日を取得する
|
|
/// </summary>
|
|
/// <param name="iniDic"></param>
|
|
/// <param name="startDate"></param>
|
|
/// <param name="endDate"></param>
|
|
/// <param name="resultMessage"></param>
|
|
/// <returns></returns>
|
|
public static bool TryGetEndDate(Dictionary<string, string> iniDic, DateTime startDate, out DateTime? endDate, out string resultMessage)
|
|
{
|
|
endDate = null;
|
|
resultMessage = string.Empty;
|
|
|
|
// オフセット日数取得
|
|
var daysToEndOffset = DictionaryUxer.GetValueOrDefault(iniDic, DIC_KEY_DAYS_TO_END_OFFSET, string.Empty);
|
|
|
|
if (string.IsNullOrEmpty(daysToEndOffset))
|
|
{
|
|
// オフセット日数なしのとき、終了日なし
|
|
return true;
|
|
}
|
|
|
|
if (int.TryParse(daysToEndOffset, out var days) == false)
|
|
{
|
|
// 加算日数エラー
|
|
resultMessage = $"設定ファイルの終了日オフセット(加算日数)の設定値が不正です。[{daysToEndOffset}]";
|
|
return false;
|
|
}
|
|
|
|
// 開始日に加算日数を加算して終了日とする
|
|
endDate = startDate.AddDays(days);
|
|
return true;
|
|
}
|
|
}
|
|
}
|