Re-write
This commit is contained in:
@ -48,12 +48,23 @@ internal abstract class Person
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void SetSegments(ref string[] segments, string KeyFormat, ref DateTime incrementDate)
|
||||
{
|
||||
if (segments[0].Length != KeyFormat.Length || !segments[0].Contains('-') || !segments[0].Contains('_'))
|
||||
{
|
||||
List<string> temporarySegments;
|
||||
temporarySegments = segments.ToList();
|
||||
temporarySegments.Insert(0, incrementDate.ToString(KeyFormat));
|
||||
segments = temporarySegments.ToArray();
|
||||
incrementDate = incrementDate.AddDays(1);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
@ -66,13 +77,7 @@ internal abstract class Person
|
||||
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);
|
||||
}
|
||||
SetSegments(ref segments, KeyFormat, ref incrementDate);
|
||||
personKey = DateTime.ParseExact(segments[0], KeyFormat, cultureInfo);
|
||||
if (results.ContainsKey(personKey))
|
||||
continue;
|
||||
@ -88,7 +93,29 @@ internal abstract class Person
|
||||
return results.OrderBy(l => l.Key).ToDictionary(l => l.Key, l => l.Value);
|
||||
}
|
||||
|
||||
internal static Dictionary<DateTime, PersonImport> GetPersonCollection(string knownPeopleFile)
|
||||
private static void SetValues(ref string name, ref string comment, ref string mergeName, KeyValuePair<DateTime, string[]> splitLine)
|
||||
{
|
||||
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];
|
||||
}
|
||||
|
||||
private static void CheckSplitLineAndSetValues(ref string name, ref string comment, ref string mergeName, KeyValuePair<DateTime, string[]> splitLine)
|
||||
{
|
||||
if (splitLine.Value.Length > 1)
|
||||
SetValues(ref name, ref comment, ref mergeName, splitLine);
|
||||
}
|
||||
|
||||
private static Dictionary<DateTime, PersonImport> GetPersonCollection(string knownPeopleFile)
|
||||
{
|
||||
Dictionary<DateTime, PersonImport> results = new();
|
||||
string name;
|
||||
@ -105,21 +132,7 @@ internal abstract class Person
|
||||
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];
|
||||
}
|
||||
CheckSplitLineAndSetValues(ref name, ref comment, ref mergeName, splitLine);
|
||||
person = new(key, name, mergeName, oldName, comment);
|
||||
results.Add(splitLine.Key, person);
|
||||
}
|
||||
@ -133,6 +146,19 @@ internal abstract class Person
|
||||
_ = IStorage.WriteAllText(fileName, json, updateDateWhenMatches: true, compareBeforeWrite: true);
|
||||
}
|
||||
|
||||
private static string GetComment(List<Models.PersonURL> urls, List<Models.PersonComment> comments, KeyValuePair<DateTime, PersonImport> keyValuePair)
|
||||
{
|
||||
string result = keyValuePair.Value.Comment[2..];
|
||||
if (!string.IsNullOrEmpty(result))
|
||||
{
|
||||
if (result.StartsWith("http://") || result.StartsWith("https://"))
|
||||
urls.Add(new(new(result)));
|
||||
else
|
||||
comments.Add(new(new(result)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<Models.Person> GetPeopleFromText(Properties.IStorage storage, string localKnownPeopleFile)
|
||||
{
|
||||
List<Models.Person> results = new();
|
||||
@ -156,16 +182,7 @@ internal abstract class Person
|
||||
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)));
|
||||
}
|
||||
}
|
||||
comment = GetComment(urls, comments, keyValuePair);
|
||||
if (!string.IsNullOrEmpty(keyValuePair.Value.OldName))
|
||||
comments.Add(new(new(keyValuePair.Value.OldName)));
|
||||
person = IPerson.CreatePerson(storage, birthday, name, comments, urls, numbers, emails, addresses);
|
||||
|
Reference in New Issue
Block a user