2023-10-09 20:25:57 -07:00
|
|
|
using System.Collections.Generic;
|
2020-07-03 00:24:31 -07:00
|
|
|
|
2021-04-29 05:05:55 -07:00
|
|
|
namespace SourceGit.Models {
|
2020-07-03 00:24:31 -07:00
|
|
|
/// <summary>
|
2021-04-29 05:05:55 -07:00
|
|
|
/// Git用户
|
2020-07-03 00:24:31 -07:00
|
|
|
/// </summary>
|
|
|
|
public class User {
|
2023-10-09 20:25:57 -07:00
|
|
|
public static User Invalid = new User();
|
|
|
|
public static Dictionary<string, User> Caches = new Dictionary<string, 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
|
|
|
|
2023-10-09 20:25:57 -07:00
|
|
|
public override bool Equals(object obj) {
|
|
|
|
if (obj == null || !(obj is User)) return false;
|
|
|
|
|
|
|
|
var other = obj as User;
|
|
|
|
return Name == other.Name && Email == other.Email;
|
|
|
|
}
|
2020-07-03 00:24:31 -07:00
|
|
|
|
2023-10-09 20:25:57 -07:00
|
|
|
public override int GetHashCode() {
|
|
|
|
return base.GetHashCode();
|
|
|
|
}
|
2020-07-03 00:24:31 -07:00
|
|
|
|
2023-10-11 21:02:41 -07:00
|
|
|
public static User FindOrAdd(string data) {
|
|
|
|
if (Caches.ContainsKey(data)) {
|
|
|
|
return Caches[data];
|
2023-10-09 20:25:57 -07:00
|
|
|
} else {
|
2023-10-11 21:02:41 -07:00
|
|
|
var nameEndIdx = data.IndexOf('<');
|
|
|
|
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 };
|
2023-10-11 21:02:41 -07:00
|
|
|
Caches.Add(data, user);
|
2023-10-09 20:25:57 -07:00
|
|
|
return user;
|
|
|
|
}
|
2020-07-03 00:24:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|