2024-05-11 02:00:35 -07:00
|
|
|
|
using System.Collections.Concurrent;
|
2020-07-03 00:24:31 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.Models
|
|
|
|
|
{
|
|
|
|
|
public class User
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
public static readonly User Invalid = new User();
|
2020-07-03 00:24:31 -07:00
|
|
|
|
|
2023-10-09 20:25:57 -07:00
|
|
|
|
public string Name { get; set; } = string.Empty;
|
|
|
|
|
public string Email { get; set; } = string.Empty;
|
2020-07-03 00:24:31 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (obj == null || !(obj is User))
|
|
|
|
|
return false;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2023-10-09 20:25:57 -07:00
|
|
|
|
var other = obj as User;
|
|
|
|
|
return Name == other.Name && Email == other.Email;
|
|
|
|
|
}
|
2020-07-03 00:24:31 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
2023-10-09 20:25:57 -07:00
|
|
|
|
return base.GetHashCode();
|
|
|
|
|
}
|
2020-07-03 00:24:31 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static User FindOrAdd(string data)
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (_caches.TryGetValue(data, out var value))
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
return value;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-03-13 20:09:05 -07:00
|
|
|
|
var nameEndIdx = data.IndexOf('<', System.StringComparison.Ordinal);
|
2023-10-11 21:02:41 -07:00
|
|
|
|
var name = nameEndIdx >= 2 ? data.Substring(0, nameEndIdx - 1) : string.Empty;
|
|
|
|
|
var email = data.Substring(nameEndIdx + 1);
|
|
|
|
|
|
2023-10-09 20:25:57 -07:00
|
|
|
|
User user = new User() { Name = name, Email = email };
|
2024-05-11 02:00:35 -07:00
|
|
|
|
_caches.TryAdd(data, user);
|
2023-10-09 20:25:57 -07:00
|
|
|
|
return user;
|
|
|
|
|
}
|
2020-07-03 00:24:31 -07:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
|
2024-05-11 02:00:35 -07:00
|
|
|
|
private static ConcurrentDictionary<string, User> _caches = new ConcurrentDictionary<string, User>();
|
2020-07-03 00:24:31 -07:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|