Init
This commit is contained in:
148
Shared/Models/Stateless/IExif.cs
Normal file
148
Shared/Models/Stateless/IExif.cs
Normal file
@ -0,0 +1,148 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless;
|
||||
|
||||
public interface IExif
|
||||
{
|
||||
|
||||
enum Tags : ushort
|
||||
{
|
||||
GPSVersionID = 0,
|
||||
GPSLatitudeRef = 1,
|
||||
GPSLatitude = 2,
|
||||
GPSLongitudeRef = 3,
|
||||
GPSLongitude = 4,
|
||||
GPSAltitudeRef = 5,
|
||||
GPSAltitude = 6,
|
||||
GPSTimestamp = 7,
|
||||
GPSSatellites = 8,
|
||||
GPSStatus = 9,
|
||||
GPSMeasureMode = 10,
|
||||
GPSDOP = 11,
|
||||
GPSSpeedRef = 12,
|
||||
GPSSpeed = 13,
|
||||
GPSTrackRef = 14,
|
||||
GPSTrack = 15,
|
||||
GPSImgDirectionRef = 16,
|
||||
GPSImgDirection = 17,
|
||||
GPSMapDatum = 18,
|
||||
GPSDestLatitudeRef = 19,
|
||||
GPSDestLatitude = 20,
|
||||
GPSDestLongitudeRef = 21,
|
||||
GPSDestLongitude = 22,
|
||||
GPSDestBearingRef = 23,
|
||||
GPSDestBearing = 24,
|
||||
GPSDestDistanceRef = 25,
|
||||
GPSDestDistance = 26,
|
||||
GPSProcessingMethod = 27,
|
||||
GPSAreaInformation = 28,
|
||||
GPSDateStamp = 29,
|
||||
GPSDifferential = 30,
|
||||
GPSHPositioningError = 31,
|
||||
ImageWidth = 256,
|
||||
ImageLength = 257,
|
||||
BitsPerSample = 258,
|
||||
Compression = 259,
|
||||
PhotometricInterpretation = 262,
|
||||
ImageDescription = 270,
|
||||
Make = 271,
|
||||
Model = 272,
|
||||
StripOffsets = 273,
|
||||
Orientation = 274,
|
||||
SamplesPerPixel = 277,
|
||||
RowsPerStrip = 278,
|
||||
StripByteCounts = 279,
|
||||
XResolution = 282,
|
||||
YResolution = 283,
|
||||
PlanarConfiguration = 284,
|
||||
ResolutionUnit = 296,
|
||||
TransferFunction = 301,
|
||||
Software = 305,
|
||||
DateTime = 306,
|
||||
Artist = 315,
|
||||
WhitePoint = 318,
|
||||
PrimaryChromaticities = 319,
|
||||
JPEGInterchangeFormat = 513,
|
||||
JPEGInterchangeFormatLength = 514,
|
||||
YCbCrCoefficients = 529,
|
||||
YCbCrSubSampling = 530,
|
||||
YCbCrPositioning = 531,
|
||||
ReferenceBlackWhite = 532,
|
||||
Copyright = 33432,
|
||||
ExposureTime = 33434,
|
||||
FNumber = 33437,
|
||||
ExposureProgram = 34850,
|
||||
SpectralSensitivity = 34852,
|
||||
ISOSpeedRatings = 34855,
|
||||
#pragma warning disable CA1069
|
||||
PhotographicSensitivity = 34855,
|
||||
#pragma warning restore CA1069
|
||||
OECF = 34856,
|
||||
SensitivityType = 34864,
|
||||
StandardOutputSensitivity = 34865,
|
||||
RecommendedExposureIndex = 34866,
|
||||
ISOSpeed = 34867,
|
||||
ISOSpeedLatitudeyyy = 34868,
|
||||
ISOSpeedLatitudezzz = 34869,
|
||||
ExifVersion = 36864,
|
||||
DateTimeOriginal = 36867,
|
||||
DateTimeDigitized = 36868,
|
||||
ComponentsConfiguration = 37121,
|
||||
CompressedBitsPerPixel = 37122,
|
||||
ShutterSpeedValue = 37377,
|
||||
ApertureValue = 37378,
|
||||
BrightnessValue = 37379,
|
||||
ExposureBiasValue = 37380,
|
||||
MaxApertureValue = 37381,
|
||||
SubjectDistance = 37382,
|
||||
MeteringMode = 37383,
|
||||
LightSource = 37384,
|
||||
Flash = 37385,
|
||||
FocalLength = 37386,
|
||||
SubjectArea = 37396,
|
||||
MakerNote = 37500,
|
||||
UserComment = 37510,
|
||||
SubsecTime = 37520,
|
||||
SubsecTimeOriginal = 37521,
|
||||
SubsecTimeDigitized = 37522,
|
||||
XPTitle = 40091,
|
||||
XPComment = 40092,
|
||||
XPAuthor = 40093,
|
||||
XPKeywords = 40094,
|
||||
XPSubject = 40095,
|
||||
FlashpixVersion = 40960,
|
||||
ColorSpace = 40961,
|
||||
PixelXDimension = 40962,
|
||||
PixelYDimension = 40963,
|
||||
RelatedSoundFile = 40964,
|
||||
FlashEnergy = 41483,
|
||||
SpatialFrequencyResponse = 41484,
|
||||
FocalPlaneXResolution = 41486,
|
||||
FocalPlaneYResolution = 41487,
|
||||
FocalPlaneResolutionUnit = 41488,
|
||||
SubjectLocation = 41492,
|
||||
ExposureIndex = 41493,
|
||||
SensingMethod = 41495,
|
||||
FileSource = 41728,
|
||||
SceneType = 41729,
|
||||
CFAPattern = 41730,
|
||||
CustomRendered = 41985,
|
||||
ExposureMode = 41986,
|
||||
WhiteBalance = 41987,
|
||||
DigitalZoomRatio = 41988,
|
||||
FocalLengthIn35mmFilm = 41989,
|
||||
SceneCaptureType = 41990,
|
||||
GainControl = 41991,
|
||||
Contrast = 41992,
|
||||
Saturation = 41993,
|
||||
Sharpness = 41994,
|
||||
DeviceSettingDescription = 41995,
|
||||
SubjectDistanceRange = 41996,
|
||||
ImageUniqueID = 42016,
|
||||
CameraOwnerName = 42032,
|
||||
BodySerialNumber = 42033,
|
||||
LensSpecification = 42034,
|
||||
LensMake = 42035,
|
||||
LensModel = 42036,
|
||||
LensSerialNumber = 42037
|
||||
}
|
||||
|
||||
}
|
0
Shared/Models/Stateless/Methods/%ClassName%.cs .ai
Normal file
0
Shared/Models/Stateless/Methods/%ClassName%.cs .ai
Normal file
99
Shared/Models/Stateless/Methods/Face.cs
Normal file
99
Shared/Models/Stateless/Methods/Face.cs
Normal file
@ -0,0 +1,99 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class Face
|
||||
{
|
||||
|
||||
internal static string GetJson(string jsonFileFullName)
|
||||
{
|
||||
string result;
|
||||
FileInfo fileInfo;
|
||||
string fileSegment = "FileSegment";
|
||||
result = File.ReadAllText(jsonFileFullName);
|
||||
if (result.Contains(fileSegment))
|
||||
{
|
||||
fileInfo = new FileInfo(jsonFileFullName);
|
||||
result = result.Replace(fileSegment, nameof(Properties.IIndex.RelativePaths)).Replace("\\\\", "/");
|
||||
File.WriteAllText(fileInfo.FullName, result);
|
||||
File.SetLastWriteTime(fileInfo.FullName, fileInfo.LastWriteTime);
|
||||
}
|
||||
if (result.Contains("/u0"))
|
||||
{
|
||||
fileInfo = new FileInfo(jsonFileFullName);
|
||||
result = result.Replace("/u0", "\\u0");
|
||||
File.WriteAllText(fileInfo.FullName, result);
|
||||
File.SetLastWriteTime(fileInfo.FullName, fileInfo.LastWriteTime);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static JsonElement[] GetJsonElements(string jsonFileFullName)
|
||||
{
|
||||
string json = GetJson(jsonFileFullName);
|
||||
JsonElement[]? jsonElements = JsonSerializer.Deserialize<JsonElement[]>(json);
|
||||
if (jsonElements is null)
|
||||
throw new Exception();
|
||||
return jsonElements;
|
||||
}
|
||||
|
||||
private static List<Models.Face> GetFaces(string jsonFileFullName, int? maximum)
|
||||
{
|
||||
List<Models.Face> results = new();
|
||||
Tuple<Models.Face, string>? tuple;
|
||||
JsonElement[] jsonElements = GetJsonElements(jsonFileFullName);
|
||||
foreach (JsonElement jsonElement in jsonElements)
|
||||
{
|
||||
tuple = JsonSerializer.Deserialize<Tuple<Models.Face, string>>(jsonElement.ToString());
|
||||
if (tuple is null || tuple.Item1 is null || string.IsNullOrEmpty(tuple.Item1.RelativePath))
|
||||
continue;
|
||||
results.Add(tuple.Item1);
|
||||
if (maximum.HasValue && results.Count >= maximum)
|
||||
break;
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static Models.Face GetFace(string jsonFileFullName)
|
||||
{
|
||||
Models.Face? result;
|
||||
List<Models.Face> results = GetFaces(jsonFileFullName, maximum: 1);
|
||||
if (!results.Any())
|
||||
throw new Exception();
|
||||
result = results[0];
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static Models.Face[] GetFaces(string jsonFileFullName)
|
||||
{
|
||||
List<Models.Face> results = GetFaces(jsonFileFullName, maximum: null);
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
internal static double Getα(int x1, int x2, int y1, int y2)
|
||||
{
|
||||
double result;
|
||||
if (y1 == y2)
|
||||
result = 0;
|
||||
else
|
||||
{
|
||||
int b;
|
||||
if (x1 > x2)
|
||||
b = x1 - x2;
|
||||
else
|
||||
b = x2 - x1;
|
||||
int a;
|
||||
if (y1 > y2)
|
||||
a = y1 - y2;
|
||||
else
|
||||
a = y2 - y1;
|
||||
double c = Math.Sqrt(Math.Pow(a, 2) + Math.Pow(b, 2));
|
||||
if (y1 < y2)
|
||||
result = (180 / Math.PI) * Math.Asin(a / c);
|
||||
else
|
||||
result = (180 / Math.PI) * Math.Asin(a / c) * -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
83
Shared/Models/Stateless/Methods/FaceFileSystem.cs
Normal file
83
Shared/Models/Stateless/Methods/FaceFileSystem.cs
Normal file
@ -0,0 +1,83 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class FaceFileSystem
|
||||
{ // ...
|
||||
|
||||
internal static void SearchForMissingFile(string fullFileName, FileInfo fileInfo, string dataFullFileName)
|
||||
{
|
||||
if (fileInfo is null || string.IsNullOrEmpty(fileInfo.FullName))
|
||||
fileInfo = new FileInfo(fullFileName);
|
||||
if (Directory.Exists(fileInfo.DirectoryName))
|
||||
throw new Exception($"File [{fileInfo.Name}] <{fullFileName}> doesn't exist!");
|
||||
else
|
||||
{
|
||||
string? parentDirectoryName = Path.GetDirectoryName(fileInfo.DirectoryName);
|
||||
if (!Directory.Exists(parentDirectoryName))
|
||||
throw new Exception($"Parent directory <{parentDirectoryName}> doesn't exist!");
|
||||
else
|
||||
{
|
||||
string[] files = Directory.GetFiles(parentDirectoryName, Path.GetFileName(fullFileName), SearchOption.AllDirectories);
|
||||
if (!files.Any())
|
||||
throw new Exception($"File [{fileInfo.Name}] <{fullFileName}> doesn't exist (deep search)!");
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(dataFullFileName) && !dataFullFileName.EndsWith(".json"))
|
||||
throw new Exception($"Maybe file <{Path.GetFileNameWithoutExtension(fullFileName)}> was moved to <{files[0]}>!");
|
||||
else
|
||||
{
|
||||
string json = File.ReadAllText(dataFullFileName);
|
||||
if (!json.Contains("MesaFab"))
|
||||
throw new Exception($"Maybe file <{Path.GetFileNameWithoutExtension(fullFileName)}> was moved to <{files[0]}> (unkown)!");
|
||||
else
|
||||
{
|
||||
json = json.Replace("MesaFab", "Mesa Fab");
|
||||
fileInfo = new FileInfo(dataFullFileName);
|
||||
File.WriteAllText(fileInfo.FullName, json);
|
||||
File.SetLastWriteTime(fileInfo.FullName, fileInfo.LastWriteTime);
|
||||
_ = new FileInfo(fullFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static Models.FaceFileSystem[] GetFaceFileSystemCollection(string requestPath, (string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) tuple, string selectedFileFullName)
|
||||
{
|
||||
List<Models.FaceFileSystem> results = new();
|
||||
FileInfo fileInfo;
|
||||
int? locationIndex;
|
||||
string jsonFileName;
|
||||
string? directoryName;
|
||||
string fileNameWithoutExtension;
|
||||
Models.FaceFileSystem faceFileSystem;
|
||||
string eDistanceCollectionfileFullName;
|
||||
Models.Face[] face = Face.GetFaces(selectedFileFullName);
|
||||
string extension = Path.GetExtension(selectedFileFullName);
|
||||
for (int i = 0; i < face.Length; i++)
|
||||
{
|
||||
if (face[i] is null)
|
||||
continue;
|
||||
locationIndex = face[i].LocationIndex;
|
||||
if (locationIndex is null)
|
||||
locationIndex = 0;
|
||||
else
|
||||
locationIndex = locationIndex.Value;
|
||||
directoryName = Path.GetDirectoryName(face[i].RelativePath);
|
||||
if (directoryName is null)
|
||||
continue;
|
||||
fileNameWithoutExtension = Path.GetFileNameWithoutExtension(face[i].RelativePath);
|
||||
jsonFileName = string.Concat(locationIndex.Value, " - ", fileNameWithoutExtension, extension);
|
||||
eDistanceCollectionfileFullName = string.Concat(tuple.E_DistanceCollectionDirectory, Path.Combine(directoryName, fileNameWithoutExtension, jsonFileName));
|
||||
if (i == 0 && extension is ".json" && eDistanceCollectionfileFullName != selectedFileFullName)
|
||||
throw new Exception();
|
||||
fileInfo = new(eDistanceCollectionfileFullName);
|
||||
if (!fileInfo.Exists)
|
||||
throw new Exception($"File <{eDistanceCollectionfileFullName}> doesn't exist!");
|
||||
faceFileSystem = new Models.FaceFileSystem(requestPath, tuple.RootResultsDirectoryAbsoluteUri.Length, tuple.C_ResizeContentDirectory, tuple.D_FacesContentDirectory, fileInfo.FullName, face[i]);
|
||||
results.Add(faceFileSystem);
|
||||
}
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
}
|
50
Shared/Models/Stateless/Methods/FileSystem.cs
Normal file
50
Shared/Models/Stateless/Methods/FileSystem.cs
Normal file
@ -0,0 +1,50 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class FileSystem
|
||||
{ // ...
|
||||
|
||||
internal static List<Models.FileSystem> GetFileSystemCollection(string requestPath, (string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) tuple, string[] directories, string[] files, bool all)
|
||||
{
|
||||
List<Models.FileSystem> results = new();
|
||||
Models.Face face;
|
||||
DirectoryInfo directoryInfo;
|
||||
Models.FileSystem fileSystem;
|
||||
Models.FaceFileSystem faceFileSystem;
|
||||
IEnumerator<string> subDirectoryFiles;
|
||||
List<Models.FaceFileSystem> faceFileSystemCollection = new();
|
||||
for (int i = 0; i < directories.Length; i++)
|
||||
{
|
||||
subDirectoryFiles = Directory.EnumerateFiles(directories[i], "*.json", SearchOption.TopDirectoryOnly).GetEnumerator();
|
||||
if (!subDirectoryFiles.MoveNext())
|
||||
{
|
||||
directoryInfo = new(directories[i]);
|
||||
fileSystem = new Models.DirectoryFileSystem(directoryInfo);
|
||||
results.Add(fileSystem);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int j = 0; j < int.MaxValue; j++)
|
||||
{
|
||||
face = Face.GetFace(subDirectoryFiles.Current);
|
||||
faceFileSystem = new Models.FaceFileSystem(requestPath, tuple.RootResultsDirectoryAbsoluteUri.Length, tuple.C_ResizeContentDirectory, tuple.D_FacesContentDirectory, subDirectoryFiles.Current, face);
|
||||
if (!all)
|
||||
results.Add(faceFileSystem);
|
||||
else
|
||||
faceFileSystemCollection.Add(faceFileSystem);
|
||||
if (!all || !subDirectoryFiles.MoveNext())
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
{
|
||||
face = Face.GetFace(files[i]);
|
||||
faceFileSystem = new Models.FaceFileSystem(requestPath, tuple.RootResultsDirectoryAbsoluteUri.Length, tuple.C_ResizeContentDirectory, tuple.D_FacesContentDirectory, files[i], face);
|
||||
results.Add(faceFileSystem);
|
||||
}
|
||||
if (all)
|
||||
results.AddRange(faceFileSystemCollection);
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
0
Shared/Models/Stateless/Methods/I%ClassName%.cs .ai
Normal file
0
Shared/Models/Stateless/Methods/I%ClassName%.cs .ai
Normal file
10
Shared/Models/Stateless/Methods/IBackgroundPage.cs
Normal file
10
Shared/Models/Stateless/Methods/IBackgroundPage.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IBackgroundPage
|
||||
{
|
||||
|
||||
void OnGet(bool? message_clear = null, bool? exceptions_clear = null, bool? set_is_primary_instance = null);
|
||||
|
||||
static string GetRouteName() => nameof(IBackgroundPage).Replace("Page", string.Empty)[1..];
|
||||
|
||||
}
|
6
Shared/Models/Stateless/Methods/IDirectoryFileSystem.cs
Normal file
6
Shared/Models/Stateless/Methods/IDirectoryFileSystem.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
public interface IDirectoryFileSystem
|
||||
{
|
||||
|
||||
}
|
16
Shared/Models/Stateless/Methods/IFace.cs
Normal file
16
Shared/Models/Stateless/Methods/IFace.cs
Normal file
@ -0,0 +1,16 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IFace
|
||||
{ // ...
|
||||
|
||||
double TestStatic_Getα(int x1, int x2, int y1, int y2);
|
||||
string TestStatic_GetJson(string jsonFileFullName);
|
||||
Models.Face TestStatic_GetFace(string jsonFileFullName);
|
||||
Models.Face[] TestStatic_GetFaces(string jsonFileFullName);
|
||||
|
||||
static double Getα(int x1, int x2, int y1, int y2) => Face.Getα(x1, x2, y1, y2);
|
||||
static string GetJson(string jsonFileFullName) => Face.GetJson(jsonFileFullName);
|
||||
static Models.Face GetFace(string jsonFileFullName) => Face.GetFace(jsonFileFullName);
|
||||
static Models.Face[] GetFaces(string jsonFileFullName) => Face.GetFaces(jsonFileFullName);
|
||||
|
||||
}
|
12
Shared/Models/Stateless/Methods/IFaceFileSystem.cs
Normal file
12
Shared/Models/Stateless/Methods/IFaceFileSystem.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IFaceFileSystem : IFileSystem
|
||||
{ // ...
|
||||
|
||||
void TestStatic_SearchForMissingFile(string fullFileName, FileInfo fileInfo, string dataFullFileName);
|
||||
Models.FaceFileSystem[][] TestStatic_GetFaceFileSystemCollection(string requestPath, string rootResultsDirectory, (string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) tuple, string selectedFileFullName);
|
||||
|
||||
static void SearchForMissingFile(string fullFileName, FileInfo fileInfo, string dataFullFileName) => FaceFileSystem.SearchForMissingFile(fullFileName, fileInfo, dataFullFileName);
|
||||
static Models.FaceFileSystem[] GetFaceFileSystemCollection(string requestPath, (string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) tuple, string selectedFileFullName) => FaceFileSystem.GetFaceFileSystemCollection(requestPath, tuple, selectedFileFullName);
|
||||
|
||||
}
|
10
Shared/Models/Stateless/Methods/IFileSystem.cs
Normal file
10
Shared/Models/Stateless/Methods/IFileSystem.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IFileSystem
|
||||
{ // ...
|
||||
|
||||
List<Models.FileSystem> TestStatic_GetFileSystemCollection(string requestPath, string rootResultsDirectory, (string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) tuple, string[] directories, string[] files, bool all);
|
||||
|
||||
static List<Models.FileSystem> GetFileSystemCollection(string requestPath, (string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) tuple, string[] directories, string[] files, bool all) => FileSystem.GetFileSystemCollection(requestPath, tuple, directories, files, all);
|
||||
|
||||
}
|
10
Shared/Models/Stateless/Methods/IIndex.cs
Normal file
10
Shared/Models/Stateless/Methods/IIndex.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IIndex
|
||||
{ // ...
|
||||
|
||||
string TestStatic_GetJson(string jsonFileFullName, FileInfo fileInfo);
|
||||
|
||||
static string GetJson(string jsonFileFullName, FileInfo fileInfo) => Index.GetJson(jsonFileFullName, fileInfo);
|
||||
|
||||
}
|
8
Shared/Models/Stateless/Methods/IMetadataFile.cs
Normal file
8
Shared/Models/Stateless/Methods/IMetadataFile.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IMetadataFile
|
||||
{
|
||||
|
||||
// ...
|
||||
|
||||
}
|
12
Shared/Models/Stateless/Methods/IMetadataFileCollection.cs
Normal file
12
Shared/Models/Stateless/Methods/IMetadataFileCollection.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IMetadataFileCollection
|
||||
{
|
||||
|
||||
Dictionary<string, List<KeyValuePair<string, string>>> TestStatic_GetDefaultValue() => MetadataFileCollection.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
static Dictionary<string, List<KeyValuePair<string, string>>> GetDefaultValue() => MetadataFileCollection.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
12
Shared/Models/Stateless/Methods/IMetadataFileId.cs
Normal file
12
Shared/Models/Stateless/Methods/IMetadataFileId.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IMetadataFileId
|
||||
{
|
||||
|
||||
string TestStatic_GetDefaultValue() => MetadataFileId.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
static string GetDefaultValue() => MetadataFileId.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
10
Shared/Models/Stateless/Methods/IMethodName.cs
Normal file
10
Shared/Models/Stateless/Methods/IMethodName.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IMethodName
|
||||
{
|
||||
|
||||
static string? GetActualAsyncMethodName([CallerMemberName] string? name = null) => name;
|
||||
|
||||
}
|
23
Shared/Models/Stateless/Methods/IPerson.cs
Normal file
23
Shared/Models/Stateless/Methods/IPerson.cs
Normal file
@ -0,0 +1,23 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IPerson
|
||||
{
|
||||
|
||||
// ...
|
||||
|
||||
Dictionary<DateTime, string[]> TestStatic_Split(string knownPeopleFile);
|
||||
static Dictionary<DateTime, string[]> Split(string knownPeopleFile) => Person.Split(knownPeopleFile);
|
||||
|
||||
Models.Person[] TestStatic_GetPeople(Models.Properties.IStorage storage);
|
||||
static Models.Person[] GetPeople(Models.Properties.IStorage storage) => Person.GetPeople(storage);
|
||||
|
||||
void TestStatic_SavePerson(Models.Properties.IStorage storage, Models.Person person);
|
||||
static void SavePerson(Models.Properties.IStorage storage, Models.Person person) => Person.SavePerson(storage, person);
|
||||
|
||||
string TestStatic_GetFileFullName(Models.Properties.IStorage storage, Models.Person person);
|
||||
static string GetFileFullName(Models.Properties.IStorage storage, Models.Person person) => PersonBirthday.GetFileFullName(storage, person.Birthday);
|
||||
|
||||
Models.Person TestStatic_CreatePerson(Models.Properties.IStorage storage, Models.PersonBirthday birthday, Models.PersonName name, List<Models.PersonComment> comments, List<Models.PersonURL> urls, List<Models.PersonNumber> numbers, List<Models.PersonEmail> emails, List<Models.PersonAddress> addresses);
|
||||
static Models.Person CreatePerson(Models.Properties.IStorage storage, Models.PersonBirthday birthday, Models.PersonName name, List<Models.PersonComment> comments, List<Models.PersonURL> urls, List<Models.PersonNumber> numbers, List<Models.PersonEmail> emails, List<Models.PersonAddress> addresses) => Person.CreatePerson(storage, birthday, name, comments, urls, numbers, emails, addresses);
|
||||
|
||||
}
|
8
Shared/Models/Stateless/Methods/IPersonAddress.cs
Normal file
8
Shared/Models/Stateless/Methods/IPersonAddress.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IPersonAddress
|
||||
{
|
||||
|
||||
// ...
|
||||
|
||||
}
|
12
Shared/Models/Stateless/Methods/IPersonAddressCity.cs
Normal file
12
Shared/Models/Stateless/Methods/IPersonAddressCity.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IPersonAddressCity
|
||||
{
|
||||
|
||||
string TestStatic_GetDefaultValue() => PersonAddressCity.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
static string GetDefaultValue() => PersonAddressCity.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
12
Shared/Models/Stateless/Methods/IPersonAddressState.cs
Normal file
12
Shared/Models/Stateless/Methods/IPersonAddressState.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IPersonAddressState
|
||||
{
|
||||
|
||||
string TestStatic_GetDefaultValue() => PersonAddressState.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
static string GetDefaultValue() => PersonAddressState.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
12
Shared/Models/Stateless/Methods/IPersonAddressStreet.cs
Normal file
12
Shared/Models/Stateless/Methods/IPersonAddressStreet.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IPersonAddressStreet
|
||||
{
|
||||
|
||||
string TestStatic_GetDefaultValue() => PersonAddressStreet.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
static string GetDefaultValue() => PersonAddressStreet.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
12
Shared/Models/Stateless/Methods/IPersonAddressZipCode.cs
Normal file
12
Shared/Models/Stateless/Methods/IPersonAddressZipCode.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IPersonAddressZipCode
|
||||
{
|
||||
|
||||
string TestStatic_GetDefaultValue() => PersonAddressZipCode.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
static string GetDefaultValue() => PersonAddressZipCode.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
30
Shared/Models/Stateless/Methods/IPersonBirthday.cs
Normal file
30
Shared/Models/Stateless/Methods/IPersonBirthday.cs
Normal file
@ -0,0 +1,30 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IPersonBirthday
|
||||
{
|
||||
|
||||
DateTime TestStatic_GetDefaultValue() => PersonBirthday.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
static DateTime GetDefaultValue() => PersonBirthday.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
string TestStatic_GetFormat() => PersonBirthday.GetFormat();
|
||||
static string GetFormat() => PersonBirthday.GetFormat();
|
||||
|
||||
Models.PersonBirthday TestStatic_GetNextBirthdate(Models.Properties.IStorage storage) => PersonBirthday.GetNextBirthdate(storage);
|
||||
static Models.PersonBirthday GetNextBirthdate(Models.Properties.IStorage storage) => PersonBirthday.GetNextBirthdate(storage);
|
||||
|
||||
string TestStatic_GetFormated(Models.PersonBirthday personBirthday) => PersonBirthday.GetFormated(personBirthday);
|
||||
static string GetFormated(Models.PersonBirthday personBirthday) => PersonBirthday.GetFormated(personBirthday);
|
||||
|
||||
string TestStatic_GetFileName(Models.PersonBirthday personBirthday) => PersonBirthday.GetFileName(personBirthday);
|
||||
static string GetFileName(Models.PersonBirthday personBirthday) => PersonBirthday.GetFileName(personBirthday);
|
||||
|
||||
bool TestStatic_DoesBirthDateExits(Models.Properties.IStorage storage, Models.PersonBirthday personBirthday) => DoesBirthDateExits(storage, personBirthday);
|
||||
static bool DoesBirthDateExits(Models.Properties.IStorage storage, Models.PersonBirthday personBirthday) => DoesBirthDateExits(storage, personBirthday);
|
||||
|
||||
string TestStatic_GetFileFullName(Models.Properties.IStorage storage, Models.PersonBirthday personBirthday) => PersonBirthday.GetFileFullName(storage, personBirthday);
|
||||
static string GetFileFullName(Models.Properties.IStorage storage, Models.PersonBirthday personBirthday) => PersonBirthday.GetFileFullName(storage, personBirthday);
|
||||
|
||||
}
|
12
Shared/Models/Stateless/Methods/IPersonComment.cs
Normal file
12
Shared/Models/Stateless/Methods/IPersonComment.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IPersonComment
|
||||
{
|
||||
|
||||
string TestStatic_GetDefaultValue() => PersonComment.GetDefaultValue(); // <{1}>PluralValue
|
||||
|
||||
static string GetDefaultValue() => PersonComment.GetDefaultValue(); // <{1}>PluralValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
12
Shared/Models/Stateless/Methods/IPersonEmail.cs
Normal file
12
Shared/Models/Stateless/Methods/IPersonEmail.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IPersonEmail
|
||||
{
|
||||
|
||||
string TestStatic_GetDefaultValue() => PersonEmail.GetDefaultValue(); // <{1}>PluralValue
|
||||
|
||||
static string GetDefaultValue() => PersonEmail.GetDefaultValue(); // <{1}>PluralValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
12
Shared/Models/Stateless/Methods/IPersonId.cs
Normal file
12
Shared/Models/Stateless/Methods/IPersonId.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IPersonId
|
||||
{
|
||||
|
||||
long TestStatic_GetDefaultValue() => PersonId.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
static long GetDefaultValue() => PersonId.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
8
Shared/Models/Stateless/Methods/IPersonName.cs
Normal file
8
Shared/Models/Stateless/Methods/IPersonName.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IPersonName
|
||||
{
|
||||
|
||||
// ...
|
||||
|
||||
}
|
12
Shared/Models/Stateless/Methods/IPersonNameAlias.cs
Normal file
12
Shared/Models/Stateless/Methods/IPersonNameAlias.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IPersonNameAlias
|
||||
{
|
||||
|
||||
string TestStatic_GetDefaultValue() => PersonNameAlias.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
static string GetDefaultValue() => PersonNameAlias.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
12
Shared/Models/Stateless/Methods/IPersonNameFirst.cs
Normal file
12
Shared/Models/Stateless/Methods/IPersonNameFirst.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IPersonNameFirst
|
||||
{
|
||||
|
||||
string TestStatic_GetDefaultValue() => PersonNameFirst.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
static string GetDefaultValue() => PersonNameFirst.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
12
Shared/Models/Stateless/Methods/IPersonNameLast.cs
Normal file
12
Shared/Models/Stateless/Methods/IPersonNameLast.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IPersonNameLast
|
||||
{
|
||||
|
||||
string TestStatic_GetDefaultValue() => PersonNameLast.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
static string GetDefaultValue() => PersonNameLast.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
12
Shared/Models/Stateless/Methods/IPersonNameMiddle.cs
Normal file
12
Shared/Models/Stateless/Methods/IPersonNameMiddle.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IPersonNameMiddle
|
||||
{
|
||||
|
||||
string TestStatic_GetDefaultValue() => PersonNameMiddle.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
static string GetDefaultValue() => PersonNameMiddle.GetDefaultValue(); // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
12
Shared/Models/Stateless/Methods/IPersonNumber.cs
Normal file
12
Shared/Models/Stateless/Methods/IPersonNumber.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IPersonNumber
|
||||
{
|
||||
|
||||
string TestStatic_GetDefaultValue() => PersonNumber.GetDefaultValue(); // <{1}>PluralValue
|
||||
|
||||
static string GetDefaultValue() => PersonNumber.GetDefaultValue(); // <{1}>PluralValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
12
Shared/Models/Stateless/Methods/IPersonURL.cs
Normal file
12
Shared/Models/Stateless/Methods/IPersonURL.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IPersonURL
|
||||
{
|
||||
|
||||
string TestStatic_GetDefaultValue() => PersonURL.GetDefaultValue(); // <{1}>PluralValue
|
||||
|
||||
static string GetDefaultValue() => PersonURL.GetDefaultValue(); // <{1}>PluralValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
14
Shared/Models/Stateless/Methods/IStorage.cs
Normal file
14
Shared/Models/Stateless/Methods/IStorage.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IStorage
|
||||
{
|
||||
|
||||
// ...
|
||||
|
||||
bool TestStatic_WriteAllText(string path, string contents, bool compareBeforeWrite);
|
||||
static bool WriteAllText(string path, string contents, bool compareBeforeWrite) => Storage.WriteAllText(path, contents, compareBeforeWrite);
|
||||
|
||||
(string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) TestStatic_GetTuple(Models.Properties.IStorage storage);
|
||||
static (string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) GetTuple(Models.Properties.IStorage storage) => new(new Uri(storage.RootResultsDirectory).AbsoluteUri, Path.Combine(storage.ResizeRootDirectory, "()"), Path.Combine(storage.FaceRootDirectory, "()"), Path.Combine(storage.DistanceResultRootDirectory, "[]"));
|
||||
|
||||
}
|
8
Shared/Models/Stateless/Methods/IWorkingDirectory.cs
Normal file
8
Shared/Models/Stateless/Methods/IWorkingDirectory.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IWorkingDirectory
|
||||
{
|
||||
|
||||
static string GetWorkingDirectory(string? executingAssemblyName, string subDirectoryName) => WorkingDirectory.GetWorkingDirectory(executingAssemblyName, subDirectoryName);
|
||||
|
||||
}
|
130
Shared/Models/Stateless/Methods/ImageHelper.cs
Normal file
130
Shared/Models/Stateless/Methods/ImageHelper.cs
Normal file
@ -0,0 +1,130 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class ImageHelper
|
||||
{
|
||||
|
||||
private static bool StartsWith(byte[] thisBytes, byte[] thatBytes)
|
||||
{
|
||||
for (int i = 0; i < thatBytes.Length; i += 1)
|
||||
{
|
||||
if (thisBytes[i] != thatBytes[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static short ReadLittleEndianInt16(BinaryReader binaryReader)
|
||||
{
|
||||
byte[] bytes = new byte[sizeof(short)];
|
||||
for (int i = 0; i < sizeof(short); i += 1)
|
||||
bytes[sizeof(short) - 1 - i] = binaryReader.ReadByte();
|
||||
return BitConverter.ToInt16(bytes, 0);
|
||||
}
|
||||
|
||||
private static int ReadLittleEndianInt32(BinaryReader binaryReader)
|
||||
{
|
||||
byte[] bytes = new byte[sizeof(int)];
|
||||
for (int i = 0; i < sizeof(int); i += 1)
|
||||
bytes[sizeof(int) - 1 - i] = binaryReader.ReadByte();
|
||||
return BitConverter.ToInt32(bytes, 0);
|
||||
}
|
||||
|
||||
private static Size DecodeBitmap(BinaryReader binaryReader)
|
||||
{
|
||||
_ = binaryReader.ReadBytes(16);
|
||||
int width = binaryReader.ReadInt32();
|
||||
int height = binaryReader.ReadInt32();
|
||||
return new Size(width, height);
|
||||
}
|
||||
|
||||
private static Size DecodeGif(BinaryReader binaryReader)
|
||||
{
|
||||
int width = binaryReader.ReadInt16();
|
||||
int height = binaryReader.ReadInt16();
|
||||
return new Size(width, height);
|
||||
}
|
||||
|
||||
private static Size DecodePng(BinaryReader binaryReader)
|
||||
{
|
||||
_ = binaryReader.ReadBytes(8);
|
||||
int width = ReadLittleEndianInt32(binaryReader);
|
||||
int height = ReadLittleEndianInt32(binaryReader);
|
||||
return new Size(width, height);
|
||||
}
|
||||
|
||||
private static Size DecodeJfif(BinaryReader binaryReader)
|
||||
{
|
||||
while (binaryReader.ReadByte() == 0xff)
|
||||
{
|
||||
byte marker = binaryReader.ReadByte();
|
||||
short chunkLength = ReadLittleEndianInt16(binaryReader);
|
||||
if (marker == 0xc0)
|
||||
{
|
||||
_ = binaryReader.ReadByte();
|
||||
int height = ReadLittleEndianInt16(binaryReader);
|
||||
int width = ReadLittleEndianInt16(binaryReader);
|
||||
return new Size(width, height);
|
||||
}
|
||||
_ = binaryReader.ReadBytes(chunkLength - 2);
|
||||
}
|
||||
throw new ArgumentException("Could not recognize image format.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the dimensions of an image.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the image to get the dimensions of.</param>
|
||||
/// <returns>The dimensions of the specified image.</returns>
|
||||
/// <exception cref="ArgumentException">The image was of an unrecognized format.</exception>
|
||||
public static Size GetDimensions(BinaryReader binaryReader, int? faceRight, int? faceBottom)
|
||||
{
|
||||
Size? result = null;
|
||||
Dictionary<byte[], Func<BinaryReader, Size>> _ImageFormatDecoders = new()
|
||||
{
|
||||
{ new byte[] { 0x42, 0x4D }, DecodeBitmap },
|
||||
{ new byte[] { 0x47, 0x49, 0x46, 0x38, 0x37, 0x61 }, DecodeGif },
|
||||
{ new byte[] { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61 }, DecodeGif },
|
||||
{ new byte[] { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A }, DecodePng },
|
||||
{ new byte[] { 0xff, 0xd8 }, DecodeJfif },
|
||||
};
|
||||
int maxMagicBytesLength = _ImageFormatDecoders.Keys.OrderByDescending(x => x.Length).First().Length;
|
||||
byte[] magicBytes = new byte[maxMagicBytesLength];
|
||||
for (int i = 0; i < maxMagicBytesLength; i += 1)
|
||||
{
|
||||
magicBytes[i] = binaryReader.ReadByte();
|
||||
foreach (KeyValuePair<byte[], Func<BinaryReader, Size>> kvPair in _ImageFormatDecoders)
|
||||
{
|
||||
if (!StartsWith(magicBytes, kvPair.Key))
|
||||
continue;
|
||||
result = kvPair.Value(binaryReader);
|
||||
break;
|
||||
}
|
||||
if (result is not null)
|
||||
break;
|
||||
}
|
||||
if (result is null)
|
||||
{
|
||||
if (faceRight is null || faceBottom is null)
|
||||
throw new Exception("face is null!");
|
||||
result = new(faceRight.Value, faceBottom.Value);
|
||||
}
|
||||
return result.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the dimensions of an image.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the image to get the dimensions of.</param>
|
||||
/// <returns>The dimensions of the specified image.</returns>
|
||||
/// <exception cref="ArgumentException">The image was of an unrecognized format.</exception>
|
||||
public static Size GetDimensions(string path, int? faceRight, int? faceBottom)
|
||||
{
|
||||
Size result;
|
||||
using BinaryReader binaryReader = new(File.OpenRead(path));
|
||||
result = GetDimensions(binaryReader, faceRight, faceBottom);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
31
Shared/Models/Stateless/Methods/Index.cs
Normal file
31
Shared/Models/Stateless/Methods/Index.cs
Normal file
@ -0,0 +1,31 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class Index
|
||||
{
|
||||
|
||||
internal static string GetJson(string jsonFileFullName, FileInfo fileInfo)
|
||||
{
|
||||
string result;
|
||||
string fileSegment = "FileSegment";
|
||||
string fileSegmentCollection = "FileSegmentCollection";
|
||||
result = File.ReadAllText(jsonFileFullName).Replace("Goolgle", "Google");
|
||||
if (result.Contains(fileSegment) || result.Contains(fileSegmentCollection))
|
||||
{
|
||||
if (fileInfo is null)
|
||||
fileInfo = new FileInfo(jsonFileFullName);
|
||||
result = result.Replace(fileSegmentCollection, nameof(Properties.IIndex.RelativePaths)).Replace("\\\\", "/");
|
||||
File.WriteAllText(fileInfo.FullName, result);
|
||||
File.SetLastWriteTime(fileInfo.FullName, fileInfo.LastWriteTime);
|
||||
}
|
||||
if (result.Contains("/u0"))
|
||||
{
|
||||
if (fileInfo is null)
|
||||
fileInfo = new FileInfo(jsonFileFullName);
|
||||
result = result.Replace("/u0", "\\u0");
|
||||
File.WriteAllText(fileInfo.FullName, result);
|
||||
File.SetLastWriteTime(fileInfo.FullName, fileInfo.LastWriteTime);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
8
Shared/Models/Stateless/Methods/MetadataFile.cs
Normal file
8
Shared/Models/Stateless/Methods/MetadataFile.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class MetadataFile
|
||||
{
|
||||
|
||||
// ...
|
||||
|
||||
}
|
10
Shared/Models/Stateless/Methods/MetadataFileCollection.cs
Normal file
10
Shared/Models/Stateless/Methods/MetadataFileCollection.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class MetadataFileCollection
|
||||
{
|
||||
|
||||
internal static Dictionary<string, List<KeyValuePair<string, string>>> GetDefaultValue() => new(); // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
10
Shared/Models/Stateless/Methods/MetadataFileId.cs
Normal file
10
Shared/Models/Stateless/Methods/MetadataFileId.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class MetadataFileId
|
||||
{
|
||||
|
||||
internal static string GetDefaultValue() => string.Empty; // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
229
Shared/Models/Stateless/Methods/Person.cs
Normal file
229
Shared/Models/Stateless/Methods/Person.cs
Normal file
@ -0,0 +1,229 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class Person
|
||||
{
|
||||
|
||||
// ...
|
||||
|
||||
private static List<string> ValidatePerson(Models.Properties.IStorage storage, Models.PersonId id, Models.PersonBirthday birthday, Models.PersonName name)
|
||||
{
|
||||
List<string> results = new();
|
||||
if (birthday is null)
|
||||
throw new Exception("Birthday must be supplied!");
|
||||
if (birthday.Value > DateTime.Now)
|
||||
results.Add("Birthday must be in the past!");
|
||||
if (id is null)
|
||||
throw new Exception("Birthday must be supplied!");
|
||||
if (id.Value != birthday.Value.Ticks)
|
||||
results.Add("Id must be Birthday ticks!");
|
||||
if (name.First is null || string.IsNullOrEmpty(name.First.Value))
|
||||
results.Add("Fist Name must be supplied!");
|
||||
if (PersonBirthday.DoesBirthDateExits(storage, birthday))
|
||||
results.Add("Birthdate already exits!");
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static Models.Person CreatePerson(Models.Properties.IStorage storage, Models.PersonBirthday birthday, Models.PersonName name, List<Models.PersonComment> comments, List<Models.PersonURL> urls, List<Models.PersonNumber> numbers, List<Models.PersonEmail> emails, List<Models.PersonAddress> addresses)
|
||||
{
|
||||
Models.Person result;
|
||||
Models.PersonId id = new(birthday.Value.Ticks);
|
||||
if (birthday.Value == DateTime.MinValue)
|
||||
birthday = PersonBirthday.GetNextBirthdate(storage);
|
||||
List<string> results = ValidatePerson(storage, id, birthday, name);
|
||||
if (results.Any())
|
||||
throw new Exception(string.Join(Environment.NewLine, results));
|
||||
if (comments is null)
|
||||
comments = new();
|
||||
if (urls is null)
|
||||
urls = new();
|
||||
if (numbers is null)
|
||||
numbers = new();
|
||||
if (emails is null)
|
||||
emails = new();
|
||||
if (addresses is null)
|
||||
addresses = new();
|
||||
result = new(id, birthday, name, comments, urls, numbers, emails, addresses);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static Dictionary<DateTime, string[]> Split(string knownPeopleFile)
|
||||
{
|
||||
Dictionary<DateTime, string[]> results = new();
|
||||
string[] segments;
|
||||
DateTime personKey;
|
||||
List<string> temporarySegments;
|
||||
const string KeyFormat = "yyyy-MM-dd_HH";
|
||||
DateTime incrementDate = new(1500, 1, 1);
|
||||
string[] lines = File.ReadAllLines(knownPeopleFile);
|
||||
_ = incrementDate.AddDays(lines.Length);
|
||||
System.Globalization.CultureInfo cultureInfo = System.Globalization.CultureInfo.InvariantCulture;
|
||||
foreach (string line in lines)
|
||||
{
|
||||
if (string.IsNullOrEmpty(line))
|
||||
continue;
|
||||
segments = line.Replace(" //", "\t//").Split('\t');
|
||||
if (segments.Length < 1)
|
||||
continue;
|
||||
if (segments[0].Length != KeyFormat.Length || !segments[0].Contains('-') || !segments[0].Contains('_'))
|
||||
{
|
||||
temporarySegments = segments.ToList();
|
||||
temporarySegments.Insert(0, incrementDate.ToString(KeyFormat));
|
||||
segments = temporarySegments.ToArray();
|
||||
incrementDate = incrementDate.AddDays(1);
|
||||
}
|
||||
personKey = DateTime.ParseExact(segments[0], KeyFormat, cultureInfo);
|
||||
if (results.ContainsKey(personKey))
|
||||
continue;
|
||||
results.Add(personKey, segments);
|
||||
}
|
||||
int countBefore = results.Count;
|
||||
DateTime minimumDateTime = results.Keys.Min();
|
||||
for (int i = 1; i < (1000 - countBefore); i++)
|
||||
{
|
||||
personKey = minimumDateTime.AddDays(i * -1);
|
||||
results.Add(personKey, new string[] { personKey.ToString(KeyFormat) });
|
||||
}
|
||||
return results.OrderBy(l => l.Key).ToDictionary(l => l.Key, l => l.Value);
|
||||
}
|
||||
|
||||
internal static Dictionary<DateTime, PersonImport> GetPersonCollection(string knownPeopleFile)
|
||||
{
|
||||
Dictionary<DateTime, PersonImport> results = new();
|
||||
string name;
|
||||
DateTime key;
|
||||
string comment;
|
||||
string oldName;
|
||||
string mergeName;
|
||||
PersonImport person;
|
||||
Dictionary<DateTime, string[]> splitLines = Split(knownPeopleFile);
|
||||
foreach (KeyValuePair<DateTime, string[]> splitLine in splitLines)
|
||||
{
|
||||
name = string.Empty;
|
||||
key = splitLine.Key;
|
||||
comment = string.Empty;
|
||||
oldName = string.Empty;
|
||||
mergeName = string.Empty;
|
||||
if (splitLine.Value.Length > 1)
|
||||
{
|
||||
foreach (string segment in splitLine.Value)
|
||||
{
|
||||
if (!segment.Contains('*'))
|
||||
continue;
|
||||
mergeName = segment.Split('*')[1].Split('\t')[0];
|
||||
}
|
||||
if (splitLine.Value[1].StartsWith("//"))
|
||||
comment = splitLine.Value[1];
|
||||
else
|
||||
name = splitLine.Value[1].Split('\t')[0];
|
||||
if (splitLine.Value.Length > 2)
|
||||
comment = splitLine.Value[2];
|
||||
}
|
||||
person = new(key, name, mergeName, oldName, comment);
|
||||
results.Add(splitLine.Key, person);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static void SavePerson(Models.Properties.IStorage storage, Models.Person person)
|
||||
{
|
||||
string fileName = IPerson.GetFileFullName(storage, person);
|
||||
string json = JsonSerializer.Serialize(person, new JsonSerializerOptions { WriteIndented = true });
|
||||
_ = IStorage.WriteAllText(fileName, json, compareBeforeWrite: true);
|
||||
}
|
||||
|
||||
private static List<Models.Person> GetPeopleFromText(Models.Properties.IStorage storage, string localKnownPeopleFile)
|
||||
{
|
||||
List<Models.Person> results = new();
|
||||
string comment;
|
||||
Models.Person person;
|
||||
Models.PersonName name;
|
||||
List<Models.PersonURL> urls;
|
||||
Models.PersonBirthday birthday;
|
||||
List<Models.PersonEmail> emails = new();
|
||||
List<Models.PersonNumber> numbers = new();
|
||||
List<Models.PersonComment> comments = new();
|
||||
List<Models.PersonAddress> addresses = new();
|
||||
Dictionary<DateTime, PersonImport> keyValuePairs = GetPersonCollection(localKnownPeopleFile);
|
||||
foreach (KeyValuePair<DateTime, PersonImport> keyValuePair in keyValuePairs)
|
||||
{
|
||||
if (string.IsNullOrEmpty(keyValuePair.Value.Name))
|
||||
continue;
|
||||
urls = new();
|
||||
birthday = new(keyValuePair.Key);
|
||||
name = PersonName.Create(keyValuePair.Value.Name);
|
||||
if (name.First is null || string.IsNullOrEmpty(name.First.Value))
|
||||
continue;
|
||||
if (!string.IsNullOrEmpty(keyValuePair.Value.Comment))
|
||||
{
|
||||
comment = keyValuePair.Value.Comment[2..];
|
||||
if (!string.IsNullOrEmpty(comment))
|
||||
{
|
||||
if (comment.StartsWith("http://") || comment.StartsWith("https://"))
|
||||
urls.Add(new(new(comment)));
|
||||
else
|
||||
comments.Add(new(new(comment)));
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(keyValuePair.Value.OldName))
|
||||
comments.Add(new(new(keyValuePair.Value.OldName)));
|
||||
person = IPerson.CreatePerson(storage, birthday, name, comments, urls, numbers, emails, addresses);
|
||||
SavePerson(storage, person);
|
||||
results.Add(person);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static Models.Person[] GetPeople(Models.Properties.IStorage storage)
|
||||
{
|
||||
List<Models.Person> results = new();
|
||||
string json;
|
||||
string[] files;
|
||||
FileInfo fileInfo;
|
||||
Models.Person? person;
|
||||
string localKnownPeopleFile;
|
||||
DateTime dateTime = DateTime.MinValue;
|
||||
string directory = Path.Combine(storage.PeopleRootDirectory, "{}");
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
if (!Directory.Exists(storage.RootDirectory))
|
||||
localKnownPeopleFile = string.Empty;
|
||||
else
|
||||
{
|
||||
files = Directory.GetFiles(storage.RootDirectory, "*People*.txt", SearchOption.TopDirectoryOnly);
|
||||
if (files.Any())
|
||||
localKnownPeopleFile = files[0];
|
||||
else
|
||||
localKnownPeopleFile = string.Empty;
|
||||
}
|
||||
files = Directory.GetFiles(directory, "*.json", SearchOption.TopDirectoryOnly);
|
||||
if (!files.Any() && string.IsNullOrEmpty(localKnownPeopleFile))
|
||||
throw new Exception("Copy \"KnownPeople.txt\" file from server!");
|
||||
foreach (string file in files)
|
||||
{
|
||||
fileInfo = new(file);
|
||||
if (dateTime < fileInfo.LastWriteTime)
|
||||
dateTime = fileInfo.LastWriteTime;
|
||||
json = File.ReadAllText(file);
|
||||
person = JsonSerializer.Deserialize<Models.Person>(json);
|
||||
if (person is null)
|
||||
continue;
|
||||
results.Add(person);
|
||||
}
|
||||
if (!results.Any())
|
||||
results = GetPeopleFromText(storage, localKnownPeopleFile);
|
||||
else if (!string.IsNullOrEmpty(localKnownPeopleFile))
|
||||
{
|
||||
fileInfo = new FileInfo(localKnownPeopleFile);
|
||||
if (fileInfo.LastWriteTime > dateTime)
|
||||
{
|
||||
foreach (string file in files)
|
||||
File.Delete(file);
|
||||
results = GetPeopleFromText(storage, localKnownPeopleFile);
|
||||
}
|
||||
}
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
}
|
8
Shared/Models/Stateless/Methods/PersonAddress.cs
Normal file
8
Shared/Models/Stateless/Methods/PersonAddress.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class PersonAddress
|
||||
{
|
||||
|
||||
// ...
|
||||
|
||||
}
|
10
Shared/Models/Stateless/Methods/PersonAddressCity.cs
Normal file
10
Shared/Models/Stateless/Methods/PersonAddressCity.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class PersonAddressCity
|
||||
{
|
||||
|
||||
internal static string GetDefaultValue() => string.Empty; // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
10
Shared/Models/Stateless/Methods/PersonAddressState.cs
Normal file
10
Shared/Models/Stateless/Methods/PersonAddressState.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class PersonAddressState
|
||||
{
|
||||
|
||||
internal static string GetDefaultValue() => string.Empty; // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
10
Shared/Models/Stateless/Methods/PersonAddressStreet.cs
Normal file
10
Shared/Models/Stateless/Methods/PersonAddressStreet.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class PersonAddressStreet
|
||||
{
|
||||
|
||||
internal static string GetDefaultValue() => string.Empty; // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
10
Shared/Models/Stateless/Methods/PersonAddressZipCode.cs
Normal file
10
Shared/Models/Stateless/Methods/PersonAddressZipCode.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class PersonAddressZipCode
|
||||
{
|
||||
|
||||
internal static string GetDefaultValue() => string.Empty; // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
16
Shared/Models/Stateless/Methods/PersonBirthday.cs
Normal file
16
Shared/Models/Stateless/Methods/PersonBirthday.cs
Normal file
@ -0,0 +1,16 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class PersonBirthday
|
||||
{
|
||||
|
||||
internal static DateTime GetDefaultValue() => DateTime.MinValue; // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
internal static string GetFormat() => "yyyy-MM-dd_HH";
|
||||
internal static Models.PersonBirthday GetNextBirthdate(Models.Properties.IStorage storage) => throw new Exception(storage.ToString()); // Person.GetNextBirthdate(storage);
|
||||
internal static string GetFormated(Models.PersonBirthday personBirthday) => personBirthday.Value.ToString(GetFormat());
|
||||
internal static string GetFileName(Models.PersonBirthday personBirthday) => $"{personBirthday.Value.ToString(GetFormat())}.json";
|
||||
internal static bool DoesBirthDateExits(Models.Properties.IStorage storage, Models.PersonBirthday personBirthday) => File.Exists(GetFileFullName(storage, personBirthday));
|
||||
internal static string GetFileFullName(Models.Properties.IStorage storage, Models.PersonBirthday personBirthday) => Path.Combine(storage.PeopleRootDirectory, "{}", GetFileName(personBirthday));
|
||||
}
|
10
Shared/Models/Stateless/Methods/PersonComment.cs
Normal file
10
Shared/Models/Stateless/Methods/PersonComment.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class PersonComment
|
||||
{
|
||||
|
||||
internal static string GetDefaultValue() => string.Empty; // <{1}>PluralValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
10
Shared/Models/Stateless/Methods/PersonEmail.cs
Normal file
10
Shared/Models/Stateless/Methods/PersonEmail.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class PersonEmail
|
||||
{
|
||||
|
||||
internal static string GetDefaultValue() => string.Empty; // <{1}>PluralValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
10
Shared/Models/Stateless/Methods/PersonId.cs
Normal file
10
Shared/Models/Stateless/Methods/PersonId.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class PersonId
|
||||
{
|
||||
|
||||
internal static long GetDefaultValue() => long.MinValue; // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
60
Shared/Models/Stateless/Methods/PersonName.cs
Normal file
60
Shared/Models/Stateless/Methods/PersonName.cs
Normal file
@ -0,0 +1,60 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class PersonName
|
||||
{
|
||||
|
||||
// ...
|
||||
|
||||
internal static Models.PersonName Create(string name)
|
||||
{
|
||||
Models.PersonName result;
|
||||
Models.PersonNameLast personNameLast;
|
||||
Models.PersonNameAlias personNameAlias;
|
||||
Models.PersonNameFirst personNameFirst;
|
||||
Models.PersonNameMiddle personNameMiddle;
|
||||
string[] segments = name.Split(' ');
|
||||
if (segments.Length == 1)
|
||||
{
|
||||
personNameFirst = new(string.Empty);
|
||||
personNameLast = new(string.Empty);
|
||||
personNameMiddle = new(string.Empty);
|
||||
personNameAlias = new(segments[0]);
|
||||
}
|
||||
else if (segments.Length == 2)
|
||||
{
|
||||
personNameFirst = new(segments[0]);
|
||||
personNameLast = new(segments[1]);
|
||||
personNameMiddle = new(string.Empty);
|
||||
personNameAlias = new(string.Empty);
|
||||
}
|
||||
else if (segments.Length == 3 && segments[2] is "Jr." or "Jr" or "Sr")
|
||||
{
|
||||
personNameFirst = new(segments[0]);
|
||||
personNameLast = new(segments[1]);
|
||||
personNameMiddle = new(string.Empty);
|
||||
personNameAlias = new(string.Join(' ', segments));
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] comment = name.Split(new string[] { " (" }, StringSplitOptions.None);
|
||||
if (comment.Length == 1)
|
||||
{
|
||||
personNameFirst = new(segments[0]);
|
||||
personNameLast = new(segments[^1]);
|
||||
personNameMiddle = new(string.Empty);
|
||||
personNameAlias = new(string.Join(' ', segments));
|
||||
}
|
||||
else
|
||||
{
|
||||
segments = comment[0].Split(' ');
|
||||
personNameFirst = new(segments[0]);
|
||||
personNameLast = new(segments[^1]);
|
||||
personNameMiddle = new(string.Empty);
|
||||
personNameAlias = new(string.Concat(string.Join(' ', segments), " (", comment[1]));
|
||||
}
|
||||
}
|
||||
result = new(personNameFirst, personNameMiddle, personNameLast, personNameAlias);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
10
Shared/Models/Stateless/Methods/PersonNameAlias.cs
Normal file
10
Shared/Models/Stateless/Methods/PersonNameAlias.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class PersonNameAlias
|
||||
{
|
||||
|
||||
internal static string GetDefaultValue() => string.Empty; // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
10
Shared/Models/Stateless/Methods/PersonNameFirst.cs
Normal file
10
Shared/Models/Stateless/Methods/PersonNameFirst.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class PersonNameFirst
|
||||
{
|
||||
|
||||
internal static string GetDefaultValue() => string.Empty; // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
10
Shared/Models/Stateless/Methods/PersonNameLast.cs
Normal file
10
Shared/Models/Stateless/Methods/PersonNameLast.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class PersonNameLast
|
||||
{
|
||||
|
||||
internal static string GetDefaultValue() => string.Empty; // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
10
Shared/Models/Stateless/Methods/PersonNameMiddle.cs
Normal file
10
Shared/Models/Stateless/Methods/PersonNameMiddle.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class PersonNameMiddle
|
||||
{
|
||||
|
||||
internal static string GetDefaultValue() => string.Empty; // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
10
Shared/Models/Stateless/Methods/PersonNumber.cs
Normal file
10
Shared/Models/Stateless/Methods/PersonNumber.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class PersonNumber
|
||||
{
|
||||
|
||||
internal static string GetDefaultValue() => string.Empty; // <{1}>PluralValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
10
Shared/Models/Stateless/Methods/PersonURL.cs
Normal file
10
Shared/Models/Stateless/Methods/PersonURL.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class PersonURL
|
||||
{
|
||||
|
||||
internal static string GetDefaultValue() => string.Empty; // <{1}>PluralValue
|
||||
|
||||
// ...
|
||||
|
||||
}
|
27
Shared/Models/Stateless/Methods/Storage.cs
Normal file
27
Shared/Models/Stateless/Methods/Storage.cs
Normal file
@ -0,0 +1,27 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class Storage
|
||||
{
|
||||
|
||||
// ...
|
||||
|
||||
internal static bool WriteAllText(string path, string contents, bool compareBeforeWrite)
|
||||
{
|
||||
bool result;
|
||||
string text;
|
||||
if (!compareBeforeWrite)
|
||||
result = true;
|
||||
else
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
text = string.Empty;
|
||||
else
|
||||
text = File.ReadAllText(path);
|
||||
result = text != contents;
|
||||
}
|
||||
if (result)
|
||||
File.WriteAllText(path, contents);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
50
Shared/Models/Stateless/Methods/WorkingDirectory.cs
Normal file
50
Shared/Models/Stateless/Methods/WorkingDirectory.cs
Normal file
@ -0,0 +1,50 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class WorkingDirectory
|
||||
{
|
||||
|
||||
internal static string GetWorkingDirectory(string? executingAssemblyName, string subDirectoryName)
|
||||
{
|
||||
string result = string.Empty;
|
||||
if (executingAssemblyName is null)
|
||||
throw new Exception();
|
||||
string traceFile;
|
||||
List<string> directories = new();
|
||||
Environment.SpecialFolder[] specialFolders = new Environment.SpecialFolder[]
|
||||
{
|
||||
Environment.SpecialFolder.LocalApplicationData,
|
||||
Environment.SpecialFolder.ApplicationData,
|
||||
Environment.SpecialFolder.History,
|
||||
Environment.SpecialFolder.CommonApplicationData,
|
||||
Environment.SpecialFolder.InternetCache
|
||||
};
|
||||
foreach (Environment.SpecialFolder specialFolder in specialFolders)
|
||||
directories.Add(Path.Combine(Environment.GetFolderPath(specialFolder), subDirectoryName, executingAssemblyName));
|
||||
foreach (string directory in directories)
|
||||
{
|
||||
for (int i = 1; i < 3; i++)
|
||||
{
|
||||
if (i == 1)
|
||||
result = directory;
|
||||
else
|
||||
result = string.Concat("D", directory[1..]);
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(result))
|
||||
_ = Directory.CreateDirectory(result);
|
||||
traceFile = string.Concat(result, @"\", DateTime.Now.Ticks, ".txt");
|
||||
File.WriteAllText(traceFile, traceFile);
|
||||
File.Delete(traceFile);
|
||||
break;
|
||||
}
|
||||
catch (Exception) { result = string.Empty; }
|
||||
}
|
||||
if (!string.IsNullOrEmpty(result))
|
||||
break;
|
||||
}
|
||||
if (string.IsNullOrEmpty(result))
|
||||
throw new Exception("Unable to set working directory!");
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user