Integrated Provider to ProgrartExecutor.
This commit is contained in:
@@ -3,6 +3,7 @@ using Jint.Native;
|
|||||||
using Jint.Native.Function;
|
using Jint.Native.Function;
|
||||||
using Jint.Native.Json;
|
using Jint.Native.Json;
|
||||||
using Progrart.Core.Graphics;
|
using Progrart.Core.Graphics;
|
||||||
|
using Progrart.Core.Storage;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
@@ -12,12 +13,14 @@ namespace Progrart.Core.JSExecution
|
|||||||
{
|
{
|
||||||
public ExecutionEngine engine;
|
public ExecutionEngine engine;
|
||||||
public Dictionary<string, object> ObjectPool = new();
|
public Dictionary<string, object> ObjectPool = new();
|
||||||
public ProgrartExecutor()
|
public IStorageProvider StorageProvider;
|
||||||
{
|
public ProgrartExecutor(IStorageProvider storageProvider)
|
||||||
engine = new ExecutionEngine();
|
{
|
||||||
SetupCalls();
|
engine = new ExecutionEngine();
|
||||||
}
|
SetupCalls();
|
||||||
public void SetupCalls()
|
StorageProvider = storageProvider;
|
||||||
|
}
|
||||||
|
public void SetupCalls()
|
||||||
{
|
{
|
||||||
Jint.Native.Json.JsonSerializer serializer = new Jint.Native.Json.JsonSerializer(engine.Engine);
|
Jint.Native.Json.JsonSerializer serializer = new Jint.Native.Json.JsonSerializer(engine.Engine);
|
||||||
engine.Engine.SetValue("log", new Action<JsValue>((v) =>
|
engine.Engine.SetValue("log", new Action<JsValue>((v) =>
|
||||||
|
|||||||
@@ -1,42 +1,47 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Progrart.Core.JSExecution;
|
using Progrart.Core.JSExecution;
|
||||||
|
using Progrart.Core.Storage;
|
||||||
|
|
||||||
namespace Progrart.Core.ProjectSystem
|
namespace Progrart.Core.ProjectSystem
|
||||||
{
|
{
|
||||||
public class Builder
|
public class Builder
|
||||||
{
|
{
|
||||||
public Project project;
|
public Project project;
|
||||||
public string basePath;
|
public IStorageProvider provider;
|
||||||
public Action<int, int>? OnProgressUpdate;
|
public Action<int, int>? OnProgressUpdate;
|
||||||
public Action? OnCompleted;
|
public Action? OnCompleted;
|
||||||
public Builder(StreamReader reader, string basePath)
|
public Builder(StreamReader reader, IStorageProvider provider)
|
||||||
{
|
{
|
||||||
var project = JsonConvert.DeserializeObject<Project>(reader.ReadToEnd());
|
var project = JsonConvert.DeserializeObject<Project>(reader.ReadToEnd());
|
||||||
if (project is null) throw new JsonSerializationException();
|
if (project is null) throw new JsonSerializationException();
|
||||||
this.project = project;
|
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.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 src = new FileInfo(Path.Combine(basePath, item.Source));
|
||||||
FileInfo tgt = new FileInfo(Path.Combine(basePath, project.OutputDir, item.Target ?? item.Source + ".png"));
|
//FileInfo tgt = new FileInfo(Path.Combine(basePath, project.OutputDir, item.Target ?? item.Source + ".png"));
|
||||||
var args = project.Arguments.Clone();
|
var args = project.Arguments.Clone();
|
||||||
args.MergeFrom(config.Arguments);
|
args.MergeFrom(config.Arguments);
|
||||||
args.MergeFrom(item.Arguments);
|
args.MergeFrom(item.Arguments);
|
||||||
ProgrartExecutor executor = new ProgrartExecutor();
|
ProgrartExecutor executor = new ProgrartExecutor(provider);
|
||||||
using var stream = src.OpenRead();
|
using var stream = await provider.TryOpenRead(item.Source);
|
||||||
|
if (stream is null)
|
||||||
|
return;
|
||||||
using var reader = new StreamReader(stream);
|
using var reader = new StreamReader(stream);
|
||||||
var img = executor.RenderImage(item.Size, reader.ReadToEnd(), args);
|
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.DrawingCore.ToData().SaveTo(img_stream);
|
||||||
img_stream.Flush();
|
img_stream.Flush();
|
||||||
}
|
}
|
||||||
public void Build(string targetConfig)
|
public async Task Build(string targetConfig)
|
||||||
{
|
{
|
||||||
foreach (var config in project.Configurations)
|
foreach (var config in project.Configurations)
|
||||||
{
|
{
|
||||||
@@ -45,7 +50,7 @@ namespace Progrart.Core.ProjectSystem
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
foreach (var item in config.Items)
|
foreach (var item in config.Items)
|
||||||
{
|
{
|
||||||
Execute(config, item);
|
await Execute(config, item);
|
||||||
index++;
|
index++;
|
||||||
OnProgressUpdate?.Invoke(config.Items.Count, index);
|
OnProgressUpdate?.Invoke(config.Items.Count, index);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,14 @@ using Avalonia.Markup.Xaml;
|
|||||||
using Progrart.Views;
|
using Progrart.Views;
|
||||||
using Progrart.Icons;
|
using Progrart.Icons;
|
||||||
using Progrart.Pages;
|
using Progrart.Pages;
|
||||||
|
using Avalonia.Platform.Storage;
|
||||||
|
|
||||||
namespace Progrart;
|
namespace Progrart;
|
||||||
|
|
||||||
public partial class App : Application
|
public partial class App : Application
|
||||||
{
|
{
|
||||||
public static bool isDesktop = false;
|
public static bool isDesktop = false;
|
||||||
|
public static IStorageFolder? CurrentOpenFolder = null;
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
AvaloniaXamlLoader.Load(this);
|
AvaloniaXamlLoader.Load(this);
|
||||||
|
|||||||
@@ -9,15 +9,16 @@ namespace Progrart.Core.Storage
|
|||||||
{
|
{
|
||||||
public class AvaloniaStorageProvider : IStorageProvider
|
public class AvaloniaStorageProvider : IStorageProvider
|
||||||
{
|
{
|
||||||
IStorageFolder baseFolder;
|
IStorageFolder? baseFolder;
|
||||||
|
|
||||||
public AvaloniaStorageProvider(IStorageFolder baseFolder)
|
public AvaloniaStorageProvider(IStorageFolder? baseFolder)
|
||||||
{
|
{
|
||||||
this.baseFolder = baseFolder;
|
this.baseFolder = baseFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Stream?> TryOpenRead(string path)
|
public async Task<Stream?> TryOpenRead(string path)
|
||||||
{
|
{
|
||||||
|
if (baseFolder is null) return null;
|
||||||
var file = await baseFolder.GetFileAsync(path);
|
var file = await baseFolder.GetFileAsync(path);
|
||||||
if (file != null)
|
if (file != null)
|
||||||
{
|
{
|
||||||
@@ -28,6 +29,7 @@ namespace Progrart.Core.Storage
|
|||||||
|
|
||||||
public async Task<Stream?> TryOpenWrite(string path)
|
public async Task<Stream?> TryOpenWrite(string path)
|
||||||
{
|
{
|
||||||
|
if (baseFolder is null) return null;
|
||||||
var file = await baseFolder.GetFileAsync(path);
|
var file = await baseFolder.GetFileAsync(path);
|
||||||
if (file != null)
|
if (file != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Avalonia.Controls;
|
|||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
using Avalonia.Platform.Storage;
|
using Avalonia.Platform.Storage;
|
||||||
using Jint;
|
using Jint;
|
||||||
|
using Progrart.Commands;
|
||||||
using Progrart.Controls.TabSystem;
|
using Progrart.Controls.TabSystem;
|
||||||
using Progrart.Core;
|
using Progrart.Core;
|
||||||
using System;
|
using System;
|
||||||
@@ -21,7 +22,7 @@ public partial class Console : UserControl, ITabPage, IEditorPage
|
|||||||
{
|
{
|
||||||
Output.Text += $"{obj}\n";
|
Output.Text += $"{obj}\n";
|
||||||
}));
|
}));
|
||||||
engine.SetValue("getWDName", new Func<string>(() =>
|
engine.SetValue("getWD", new Func<string>(() =>
|
||||||
{
|
{
|
||||||
return workdirectory?.Name ?? "<null>";
|
return workdirectory?.Name ?? "<null>";
|
||||||
}));
|
}));
|
||||||
@@ -30,6 +31,7 @@ public partial class Console : UserControl, ITabPage, IEditorPage
|
|||||||
if (workdirectory != null)
|
if (workdirectory != null)
|
||||||
{
|
{
|
||||||
Task.Run(async () => workdirectory = await workdirectory.GetFolderAsync(str));
|
Task.Run(async () => workdirectory = await workdirectory.GetFolderAsync(str));
|
||||||
|
Output.Text += $"Executed\n";
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
engine.SetValue("mkdir", new Action<string>((str) =>
|
engine.SetValue("mkdir", new Action<string>((str) =>
|
||||||
@@ -37,14 +39,28 @@ public partial class Console : UserControl, ITabPage, IEditorPage
|
|||||||
if (workdirectory != null)
|
if (workdirectory != null)
|
||||||
{
|
{
|
||||||
Task.Run(async () => await workdirectory.CreateFolderAsync(str));
|
Task.Run(async () => await workdirectory.CreateFolderAsync(str));
|
||||||
|
Output.Text += $"Executed\n";
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
CommandBox.KeyBindings.Add(new Avalonia.Input.KeyBinding()
|
||||||
|
{
|
||||||
|
Gesture = new Avalonia.Input.KeyGesture(Avalonia.Input.Key.Enter),
|
||||||
|
Command = new GenericCommand()
|
||||||
|
{
|
||||||
|
Checker = (_) => true,
|
||||||
|
onExecute = (_) => executeCmd()
|
||||||
|
}
|
||||||
|
});
|
||||||
ExecuteBtn.Click += (_, _) =>
|
ExecuteBtn.Click += (_, _) =>
|
||||||
{
|
{
|
||||||
engine.Execute(CommandBox.Text ?? "");
|
executeCmd();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
void executeCmd()
|
||||||
|
{
|
||||||
|
Output.Text += $"{engine.Evaluate(CommandBox.Text ?? "")}\n";
|
||||||
|
|
||||||
|
}
|
||||||
public void BindButton(TabButton button)
|
public void BindButton(TabButton button)
|
||||||
{
|
{
|
||||||
button.Title = "Console";
|
button.Title = "Console";
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using Avalonia.Threading;
|
|||||||
using Progrart.Controls.TabSystem;
|
using Progrart.Controls.TabSystem;
|
||||||
using Progrart.Core;
|
using Progrart.Core;
|
||||||
using Progrart.Core.JSExecution;
|
using Progrart.Core.JSExecution;
|
||||||
|
using Progrart.Core.Storage;
|
||||||
using Progrart.Pages;
|
using Progrart.Pages;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@@ -40,7 +41,8 @@ public partial class ProgrartEditorPage : UserControl, ITabPage, IEditorPage
|
|||||||
|
|
||||||
public void Execute(ExecuteArguments? args = null)
|
public void Execute(ExecuteArguments? args = null)
|
||||||
{
|
{
|
||||||
using ProgrartExecutor executor = new ProgrartExecutor();
|
AvaloniaStorageProvider provider = new AvaloniaStorageProvider(App.CurrentOpenFolder);
|
||||||
|
using ProgrartExecutor executor = new ProgrartExecutor(provider);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int Scale = 1024;
|
int Scale = 1024;
|
||||||
@@ -82,7 +84,6 @@ public partial class ProgrartEditorPage : UserControl, ITabPage, IEditorPage
|
|||||||
{
|
{
|
||||||
return (this.file?.Path == file.Path);
|
return (this.file?.Path == file.Path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadDocument(IStorageFile file)
|
public void LoadDocument(IStorageFile file)
|
||||||
{
|
{
|
||||||
this.file = file;
|
this.file = file;
|
||||||
|
|||||||
@@ -99,8 +99,8 @@ public partial class MainView : UserControl
|
|||||||
if (folders.Count >= 1)
|
if (folders.Count >= 1)
|
||||||
{
|
{
|
||||||
FileContainer.Children.Clear();
|
FileContainer.Children.Clear();
|
||||||
var folderPath = folders[0].TryGetLocalPath();
|
|
||||||
var folder = folders[0];
|
var folder = folders[0];
|
||||||
|
App.CurrentOpenFolder = folder;
|
||||||
FileContainer.Children.Add(new FileItem(folder));
|
FileContainer.Children.Add(new FileItem(folder));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user