131 lines
3.8 KiB
C#
131 lines
3.8 KiB
C#
using LCU.Library.Internal.FileOperationsModels.Models;
|
|
using LCU.Library.Internal.FileOperationsModels.Models.NameSettings;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using LCU.Library.Internal.FileOperationsModels.Models.Requests;
|
|
|
|
namespace LCU.Library.Internal.FileOperationsModels.Shared
|
|
{
|
|
public static class DynamicNameBuilder
|
|
{
|
|
public static List<TRequest> BuildListOfRequest<TRequest>(TRequest originalRequest) where TRequest : FileRequest
|
|
{
|
|
var nameList = RegexNameHandler.BuildFileList(originalRequest.SourcePath,
|
|
originalRequest.FinalSourceFile,
|
|
originalRequest.FileNameSetting);
|
|
var requests = new List<TRequest>();
|
|
|
|
foreach (var name in nameList)
|
|
{
|
|
var newRequest = originalRequest.DeepClone();
|
|
newRequest.SourceFile = name;
|
|
|
|
requests.Add(newRequest);
|
|
}
|
|
|
|
return requests;
|
|
}
|
|
|
|
public static List<TRequest> BuildListOfRequests<TRequest>(TRequest originalRequest) where TRequest : IFileSourceRequest
|
|
{
|
|
var nameList = RegexNameHandler.BuildFileList(originalRequest.FileSourceRequest.FinalSourcePath,
|
|
originalRequest.FileSourceRequest.FinalSourceFile,
|
|
originalRequest.FileSourceRequest.SourceFileSettings);
|
|
|
|
var requests = new List<TRequest>();
|
|
|
|
foreach (var name in nameList)
|
|
{
|
|
var newRequest = originalRequest.DeepClone();
|
|
newRequest.FileSourceRequest.SourceFile = name;
|
|
|
|
requests.Add(newRequest);
|
|
}
|
|
|
|
return requests;
|
|
}
|
|
|
|
public static List<ModifyFileRequest> BuildListOfRequest(ModifyFileRequest originalRequest)
|
|
{
|
|
var nameList = RegexNameHandler.BuildFileList(originalRequest.SourcePath,
|
|
originalRequest.OriginalSourceFile,
|
|
originalRequest.FileNameSetting);
|
|
|
|
var requests = new List<ModifyFileRequest>();
|
|
|
|
foreach (var name in nameList)
|
|
{
|
|
var newRequest = originalRequest.DeepClone();
|
|
newRequest.SourceFile = ModifyFileRequest.GetNameWithoutExtension(name, newRequest.SourceExtension);
|
|
|
|
requests.Add(newRequest);
|
|
}
|
|
|
|
return requests;
|
|
}
|
|
|
|
[Obsolete ("As of 7/7/2025, this method is obsolete. Use BuildListOfRequests instead.")]
|
|
public static List<ExtractIndexFileDataRequest> BuildListOfRequest(ExtractIndexFileDataRequest originalRequest)
|
|
{
|
|
var nameList = RegexNameHandler.BuildFileList(originalRequest.FinalIndexFileDirectory,
|
|
originalRequest.FinalIndexFileName,
|
|
originalRequest.IndexFileNameSetting);
|
|
|
|
var requests = new List<ExtractIndexFileDataRequest>();
|
|
|
|
foreach (var name in nameList)
|
|
{
|
|
var newRequest = originalRequest.DeepClone();
|
|
newRequest.IndexFileName = name;
|
|
|
|
requests.Add(newRequest);
|
|
}
|
|
|
|
return requests;
|
|
}
|
|
|
|
public static string BuildDynamicName(string name, DynamicNameSetting nameSetting)
|
|
{
|
|
if (nameSetting == null ||
|
|
nameSetting.DateFormatSettings == null)
|
|
{
|
|
return name;
|
|
}
|
|
|
|
name = AddFormattedDateSettings(name, nameSetting);
|
|
return name;
|
|
}
|
|
|
|
public static string AddFormattedDateSettings(string name, DynamicNameSetting nameSettings)
|
|
{
|
|
foreach (var formatSetting in nameSettings.DateFormatSettings)
|
|
{
|
|
var convertedFormat = DateTimeStringBuilder(formatSetting.DateFormat, nameSettings.DaysFromToday);
|
|
name = ReplaceTagWithFormattedSTring(name, formatSetting.Tag, convertedFormat);
|
|
}
|
|
|
|
return name;
|
|
}
|
|
|
|
public static string DateTimeStringBuilder(string format, int daysFromToday)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(format))
|
|
{
|
|
return "";
|
|
}
|
|
|
|
return DateTime.Now.AddDays(daysFromToday).ToString(format);
|
|
}
|
|
|
|
public static string ReplaceTagWithFormattedSTring(string name, string tag, string convertedFormat)
|
|
{
|
|
if (string.IsNullOrEmpty(tag) || string.IsNullOrWhiteSpace(convertedFormat))
|
|
{
|
|
return name.Trim();
|
|
}
|
|
|
|
return name.Replace(tag, convertedFormat);
|
|
}
|
|
}
|
|
}
|