Compare commits

..
15 Commits
Author SHA1 Message Date
james262 67fa25e385 updated .net to .net 10.
updated libraries.
2026-04-22 15:07:43 -04:00
james262 9333386aa7 added async to long load time items. 2026-04-22 15:07:01 -04:00
james262 9cc04a6133 added check for old expiry upon date entry. 2026-04-22 15:06:04 -04:00
james262 334a8e95bc Added a puce listing so listings sent to puce can be checked
for any updates.
2026-04-22 15:05:21 -04:00
james262 cc90e7f682 Updated gitignore for appdata/puce folder. 2026-04-22 15:00:43 -04:00
james262 a57e3f48cf Updated Packages. 2024-08-08 13:21:11 -04:00
james262 8181f31d27 Added web order hard copy save to local hdd
from external server.
2023-11-10 15:14:17 -05:00
james262 ecb0873f7f Added file path references. 2023-11-09 14:29:28 -05:00
james262 de55203a12 Updated Libraries. 2023-11-09 14:28:50 -05:00
james262 9347ab03a6 merge? 2023-06-29 11:07:48 -04:00
james262 4f3719b71f Added sys.threading.ratelimiting 2023-06-08 12:20:32 -04:00
james262 1a71f4bd71 Added Newtonsoft JSON.
Added input formatter for Cart saving.
Added preload for INV, Customers.
Added System Text Json.
Added ANC Newstonsoft integration.
Added Debug/Release Switch for libraries.
Added HtmlFactory
2023-05-18 15:18:41 -04:00
james262 677582d4bb Added Newtonsoft JSON.
Added input formatter for Cart saving.
Added preload for INV, Customers.
2023-05-18 15:16:14 -04:00
james262 6466d17905 Added incoming Cart save functions. 2023-05-18 15:15:17 -04:00
james262 ebf3d3069b Email Namespace change update from CVRLIB 2023-05-18 15:14:43 -04:00
9 changed files with 469 additions and 27 deletions
+1
View File
@@ -452,3 +452,4 @@ $RECYCLE.BIN/
!.vscode/tasks.json !.vscode/tasks.json
!.vscode/launch.json !.vscode/launch.json
!.vscode/extensions.json !.vscode/extensions.json
/AppData/Puce
+28
View File
@@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Mvc.Formatters;
namespace CA_ANC.Formatters;
public class Formatters {
}
public class ByteArrayInputFormatter : InputFormatter
{
public ByteArrayInputFormatter()
{
SupportedMediaTypes.Add(Microsoft.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/octet-stream"));
}
protected override bool CanReadType(Type type)
{
return type == typeof(byte[]);
}
public async override Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context)
{
var stream = new MemoryStream();
await context.HttpContext.Request.Body.CopyToAsync(stream);
return await InputFormatterResult.SuccessAsync(stream.ToArray());
}
}
-1
View File
@@ -29,6 +29,5 @@ namespace VSERVERWS.Global {
} }
} }
} }
+164
View File
@@ -0,0 +1,164 @@
using System.Web;
using System.Net;
using System.Net.Http;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using CVRLIB.CARTS;
using static CVRLIB.CVSTRINGS.TextFuncs;
using CVRLIB;
using CVRLIB.Generic;
using ZXing;
using Newtonsoft.Json;
namespace VSERVERWS.Controllers;
//https://vserverws.cvr.cvrco.ca/api/cart/CartStatus
[Route("api/Cart/[action]")]
[ApiController]
public class CartController : ControllerBase {
[HttpGet]
public IActionResult CartStatus() {
var rOBJ = new { STATUS = "OK" };
return new JsonResult(rOBJ);
}
//https://localhost:7210/api/Cart/SubmitCartHTML?id=1337&source=beta%2Ecvr%2Ecvrco%2Eca
[HttpPost]
[Consumes("text/plain")]
public async Task<IActionResult> SubmitCartHTML(string id, string source) {
var rTOR = new TryOperationResult();
var isEncrypted = false;
var tdata = "";
var data = "";
var HTML_PATH = Program.XDRIVE + "\\CVRCO\\BU\\Carts\\HTML";
var inSource = HttpUtility.UrlDecode(source);
if (!string.IsNullOrEmpty(inSource)) {
HTML_PATH = HTML_PATH + "\\" + inSource;
if (!Directory.Exists(HTML_PATH)) {
Directory.CreateDirectory(HTML_PATH);
}
} else {
rTOR.AddResult(false, "READ_SOURCE", "no source provided!");
return new JsonResult(rTOR);
}
using (var SR = new StreamReader(Request.Body)) {
data = await SR.ReadToEndAsync();
}
if (!Directory.Exists(HTML_PATH)) {
Directory.CreateDirectory(HTML_PATH);
}
if (!tdata.Contains("<html>")) { isEncrypted = true; }
try {
if (isEncrypted) {
tdata = NonSecureDecryptHexStringToString(data);
}
if (!tdata.Contains("<html>")) {
throw new Exception("Invalid html string");
}
using (var FS = new FileStream(HTML_PATH + "\\" + id + ".txt", FileMode.Create, FileAccess.Write, FileShare.None)) {
using (var SW = new StreamWriter(FS)) {
if (isEncrypted) {
await SW.WriteAsync(data);
} else {
await SW.WriteAsync(NonSecureEncryptStringToHexString(tdata));
}
};
};
rTOR.AddResult(true, "TRY_SAVE_HTML_CART");
} catch (Exception ex) {
rTOR.AddResult(false, "TRY_SAVE_HTML_CART", ex.Message, ex);
Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
}
return new JsonResult(rTOR);
}
[HttpPost]
public async Task<IActionResult> SubmitCartData([FromBody] byte[] data) {
var JSON = await NonSecureDecryptByteAToStringAsync(data);
var rOBJ = new TryCartOperationResult();
try {
var tCART = JsonConvert.DeserializeObject<ShoppingCart>(JSON);
if (tCART != null) {
tCART.TrySyncToInventory(CVGlobal.INVENTORY);
await tCART.SaveToDBAsync();
rOBJ.AddResult(true, "CART_SAVE_TO_DB");
} else {
rOBJ.AddResult(false, "CONVERT_TO_JSON", "Failed to convert to json from byte data.");
}
} catch (Exception ex) {
rOBJ.AddResult(false, "CART_SAVE_TRY", ex.Message, ex);
}
//return new result
return new JsonResult(rOBJ);
}
}
+12 -3
View File
@@ -35,9 +35,9 @@ namespace VSERVERWS.Controllers {
[HttpGet] [HttpGet]
public IActionResult PaymentStatus() { public IActionResult PaymentStatus() {
//api/Payment/PaymentStatus
CVRPRINTER_MF264dw? CVP2 = CVP_MF264dw; CVRPRINTER_MF264dw? CVP2 = CVP_MF264dw;
CVRPRINTER_MFC_L8900CDW? CVP3 = CVP_MFC_L8900CDW; CVRPRINTER_MFC_L8900CDW? CVP3 = CVP_MFC_L8900CDW;
@@ -115,7 +115,7 @@ namespace VSERVERWS.Controllers {
if (DateTime.Now.Subtract(LastError).Hours > 2) { if (DateTime.Now.Subtract(LastError).Hours > 2) {
Email E = new Email(); Email E = new Email();
E.SEND_FROM = Email.SEND_FROM_ENUM.OFFICE365; E.SEND_FROM = SEND_FROM_ENUM.OFFICE365;
string B = "Payment System Printer error / offline: Check applicable printer(s) for error or offline!"; string B = "Payment System Printer error / offline: Check applicable printer(s) for error or offline!";
string S = "<cc> Payment System Printer Error: Check Printer(s)!"; string S = "<cc> Payment System Printer Error: Check Printer(s)!";
@@ -148,7 +148,7 @@ namespace VSERVERWS.Controllers {
object? rOBJ = null; object? rOBJ = null;
Email E = new Email(); Email E = new Email();
E.SEND_FROM = Email.SEND_FROM_ENUM.OFFICE365; E.SEND_FROM = SEND_FROM_ENUM.OFFICE365;
bool DupRetry = false; bool DupRetry = false;
@@ -249,6 +249,13 @@ CCRETRY:
CI_N.EMAIL.ToLower().Trim() == tCI.EMAIL.ToLower().Trim() CI_N.EMAIL.ToLower().Trim() == tCI.EMAIL.ToLower().Trim()
)) { )) {
if (tCI.EXPIRY.Ticks > CI_N.EXPIRY.Ticks) {
//had to be added in case they send a duplicate card #, but provide old expiry date.
//so skip saving if the current expiry is greater than the one provided.
goto SKIP_REENTER;
}
CI_N.UID = tCI.UID; CI_N.UID = tCI.UID;
CI_N.LNAME = tCI.LNAME; CI_N.LNAME = tCI.LNAME;
@@ -256,6 +263,8 @@ CCRETRY:
goto CCRETRY; goto CCRETRY;
} }
SKIP_REENTER:
D += "-" + tCI.UID; D += "-" + tCI.UID;
B = "Attempted to Add duplicate Credit Card from WEB. <br><br><b>Details (OLD | NEW):</b><br> Ref: " + CI_N.REF_NUM + "<br> USE: " + tCI.UID + "<br>CVNUM: " + tCI.CUST_UID + " | " + CI_N.CUST_UID + "<br>FNAME: " + tCI.FNAME + " | " + CI_N.FNAME + "<br>LNAME: " + tCI.LNAME + " | " + CI_N.LNAME + "<br>PHONE: " + tCI.PHONE + " | " + CI_N.PHONE + "<br>EMAIL: " + tCI.EMAIL + " | " + CI_N.EMAIL + "<br>LAST5: " + tCI.LAST5 + " | " + CI_N.LAST5 + "<br>EXPIRY: " + tCI.EXPIRY.ToString("MM / yyyy") + " | " + CI_N.EXPIRY.ToString("MM / yyyy") + "<br>CVV (NEW ONLY): " + CI_N.SD; B = "Attempted to Add duplicate Credit Card from WEB. <br><br><b>Details (OLD | NEW):</b><br> Ref: " + CI_N.REF_NUM + "<br> USE: " + tCI.UID + "<br>CVNUM: " + tCI.CUST_UID + " | " + CI_N.CUST_UID + "<br>FNAME: " + tCI.FNAME + " | " + CI_N.FNAME + "<br>LNAME: " + tCI.LNAME + " | " + CI_N.LNAME + "<br>PHONE: " + tCI.PHONE + " | " + CI_N.PHONE + "<br>EMAIL: " + tCI.EMAIL + " | " + CI_N.EMAIL + "<br>LAST5: " + tCI.LAST5 + " | " + CI_N.LAST5 + "<br>EXPIRY: " + tCI.EXPIRY.ToString("MM / yyyy") + " | " + CI_N.EXPIRY.ToString("MM / yyyy") + "<br>CVV (NEW ONLY): " + CI_N.SD;
S = "<cc> Duplicate CC received for Ref Num: " + CI_N.REF_NUM + " Use Card: " + tCI.UID; S = "<cc> Duplicate CC received for Ref Num: " + CI_N.REF_NUM + " Use Card: " + tCI.UID;
+67
View File
@@ -0,0 +1,67 @@
@page "/Puce"
@model PuceModel
@{
ViewData["Title"] = "Puce Listing";
Layout = "";
}
<h1>@ViewData["Title"]</h1>
<br />
<p>
Anything not listed in the table(s) below are out of stock and no longer available.
</p>
@{
List<string> prefixkeys = new();
if (Model.PuceCVINV.Count > 0)
{
prefixkeys = Model.PuceCVINV.Keys.ToList();
prefixkeys.Sort();
}
}
@foreach(var PREFIX in prefixkeys) {
var tCVINV = Model.PuceCVINV[PREFIX];
List<string> CVI_KEYS = tCVINV.Keys.ToList();
CVI_KEYS.Sort();
var firstCVI = tCVINV.ToListofCVITEMS().First();
<h3>@firstCVI.VENDOR_NAME - @firstCVI.SCALE</h3>
<table border="1" cellpadding="5">
<thead>
<tr>
<th>Item Code</th>
<th>Description</th>
<th>Quantity</th>
<th>Price</th>
</tr>
</thead>
<tbody>
@foreach (var CVI_KEY in CVI_KEYS) {
CVRLIB.Inventory.CVITEM CVI = tCVINV[CVI_KEY];
var PCOST = CVI.PRODUCT_COST == 0 ? CVI.PRICE : CVI.PRODUCT_COST * 1.05m;
<tr>
<td>@CVI.ITEM_UID</td>
<td>@CVI.PRODUCT_DESCRIPTION</td>
<td>@CVI.STOCK_RAW</td>
<td>@PCOST.ToString("c")</td>
</tr>
}
</tbody>
</table>
}
+72
View File
@@ -0,0 +1,72 @@
using System.IO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using CVRLIB.Inventory;
namespace VSERVERWS.Pages;
public class PuceModel : PageModel {
private readonly ILogger<PrivacyModel> _logger;
public Dictionary<string, CVINVENTORY> PuceCVINV = new Dictionary<string, CVINVENTORY>();
public PuceModel(ILogger<PrivacyModel> logger) {
_logger = logger;
}
public async Task OnGet() {
var tCVINV = await PuceListINV();
PuceCVINV = tCVINV.ParseByCodePrefix();
}
public async Task<CVINVENTORY> PuceListINV() {
CVINVENTORY rCVI;
var PCODES = new SortedSet<string>();
var pcodefiles = Directory.GetFiles(Program.AppData + @"\Puce", "*.csv");
foreach ( var filepath in pcodefiles ) {
var LINES = await System.IO.File.ReadAllLinesAsync(filepath);
foreach (var line in LINES) {
if (string.IsNullOrWhiteSpace(line)) continue;
string PCODE = line.Split(',')[0].Trim(['"']);
PCODES.Add(PCODE);
}
}
rCVI = await CVINVENTORY.LoadItemsAsync(PCODES);
rCVI.RemoveZeroQTY();
return rCVI;
}
}
+70 -7
View File
@@ -1,18 +1,32 @@
using CVRLIB.CVENVIRONMENT;
using static CVRLIB.CVGlobal;
using CA_ANC.Formatters;
using CVRLIB;
using CVRLIB.Inventory;
using CVRLIB.Customers;
//ZXING.dll does not copy properly to publish folder, copy manually from another lib, ie cvrlib-nf. //ZXING.dll does not copy properly to publish folder, copy manually from another lib, ie cvrlib-nf.
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
builder.Services.AddRazorPages(); builder.Services.AddRazorPages();
builder.Services.AddControllers().AddJsonOptions((options => { //builder.Services.AddControllers().AddJsonOptions((options => {
//was changing PRINTER_NAME to printeR_NAME (pascal Case: https://github.com/dotnet/runtime/issues/30887) // //was changing PRINTER_NAME to printeR_NAME (pascal Case: https://github.com/dotnet/runtime/issues/30887)
options.JsonSerializerOptions.PropertyNamingPolicy = null; // options.JsonSerializerOptions.PropertyNamingPolicy = null;
})); //}));
builder.Services
.AddControllers(options => { options.InputFormatters.Add(new ByteArrayInputFormatter()); })
.AddNewtonsoftJson()
;
var app = builder.Build(); var app = builder.Build();
@@ -24,7 +38,27 @@ if (!app.Environment.IsDevelopment()) {
} }
VSERVERWS.Global.Globals.IsDevelopment = app.Environment.IsDevelopment();
var env = builder.Environment;
//X:\CVRCO\C#\VSERVERWS\VSERVERWS\wwwroot
AppPath = env.WebRootPath;
AppData = env.ContentRootPath + @"\AppData";
//X:\CVRCO\C#\VSERVERWS\VSERVERWS\
HTTPROOT = env.ContentRootPath;
//VSERVERWS.Global.Globals.IsDevelopment = app.Environment.IsDevelopment();
VSERVERWS.Global.Globals.IsDevelopment = false;
await Task.Run(() => VSERVERWS.Global.Globals.LoadPrinters());
await Task.Run(() => CVGlobal.TryGlobalPRELoadCVCollections(new[] { typeof(CVINVENTORY), typeof(CVCustomers) }));
@@ -39,7 +73,36 @@ app.UseAuthorization();
app.MapRazorPages(); app.MapRazorPages();
app.Run(); // app.Run();
await app.RunAsync();
VSERVERWS.Global.Globals.LoadPrinters();
public partial class Program {
public static CVSECRETS? CVS { get; set; } = null;
public static string AppPath { get; set; } = "";
public static string HTTPROOT { get; set; } = "";
public static string AppData { get; set; } = "";
public static bool IsDevMode { get; set; } = false;
public static string XDRIVE {
get {
if (Directory.Exists("X:\\Shares\\cvrdata")) {
return "X:\\Shares\\cvrdata";
} else {
return "X:";
}
}
}
}
+55 -16
View File
@@ -1,27 +1,66 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net10.0-windows7.0</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
<AssemblyVersion>1.0.17.1850</AssemblyVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Magick.NET-Q8-AnyCPU" Version="11.3.0" />
<PackageReference Include="Magick.NET.Core" Version="11.3.0" /> <ItemGroup>
<PackageReference Include="Microsoft.Windows.Compatibility" Version="6.0.0" /> <PackageReference Include="Magick.NET-Q8-AnyCPU" Version="14.12.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" /> <PackageReference Include="Magick.NET.Core" Version="14.12.0" />
<PackageReference Include="ZXing.Net" Version="0.16.8" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="10.0.6" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="10.0.6" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="7.0.0" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="10.0.6" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="System.Drawing.Common" Version="10.0.6" />
<PackageReference Include="System.Formats.Asn1" Version="10.0.6" />
<PackageReference Include="System.IO.Packaging" Version="10.0.6" />
<PackageReference Include="System.Text.Json" Version="10.0.6" />
<PackageReference Include="System.Threading.RateLimiting" Version="10.0.6" />
<PackageReference Include="ZXing.Net" Version="0.16.11" />
<FrameworkReference Include="Microsoft.WindowsDesktop.App" /> <FrameworkReference Include="Microsoft.WindowsDesktop.App" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Reference Include="CVRLIB">
<HintPath>..\..\VB.NET\CVRLIB\CVRLIB\bin\Release\netstandard2.0\CVRLIB.dll</HintPath> <ItemGroup>
</Reference> <Folder Include="AppData\Puce\" />
<Reference Include="CVRLIB-NF"> </ItemGroup>
<HintPath>..\..\VB.NET\CVRLIB-NF\CVRLIB-NF\bin\Release\CVRLIB-NF.dll</HintPath>
</Reference>
</ItemGroup> <Choose>
<When Condition=" '$(Configuration)'=='Debug' ">
<ItemGroup>
<Reference Include="CVRLIB">
<HintPath>..\..\VB.NET\CVRLIB\CVRLIB\bin\Debug\netstandard2.0\CVRLIB.dll</HintPath>
</Reference>
<Reference Include="CVRLIB-NF">
<HintPath>..\..\VB.NET\CVRLIB-NF\CVRLIB-NF\bin\Debug\CVRLIB-NF.dll</HintPath>
</Reference>
<Reference Include="HtmlFactory">
<HintPath>..\HtmlFactory\HtmlFactory\bin\Debug\netstandard2.0\HtmlFactory.dll</HintPath>
</Reference>
</ItemGroup>
</When>
<When Condition=" '$(Configuration)'=='Release' ">
<ItemGroup>
<Reference Include="CVRLIB">
<HintPath>..\..\VB.NET\CVRLIB\CVRLIB\bin\Release\netstandard2.0\CVRLIB.dll</HintPath>
</Reference>
<Reference Include="CVRLIB-NF">
<HintPath>..\..\VB.NET\CVRLIB-NF\CVRLIB-NF\bin\Release\CVRLIB-NF.dll</HintPath>
</Reference>
<Reference Include="HtmlFactory">
<HintPath>..\HtmlFactory\HtmlFactory\bin\Release\netstandard2.0\HtmlFactory.dll</HintPath>
</Reference>
</ItemGroup>
</When>
</Choose>
</Project> </Project>