Skip to content

Commit

Permalink
Feature parity with Rust counterpart
Browse files Browse the repository at this point in the history
- C# rewrite of Art Manager is now feature parity with it's Rust counterpart with file I/O now implemented. The only minor difference between the two is the file I/O is now asynchronous.
- Dockerfile for Linux
- Prep for database with Entity Framework
  • Loading branch information
tonytins committed Jul 12, 2019
1 parent 720a003 commit 1318fc7
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 35 deletions.
20 changes: 20 additions & 0 deletions Src/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.vs
**/.vscode
**/*.*proj.user
**/azds.yaml
**/charts
**/bin
**/obj
**/Dockerfile
**/Dockerfile.develop
**/docker-compose.yml
**/docker-compose.*.yml
**/*.dbmdl
**/*.jfm
**/secrets.dev.yaml
**/values.dev.yaml
**/.toolstarget
3 changes: 3 additions & 0 deletions Src/ArtManager/ArtManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
<AssemblyName>artm</AssemblyName>
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64</RuntimeIdentifiers>
<PublishTrimmed>true</PublishTrimmed>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EntityFramework" Version="6.2.0" />
<PackageReference Include="EntryPoint" Version="1.2.3" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.7.11" />
</ItemGroup>

</Project>
10 changes: 0 additions & 10 deletions Src/ArtManager/ArtmConsts.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Src/ArtManager/CliArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace ArtManager
{
class BaseArgs : BaseCliArguments
{
public BaseArgs() : base(ArtmConsts.PROGNAME) { }
public BaseArgs() : base("Art Manager") { }

[Option("debug", 'D')]
public bool Debug { get; set; }
Expand Down
33 changes: 13 additions & 20 deletions Src/ArtManager/CliCmd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
// 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 void Request(string[] args)
public async Task Request(string[] args)
{
var cli = Cli.Parse<BaseArgs>(args);
var art = new Art()
Expand All @@ -25,14 +28,11 @@ public void Request(string[] args)
};
var order = new Order(art);

if (cli.Debug)
{
Console.WriteLine(order.ToJson);
}
await order.JsonFileAsync($"{_dbDir}\\{cli.Name}.arty");
}

[Command("com")]
public void Commission(string[] args)
public async Task Commission(string[] args)
{
var cli = Cli.Parse<PayArgs>(args);
var art = new Art()
Expand All @@ -49,14 +49,11 @@ public void Commission(string[] args)
};
var order = new Order(art);

if (cli.Debug)
{
Console.WriteLine(order.ToJson);
}
await order.JsonFileAsync($"{_dbDir}\\{cli.Name}.artc");
}

[Command("ych")]
public void YCH(string[] args)
public async Task YCH(string[] args)
{
var cli = Cli.Parse<YchArgs>(args);
var art = new Art()
Expand All @@ -74,14 +71,12 @@ public void YCH(string[] args)
};
var order = new Order(art);

if (cli.Debug)
{
Console.WriteLine(order.ToJson);
}
await order.JsonFileAsync($"{_dbDir}\\{cli.Name}-{cli.Ticket}-{cli.Slot}.arty");
}

/*
[Command("raf")]
public void Raffle(string[] args)
public async Task Raffle(string[] args)
{
var cli = Cli.Parse<YchArgs>(args);
var rand = new Random();
Expand All @@ -100,10 +95,8 @@ public void Raffle(string[] args)
};
var order = new Order(art);
if (cli.Debug)
{
Console.WriteLine(order.ToJson);
}
await order.JsonFileAsync($"{Environment.CurrentDirectory}\\{cli.Name}.arty");
}
*/
}
}
18 changes: 18 additions & 0 deletions Src/ArtManager/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM mcr.microsoft.com/dotnet/core/runtime:3.0-buster-slim AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build
WORKDIR /src
COPY ["ArtManager/ArtManager.csproj", "ArtManager/"]
RUN dotnet restore "ArtManager/ArtManager.csproj"
COPY . .
WORKDIR "/src/ArtManager"
RUN dotnet build "ArtManager.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "ArtManager.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "artm.dll"]
30 changes: 26 additions & 4 deletions Src/ArtManager/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
// 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 NewOrder { get; set; }
Art Art { get; set; }

public Order(Art order)
{
NewOrder = order;
Art = order;
}

public string ToJson
public string JsonString
{
get
{
Expand All @@ -25,7 +28,26 @@ public string ToJson
WriteIndented = true,
};

return JsonSerializer.ToString(NewOrder, op);
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);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Src/ArtManager/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"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"
}
}
}

0 comments on commit 1318fc7

Please sign in to comment.