diff --git a/EPS.SDK/Git/GitManager.cs b/EPS.SDK/Git/GitManager.cs index 3167675..d56cc29 100644 --- a/EPS.SDK/Git/GitManager.cs +++ b/EPS.SDK/Git/GitManager.cs @@ -9,6 +9,7 @@ namespace ExtensiblePortfolioSite.SDK.Git public static void Register(String Service, IGitProvider Provider) { + Console.WriteLine($"Registering service {Service}"); if (Providers.TryGetValue(Service, out GitService? GitService)) { GitService.addProvider(Provider); diff --git a/EPS.SDK/Git/ICommit.cs b/EPS.SDK/Git/ICommit.cs index 4d2e065..6a59a5b 100644 --- a/EPS.SDK/Git/ICommit.cs +++ b/EPS.SDK/Git/ICommit.cs @@ -20,5 +20,10 @@ namespace ExtensiblePortfolioSite.SDK.Git /// List of files modified in the commit /// public IReadOnlyCollection ModifiedFiles { get; } + + /// + /// URL to the commit author's avatar + /// + public string AuthorAvatarUrl { get; } } } diff --git a/EPS.SDK/Json.cs b/EPS.SDK/Json.cs index fee6e39..3ac487c 100644 --- a/EPS.SDK/Json.cs +++ b/EPS.SDK/Json.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; namespace ExtensiblePortfolioSite.SDK { - internal static class Json + public static class Json { private static class DefaultConverters { @@ -40,7 +40,7 @@ namespace ExtensiblePortfolioSite.SDK IncludeFields = true, MaxDepth = 64, NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals | JsonNumberHandling.AllowReadingFromString, - PropertyNameCaseInsensitive = false, + PropertyNameCaseInsensitive = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase, ReadCommentHandling = JsonCommentHandling.Skip, UnknownTypeHandling = JsonUnknownTypeHandling.JsonElement, @@ -61,6 +61,7 @@ namespace ExtensiblePortfolioSite.SDK public static T? Deserialize(String String) => JsonSerializer.Deserialize(String, Options); public static T? Deserialize(Stream STM) => JsonSerializer.Deserialize(STM, Options); public static T? Deserialize(ref Utf8JsonReader Reader) => JsonSerializer.Deserialize(ref Reader, Options); + public static T? Deserialize(JsonElement Element) => JsonSerializer.Deserialize(Element, Options); public static ValueTask DeserializeAsync(Stream STM) => JsonSerializer.DeserializeAsync(STM, Options); public static ValueTask DeserializeAsync(Stream STM, CancellationToken cancellationToken) => JsonSerializer.DeserializeAsync(STM, Options, cancellationToken); diff --git a/EPS.SDK/Plugins/PluginManager.cs b/EPS.SDK/Plugins/PluginManager.cs index fcd85af..7949be8 100644 --- a/EPS.SDK/Plugins/PluginManager.cs +++ b/EPS.SDK/Plugins/PluginManager.cs @@ -31,6 +31,7 @@ namespace ExtensiblePortfolioSite.SDK.Plugins List PublicKeyTokens = new(); PublicKeyTokens.Add(typeof(String).Assembly.GetName().GetPublicKeyToken()!); // Framework Libraries PublicKeyTokens.Add(new byte[8] { 0xb0, 0x3f, 0x5f, 0x7f, 0x11, 0xd5, 0x0a, 0x3a }); // System.Runtime + PublicKeyTokens.Add(new byte[8] { 0xcc, 0x7b, 0x13, 0xff, 0xcd, 0x2d, 0xdd, 0x51 }); // System.Text.Json KnownPublicKeyTokens = PublicKeyTokens.ToArray(); } diff --git a/ExtensiblePortfolioSite/Config.cs b/ExtensiblePortfolioSite/Config.cs index ca87418..650c68b 100644 --- a/ExtensiblePortfolioSite/Config.cs +++ b/ExtensiblePortfolioSite/Config.cs @@ -68,6 +68,10 @@ namespace ExtensiblePortfolioSite [JsonIgnore(Condition = JsonIgnoreCondition.Never)] public string[] Description { get; set; } = Array.Empty(); + [JsonPropertyName("Biography")] + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + public string[] Biography { get; set; } = Array.Empty(); + [JsonPropertyName("Languages")] [JsonIgnore(Condition = JsonIgnoreCondition.Never)] public LanguageObject[] Languages { get; set; } = Array.Empty(); diff --git a/ExtensiblePortfolioSite/ExtensiblePortfolioSite.csproj b/ExtensiblePortfolioSite/ExtensiblePortfolioSite.csproj index cf9aa21..b2a2be9 100644 --- a/ExtensiblePortfolioSite/ExtensiblePortfolioSite.csproj +++ b/ExtensiblePortfolioSite/ExtensiblePortfolioSite.csproj @@ -27,14 +27,10 @@ - - - - - + diff --git a/ExtensiblePortfolioSite/Pages/About/Index.cshtml b/ExtensiblePortfolioSite/Pages/About/Index.cshtml index 59c81a2..923a6d8 100644 --- a/ExtensiblePortfolioSite/Pages/About/Index.cshtml +++ b/ExtensiblePortfolioSite/Pages/About/Index.cshtml @@ -22,8 +22,10 @@

About Me

-

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce commodo imperdiet hendrerit. Vestibulum pretium mauris eu sagittis tristique. Sed tellus nulla, facilisis in molestie id, fermentum facilisis nulla. Nullam vel tristique neque. Nam accumsan arcu vel nulla efficitur, posuere convallis diam rhoncus. Mauris mollis at sapien eu gravida. Nullam viverra velit porttitor ex mattis, in iaculis justo tincidunt. Morbi pulvinar odio nec mauris luctus facilisis. Phasellus aliquam commodo turpis. Quisque in tincidunt tellus, vel facilisis massa.

-

Pellentesque auctor eros vitae pretium ornare. Donec quam erat, tempor id elit eu, aliquet suscipit mi. Morbi facilisis nisi vel dapibus facilisis. Phasellus efficitur ac odio id ultricies. Cras ullamcorper lacinia posuere. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Vivamus lobortis, arcu a mollis venenatis, nisi libero cursus risus, ut sodales felis erat quis lorem. Praesent nisl turpis, egestas ac auctor et, tempor ac mauris. Donec aliquam lacus nisi, id hendrerit neque aliquam ut. Nullam maximus velit nulla, quis euismod lacus porttitor ac. Nullam lacinia non arcu vitae scelerisque. Nulla nisl nibh, vestibulum eget ex sit amet, viverra vulputate purus. Nullam non arcu ac diam sagittis consectetur.

+ @foreach(String s in Config.GetConfig().ProfileSection.Biography) + { +

@s

+ }
diff --git a/ExtensiblePortfolioSite/Pages/Projects/Index.cshtml b/ExtensiblePortfolioSite/Pages/Projects/Index.cshtml index 83ad126..c0ecd78 100644 --- a/ExtensiblePortfolioSite/Pages/Projects/Index.cshtml +++ b/ExtensiblePortfolioSite/Pages/Projects/Index.cshtml @@ -9,84 +9,69 @@
- @{ - //var githubService = GitManager.GetService("github.com"); - //var user = githubService.GetUser(new Uri("https://github.com/KoromaruKoruko")); - //Console.WriteLine("FOUND USER"); - //Console.WriteLine(user.Name); - //var repos = user.GetUserRepositories(); - //Console.WriteLine("REPOSITORIES"); - //foreach(var repo in repos) - // Console.WriteLine(repo.Name); - var client = new HttpClient(); - client.DefaultRequestHeaders.Add("User-Agent", "KoromaruKoruko"); - client.DefaultRequestHeaders.Add("Authorization", "Bearer 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"); - HttpResponseMessage response = await client.GetAsync("https://api.github.com/users/KoromaruKoruko/repos"); - JsonDocument json = await JsonDocument.ParseAsync(await response.Content.ReadAsStreamAsync()); + @{ + foreach(Config.ConfigObject.GitRepoObject repo in Config.GetConfig().GitRepos) + { + IRepository repository = GitManager.GetService(repo.ServiceProvider).GetRepository(repo.Repository); - foreach(JsonElement elem in json.RootElement.EnumerateArray()) - { - int popout_id = Random.Shared.Next(); - HttpResponseMessage commitResponse = await client.GetAsync(elem.GetProperty("commits_url").GetString()!.Split('{')[0]); - JsonDocument commitInfo = await JsonDocument.ParseAsync(await commitResponse.Content.ReadAsStreamAsync()); - JsonElement commitJson = commitInfo.RootElement.EnumerateArray().First(); - String[] lastCommitMessage = commitJson.GetProperty("commit").GetProperty("message")!.GetString()!.Split("\n").Where(s => s != "").ToArray(); + repository.TryGetCommit(0, out ICommit commit); + String[] lastCommitMessage = commit!.Description.Split("\n").Where(s => s != "").ToArray(); - // Begin repo -
-
- KoromaruKoruko/ - @elem.GetProperty("name") + // Begin repo +
+
+ @repository.Owner.Name/ + @repository.Name +
+
+ @repo.Description.Aggregate((a, b) => a + "\n" + b) +
+
+ @repo.Description.Aggregate((a, b) => a + "\n" + b) +
+
+ +
+
+ @if(lastCommitMessage.Length > 0) + { + @lastCommitMessage[0] + } +
+
+ @if(lastCommitMessage.Length > 1) + { + @lastCommitMessage[1] + } +
+
+
+ @if (lastCommitMessage.Length > 0) + { + @lastCommitMessage[0] +
+ var commitDescription = lastCommitMessage.Skip(1).ToHashSet(); +
+ @if(commitDescription.Count > 0) + @commitDescription.Aggregate((a, b) => a + "\n" + b) +
+ }
-
- @elem.GetProperty("description") -
-
- @elem.GetProperty("description") -
-
- -
-
- @if(lastCommitMessage.Length > 0) - { - @lastCommitMessage[0] - } -
-
- @if(lastCommitMessage.Length > 1) - { - @lastCommitMessage[1] - } +
+
-
- @if (lastCommitMessage.Length > 0) - { - @lastCommitMessage[0] -
- var commitDescription = lastCommitMessage.Skip(1).ToHashSet(); -
- @if(commitDescription.Count > 0) - @commitDescription.Aggregate((a, b) => a + "\n" + b) -
- } -
-
- -
// End repo } - + }
\ No newline at end of file diff --git a/ExtensiblePortfolioSite/Program.cs b/ExtensiblePortfolioSite/Program.cs index a2de850..fb95e52 100644 --- a/ExtensiblePortfolioSite/Program.cs +++ b/ExtensiblePortfolioSite/Program.cs @@ -86,6 +86,9 @@ namespace ExtensiblePortfolioSite // Load Plugins PluginManager.LoadPlugins(Path.GetFullPath("Plugins/")); + //Initialize Plugins + PluginManager.InitializePlugins(); + // TODO: [Resource] File Provider // TODO: [Plugin] Web Static Files Provider // TODO: [Plugin] Web Hook Provider diff --git a/ExtensiblePortfolioSite/eps_host_config.json b/ExtensiblePortfolioSite/eps_host_config.json index f683283..00fa043 100644 --- a/ExtensiblePortfolioSite/eps_host_config.json +++ b/ExtensiblePortfolioSite/eps_host_config.json @@ -13,6 +13,11 @@ "I'm a c# Programmer who prides herself in making things configurable and highly optimized." ], + // Multi paragraph biography for About Me page + "Biography": [ + "I'm a c# Programmer who prides herself in making things configurable and highly optimized." + ], + // Languages you'd like to advertise "Languages": [ { diff --git a/ExtensiblePortfolioSite/wwwroot/css/site.css b/ExtensiblePortfolioSite/wwwroot/css/site.css index c16ca44..4c92ec1 100644 --- a/ExtensiblePortfolioSite/wwwroot/css/site.css +++ b/ExtensiblePortfolioSite/wwwroot/css/site.css @@ -70,7 +70,7 @@ main .text-center { } .repo-container { - border: solid 1px #444; + /*border: solid 1px #444;*/ border-radius: .25em; width: 81.5em; display: flex; diff --git a/ExtensiblePortfolioSite/wwwroot/img/logos/github/Dark-64px.png b/ExtensiblePortfolioSite/wwwroot/img/logos/github/dark.png similarity index 100% rename from ExtensiblePortfolioSite/wwwroot/img/logos/github/Dark-64px.png rename to ExtensiblePortfolioSite/wwwroot/img/logos/github/dark.png diff --git a/ExtensiblePortfolioSite/wwwroot/img/logos/github/Light-64px.png b/ExtensiblePortfolioSite/wwwroot/img/logos/github/light.png similarity index 100% rename from ExtensiblePortfolioSite/wwwroot/img/logos/github/Light-64px.png rename to ExtensiblePortfolioSite/wwwroot/img/logos/github/light.png diff --git a/GithubPlugin/GithubCommit.cs b/GithubPlugin/GithubCommit.cs index 67289d1..2381b00 100644 --- a/GithubPlugin/GithubCommit.cs +++ b/GithubPlugin/GithubCommit.cs @@ -20,11 +20,16 @@ namespace GithubPlugin [JsonIgnore] public IGitProvider? Provider { get; internal set; } - [JsonPropertyName("sha")] - public string? Hash { get; private set; } + [JsonIgnore] + public string? AuthorAvatarUrl { get; internal set; } + [JsonInclude] + [JsonPropertyName("sha")] + public string? Hash { get; init; } + + [JsonInclude] [JsonPropertyName("message")] - public string? Description { get; private set; } + public string? Description { get; init; } public GitReference GetReference() { diff --git a/GithubPlugin/GithubProvider.cs b/GithubPlugin/GithubProvider.cs index eb7a82a..322e33d 100644 --- a/GithubPlugin/GithubProvider.cs +++ b/GithubPlugin/GithubProvider.cs @@ -1,4 +1,5 @@ -using ExtensiblePortfolioSite.SDK.Git; +using ExtensiblePortfolioSite.SDK; +using ExtensiblePortfolioSite.SDK.Git; using ExtensiblePortfolioSite.SDK.Plugins; using System.Text.Json; @@ -6,7 +7,7 @@ using System.Text.RegularExpressions; namespace GithubPlugin { - [GitProvider("github.com")] + [GitProvider("Github")] [Serializable] public class GithubProvider : IGitProvider { @@ -69,7 +70,7 @@ namespace GithubPlugin public bool TryGetRepositoryByName(IUser User, string RepositoryName, out IRepository? Repository) { - if(User.GetType() == typeof(GithubUser)) + if(User is GithubUser _user) { if (Repositories.TryGetValue(RepositoryName, out GithubRepo? _repo)) { @@ -77,15 +78,15 @@ namespace GithubPlugin return true; } else { - var response = httpClient.GetAsync($"repos/{User.Name}/{RepositoryName}").Result; + var response = httpClient.GetAsync($"repos/{_user.Name}/{RepositoryName}").Result; if (!response.IsSuccessStatusCode) { Repository = null; return false; } - GithubRepo tempRepo = JsonSerializer.Deserialize(response.Content.ReadAsStream())!; + GithubRepo tempRepo = Json.Deserialize(response.Content.ReadAsStream())!; tempRepo.Provider = this; - tempRepo.Owner = User; + tempRepo.Owner = _user; Repository = tempRepo; return true; } @@ -108,7 +109,7 @@ namespace GithubPlugin User = null; return false; } - GithubUser tempUser = JsonSerializer.Deserialize(response.Content.ReadAsStream())!; + GithubUser tempUser = Json.Deserialize(response.Content.ReadAsStringAsync().Result)!; tempUser.Provider = this; User = tempUser; return true; diff --git a/GithubPlugin/GithubRepo.cs b/GithubPlugin/GithubRepo.cs index 5c7a339..a79be1b 100644 --- a/GithubPlugin/GithubRepo.cs +++ b/GithubPlugin/GithubRepo.cs @@ -1,4 +1,5 @@ -using ExtensiblePortfolioSite.SDK.Git; +using ExtensiblePortfolioSite.SDK; +using ExtensiblePortfolioSite.SDK.Git; using System.Text.Json; using System.Text.Json.Serialization; @@ -7,14 +8,17 @@ namespace GithubPlugin [Serializable] public class GithubRepo : IRepository { + [JsonInclude] [JsonPropertyName("name")] - public string Name { get; private set; } + public string Name { get; init; } + [JsonInclude] [JsonPropertyName("description")] - public string Description { get; private set; } + public string Description { get; init; } - [JsonIgnore] - public IUser Owner { get; internal set; } + [JsonInclude] + [JsonPropertyName("owner")] + public GithubUser Owner { get; internal set; } [JsonIgnore] public GithubProvider Provider { get; internal set; } @@ -22,29 +26,16 @@ namespace GithubPlugin [JsonIgnore] IGitProvider IGitObject.Provider => this.Provider; + [JsonIgnore] + IUser IRepository.Owner => this.Owner; public ICommit? GetCommit(uint HeadOffset = 0) { var response = Provider.GetAPIResource($"repos/{Owner.Name}/{Name}/commits"); - if(response.IsSuccessStatusCode) - { - JsonDocument json = JsonDocument.Parse(response.Content.ReadAsStream()); - JsonElement commitObject = json.RootElement.EnumerateArray().Skip((int)HeadOffset).First(); - GithubCommit commit = JsonSerializer.Deserialize(commitObject.GetProperty("commit"))!; - commit.Provider = Provider; - commit.Repository = this; - List tempFiles = new(); - JsonElement files = commitObject.GetProperty("files"); - foreach(JsonElement file in files.EnumerateArray()) - { - tempFiles.Add(file.GetProperty("filename").GetString()!); - } - commit.ModifiedFiles = tempFiles; - return commit; - } else - { + if (response.IsSuccessStatusCode) + return GetCommitByRef(JsonDocument.Parse(response.Content.ReadAsStream()).RootElement.EnumerateArray().Skip((int)HeadOffset).First().GetProperty("sha").GetString()); + else return null; - } } public ICommit? GetCommitByRef(string reference) @@ -54,7 +45,8 @@ namespace GithubPlugin { JsonDocument json = JsonDocument.Parse(response.Content.ReadAsStream()); JsonElement commitObject = json.RootElement; - GithubCommit commit = JsonSerializer.Deserialize(commitObject.GetProperty("commit"))!; + GithubCommit commit = Json.Deserialize(commitObject.GetProperty("commit"))!; + commit.AuthorAvatarUrl = commitObject.GetProperty("author").GetProperty("avatar_url").GetString(); commit.Provider = Provider; commit.Repository = this; List tempFiles = new(); diff --git a/GithubPlugin/GithubUser.cs b/GithubPlugin/GithubUser.cs index 48f1da1..5a6442b 100644 --- a/GithubPlugin/GithubUser.cs +++ b/GithubPlugin/GithubUser.cs @@ -1,25 +1,24 @@ -using ExtensiblePortfolioSite.SDK.Git; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using ExtensiblePortfolioSite.SDK; +using ExtensiblePortfolioSite.SDK.Git; using System.Text.Json; using System.Text.Json.Serialization; -using System.Threading.Tasks; namespace GithubPlugin { [Serializable] public class GithubUser : IUser { + [JsonInclude] [JsonPropertyName("login")] - public string Name { get; private set; } + public string Name { get; init; } + [JsonInclude] [JsonPropertyName("id")] - public int Identifier { get; private set; } + public int Identifier { get; init; } + [JsonInclude] [JsonPropertyName("avatar_url")] - public string AvatarURL { get; private set; } + public string AvatarURL { get; init; } [JsonIgnore] public GithubProvider Provider { get; internal set; } @@ -37,15 +36,13 @@ namespace GithubPlugin var response = Provider.GetAPIResource($"users/{Name}/repos"); if(response.IsSuccessStatusCode) { - JsonDocument json = JsonDocument.Parse(response.Content.ReadAsStream()); - List ret = new(json.RootElement.GetArrayLength()); - foreach(JsonElement repo in json.RootElement.EnumerateArray()) + using Stream STM = response.Content.ReadAsStream(); + foreach (GithubRepo repo in Json.Deserialize(STM) ?? Array.Empty()) { - ret.Add(JsonSerializer.Deserialize(repo)!); + repo.Provider = this.Provider; + yield return repo; } - return ret; } - return new List(); } } }