maintenance expiration vs build date checking code

This commit is contained in:
2022-08-05 23:31:37 +00:00
parent 379ba76b31
commit d95510cf48
8 changed files with 96 additions and 14 deletions

View File

@@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
using AyaNova.Models;
using AyaNova.Biz;
using System.Reflection;
namespace AyaNova.Util
{
@@ -481,7 +482,7 @@ namespace AyaNova.Util
AttachToAType = attachToObject.AType,
LastModified = lastModified,
Size = FileSize,
AttachedByUserId=attachedByUserId
AttachedByUserId = attachedByUserId
};
@@ -828,7 +829,7 @@ namespace AyaNova.Util
{
return string.Empty;
}
//Linux ~ home folder special handling here
if (path.Contains('~'))
{
@@ -841,6 +842,34 @@ namespace AyaNova.Util
}
#endregion general utilities
#region licensing related utility to qualify upgradability
//https://www.meziantou.net/getting-the-date-of-build-of-a-dotnet-assembly-at-runtime.htm
public static DateTime GetLinkerTimestampUtc(Assembly assembly)
{
var location = assembly.Location;
return GetLinkerTimestampUtc(location);
}
public static DateTime GetLinkerTimestampUtc(string filePath)
{
const int peHeaderOffset = 60;
const int linkerTimestampOffset = 8;
var bytes = new byte[2048];
using (var file = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
file.Read(bytes, 0, bytes.Length);
}
var headerPos = BitConverter.ToInt32(bytes, peHeaderOffset);
var secondsSince1970 = BitConverter.ToInt32(bytes, headerPos + linkerTimestampOffset);
var dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
return dt.AddSeconds(secondsSince1970);
}
#endregion
}//eoc
}//eons