Removed IntelligentIdRecord
This commit is contained in:
@ -1,33 +1,31 @@
|
||||
using System.Text;
|
||||
using View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
namespace View_by_Distance.Shared.Models.Stateless;
|
||||
|
||||
internal abstract class Id
|
||||
{
|
||||
|
||||
internal static bool NameWithoutExtensionIsIdFormat(string fileNameFirstSegment)
|
||||
internal static bool NameWithoutExtensionIsIdFormat(MetadataConfiguration metadataConfiguration, string fileNameFirstSegment)
|
||||
{
|
||||
bool result;
|
||||
int intMinValueLength = int.MinValue.ToString().Length;
|
||||
if (fileNameFirstSegment.Length < 5 || fileNameFirstSegment.Length > intMinValueLength)
|
||||
if (fileNameFirstSegment.Length < 5 || fileNameFirstSegment.Length > metadataConfiguration.IntMinValueLength)
|
||||
result = false;
|
||||
else
|
||||
{
|
||||
bool skipOneAllAreNumbers = fileNameFirstSegment[1..].All(l => char.IsNumber(l));
|
||||
bool skipOneAllAreNumbers = fileNameFirstSegment[1..].All(char.IsNumber);
|
||||
result = (skipOneAllAreNumbers && fileNameFirstSegment[0] == '-') || (skipOneAllAreNumbers && char.IsNumber(fileNameFirstSegment[0]));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int GetId(MetadataConfiguration metadataConfiguration, string intelligentId)
|
||||
internal static int GetId(MetadataConfiguration metadataConfiguration, string intelligentId)
|
||||
{
|
||||
int result;
|
||||
StringBuilder results = new();
|
||||
if (metadataConfiguration.IntMinValueLength < 4)
|
||||
if (metadataConfiguration.IntMinValueLength < (metadataConfiguration.ResultConfiguration.ResultAllInOneSubdirectoryLength + 2))
|
||||
throw new NotSupportedException();
|
||||
for (int j = intelligentId.Length - 4; j > -1; j--)
|
||||
_ = results.Append(intelligentId[j]);
|
||||
for (int i = intelligentId.Length - (metadataConfiguration.ResultConfiguration.ResultAllInOneSubdirectoryLength + 2); i > -1; i--)
|
||||
_ = results.Append(intelligentId[i]);
|
||||
_ = results.Append(intelligentId[^3]).Append(intelligentId[^2]);
|
||||
result = int.Parse(results.ToString());
|
||||
if (intelligentId[^1] is '1' or '2')
|
||||
@ -37,14 +35,15 @@ internal abstract class Id
|
||||
return result;
|
||||
}
|
||||
|
||||
private static IntelligentIdRecord GetIntelligentIdRecord(MetadataConfiguration metadataConfiguration, long id, bool ignore)
|
||||
internal static string GetIntelligentId(MetadataConfiguration metadataConfiguration, long id, bool ignore)
|
||||
{
|
||||
IntelligentIdRecord result;
|
||||
string result;
|
||||
StringBuilder stringBuilder = new();
|
||||
if (metadataConfiguration.IntMinValueLength < 4)
|
||||
if (metadataConfiguration.IntMinValueLength < (metadataConfiguration.ResultConfiguration.ResultAllInOneSubdirectoryLength + 2))
|
||||
throw new NotSupportedException();
|
||||
int key;
|
||||
string value;
|
||||
List<char> resultAllInOneSubdirectoryChars = [];
|
||||
if (id > -1)
|
||||
{
|
||||
key = ignore ? 8 : 9;
|
||||
@ -55,20 +54,18 @@ internal abstract class Id
|
||||
key = ignore ? 2 : 1;
|
||||
value = id.ToString()[1..].PadLeft(metadataConfiguration.IntMinValueLength, '0');
|
||||
}
|
||||
for (int j = value.Length - 3; j > -1; j--)
|
||||
_ = stringBuilder.Append(value[j]);
|
||||
result = new(key, value[^2], value[^1], stringBuilder.ToString());
|
||||
for (int i = value.Length - metadataConfiguration.ResultConfiguration.ResultAllInOneSubdirectoryLength - 1; i > -1; i--)
|
||||
_ = stringBuilder.Append(value[i]);
|
||||
for (int i = value.Length - metadataConfiguration.ResultConfiguration.ResultAllInOneSubdirectoryLength; i < value.Length; i++)
|
||||
resultAllInOneSubdirectoryChars.Add(value[i]);
|
||||
result = $"{stringBuilder}{string.Join(string.Empty, resultAllInOneSubdirectoryChars)}{key}";
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string GetIntelligentId(IntelligentIdRecord intelligentId) =>
|
||||
$"{intelligentId.Reverse}{intelligentId.GroupChar2}{intelligentId.GroupChar1}{intelligentId.Key}";
|
||||
|
||||
internal static string GetPaddedId(MetadataConfiguration metadataConfiguration, int index, int id)
|
||||
{
|
||||
string result;
|
||||
IntelligentIdRecord intelligentIdRecord = GetIntelligentIdRecord(metadataConfiguration, id, ignore: false);
|
||||
string intelligentId = GetIntelligentId(intelligentIdRecord);
|
||||
string intelligentId = GetIntelligentId(metadataConfiguration, id, ignore: false);
|
||||
int check = GetId(metadataConfiguration, intelligentId);
|
||||
if (check != id)
|
||||
throw new NotSupportedException();
|
||||
@ -76,46 +73,6 @@ internal abstract class Id
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static FilePath GetFilePath(MetadataConfiguration metadataConfiguration, string file, int? index)
|
||||
{
|
||||
FilePath result;
|
||||
int? id;
|
||||
int? sortOder;
|
||||
string fileName = Path.GetFileName(file);
|
||||
string[] segments = Path.GetFileName(fileName).Split('.');
|
||||
string fileExtensionLowered = Path.GetExtension(file).ToLower();
|
||||
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file);
|
||||
string fileDirectoryName = Path.GetDirectoryName(file) ?? throw new NullReferenceException();
|
||||
short sortOrderOnlyLengthIndex = IId.GetSortOrderOnlyLengthIndex(metadataConfiguration);
|
||||
string fileNameFirstSegment = segments[0];
|
||||
bool fileNameFirstSegmentIsIntelligentIdFormat = IId.NameWithoutExtensionIsIntelligentIdFormat(metadataConfiguration, fileNameFirstSegment);
|
||||
bool fileNameFirstSegmentIsPaddedIntelligentIdFormat = IId.NameWithoutExtensionIsPaddedIntelligentIdFormat(metadataConfiguration, sortOrderOnlyLengthIndex, fileNameFirstSegment);
|
||||
bool fileNameFirstSegmentIsIdFormat = !fileNameFirstSegmentIsPaddedIntelligentIdFormat && !fileNameFirstSegmentIsIntelligentIdFormat && IId.NameWithoutExtensionIsIdFormat(fileNameFirstSegment);
|
||||
if (fileNameFirstSegmentIsIdFormat)
|
||||
{
|
||||
if (index is null)
|
||||
throw new NullReferenceException(nameof(index));
|
||||
if (!int.TryParse(fileNameFirstSegment, out int valueOfFileNameFirstSegment))
|
||||
throw new NotSupportedException();
|
||||
(id, sortOder) = (valueOfFileNameFirstSegment, metadataConfiguration.Offset + index);
|
||||
}
|
||||
else if (!fileNameFirstSegmentIsIntelligentIdFormat && !fileNameFirstSegmentIsPaddedIntelligentIdFormat)
|
||||
(id, sortOder) = (null, null);
|
||||
else if (fileNameFirstSegmentIsIntelligentIdFormat)
|
||||
(id, sortOder) = (GetId(metadataConfiguration, fileNameFirstSegment), null);
|
||||
else if (fileNameFirstSegmentIsPaddedIntelligentIdFormat)
|
||||
{
|
||||
if (!int.TryParse(fileNameFirstSegment[..sortOrderOnlyLengthIndex], out int absoluteValueOfSortOrder))
|
||||
(id, sortOder) = (null, null);
|
||||
else
|
||||
(id, sortOder) = (GetId(metadataConfiguration, fileNameFirstSegment[sortOrderOnlyLengthIndex..]), absoluteValueOfSortOrder);
|
||||
}
|
||||
else
|
||||
throw new NotSupportedException();
|
||||
result = new(fileDirectoryName, fileExtensionLowered, fileNameFirstSegment, file, id, fileNameFirstSegmentIsIntelligentIdFormat, fileName, fileNameWithoutExtension, sortOder);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static int GetDeterministicHashCode(byte[] value)
|
||||
{
|
||||
int result;
|
||||
|
Reference in New Issue
Block a user