diff --git a/.gitignore b/.gitignore index 70e5420..c90b1d4 100644 --- a/.gitignore +++ b/.gitignore @@ -264,3 +264,4 @@ __pycache__/ /Teknik/App_Data/Config.json /Teknik/appsettings.Production.json /Teknik/appsettings.Development.json +/Teknik/App_Data/version.json diff --git a/Teknik.sln b/Teknik.sln index 6ac0ed8..ed0a41e 100644 --- a/Teknik.sln +++ b/Teknik.sln @@ -20,7 +20,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution README.md = README.md EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Piwik", "Piwik\Piwik.csproj", "{F8823907-092C-4055-9F8E-D6756793C24A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tracking", "Tracking\Tracking.csproj", "{F8823907-092C-4055-9F8E-D6756793C24A}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MailService", "MailService\MailService.csproj", "{03636C30-DA61-4307-8934-2FCC3BAC3255}" EndProject diff --git a/Teknik/App_Data/version.template.json b/Teknik/App_Data/version.template.json new file mode 100644 index 0000000..daa8908 --- /dev/null +++ b/Teknik/App_Data/version.template.json @@ -0,0 +1,4 @@ +{ + "version": "{{git_ver}}", + "hash": "{{git_hash}}" +} \ No newline at end of file diff --git a/Teknik/Areas/Stats/Controllers/StatsController.cs b/Teknik/Areas/Stats/Controllers/StatsController.cs index 8dcd2ea..73632f5 100644 --- a/Teknik/Areas/Stats/Controllers/StatsController.cs +++ b/Teknik/Areas/Stats/Controllers/StatsController.cs @@ -12,7 +12,7 @@ using Teknik.Controllers; using Teknik.Data; using Teknik.Filters; using Teknik.Logging; -using Teknik.Piwik; +using Teknik.Tracking; using Teknik.Utilities; namespace Teknik.Areas.Stats.Controllers @@ -179,7 +179,7 @@ namespace Teknik.Areas.Stats.Controllers return Json(new { result = new { uniqueVisitors = uniqueData.ToArray(), totalVisitors = totalData.ToArray() } }); } - return Json(new { error = new { message = "Piwik not configured" } }); + return Json(new { error = new { message = "Tracking not configured" } }); } } } diff --git a/Teknik/Filters/TrackDownload.cs b/Teknik/Filters/TrackDownload.cs index 02f3853..e438be9 100644 --- a/Teknik/Filters/TrackDownload.cs +++ b/Teknik/Filters/TrackDownload.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using System.Web; using Teknik.Configuration; using Teknik.Utilities; -using Teknik.Piwik; +using Teknik.Tracking; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; diff --git a/Teknik/Filters/TrackLink.cs b/Teknik/Filters/TrackLink.cs index e5fabc5..d855dc1 100644 --- a/Teknik/Filters/TrackLink.cs +++ b/Teknik/Filters/TrackLink.cs @@ -8,7 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Web; using Teknik.Configuration; -using Teknik.Piwik; +using Teknik.Tracking; using Teknik.Utilities; namespace Teknik.Filters diff --git a/Teknik/Filters/TrackPageView.cs b/Teknik/Filters/TrackPageView.cs index 9ba72e9..91c751c 100644 --- a/Teknik/Filters/TrackPageView.cs +++ b/Teknik/Filters/TrackPageView.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using System.Web; using Teknik.Configuration; using Teknik.Utilities; -using Teknik.Piwik; +using Teknik.Tracking; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; diff --git a/Teknik/TagHelpers/VersionHelper.cs b/Teknik/TagHelpers/VersionHelper.cs new file mode 100644 index 0000000..1d8fcf1 --- /dev/null +++ b/Teknik/TagHelpers/VersionHelper.cs @@ -0,0 +1,44 @@ +using Microsoft.AspNetCore.Razor.TagHelpers; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Teknik.Utilities; + +namespace Teknik.TagHelpers +{ + [HtmlTargetElement("version")] + public class VersionHelper : TagHelper + { + private const string _verFile = "version.json"; + + public string Source { get; set; } + + public override void Process(TagHelperContext context, TagHelperOutput output) + { + // Clear the initial wrap tag + output.TagName = string.Empty; + + // Get the version file info + string dataDir = (string)AppDomain.CurrentDomain.GetData("DataDirectory"); + string fullPath = Path.Combine(dataDir, _verFile); + + if (File.Exists(fullPath)) + { + using (StreamReader file = File.OpenText(fullPath)) + using (JsonTextReader reader = new JsonTextReader(file)) + { + JObject res = (JObject)JToken.ReadFrom(reader); + + string commitVer = res["version"].ToString(); + string commitHash = res["hash"].ToString(); + + output.Content.AppendHtml($"Version: {commitVer} - Hash: {commitHash.Truncate(10)}"); + } + } + } + } +} diff --git a/Teknik/Teknik.csproj b/Teknik/Teknik.csproj index 9462020..070b19b 100644 --- a/Teknik/Teknik.csproj +++ b/Teknik/Teknik.csproj @@ -77,7 +77,7 @@ - + @@ -108,4 +108,6 @@ + + diff --git a/Teknik/Views/Shared/_Footer.cshtml b/Teknik/Views/Shared/_Footer.cshtml index 42e71a8..b80ec4d 100644 --- a/Teknik/Views/Shared/_Footer.cshtml +++ b/Teknik/Views/Shared/_Footer.cshtml @@ -1,5 +1,6 @@ @using System.Diagnostics; @using System.Reflection; +@using Newtonsoft;