Dev changes (#5)

* Fixed dependency

* Updates to NeoDictionary

* Changes to NeoDictionary

* Started working on a Git implementation to integrate into Game Engines in the future

* Added commit functionality to the git library

* New changes

* Added select for NeoDictionary.cs

* Fixed issue with previous new method

* Added a Benchmarking Tool to be used mostly in game engines

* Added IndexOf to NeoDictionary.cs

* Added new method for BenchmarkUtility.cs

* added an instacedobject class

* Added a new shuffle method for lists

* fixed return type

* Added new Changelog generator

* Added new Game logic library to assist with game projects

* Added Web Project

* Added Nuget package configs

* Add workflow for publishing game library NuGet package

* Add README for OmegaLeo's Helper Library

* Updated Website to reflect all libraries

* Fixed missing library in Changelog

* Added Contributing and Code of Conduct

* Fixed web project

* new documentation changes

* fix packages

* Fixed DocumentationHelper package dependencies

* Added Serilog

* Added logging

* Fixed documentation

* Added logging for cache

* fixed documentation

* Updated README.md

* Update README.md

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update OmegaLeo.HelperLib.Web/Controllers/HomeController.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update OmegaLeo.HelperLib.Web/Controllers/HomeController.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix error

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit was merged in pull request #5.
This commit is contained in:
2025-12-23 16:37:30 +00:00
committed by GitHub
parent b8a3a78e1d
commit 53650e4bfe
21 changed files with 458 additions and 51 deletions
@@ -1,9 +1,12 @@
// File: `OmegaLeo.HelperLib.Web/Controllers/HomeController.cs`
using System.Diagnostics;
using System.Reflection;
using System.Runtime.ExceptionServices;
using GameDevLibrary.Helpers;
using Microsoft.AspNetCore.Mvc;
using NetFlow.DocumentationHelper.Library.Helpers;
using NetFlow.DocumentationHelper.Library.Models;
using OmegaLeo.HelperLib.Changelog.Tools;
using OmegaLeo.HelperLib.Web.Models;
@@ -25,31 +28,34 @@ public class HomeController : Controller
if (_libraryCache != null) return;
var root = GetSolutionRoot();
_logger.LogInformation("Initializing libraries from base directory: {Root}", root);
_libraryCache = new Dictionary<string, LibraryDocumentationViewModel>
{
["core"] = GenerateLibraryDocs(
typeof(BenchmarkUtility).Assembly,
Path.Join(root, "OmegaLeo.HelperLib", "CHANGELOG.md"),
Path.Combine(root, "changelogs", "OmegaLeo.HelperLib.CHANGELOG.md"),
"Core Library",
"Core utilities and helper functions for general C# development",
"OmegaLeo.HelperLib"
),
["changelog"] = GenerateLibraryDocs(
typeof(Changelog.Models.Changelog).Assembly,
Path.Join(root, "OmegaLeo.HelperLib.Changelog", "CHANGELOG.md"),
Path.Combine(root, "changelogs", "OmegaLeo.HelperLib.Changelog.CHANGELOG.md"),
"Changelog Library",
"Tools for managing and generating changelogs",
"OmegaLeo.HelperLib.Changelog"
),
["game"] = GenerateLibraryDocs(
typeof(OmegaLeo.HelperLib.Game.Models.ConsoleCommand).Assembly,
Path.Join(root, "OmegaLeo.HelperLib.Game", "CHANGELOG.md"),
Path.Combine(root, "changelogs", "OmegaLeo.HelperLib.Game.CHANGELOG.md"),
"Game Development Library",
"Game development utilities for Unity and Godot",
"OmegaLeo.HelperLib.Game"
)
};
_logger.LogInformation("Initialized {Count} libraries", _libraryCache.Count);
}
public IActionResult Index()
@@ -62,7 +68,18 @@ public class HomeController : Controller
if (string.IsNullOrEmpty(id) || !_libraryCache.ContainsKey(id))
return NotFound();
return View(_libraryCache[id]);
var cache = _libraryCache[id];
if (cache.Documentation.Any())
{
_logger.LogInformation($"Found cache for {id}: {cache.Documentation.Count} entries");
}
else
{
_logger.LogError($"Cache for {id} is empty!");
}
return View(cache);
}
public IActionResult Privacy()
@@ -76,55 +93,258 @@ public class HomeController : Controller
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
private LibraryDocumentationViewModel GenerateLibraryDocs(Assembly assembly, string changelogPath, string displayName, string description, string nugetPackageId)
private void LogDocumentationHelperInfo()
{
var allDocumentation = DocumentationHelperTool.GenerateDocumentation();
var assemblyName = assembly.GetName().Name;
try
{
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
var target = assemblies.FirstOrDefault(a =>
a.GetName().Name.Equals("NetFlow.DocumentationHelper.Library", StringComparison.OrdinalIgnoreCase));
var filteredDocumentation = allDocumentation
.Where(d => d.AssemblyName.Equals(assemblyName, StringComparison.OrdinalIgnoreCase))
.OrderBy(d => d.ClassName)
.ToList();
if (target == null)
{
_logger.LogWarning("NetFlow.DocumentationHelper.Library not loaded. Loaded assemblies ({Count}):",
assemblies.Length);
foreach (var a in assemblies.OrderBy(a => a.GetName().Name))
{
_logger.LogInformation(" {Name} {Version} => {Location}", a.GetName().Name, a.GetName().Version,
SafeLocation(a));
}
string changelogMarkdown = "";
return;
}
_logger.LogInformation("Found {Name} {Version} at {Location}", target.GetName().Name,
target.GetName().Version, SafeLocation(target));
Type attrType = null;
try
{
attrType = target.GetType("NetFlow.DocumentationHelper.Library.Attributes.DocumentationAttribute",
false, true);
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Failed to GetType for DocumentationAttribute in {Assembly}",
target.GetName().Name);
}
if (attrType == null)
{
_logger.LogWarning("Type 'DocumentationAttribute' not found in {Assembly}.", target.GetName().Name);
}
else
{
var ctors = attrType.GetConstructors(BindingFlags.Public | BindingFlags.Instance |
BindingFlags.NonPublic);
if (!ctors.Any())
_logger.LogWarning("No constructors found on DocumentationAttribute in {Assembly}.",
target.GetName().Name);
foreach (var ctor in ctors)
{
var sig = string.Join(", ", ctor.GetParameters().Select(p => p.ParameterType.Name + " " + p.Name));
_logger.LogInformation("DocumentationAttribute ctor: ({Signature})", sig);
}
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to log DocumentationHelper assembly info.");
}
static string SafeLocation(Assembly a)
{
try
{
return string.IsNullOrEmpty(a.Location) ? "<in-memory>" : a.Location;
}
catch
{
return "<unknown>";
}
}
}
private void InspectDocumentationHelperMethod()
{
try
{
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
Type helperType = null;
foreach (var asm in assemblies)
{
try
{
var t = asm.GetTypes().FirstOrDefault(tt =>
tt.Name.Equals("DocumentationHelperTool", StringComparison.OrdinalIgnoreCase)
|| tt.FullName?.EndsWith(".DocumentationHelperTool") == true);
if (t != null)
{
helperType = t;
break;
}
}
catch (ReflectionTypeLoadException rtlex)
{
_logger.LogDebug(rtlex, "Could not enumerate types in {Assembly}", asm.GetName().Name);
foreach (var loaderEx in rtlex.LoaderExceptions ?? Array.Empty<Exception>())
_logger.LogDebug(loaderEx, "Loader exception for {Assembly}", asm.GetName().Name);
}
catch (Exception ex)
{
_logger.LogDebug(ex, "Failed enumerating types in {Assembly}", asm.GetName().Name);
}
}
if (helperType == null)
{
_logger.LogWarning("DocumentationHelperTool type not found in loaded assemblies.");
return;
}
_logger.LogInformation("DocumentationHelperTool found: {Type} in {Assembly} ({Location})",
helperType.FullName, helperType.Assembly.GetName().Name, SafeLocation(helperType.Assembly));
var method = helperType.GetMethod("GenerateDocumentation",
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
if (method == null)
{
_logger.LogWarning("GenerateDocumentation method not found on {Type}.", helperType.FullName);
}
else
{
var parameters = string.Join(", ",
method.GetParameters().Select(p => p.ParameterType.Name + " " + p.Name));
_logger.LogInformation("Method: {Name} ({Parameters}) -> {ReturnType}", method.Name, parameters,
method.ReturnType.FullName);
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to inspect DocumentationHelperTool type/method.");
}
static string SafeLocation(Assembly a)
{
try
{
return string.IsNullOrEmpty(a.Location) ? "<in-memory>" : a.Location;
}
catch
{
return "<unknown>";
}
}
}
private LibraryDocumentationViewModel GenerateLibraryDocs(Assembly assembly, string changelogPath,
string displayName, string description, string nugetPackageId)
{
_logger.LogInformation("=== Starting GenerateLibraryDocs for {Assembly} ===", assembly.GetName().Name);
_logger.LogInformation("Assembly location: {Location}", assembly.Location ?? "<in-memory>");
_logger.LogInformation("Changelog path: {Path}", changelogPath);
_logger.LogInformation("Changelog exists: {Exists}", System.IO.File.Exists(changelogPath));
// Log types in assembly and their attributes
try
{
var types = assembly.GetTypes();
_logger.LogInformation("Assembly {Name} contains {Count} types", assembly.GetName().Name, types.Length);
var typesWithDocAttr = types.Where(t =>
t.GetCustomAttributes().Any(a =>
a.GetType().Name.Contains("Documentation", StringComparison.OrdinalIgnoreCase)))
.ToList();
_logger.LogInformation("Found {Count} types with DocumentationAttribute-like attributes",
typesWithDocAttr.Count);
if (typesWithDocAttr.Any())
{
foreach (var type in typesWithDocAttr.Take(5))
{
_logger.LogInformation(" Type with doc attr: {TypeName}", type.FullName);
}
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to inspect assembly types");
}
LogDocumentationHelperInfo();
IEnumerable<DocumentationStructure> allDocumentation = Enumerable.Empty<DocumentationStructure>();
try
{
// Pass the specific assembly to only scan that assembly
var result = DocumentationHelperTool.GenerateDocumentation();
allDocumentation = result?
.Where(d => d.AssemblyName?.Equals(assembly.GetName().Name ,StringComparison.OrdinalIgnoreCase) == true)
.ToList() ?? Enumerable.Empty<DocumentationStructure>();
_logger.LogInformation("GenerateDocumentation returned {Count} items for {Assembly}",
allDocumentation.Count(), assembly.GetName().Name);
if (!allDocumentation.Any())
{
_logger.LogWarning(
"No documentation items generated for {Assembly}. Check if types have [Documentation] attribute applied.",
assembly.GetName().Name);
}
}
catch (MissingMethodException mmex)
{
_logger.LogError(mmex,
"Missing method when calling DocumentationHelperTool.GenerateDocumentation(). Possible assembly mismatch.");
InspectDocumentationHelperMethod();
ExceptionDispatchInfo.Capture(mmex).Throw();
}
catch (Exception ex)
{
_logger.LogError(ex, "DocumentationHelperTool.GenerateDocumentation threw an exception.");
InspectDocumentationHelperMethod();
throw;
}
var changelogMarkdown = string.Empty;
if (System.IO.File.Exists(changelogPath))
{
changelogMarkdown = ChangelogTool.GetMarkdown(assembly);
try
{
ChangelogTool.ExtractChangelog(assembly);
changelogMarkdown = ChangelogTool.GetMarkdown(assembly);
_logger.LogInformation("Parsed changelog for {Assembly}", assembly.GetName().Name);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to parse changelog at {Path}", changelogPath);
}
}
string version = assembly.GetCustomAttribute<System.Reflection.AssemblyInformationalVersionAttribute>()?.InformationalVersion
?? assembly.GetName().Version?.ToString()
?? "1.0.0";
if (version.Contains('+'))
else
{
version = version.Substring(0, version.IndexOf('+'));
_logger.LogWarning("Changelog file not found at {Path}", changelogPath);
}
return new LibraryDocumentationViewModel
var viewModel = new LibraryDocumentationViewModel
{
LibraryName = displayName,
Description = description,
Version = version,
NuGetPackageId = nugetPackageId,
Documentation = filteredDocumentation,
ChangelogMarkdown = changelogMarkdown
ChangelogMarkdown = changelogMarkdown,
Documentation = allDocumentation.ToList()
};
_logger.LogInformation(
"=== Completed GenerateLibraryDocs for {Assembly}. Total documentation items: {Count} ===",
assembly.GetName().Name, viewModel.Documentation.Count);
return viewModel;
}
static string GetSolutionRoot()
{
string dir = AppContext.BaseDirectory;
while (!string.IsNullOrEmpty(dir))
{
if (Directory.GetFiles(dir, "*.sln").Length > 0)
return dir;
dir = Directory.GetParent(dir)?.FullName;
}
throw new Exception("Solution root not found.");
return AppContext.BaseDirectory;
}
}