ToData now supports multiple formats.
Introduce `ProgrartC` to build a single image to work with other build tools. Added a `CombinedStorageProvider` to allow aggregate storage providers.
This commit is contained in:
47
ProgrartC/Dockerfile
Normal file
47
ProgrartC/Dockerfile
Normal file
@@ -0,0 +1,47 @@
|
||||
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||
|
||||
# These ARGs allow for swapping out the base used to make the final image when debugging from VS
|
||||
ARG LAUNCHING_FROM_VS
|
||||
# This sets the base image for final, but only if LAUNCHING_FROM_VS has been defined
|
||||
ARG FINAL_BASE_IMAGE=${LAUNCHING_FROM_VS:+aotdebug}
|
||||
|
||||
# This stage is used when running from VS in fast mode (Default for Debug configuration)
|
||||
FROM mcr.microsoft.com/dotnet/runtime:10.0 AS base
|
||||
USER $APP_UID
|
||||
WORKDIR /app
|
||||
|
||||
|
||||
# This stage is used to build the service project
|
||||
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
||||
# Install clang/zlib1g-dev dependencies for publishing to native
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
clang zlib1g-dev
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["Directory.Packages.props", "."]
|
||||
COPY ["ProgrartC/ProgrartC.csproj", "ProgrartC/"]
|
||||
RUN dotnet restore "./ProgrartC/ProgrartC.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/ProgrartC"
|
||||
RUN dotnet build "./ProgrartC.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
# This stage is used to publish the service project to be copied to the final stage
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./ProgrartC.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=true
|
||||
|
||||
# This stage is used as the base for the final stage when launching from VS to support debugging in regular mode (Default when not using the Debug configuration)
|
||||
FROM base AS aotdebug
|
||||
USER root
|
||||
# Install GDB to support native debugging
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
gdb
|
||||
USER app
|
||||
|
||||
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
|
||||
FROM ${FINAL_BASE_IMAGE:-mcr.microsoft.com/dotnet/runtime-deps:10.0} AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["./ProgrartC"]
|
||||
102
ProgrartC/Program.cs
Normal file
102
ProgrartC/Program.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using Progrart.Core;
|
||||
using Progrart.Core.JSExecution;
|
||||
using Progrart.Core.ProjectSystem;
|
||||
using Progrart.Core.Storage;
|
||||
using SkiaSharp;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace ProgrartC
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
|
||||
List<string> includePaths = new List<string>();
|
||||
string? sourceFile = null;
|
||||
string? outputFile = null;
|
||||
ExecuteArguments executeArguments = new ExecuteArguments();
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
{
|
||||
string? item = args[i];
|
||||
switch (item)
|
||||
{
|
||||
case "-I":
|
||||
i++;
|
||||
includePaths.Add(args[i]);
|
||||
break;
|
||||
case "-o":
|
||||
i++;
|
||||
outputFile = args[i];
|
||||
break;
|
||||
default:
|
||||
if (File.Exists(item))
|
||||
{
|
||||
sourceFile = item;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.StartsWith("-D"))
|
||||
{
|
||||
string define = item.Substring(2);
|
||||
string[] parts = define.Split('=', 2);
|
||||
if (parts.Length == 2)
|
||||
{
|
||||
executeArguments.data[parts[0]] = parts[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
executeArguments.data[parts[0]] = "true";
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (sourceFile == null)
|
||||
{
|
||||
Trace.WriteLine("no input files");
|
||||
return;
|
||||
}
|
||||
if (outputFile == null)
|
||||
{
|
||||
outputFile = Path.ChangeExtension(sourceFile, "png");
|
||||
}
|
||||
CombinedStorageProvider storageProvider = new();
|
||||
{
|
||||
FileInfo sourceFileInfo = new FileInfo(sourceFile);
|
||||
if (sourceFileInfo.Directory is not null)
|
||||
includePaths.Add(sourceFileInfo.Directory.FullName);
|
||||
}
|
||||
if (!includePaths.Contains("."))
|
||||
includePaths.Add(".");
|
||||
foreach (var item in includePaths)
|
||||
{
|
||||
storageProvider.providers.Add(new ClassicStorageProvider(new DirectoryInfo(item)));
|
||||
}
|
||||
int Scale = 1024;
|
||||
|
||||
if (executeArguments.data.TryGetValue("Scale", out var scale))
|
||||
{
|
||||
if (!int.TryParse(scale, out Scale)) Scale = 1024;
|
||||
}
|
||||
ProgrartExecutor progrartExecutor = new(storageProvider);
|
||||
var result = progrartExecutor.RenderImage(Scale, File.ReadAllText(sourceFile), executeArguments);
|
||||
|
||||
SKData data;
|
||||
FileInfo fi = new FileInfo(outputFile);
|
||||
var ext = fi.Extension.ToLower();
|
||||
data = result.DrawingCore.ToData(ext);
|
||||
if(data is null)
|
||||
{
|
||||
Trace.WriteLine("failed to encode image");
|
||||
return;
|
||||
}
|
||||
using var img_stream = File.OpenWrite(outputFile);
|
||||
if (img_stream is null)
|
||||
return;
|
||||
data.SaveTo(img_stream);
|
||||
img_stream.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
21
ProgrartC/ProgrartC.csproj
Normal file
21
ProgrartC/ProgrartC.csproj
Normal file
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Progrart.Core\Progrart.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
10
ProgrartC/Properties/launchSettings.json
Normal file
10
ProgrartC/Properties/launchSettings.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"profiles": {
|
||||
"ProgrartC": {
|
||||
"commandName": "Project"
|
||||
},
|
||||
"Container (Dockerfile)": {
|
||||
"commandName": "Docker"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user