diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2022-06-01 21:13:43 +0200 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2022-06-01 21:13:43 +0200 |
| commit | 9383a2fb09ffb60cfe63683106945bd688affa59 (patch) | |
| tree | 65b3f4b48841583e355887db5de5a16e7005fc87 /src/Utilities | |
| download | vinjesvingenhandel.no-9383a2fb09ffb60cfe63683106945bd688affa59.tar.xz vinjesvingenhandel.no-9383a2fb09ffb60cfe63683106945bd688affa59.zip | |
feat: Initial commit after clean slate
Diffstat (limited to 'src/Utilities')
| -rw-r--r-- | src/Utilities/ConfigurationExtensions.cs | 26 | ||||
| -rw-r--r-- | src/Utilities/EnumName.cs | 38 | ||||
| -rw-r--r-- | src/Utilities/ImageFunctions.cs | 61 |
3 files changed, 125 insertions, 0 deletions
diff --git a/src/Utilities/ConfigurationExtensions.cs b/src/Utilities/ConfigurationExtensions.cs new file mode 100644 index 0000000..9205567 --- /dev/null +++ b/src/Utilities/ConfigurationExtensions.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using System.IO; +using Microsoft.Extensions.Configuration; +using VSH.Data.Static; + +namespace VSH.Utilities; + +public static class ConfigurationExtensions +{ + public static string GetVersion(this IConfiguration configuration) { + var versionFilePath = Path.Combine(AppPaths.WwwRoot.HostPath, "version.txt"); + if (!File.Exists(versionFilePath)) + return "unknown-" + configuration.GetValue<string>("ASPNETCORE_ENVIRONMENT"); + var versionText = File.ReadAllText(versionFilePath); + return versionText + "-" + configuration.GetValue<string>("ASPNETCORE_ENVIRONMENT"); + } + + public static IEnumerable<string> GetOrderStatusEmailRecipients(this IConfiguration configuration) { + var orderEmailRecipientsFilePath = + Path.Combine(AppPaths.AppData.HostPath, "settings", "order_email_addresses"); + if (!File.Exists(orderEmailRecipientsFilePath)) + return default; + var fileContent = File.ReadAllText(orderEmailRecipientsFilePath); + return fileContent.Split(";"); + } +}
\ No newline at end of file diff --git a/src/Utilities/EnumName.cs b/src/Utilities/EnumName.cs new file mode 100644 index 0000000..0bd871d --- /dev/null +++ b/src/Utilities/EnumName.cs @@ -0,0 +1,38 @@ +using System; +using VSH.Data.Enums; + +namespace VSH.Utilities; + +public static class EnumName +{ + public static string ForDocumentType(DocumentType type) => type switch { + DocumentType.SALES_TERMS => "Salsvilkår", + DocumentType.CONTACT_PAGE => "Kontaktside", + DocumentType.PRIVACY_POLICY => "Personvernerklæring", + DocumentType.ABOUT_PAGE => "Om oss", + DocumentType.DEALERS_PAGE => "Leverandørar", + _ => throw new ArgumentException("Unknown DocumentType " + type) + }; + + public static string ForOrderStatus(OrderStatus type) => type switch { + OrderStatus.FAILED => "Feila", + OrderStatus.CANCELLED => "Kansellert", + OrderStatus.COMPLETED => "Fullført", + OrderStatus.IN_PROGRESS => "Pågåande", + OrderStatus.AWAITING_VIPPS => "Ventar på vipps", + OrderStatus.AWAITING_INVOICE => "Ventar på faktura", + _ => throw new ArgumentException("Unknown OrderStatus " + type) + }; + + public static string ForPriceSuffix(PriceSuffix type) => type switch { + PriceSuffix.PER => ",-", + PriceSuffix.KILOS => ",- kg", + _ => throw new ArgumentException("Unknown PriceSuffix " + type) + }; + + public static string ForPaymentType(OrderPaymentType type) => type switch { + OrderPaymentType.VIPPS => "Vipps", + OrderPaymentType.INVOICE_BY_EMAIL => "Faktura på mail", + _ => throw new ArgumentException("Unknown OrderPaymentType " + type) + }; +}
\ No newline at end of file diff --git a/src/Utilities/ImageFunctions.cs b/src/Utilities/ImageFunctions.cs new file mode 100644 index 0000000..dd2e07c --- /dev/null +++ b/src/Utilities/ImageFunctions.cs @@ -0,0 +1,61 @@ +using System; +using System.Diagnostics; +using System.IO; +using ImageMagick; +using IOL.Helpers; +using VSH.Data.Static; + +namespace VSH.Utilities; + +public static class ImageFunctions +{ + private static MagickGeometry SmallGeometry => new(300); + private static MagickGeometry MiniGeometry => new(150); + private static MagickGeometry NormalGeometry => new(1280, 720); + + public static void CreateProductImageCollection(FileInfo path) { + try { + using var image = new MagickImage(path); + if (image.Width > NormalGeometry.Width) { + image.Resize(NormalGeometry); + image.Write(path); + } + + Debug.WriteLine(path.Name); + + if (image.Width > SmallGeometry.Width) { + var fileName = Path.Combine(path.DirectoryName ?? AppPaths.ProductImages.HostPath, + path.Name.ExtractFileName() + "-300" + path.Extension); + if (!File.Exists(fileName)) { + image.Resize(SmallGeometry); + image.Write(fileName); + } + } + + if (image.Width > MiniGeometry.Width) { + var fileName = Path.Combine(path.DirectoryName ?? AppPaths.ProductImages.HostPath, + path.Name.ExtractFileName() + "-150" + path.Extension); + if (!File.Exists(fileName)) { + image.Resize(MiniGeometry); + image.Write(fileName); + } + } + } catch (Exception e) { + Console.WriteLine(e); + throw; + } + } + + public static void EnsureNormalOrLessImageResolution(FileInfo path) { + try { + using var image = new MagickImage(path); + if (image.Width <= NormalGeometry.Width) + return; + image.Resize(NormalGeometry); + image.Write(path); + } catch (Exception e) { + Console.WriteLine(e); + throw; + } + } +}
\ No newline at end of file |
