The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VersionHelper.cs 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Microsoft.AspNetCore.Razor.TagHelpers;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using System;
  5. using System.IO;
  6. namespace Teknik.Utilities.TagHelpers
  7. {
  8. [HtmlTargetElement("version")]
  9. public class VersionHelper : TagHelper
  10. {
  11. private const string _verFile = "version.json";
  12. public string Source { get; set; }
  13. public override void Process(TagHelperContext context, TagHelperOutput output)
  14. {
  15. // Clear the initial wrap tag
  16. output.TagName = string.Empty;
  17. // Get the version file info
  18. string dataDir = (string)AppDomain.CurrentDomain.GetData("DataDirectory");
  19. string fullPath = Path.Combine(dataDir, _verFile);
  20. if (File.Exists(fullPath))
  21. {
  22. using (StreamReader file = File.OpenText(fullPath))
  23. using (JsonTextReader reader = new JsonTextReader(file))
  24. {
  25. JObject res = (JObject)JToken.ReadFrom(reader);
  26. string commitVer = res["version"].ToString();
  27. string commitHash = res["hash"].ToString();
  28. output.Content.AppendHtml($"Version: {commitVer} - Hash: <a href=\"{Source}{commitHash}\">{commitHash.Truncate(10)}</a>");
  29. }
  30. }
  31. }
  32. }
  33. }