diff --git a/NuGet.Config b/NuGet.Config
new file mode 100644
index 0000000..a3c7cd7
--- /dev/null
+++ b/NuGet.Config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
index 77f1e0e..ceec584 100644
--- a/README.md
+++ b/README.md
@@ -6,13 +6,23 @@
[Usage](docs/Usage.md) | [To-do](TODO.md)
-A command line application for storing art request, commission, and YCH information. The application is a work in progress but contribution is welcomed.
+Art Manager (``artm``) is a command line application for storing art request, commission, and YCH information. The application is a work in progress but contribution is welcomed.
## Prerequisites
-- [.NET Core 3.0 SDK](https://dotnet.microsoft.com/download/dotnet-core/3.0)
- - Preview 6 or above
+- SDKs
+ - [.NET Core 2.1](https://dotnet.microsoft.com/download/dotnet-core/2.1)
+ - [.NET Core 3.0 Preview 7+](https://dotnet.microsoft.com/download/dotnet-core/2.1) for unit tests
+- IDEs or Text Editors
+ - Rider
+ - VSCode
+ - VS2019 16.2 (recommended)
+ - 16.3 for unit tests
## Platforms
-See the [platforms](Docs/Platforms.md) page.
\ No newline at end of file
+See the [platforms](Docs/Platforms.md) page.
+
+## Developer Note
+
+The unit tests are written in VB.NET. While Art Manager is being developed for production purposes, the unit tests were written in VB.NET in order to better understand the language without having to starting from scratch with a new project.
\ No newline at end of file
diff --git a/Src/.editorconfig b/Src/.editorconfig
index 3eea406..f6006f1 100644
--- a/Src/.editorconfig
+++ b/Src/.editorconfig
@@ -12,10 +12,6 @@ trim_trailing_whitespace = true
indent_style = space
indent_size = 2
-[*.{fs,fsx,fsi}]
-indent_style = space
-indent_size = 4
-
# VB and C# files
[*.{vb,cs}]
# avoid this. unless absolutely necessary
diff --git a/Src/ArtManager.CLI/ArtManager.CLI.csproj b/Src/ArtManager.CLI/ArtManager.CLI.csproj
new file mode 100644
index 0000000..14b6e2e
--- /dev/null
+++ b/Src/ArtManager.CLI/ArtManager.CLI.csproj
@@ -0,0 +1,22 @@
+
+
+
+ Exe
+ netcoreapp2.1
+ artm
+ Linux
+ 0.2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Src/ArtManager.CLI/ArtManager.CLI.licenseheader b/Src/ArtManager.CLI/ArtManager.CLI.licenseheader
new file mode 100644
index 0000000..1c10afc
--- /dev/null
+++ b/Src/ArtManager.CLI/ArtManager.CLI.licenseheader
@@ -0,0 +1,5 @@
+extensions: designer.cs generated.cs
+extensions: .cs .cpp .h
+// Copyright (c) Anthony Wilcox and contributors. All rights reserved.
+// Licensed under the GNU GPL v3 license. See LICENSE file in the project
+// root for full license information.
\ No newline at end of file
diff --git a/Src/ArtManager.CLI/ArtmConsts.cs b/Src/ArtManager.CLI/ArtmConsts.cs
new file mode 100644
index 0000000..7ab74b7
--- /dev/null
+++ b/Src/ArtManager.CLI/ArtmConsts.cs
@@ -0,0 +1,13 @@
+// Copyright (c) Anthony Wilcox and contributors. All rights reserved.
+// Licensed under the GNU GPL v3 license. See LICENSE file in the project
+// root for full license information.
+namespace ArtManager.CLI
+{
+ struct ArtmConsts
+ {
+ public const string APPNAME = "Art Manager";
+ public const string DBERR = "Failed to connect to database";
+ public const string DBFILE = "artm.db";
+ public const string DBCOL = "art";
+ }
+}
\ No newline at end of file
diff --git a/Src/ArtManager/CliArgs.cs b/Src/ArtManager.CLI/CliArgs.cs
similarity index 68%
rename from Src/ArtManager/CliArgs.cs
rename to Src/ArtManager.CLI/CliArgs.cs
index 9ef993d..80e8cf1 100644
--- a/Src/ArtManager/CliArgs.cs
+++ b/Src/ArtManager.CLI/CliArgs.cs
@@ -3,15 +3,19 @@
// root for full license information.
using EntryPoint;
-namespace ArtManager
+namespace ArtManager.CLI
{
- class BaseArgs : BaseCliArguments
+ class GlobalArgs : BaseCliArguments
{
- public BaseArgs() : base("Art Manager") { }
+ public GlobalArgs() : base(ArtmConsts.APPNAME) { }
[Option("debug", 'D')]
public bool Debug { get; set; }
+ }
+
+ class BaseArgs : GlobalArgs
+ {
///
/// Artwork name
///
@@ -49,14 +53,39 @@ class BaseArgs : BaseCliArguments
class YchArgs : PayArgs
{
[Required]
- [OptionParameter("ticket", 't')]
+ [OptionParameter("tickets", 't')]
public int Ticket { get; set; }
[Required]
- [OptionParameter("slot", 's')]
+ [OptionParameter("slots", 's')]
public int Slot { get; set; }
}
+ class RaffleArgs : GlobalArgs
+ {
+
+ ///
+ /// Artwork name
+ ///
+ [Required]
+ [OptionParameter("name", 'n')]
+ public string Name { get; set; }
+
+ ///
+ /// Maximum number of slots
+ ///
+ [Required]
+ [OptionParameter("tickets", 't')]
+ public int Tickets { get; set; }
+
+ ///
+ /// Maximum number of slots
+ ///
+ [Required]
+ [OptionParameter("slots", 's')]
+ public int Slots { get; set; }
+ }
+
///
/// Commission arguments extend the request by adding
/// price and payment options.
diff --git a/Src/ArtManager.CLI/CliCmd.cs b/Src/ArtManager.CLI/CliCmd.cs
new file mode 100644
index 0000000..9d5e052
--- /dev/null
+++ b/Src/ArtManager.CLI/CliCmd.cs
@@ -0,0 +1,116 @@
+// Copyright (c) Anthony Wilcox and contributors. All rights reserved.
+// Licensed under the GNU GPL v3 license. See LICENSE file in the project
+// root for full license information.
+using System;
+using System.Diagnostics;
+using System.IO;
+using ArtManager.Models;
+using EntryPoint;
+
+namespace ArtManager.CLI
+{
+ class CliCmd : BaseCliCommands
+ {
+ Art _art;
+ Order _order;
+
+ [DefaultCommand]
+ [Command("list")]
+ public void ListAll(string[] args)
+ {
+ if (File.Exists(ArtmConsts.DBFILE))
+ {
+ _order = new Order();
+ _order.DbListAll();
+ }
+ else
+ {
+ Console.WriteLine(ArtmConsts.DBERR);
+ }
+ }
+
+ [Command("req")]
+ public void Request(string[] args)
+ {
+ var cli = Cli.Parse(args);
+ _art = new Art()
+ {
+ Name = cli.Name,
+ Custmer = new Customer
+ {
+ Name = cli.Customer,
+ Contact = cli.Contact,
+ },
+ Description = cli.Description,
+ };
+ _order = new Order(_art);
+ _order.DBInsert();
+
+ if (cli.Debug)
+ _order.DbListAll();
+ }
+
+ [Command("com")]
+ public void Commission(string[] args)
+ {
+ var cli = Cli.Parse(args);
+ _art = new Art()
+ {
+ Name = cli.Name,
+ Custmer = new Customer
+ {
+ Name = cli.Customer,
+ Contact = cli.Contact,
+ Payment = cli.Payment,
+ },
+ Price = cli.Price,
+ Description = cli.Description,
+ };
+ _order = new Order(_art);
+ _order.DBInsert();
+
+ if (cli.Debug)
+ _order.DbListAll();
+ }
+
+ [Command("ych")]
+ public void YCH(string[] args)
+ {
+ var cli = Cli.Parse(args);
+ _art = new Art()
+ {
+ Name = cli.Name,
+ Custmer = new Customer
+ {
+ Name = cli.Customer,
+ Contact = cli.Contact,
+ Payment = cli.Payment,
+ },
+ Price = cli.Price,
+ Slot = cli.Slot,
+ Ticket = cli.Ticket
+ };
+ _order = new Order(_art);
+ _order.DBInsert();
+
+ if (cli.Debug || Debugger.IsAttached)
+ _order.DbListAll();
+ }
+
+ [Command("raf")]
+ public void Raffle(string[] args)
+ {
+ _order = new Order();
+ _order.DBRaffle(args);
+ }
+
+ public override void OnHelpInvoked(string helpText)
+ {
+ var monero = "44xZM7FSdJ9TpYK99Y2e4JYyprRWR3fKxJWsw4jEFL6CWtWQG35qWAPDTPDuAGy1v74bL2arKP2Eq7GVPfsWTZVs7MhKhf4";
+ var about = "A command line application used for storing request, commission, and YCH information.";
+ Console.WriteLine($"## About ##{Environment.NewLine}{about}{Environment.NewLine}");
+ Console.WriteLine($"{Environment.NewLine}## Donate ##{Environment.NewLine}Ko-Fi: ko-fi.com/antonwilc0x{Environment.NewLine}Monero: {monero}");
+ Console.WriteLine($"{Environment.NewLine}{helpText}");
+ }
+ }
+}
\ No newline at end of file
diff --git a/Src/ArtManager/Dockerfile b/Src/ArtManager.CLI/Dockerfile
similarity index 70%
rename from Src/ArtManager/Dockerfile
rename to Src/ArtManager.CLI/Dockerfile
index b0c058b..11e70b8 100644
--- a/Src/ArtManager/Dockerfile
+++ b/Src/ArtManager.CLI/Dockerfile
@@ -1,7 +1,7 @@
-FROM mcr.microsoft.com/dotnet/core/runtime:3.0-buster-slim AS base
+FROM mcr.microsoft.com/dotnet/core/runtime:2.1-buster-slim AS base
WORKDIR /app
-FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build
+FROM mcr.microsoft.com/dotnet/core/sdk:2.1-buster AS build
WORKDIR /src
COPY ["ArtManager/ArtManager.csproj", "ArtManager/"]
RUN dotnet restore "ArtManager/ArtManager.csproj"
diff --git a/Src/ArtManager.CLI/Order.cs b/Src/ArtManager.CLI/Order.cs
new file mode 100644
index 0000000..a8eb2f4
--- /dev/null
+++ b/Src/ArtManager.CLI/Order.cs
@@ -0,0 +1,92 @@
+// Copyright (c) Anthony Wilcox and contributors. All rights reserved.
+// Licensed under the GNU GPL v3 license. See LICENSE file in the project
+// root for full license information.
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using ArtManager.Models;
+using LiteDB;
+
+namespace ArtManager.CLI
+{
+ class Order
+ {
+ Art Art { get; set; }
+
+ public bool IsDebug { get; set; }
+
+ readonly List _arts = new List();
+
+ public Order() { }
+
+ public Order(Art order)
+ {
+ Art = order;
+ }
+
+ public void DBInsert()
+ {
+ try
+ {
+ using (var db = new LiteDatabase(ArtmConsts.DBFILE))
+ {
+ var art = db.GetCollection(ArtmConsts.DBCOL);
+ art.Insert(Art);
+ }
+ }
+ catch (Exception err)
+ {
+ throw new Exception(err.Message);
+ }
+ }
+
+ public void DBRaffle(string[] args)
+ {
+ /*
+ var cli = Cli.Parse(args);
+ var rand = new Random();
+ var tickets = rand.Next(cli.Tickets);
+ var slots = rand.Next(cli.Slots);
+ */
+
+ if (IsDebug)
+ {
+
+ }
+ else
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+ public void DbListAll()
+ {
+ try
+ {
+ using (var db = new LiteDatabase(ArtmConsts.DBFILE))
+ {
+ var art = db.GetCollection(ArtmConsts.DBCOL);
+ art.EnsureIndex(x => x.Hash);
+ var query = art.Include(x => x.Hash)
+ .Include(x => x.Custmer)
+ .Include(x => x.Name)
+ .FindAll();
+
+ foreach (var q in query)
+ _arts.Add(q);
+
+ var json = ArtUtils.AsJson(_arts);
+
+ if (IsDebug)
+ Console.WriteLine(json);
+ else if (Debugger.IsAttached)
+ Debug.WriteLine(json);
+ }
+ }
+ catch (Exception err)
+ {
+ throw new Exception(err.Message);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Src/ArtManager/Program.cs b/Src/ArtManager.CLI/Program.cs
similarity index 93%
rename from Src/ArtManager/Program.cs
rename to Src/ArtManager.CLI/Program.cs
index 8b7160e..939c3aa 100644
--- a/Src/ArtManager/Program.cs
+++ b/Src/ArtManager.CLI/Program.cs
@@ -3,7 +3,7 @@
// root for full license information.
using EntryPoint;
-namespace ArtManager
+namespace ArtManager.CLI
{
class Program
{
diff --git a/Src/ArtManager.CLI/Properties/launchSettings.json b/Src/ArtManager.CLI/Properties/launchSettings.json
new file mode 100644
index 0000000..2f9f30c
--- /dev/null
+++ b/Src/ArtManager.CLI/Properties/launchSettings.json
@@ -0,0 +1,11 @@
+{
+ "profiles": {
+ "ArtManager": {
+ "commandName": "Project",
+ "commandLineArgs": "-f \"test\""
+ },
+ "Docker": {
+ "commandName": "Docker"
+ }
+ }
+}
\ No newline at end of file
diff --git a/Src/ArtManager.Tests/ArtManager.Tests.vbproj b/Src/ArtManager.Tests/ArtManager.Tests.vbproj
new file mode 100644
index 0000000..6b6ebc4
--- /dev/null
+++ b/Src/ArtManager.Tests/ArtManager.Tests.vbproj
@@ -0,0 +1,20 @@
+
+
+
+ ArtManager.Tests
+ netcoreapp3.0
+
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Src/ArtManager.Tests/DatabaseTests.vb b/Src/ArtManager.Tests/DatabaseTests.vb
new file mode 100644
index 0000000..8c42f30
--- /dev/null
+++ b/Src/ArtManager.Tests/DatabaseTests.vb
@@ -0,0 +1,3 @@
+Public Class DatabaseTests
+
+End Class
diff --git a/Src/ArtManager.Tests/HashTests.vb b/Src/ArtManager.Tests/HashTests.vb
new file mode 100644
index 0000000..13dc538
--- /dev/null
+++ b/Src/ArtManager.Tests/HashTests.vb
@@ -0,0 +1,88 @@
+Imports ArtManager.Models
+Imports Xunit
+
+Namespace ArtManager.Tests
+
+ Public Class HashTests
+
+ Const VERSION = "0.2"
+ Const ORDER_TYPE = "order type:"
+
+ Dim _art As Art
+
+
+
+ Sub TestRequest(name As String, cust As String, desc As String, cont As String)
+
+ _art = New Art() With {
+ .Name = name,
+ .Description = desc,
+ .Custmer = New Customer() With {
+ .Name = cust,
+ .Contact = cont
+ }
+ }
+
+ VersionCheck(_art.Version, VERSION)
+
+ Assert.Equal(_art.Hash, ArtUtils.SearchHash(name, cust, cont))
+
+ Debug.WriteLine($"{Environment.NewLine}{_art.Name}, {ORDER_TYPE} {_art.Catagory}")
+ Debug.WriteLine(ArtUtils.AsJson(_art))
+
+ End Sub
+
+
+
+ Sub TestCommission(name As String, cust As String, desc As String,
+ cont As String, payment As String, price As Decimal)
+
+ _art = New Art() With {
+ .Name = name,
+ .Description = desc,
+ .Custmer = New Customer() With {
+ .Name = cust,
+ .Contact = cont,
+ .Payment = payment
+ },
+ .Price = price
+ }
+
+ VersionCheck(_art.Version, VERSION)
+
+ Assert.Equal(_art.Hash, ArtUtils.SearchHash(name, price, cust, cont))
+ Debug.WriteLine($"{Environment.NewLine}{_art.Name}, {ORDER_TYPE} {_art.Catagory}")
+ Debug.WriteLine(ArtUtils.AsJson(_art))
+
+ End Sub
+
+
+
+ Sub TestYCH(name As String, cust As String, cont As String, payment As String,
+ price As Decimal, ticket As Integer, slot As Integer)
+
+ _art = New Art() With {
+ .Name = name,
+ .Custmer = New Customer() With {
+ .Name = cust,
+ .Contact = cont,
+ .Payment = payment
+ },
+ .Price = price,
+ .Ticket = ticket,
+ .Slot = slot
+ }
+
+ VersionCheck(_art.Version, VERSION)
+
+ Assert.Equal(_art.Hash, ArtUtils.SearchHash(name, price, ticket, slot))
+ Debug.WriteLine($"{Environment.NewLine}{_art.Name}, {ORDER_TYPE} {_art.Catagory}")
+ Debug.WriteLine(ArtUtils.AsJson(_art))
+
+ End Sub
+
+ End Class
+End Namespace
+
diff --git a/Src/ArtManager.Tests/TestUtils.vb b/Src/ArtManager.Tests/TestUtils.vb
new file mode 100644
index 0000000..d9b4c20
--- /dev/null
+++ b/Src/ArtManager.Tests/TestUtils.vb
@@ -0,0 +1,11 @@
+Module TestUtils
+
+ Sub VersionCheck(actualVer As String, expectedVer As String)
+
+ If actualVer IsNot expectedVer Then
+ Debug.WriteLine($"Version mismatch: {actualVer} is not {expectedVer}")
+ End If
+
+ End Sub
+
+End Module
diff --git a/Src/ArtManager.sln b/Src/ArtManager.sln
index d559aa1..238bc32 100644
--- a/Src/ArtManager.sln
+++ b/Src/ArtManager.sln
@@ -8,9 +8,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
..\Platforms.md = ..\Platforms.md
..\README.md = ..\README.md
+ ..\docs\Usage.md = ..\docs\Usage.md
EndProjectSection
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ArtManager", "ArtManager\ArtManager.csproj", "{805F7833-D1E2-44ED-A0CA-1686AA6EEC5D}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ArtManager.CLI", "ArtManager.CLI\ArtManager.CLI.csproj", "{BD362A20-1E1B-4821-BD60-38DEC809738B}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ArtManager", "ArtManager\ArtManager.csproj", "{5E7E5428-DC14-455A-8765-3F5E82D3A21B}"
+EndProject
+Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "ArtManager.Tests", "ArtManager.Tests\ArtManager.Tests.vbproj", "{1559C02C-9FE5-4438-A7E2-502EAB7FF09C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -18,10 +23,18 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {805F7833-D1E2-44ED-A0CA-1686AA6EEC5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {805F7833-D1E2-44ED-A0CA-1686AA6EEC5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {805F7833-D1E2-44ED-A0CA-1686AA6EEC5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {805F7833-D1E2-44ED-A0CA-1686AA6EEC5D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {BD362A20-1E1B-4821-BD60-38DEC809738B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {BD362A20-1E1B-4821-BD60-38DEC809738B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {BD362A20-1E1B-4821-BD60-38DEC809738B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {BD362A20-1E1B-4821-BD60-38DEC809738B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {5E7E5428-DC14-455A-8765-3F5E82D3A21B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {5E7E5428-DC14-455A-8765-3F5E82D3A21B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {5E7E5428-DC14-455A-8765-3F5E82D3A21B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {5E7E5428-DC14-455A-8765-3F5E82D3A21B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {1559C02C-9FE5-4438-A7E2-502EAB7FF09C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {1559C02C-9FE5-4438-A7E2-502EAB7FF09C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {1559C02C-9FE5-4438-A7E2-502EAB7FF09C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {1559C02C-9FE5-4438-A7E2-502EAB7FF09C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Src/ArtManager/Art.cs b/Src/ArtManager/Art.cs
deleted file mode 100644
index 86f36f9..0000000
--- a/Src/ArtManager/Art.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (c) Anthony Wilcox and contributors. All rights reserved.
-// Licensed under the GNU GPL v3 license. See LICENSE file in the project
-// root for full license information.
-using System;
-
-namespace ArtManager
-{
- class Customer
- {
- public string Name { get; set; }
- public string Contact { get; set; }
- public string Payment { get; set; }
- }
-
- class Art
- {
- public Guid Id { get; } = Guid.NewGuid();
- public DateTime Date { get; } = DateTime.Now;
- public string Version { get; } = "0.1.1";
- public string Name { get; set; }
- public int? Ticket { get; set; }
- public int? Slot { get; set; }
- public decimal? Price { get; set; }
- public string Reference { get; set; }
- public string Description { get; set; }
- public Customer Custmer { get; set; }
- }
-}
diff --git a/Src/ArtManager/ArtManager.csproj b/Src/ArtManager/ArtManager.csproj
index 228d26e..d9076ad 100644
--- a/Src/ArtManager/ArtManager.csproj
+++ b/Src/ArtManager/ArtManager.csproj
@@ -1,18 +1,12 @@
- Exe
- netcoreapp3.0
- artm
- win-x64;osx-x64;linux-x64
- true
- Linux
+ netstandard2.0
-
-
-
+
+
diff --git a/Src/ArtManager/ArtUtils.cs b/Src/ArtManager/ArtUtils.cs
new file mode 100644
index 0000000..2268e5f
--- /dev/null
+++ b/Src/ArtManager/ArtUtils.cs
@@ -0,0 +1,109 @@
+using System;
+using System.Collections.Generic;
+using System.Security.Cryptography;
+using System.Text;
+using ArtManager.Models;
+using Newtonsoft.Json;
+
+namespace ArtManager
+{
+ public static class ArtUtils
+ {
+ static readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings
+ {
+ NullValueHandling = NullValueHandling.Ignore,
+ };
+
+ ///
+ /// Returns a Json string of the Art class, ignoring the
+ /// null values.
+ ///
+ ///
+ ///
+ public static string AsJson(Art art)
+ {
+ return JsonConvert.SerializeObject(art, Formatting.Indented, _serializerSettings);
+ }
+
+ ///
+ /// Returns a Json string of the Art class as an list,
+ /// ignoring the null values.
+ ///
+ ///
+ ///
+ public static string AsJson(List art)
+ {
+ return JsonConvert.SerializeObject(art, Formatting.Indented, _serializerSettings);
+ }
+
+ internal static string CalculateHash(Art art)
+ {
+ using (var sha = SHA256.Create())
+ {
+ var input = string.Empty;
+
+ switch (art.Catagory)
+ {
+ case Catagory.Commission:
+ input = $"{art.Name}/{art.Price}/{art.Custmer.Name}/{art.Custmer.Contact}";
+ break;
+ case Catagory.YCH:
+ input = $"{art.Name}/{art.Price}/{art.Ticket}/{art.Slot}";
+ break;
+ case Catagory.Request:
+ default:
+ input = $"{art.Name}/{art.Custmer.Name}/{art.Custmer.Contact}";
+ break;
+ }
+
+ var toBytes = Encoding.Unicode.GetBytes(input);
+ var computeHash = sha.ComputeHash(toBytes);
+ return Convert.ToBase64String(computeHash);
+ }
+ }
+
+ public static string SearchHash(string name, string cust, string cont)
+ {
+ var art = new Art
+ {
+ Name = name,
+ Custmer = new Customer
+ {
+ Name = cust,
+ Contact = cont,
+ },
+ };
+
+ return CalculateHash(art);
+ }
+
+ public static string SearchHash(string name, decimal price, string cust, string cont)
+ {
+ var art = new Art
+ {
+ Name = name,
+ Custmer = new Customer
+ {
+ Name = cust,
+ Contact = cont,
+ },
+ Price = price,
+ };
+
+ return CalculateHash(art);
+ }
+
+ public static string SearchHash(string name, decimal price, int ticket, int slot)
+ {
+ var art = new Art
+ {
+ Name = name,
+ Ticket = ticket,
+ Slot = slot,
+ Price = price,
+ };
+
+ return CalculateHash(art);
+ }
+ }
+}
diff --git a/Src/ArtManager/CliCmd.cs b/Src/ArtManager/CliCmd.cs
deleted file mode 100644
index f8d96c2..0000000
--- a/Src/ArtManager/CliCmd.cs
+++ /dev/null
@@ -1,102 +0,0 @@
-// Copyright (c) Anthony Wilcox and contributors. All rights reserved.
-// Licensed under the GNU GPL v3 license. See LICENSE file in the project
-// root for full license information.
-using System;
-using System.Threading.Tasks;
-using EntryPoint;
-
-namespace ArtManager
-{
- class CliCmd : BaseCliCommands
- {
- readonly string _dbDir = $"{Environment.CurrentDirectory}\\db";
-
- [DefaultCommand]
- [Command("req")]
- public async Task Request(string[] args)
- {
- var cli = Cli.Parse(args);
- var art = new Art()
- {
- Name = cli.Name,
- Custmer = new Customer
- {
- Name = cli.Customer,
- Contact = cli.Contact,
- },
- Description = cli.Description,
- };
- var order = new Order(art);
-
- await order.JsonFileAsync($"{_dbDir}\\{cli.Name}.arty");
- }
-
- [Command("com")]
- public async Task Commission(string[] args)
- {
- var cli = Cli.Parse(args);
- var art = new Art()
- {
- Name = cli.Name,
- Custmer = new Customer
- {
- Name = cli.Customer,
- Contact = cli.Contact,
- Payment = cli.Payment,
- },
- Price = cli.Price,
- Description = cli.Description,
- };
- var order = new Order(art);
-
- await order.JsonFileAsync($"{_dbDir}\\{cli.Name}.artc");
- }
-
- [Command("ych")]
- public async Task YCH(string[] args)
- {
- var cli = Cli.Parse(args);
- var art = new Art()
- {
- Name = cli.Name,
- Custmer = new Customer
- {
- Name = cli.Customer,
- Contact = cli.Contact,
- Payment = cli.Payment,
- },
- Price = cli.Price,
- Slot = cli.Slot,
- Ticket = cli.Ticket
- };
- var order = new Order(art);
-
- await order.JsonFileAsync($"{_dbDir}\\{cli.Name}-{cli.Ticket}-{cli.Slot}.arty");
- }
-
- /*
- [Command("raf")]
- public async Task Raffle(string[] args)
- {
- var cli = Cli.Parse(args);
- var rand = new Random();
- var slot = rand.Next(cli.Slot);
- var art = new Art()
- {
- Name = cli.Name,
- Custmer = new Customer
- {
- Name = cli.Customer,
- Contact = cli.Contact,
- Payment = cli.Payment,
- },
- Slot = slot,
- Ticket = cli.Ticket
- };
- var order = new Order(art);
-
- await order.JsonFileAsync($"{Environment.CurrentDirectory}\\{cli.Name}.arty");
- }
- */
- }
-}
\ No newline at end of file
diff --git a/Src/ArtManager/Models/Art.cs b/Src/ArtManager/Models/Art.cs
new file mode 100644
index 0000000..763999a
--- /dev/null
+++ b/Src/ArtManager/Models/Art.cs
@@ -0,0 +1,124 @@
+// Copyright (c) Anthony Wilcox and contributors. All rights reserved.
+// Licensed under the GNU GPL v3 license. See LICENSE file in the project
+// root for full license information.
+using System;
+using System.Diagnostics;
+using System.IO;
+using System.Threading.Tasks;
+using LiteDB;
+using Newtonsoft.Json;
+
+namespace ArtManager.Models
+{
+ public enum Catagory
+ {
+ Unknown,
+ Request,
+ Commission,
+ YCH,
+ Raffle,
+ }
+ public class Customer
+ {
+ public string Name { get; set; }
+ public string Contact { get; set; }
+ public string Payment { get; set; }
+ }
+
+ public class Art
+ {
+
+ public string Hash
+ {
+ get
+ {
+ return ArtUtils.CalculateHash(this);
+ }
+ }
+ public DateTime Timestamp { get; internal set; } = DateTime.Now;
+
+ // Only used in data export
+ [BsonIgnore]
+ public string Version { get; } = "0.2";
+
+ // Ignored in Json export since 0.1.1
+ [JsonIgnore]
+ public Catagory Catagory
+ {
+ get
+ {
+ if (Slot.HasValue && Ticket.HasValue)
+ return Catagory.YCH;
+ if (Description != string.Empty && Price.HasValue)
+ return Catagory.Commission;
+ else
+ return Catagory.Request;
+ }
+ }
+
+ public string Name { get; set; }
+ public int? Ticket { get; set; }
+ public int? Slot { get; set; }
+ public decimal? Price { get; set; }
+ public string Reference { get; set; }
+ public string Description { get; set; }
+ public Customer Custmer { get; set; }
+
+ public void Save(string dir, string filename)
+ {
+ var json = ArtUtils.AsJson(this);
+ var path = Path.Combine(dir, $"{filename}.artm");
+
+ try
+ {
+ using (var writer = new StreamWriter(path))
+ {
+ writer.Write(json);
+ }
+
+ if (Debugger.IsAttached)
+ Debug.WriteLine(json);
+ }
+ catch (IOException err)
+ {
+ throw new IOException(err.Message);
+ }
+ catch (Exception err)
+ {
+ throw new Exception(err.Message);
+ }
+ }
+
+ ///
+ /// Writes a formatted Json file with the proper data provided
+ /// by the database. Exention is not required.
+ ///
+ /// Path to directory
+ /// [filename].artm
+ ///
+ public async Task SaveAsync(string dir, string filename)
+ {
+ var json = ArtUtils.AsJson(this);
+ var path = Path.Combine(dir, $"{filename}.artm");
+
+ try
+ {
+ using (var writer = new StreamWriter(path))
+ {
+ await writer.WriteAsync(json);
+ }
+
+ if (Debugger.IsAttached)
+ Debug.WriteLine(json);
+ }
+ catch (IOException err)
+ {
+ throw new IOException(err.Message);
+ }
+ catch (Exception err)
+ {
+ throw new Exception(err.Message);
+ }
+ }
+ }
+}
diff --git a/Src/ArtManager/Order.cs b/Src/ArtManager/Order.cs
deleted file mode 100644
index 7607895..0000000
--- a/Src/ArtManager/Order.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright (c) Anthony Wilcox and contributors. All rights reserved.
-// Licensed under the GNU GPL v3 license. See LICENSE file in the project
-// root for full license information.
-using System;
-using System.IO;
-using System.Text.Json.Serialization;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace ArtManager
-{
- class Order
- {
- Art Art { get; set; }
-
- public Order(Art order)
- {
- Art = order;
- }
-
- public string JsonString
- {
- get
- {
- var op = new JsonSerializerOptions()
- {
- IgnoreNullValues = true,
- WriteIndented = true,
- };
-
- return JsonSerializer.ToString(Art, op);
- }
- }
-
- public async Task JsonFileAsync(string path)
- {
- try
- {
- if (!File.Exists(path))
- {
- var encodedTxt = Encoding.Unicode.GetBytes(JsonString);
-
- using var fstream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None, 4096, true);
-
- await fstream.WriteAsync(encodedTxt, 0, encodedTxt.Length);
- }
- }
- catch (IOException ex)
- {
- throw new IOException(ex.Message);
- }
- }
- }
-}
diff --git a/Src/ArtManager/Properties/launchSettings.json b/Src/ArtManager/Properties/launchSettings.json
deleted file mode 100644
index 6129295..0000000
--- a/Src/ArtManager/Properties/launchSettings.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "profiles": {
- "ArtManager": {
- "commandName": "Project",
- "commandLineArgs": "-D -c \"Lupe Jacobson\" -C \"Kasey.Goyette18\" -n \"virtual\" -d \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ut pretium enim. Sed a neque.\""
- },
- "Docker": {
- "commandName": "Docker"
- }
- }
-}
\ No newline at end of file
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644
index 0000000..ad21372
--- /dev/null
+++ b/appveyor.yml
@@ -0,0 +1,32 @@
+version: '{build}'
+
+clone_depth: 50
+
+cache:
+ - '%LOCALAPPDATA%\Microsoft\dotnet -> appveyor.yml'
+ - '%USERPROFILE%\.nuget\packages -> appveyor.yml, **\*.csproj, Nuget.Config'
+
+before_build:
+ # Install dotnet cli
+ - appveyor DownloadFile https://raw.githubusercontent.com/dotnet/cli/rel/1.0.1/scripts/obtain/dotnet-install.ps1
+ - powershell -File dotnet-install.ps1
+ - set PATH=%PATH%;%LOCALAPPDATA%\Microsoft\dotnet
+ - dotnet --version
+
+ # Restore packages
+ - dotnet restore .\src\EntryPoint
+ - dotnet restore .\test\EntryPointTests
+
+build_script:
+ - dotnet build .\src\EntryPoint
+ - dotnet build .\test\EntryPointTests
+
+test_script:
+ # .NET Core
+ - dotnet test .\test\EntryPointTests\EntryPointTests.csproj
+
+after_test:
+ - dotnet pack .\src\EntryPoint --configuration=Release --output=".\Nuget"
+
+artifacts:
+ - path: .\src\EntryPoint\Nuget\*.nupkg
\ No newline at end of file