Saxonite 1.2.11.3. Sandtrap.

This commit is contained in:
Andy Howard
2024-04-24 17:18:05 +01:00
parent 496aaeee0b
commit 7748941680
104 changed files with 5615 additions and 177 deletions
@@ -45,6 +45,10 @@ namespace Sarand.Net.Standard.Base.Helpers
IconShock_TrashCan_Grey_72_png,
}
//-------------------------------------------------------------------
// Properties.
public static Assembly MyAssembly { get; } = typeof(SacsResourceHelper).GetTypeInfo().Assembly;
//-------------------------------------------------------------------
// NB 'Properties' not available in Core .Net project.
// Resources must be loaded via csproj so that they are available in the Manifest Resources:
@@ -58,7 +62,7 @@ namespace Sarand.Net.Standard.Base.Helpers
// </ItemGroup>
// REf. https://stackoverflow.com/questions/38762368/embedded-resource-in-net-core-libraries
//-------------------------------------------------------------------
public static String GetTextResource(TextResource textResource)
public static String GetResourceText(TextResource textResource)
{
String partialPath = "";
String resourceFilename = "";
@@ -85,18 +89,17 @@ namespace Sarand.Net.Standard.Base.Helpers
resourceFilename = "jquery-ui-1.12.1.min.js";
break;
}
if (!StringUtil.IsEmpty(resourceFilename))
if (!StringUtil.IsBlank(resourceFilename))
{
var assembly = typeof(SacsResourceHelper).GetTypeInfo().Assembly;
String resourceText = GetManifestResourceAsText(assembly, partialPath, resourceFilename);
if (!StringUtil.IsEmpty(resourceText))
String resourceText = GetManifestResourceAsText(MyAssembly, partialPath, resourceFilename);
if (!StringUtil.IsBlank(resourceText))
return resourceText;
}
return "";
}
//-------------------------------------------------------------------
public static byte[] GetImageResource(ImageResource imageResource)
public static byte[] GetResourceImage(ImageResource imageResource)
{
String partialPath = "";
String resourceFilename = "";
@@ -164,10 +167,9 @@ namespace Sarand.Net.Standard.Base.Helpers
break;
//-----------------------------------------------------------
}
if (!StringUtil.IsEmpty(resourceFilename))
if (!StringUtil.IsBlank(resourceFilename))
{
var assembly = typeof(SacsResourceHelper).GetTypeInfo().Assembly;
byte[] resourceData = GetManifestResourceAsBinary(assembly, partialPath, resourceFilename);
byte[] resourceData = GetManifestResourceAsBinary(MyAssembly, partialPath, resourceFilename);
if (resourceData != null)
return resourceData;
}
@@ -175,11 +177,12 @@ namespace Sarand.Net.Standard.Base.Helpers
}
//-------------------------------------------------------------------
// Text resources.
/// <summary>Retrieve resource as String based on assembly and partial resource name.</summary>
public static String GetManifestResourceAsText(Assembly assembly, String partialPath, String resourceNameEndsWith)
{
String fn = typeof(SacsResourceHelper).Name + ".GetManifestResourceAsText";
if (StringUtil.IsEmpty(resourceNameEndsWith)) return "";
if (StringUtil.IsBlank(resourceNameEndsWith)) return "";
using (Stream resourceStream = GetManifestResourceStream(assembly, partialPath, resourceNameEndsWith))
{
@@ -195,12 +198,13 @@ namespace Sarand.Net.Standard.Base.Helpers
}
//-------------------------------------------------------------------
// Binary resources.
/// <summary>Retrieve resource as byte array based on assembly and partial resource name.</summary>
public static byte[] GetManifestResourceAsBinary(Assembly assembly, String partialPath, String resourceNameEndsWith)
{
String fn = typeof(SacsResourceHelper).Name + ".GetManifestResourceAsBinary";
if (
StringUtil.IsEmpty(resourceNameEndsWith)) return null;
StringUtil.IsBlank(resourceNameEndsWith)) return null;
using (Stream resourceStream = GetManifestResourceStream(assembly, partialPath, resourceNameEndsWith))
{
if (resourceStream != null)
@@ -211,29 +215,36 @@ namespace Sarand.Net.Standard.Base.Helpers
}
}
}
SaLogger.Warn(fn + " Failed to locate text resource: " + resourceNameEndsWith);
SaLogger.Warn(SysUtil.Fn + " Failed to locate text resource: " + resourceNameEndsWith);
return null;
}
//-------------------------------------------------------------------
// Resource stream.
/// <summary>Retrieve resource as stream based on assembly and partial resource name.</summary>
public static Stream GetResourceStream(String partialPath, String resourceNameEndsWith)
{
return GetManifestResourceStream(MyAssembly, partialPath, resourceNameEndsWith);
}
/// <summary>Retrieve resource as stream based on assembly and partial resource name.</summary>
public static Stream GetManifestResourceStream(Assembly assembly, String partialPath, String resourceNameEndsWith)
{
String fn = typeof(SacsResourceHelper).Name + ".GetManifestResourceStream";
//Logger.Debug(fn + " Manifest resource names: " + new List<String>(assembly.GetManifestResourceNames()).Concat("","\n\t"));
//Logger.Debug(SysUtil.Fn + " Manifest resource names: " + new List<String>(assembly.GetManifestResourceNames()).Concat("","\n\t"));
foreach (String resourceName in assembly.GetManifestResourceNames())
{
//SaLogger.Debug(fn + " Resource: " + resourceName);
//SaLogger.Debug(SysUtil.Fn + " Resource: " + resourceName);
// Match the partial path.
if (!StringUtil.IsEmpty(partialPath) && !resourceName.ContainsCI(partialPath)) continue;
if (!StringUtil.IsBlank(partialPath) && !resourceName.ContainsCI(partialPath)) continue;
// Match the resource filename to the end of the resource name - resource names start with default namespace (eg. 'Sarand').
if (!resourceName.EndsWithCI(resourceNameEndsWith)) continue;
//SaLogger.Debug(fn + " Resource filename: " + resourceNameEndsWith + ". Matched to resource: " + resourceName);
//SaLogger.Debug(SysUtil.Fn + " Resource filename: " + resourceNameEndsWith + ". Matched to resource: " + resourceName);
return assembly.GetManifestResourceStream(resourceName);
}
SaLogger.Warn(fn + " Resource filename not found: " + resourceNameEndsWith);
SaLogger.Warn(SysUtil.Fn + " Resource filename not found: " + resourceNameEndsWith);
return null;
}
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using Sarand.Net.Standard.Base.App;
using Sarand.Net.Standard.Base.Core;
@@ -140,6 +141,14 @@ namespace Sarand.Net.Standard.Base.IO
return null;
}
//-------------------------------------------------------------------
// Utilities.
public static String TrimTrailingSlashes (String path)
{
return Regex.Replace(path, "[\\\\/]+$", "");
}
//-------------------------------------------------------------------
}
//=======================================================================
+4 -7
View File
@@ -14,7 +14,6 @@ namespace Sarand.Net.Standard.Base.Utils
#region Gets the build date and time (by reading the COFF header)
// http://msdn.microsoft.com/en-us/library/ms680313
/*
struct _IMAGE_FILE_HEADER
{
public ushort Machine;
@@ -25,11 +24,9 @@ namespace Sarand.Net.Standard.Base.Utils
public ushort SizeOfOptionalHeader;
public ushort Characteristics;
};
*/
static DateTime GetBuildDateTime (Assembly assembly)
public static DateTime GetBuildDateTime (this Assembly assembly)
{
/*
// Not available until .Net Standard 1.5.
var path = assembly.GetName().CodeBase;
if (File.Exists(path))
@@ -47,15 +44,15 @@ namespace Sarand.Net.Standard.Base.Utils
try
{
var coffHeader = (_IMAGE_FILE_HEADER)Marshal.PtrToStructure(pinnedBuffer.AddrOfPinnedObject(), typeof(_IMAGE_FILE_HEADER));
return TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1) + new TimeSpan(coffHeader.TimeDateStamp * TimeSpan.TicksPerSecond));
DateTime buildDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
return buildDate.AddSeconds(coffHeader.TimeDateStamp);
//return TimeZoneInfo.Local.ToLocalTime(new DateTime(1970, 1, 1) + new TimeSpan(coffHeader.TimeDateStamp * TimeSpan.TicksPerSecond));
}
finally
{
pinnedBuffer.Free();
}
}
*/
return new DateTime();
}
#endregion
+1 -1
View File
@@ -381,7 +381,7 @@ namespace Sarand.Net.Standard.Base.Utils
}
/// <summary>
/// Concatenate the partial path values with the specified dlimiter, stripping leading and trailing slashes and delimiters, and converting slashes and delimiters to the required delimiter.
/// Concatenate the partial path values with the specified delimiter, stripping leading and trailing slashes and delimiters, and converting slashes and delimiters to the required delimiter.
/// </summary>
private static String CombineFilePath(char delim, params String[] values)
{
+2 -2
View File
@@ -7,11 +7,11 @@
<ItemGroup>
<PackageReference Include="CsvHelper" Version="19.0.0" />
<PackageReference Include="MailKit" Version="4.3.0" />
<PackageReference Include="MailKit" Version="4.5.0" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.2" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.4" />
</ItemGroup>
<ItemGroup>