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-05-16 01:33:34 -07:00
|
|
|
|
return _caches.GetOrAdd(data, key =>
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-05-16 01:33:34 -07:00
|
|
|
|
var nameEndIdx = key.IndexOf('<', System.StringComparison.Ordinal);
|
|
|
|
|
var name = nameEndIdx >= 2 ? key.Substring(0, nameEndIdx - 1) : string.Empty;
|
|
|
|
|
var email = key.Substring(nameEndIdx + 1);
|
|
|
|
|
|
|
|
|
|
return new User() { Name = name, Email = email };
|
|
|
|
|
});
|
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
|
|
|
|
}
|