Integrated Provider to ProgrartExecutor.
This commit is contained in:
@@ -3,6 +3,7 @@ using Jint.Native;
|
||||
using Jint.Native.Function;
|
||||
using Jint.Native.Json;
|
||||
using Progrart.Core.Graphics;
|
||||
using Progrart.Core.Storage;
|
||||
using System.Diagnostics;
|
||||
using System.Text.Json;
|
||||
|
||||
@@ -12,12 +13,14 @@ namespace Progrart.Core.JSExecution
|
||||
{
|
||||
public ExecutionEngine engine;
|
||||
public Dictionary<string, object> ObjectPool = new();
|
||||
public ProgrartExecutor()
|
||||
{
|
||||
engine = new ExecutionEngine();
|
||||
SetupCalls();
|
||||
}
|
||||
public void SetupCalls()
|
||||
public IStorageProvider StorageProvider;
|
||||
public ProgrartExecutor(IStorageProvider storageProvider)
|
||||
{
|
||||
engine = new ExecutionEngine();
|
||||
SetupCalls();
|
||||
StorageProvider = storageProvider;
|
||||
}
|
||||
public void SetupCalls()
|
||||
{
|
||||
Jint.Native.Json.JsonSerializer serializer = new Jint.Native.Json.JsonSerializer(engine.Engine);
|
||||
engine.Engine.SetValue("log", new Action<JsValue>((v) =>
|
||||
|
||||
@@ -1,42 +1,47 @@
|
||||
using Newtonsoft.Json;
|
||||
using Progrart.Core.JSExecution;
|
||||
using Progrart.Core.Storage;
|
||||
|
||||
namespace Progrart.Core.ProjectSystem
|
||||
{
|
||||
public class Builder
|
||||
{
|
||||
public Project project;
|
||||
public string basePath;
|
||||
public IStorageProvider provider;
|
||||
public Action<int, int>? OnProgressUpdate;
|
||||
public Action? OnCompleted;
|
||||
public Builder(StreamReader reader, string basePath)
|
||||
public Builder(StreamReader reader, IStorageProvider provider)
|
||||
{
|
||||
var project = JsonConvert.DeserializeObject<Project>(reader.ReadToEnd());
|
||||
if (project is null) throw new JsonSerializationException();
|
||||
this.project = project;
|
||||
this.basePath = basePath;
|
||||
this.provider = provider;
|
||||
}
|
||||
public Builder(Project project, string basePath)
|
||||
public Builder(Project project, IStorageProvider provider)
|
||||
{
|
||||
this.project = project;
|
||||
this.basePath = basePath;
|
||||
this.provider = provider;
|
||||
}
|
||||
public void Execute(BuildConfiguration config, BuildItem item)
|
||||
public async Task Execute(BuildConfiguration config, BuildItem item)
|
||||
{
|
||||
FileInfo src = new FileInfo(Path.Combine(basePath, item.Source));
|
||||
FileInfo tgt = new FileInfo(Path.Combine(basePath, project.OutputDir, item.Target ?? item.Source + ".png"));
|
||||
//FileInfo src = new FileInfo(Path.Combine(basePath, item.Source));
|
||||
//FileInfo tgt = new FileInfo(Path.Combine(basePath, project.OutputDir, item.Target ?? item.Source + ".png"));
|
||||
var args = project.Arguments.Clone();
|
||||
args.MergeFrom(config.Arguments);
|
||||
args.MergeFrom(item.Arguments);
|
||||
ProgrartExecutor executor = new ProgrartExecutor();
|
||||
using var stream = src.OpenRead();
|
||||
ProgrartExecutor executor = new ProgrartExecutor(provider);
|
||||
using var stream = await provider.TryOpenRead(item.Source);
|
||||
if (stream is null)
|
||||
return;
|
||||
using var reader = new StreamReader(stream);
|
||||
var img = executor.RenderImage(item.Size, reader.ReadToEnd(), args);
|
||||
using var img_stream = tgt.OpenWrite();
|
||||
using var img_stream = await provider.TryOpenWrite(Path.Combine(project.OutputDir, item.Target ?? item.Source + ".png"));
|
||||
if (img_stream is null)
|
||||
return;
|
||||
img.DrawingCore.ToData().SaveTo(img_stream);
|
||||
img_stream.Flush();
|
||||
}
|
||||
public void Build(string targetConfig)
|
||||
public async Task Build(string targetConfig)
|
||||
{
|
||||
foreach (var config in project.Configurations)
|
||||
{
|
||||
@@ -45,7 +50,7 @@ namespace Progrart.Core.ProjectSystem
|
||||
int index = 0;
|
||||
foreach (var item in config.Items)
|
||||
{
|
||||
Execute(config, item);
|
||||
await Execute(config, item);
|
||||
index++;
|
||||
OnProgressUpdate?.Invoke(config.Items.Count, index);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user