2025-03-18 21:01:15 +08:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using Newtonsoft.Json;
|
2025-01-05 08:52:37 +08:00
|
|
|
|
using Serein.Library;
|
2025-03-18 21:01:15 +08:00
|
|
|
|
using Serein.Library.Api;
|
2025-01-05 08:52:37 +08:00
|
|
|
|
using Serein.Library.Utils;
|
2025-03-18 21:01:15 +08:00
|
|
|
|
using Serein.NodeFlow.Env;
|
2025-07-07 20:40:24 +08:00
|
|
|
|
using Serein.NodeFlow.Services;
|
2025-07-18 23:17:28 +08:00
|
|
|
|
using Serein.Script;
|
2025-03-18 21:01:15 +08:00
|
|
|
|
using Serein.Workbench.Api;
|
|
|
|
|
|
using Serein.Workbench.Services;
|
|
|
|
|
|
using Serein.Workbench.ViewModels;
|
2025-07-16 16:16:19 +08:00
|
|
|
|
using System.ComponentModel;
|
2025-01-05 08:52:37 +08:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
using System.IO;
|
2025-07-06 14:34:49 +08:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2025-01-05 08:52:37 +08:00
|
|
|
|
using System.Windows;
|
2025-05-27 18:32:40 +08:00
|
|
|
|
using System.Windows.Input;
|
2025-03-18 21:01:15 +08:00
|
|
|
|
using System.Windows.Threading;
|
2025-07-06 14:34:49 +08:00
|
|
|
|
using static System.Net.Mime.MediaTypeNames;
|
2025-01-05 08:52:37 +08:00
|
|
|
|
|
|
|
|
|
|
namespace Serein.Workbench
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2025-05-31 00:20:29 +08:00
|
|
|
|
|
2025-01-05 08:52:37 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Interaction logic for App.xaml
|
|
|
|
|
|
/// </summary>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public partial class App : System.Windows.Application
|
2025-01-05 08:52:37 +08:00
|
|
|
|
{
|
2025-03-18 21:01:15 +08:00
|
|
|
|
private static IServiceProvider? ServiceProvider;
|
2025-05-30 01:02:25 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// UI线程
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static UIContextOperation UIContextOperation => App.GetService<UIContextOperation>() ?? throw new NullReferenceException();
|
2025-07-06 14:34:49 +08:00
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
internal static T GetService<T>() where T : class
|
2025-03-18 21:01:15 +08:00
|
|
|
|
{
|
|
|
|
|
|
return ServiceProvider?.GetService<T>() ?? throw new NullReferenceException();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
|
|
|
|
|
|
internal App()
|
2025-03-18 21:01:15 +08:00
|
|
|
|
{
|
|
|
|
|
|
var collection = new ServiceCollection();
|
|
|
|
|
|
collection.AddWorkbenchServices();
|
|
|
|
|
|
collection.AddFlowServices();
|
|
|
|
|
|
collection.AddViewModelServices();
|
|
|
|
|
|
var services = collection.BuildServiceProvider(); // 绑定并返回获取实例的服务接口
|
|
|
|
|
|
App.ServiceProvider = services;
|
2025-05-30 23:31:31 +08:00
|
|
|
|
#if DEBUG
|
2025-05-26 23:55:23 +08:00
|
|
|
|
_ = this.LoadLocalProjectAsync();
|
2025-05-30 23:31:31 +08:00
|
|
|
|
#endif
|
2025-03-18 21:01:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-30 23:31:31 +08:00
|
|
|
|
#if DEBUG
|
2025-03-18 21:01:15 +08:00
|
|
|
|
|
2025-05-30 23:31:31 +08:00
|
|
|
|
// 这里是测试代码,可以删除
|
2025-01-05 08:52:37 +08:00
|
|
|
|
private async Task LoadLocalProjectAsync()
|
|
|
|
|
|
{
|
2025-07-18 23:17:28 +08:00
|
|
|
|
var script = """
|
|
|
|
|
|
x = 114514;
|
|
|
|
|
|
x = (x * 100000000000) + x;
|
|
|
|
|
|
value = "调用";
|
|
|
|
|
|
value = value + "委托";
|
|
|
|
|
|
return value + x;
|
|
|
|
|
|
""";
|
|
|
|
|
|
var result = await SereinScript.ExecuteAsync(script);
|
2025-07-16 16:16:19 +08:00
|
|
|
|
|
2025-07-18 23:17:28 +08:00
|
|
|
|
/* var properties = new Dictionary<string, Type>
|
|
|
|
|
|
{
|
|
|
|
|
|
{ "Id", typeof(int) },
|
|
|
|
|
|
{ "Name", typeof(string) },
|
|
|
|
|
|
{ "CreateTime", typeof(DateTime) }
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var type = DynamicObjectHelper.CreateTypeWithINotifyPropertyChanged(properties, "MyDynamicClass");
|
|
|
|
|
|
dynamic? obj = Activator.CreateInstance(type);
|
|
|
|
|
|
if(obj is null) return;
|
|
|
|
|
|
if (obj is INotifyPropertyChanged npc)
|
|
|
|
|
|
{
|
|
|
|
|
|
npc.PropertyChanged += (s, e) => Debug.WriteLine($"属性改变: {e.PropertyName}");
|
|
|
|
|
|
}
|
|
|
|
|
|
obj.Name = "下北泽";
|
|
|
|
|
|
obj.Id = 114514;*/
|
2025-07-16 16:16:19 +08:00
|
|
|
|
|
2025-07-07 20:40:24 +08:00
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
#if false
|
2025-05-31 00:20:29 +08:00
|
|
|
|
var projectService = App.GetService<FlowProjectService>();
|
|
|
|
|
|
await Task.Delay(500);
|
2025-01-05 08:52:37 +08:00
|
|
|
|
string filePath;
|
2025-05-30 15:42:59 +08:00
|
|
|
|
filePath = @"F:\TempFile\flow\temp2\project.dnf";
|
2025-05-30 23:31:31 +08:00
|
|
|
|
projectService.LoadLocalProject(filePath);
|
2025-07-30 21:15:07 +08:00
|
|
|
|
#endif
|
2025-03-18 21:01:15 +08:00
|
|
|
|
|
2025-05-30 23:31:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
#endif
|
2025-03-18 21:01:15 +08:00
|
|
|
|
|
2025-01-05 08:52:37 +08:00
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
private void Application_Startup(object sender, StartupEventArgs e)
|
2025-01-05 08:52:37 +08:00
|
|
|
|
{
|
2025-05-30 23:31:31 +08:00
|
|
|
|
var projectService = App.GetService<FlowProjectService>();
|
2025-01-05 08:52:37 +08:00
|
|
|
|
if (e.Args.Length == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
string filePath = e.Args[0];
|
2025-05-30 23:31:31 +08:00
|
|
|
|
if (!System.IO.File.Exists(filePath)) // 检查文件是否存在
|
2025-01-05 08:52:37 +08:00
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show($"文件未找到:{filePath}");
|
|
|
|
|
|
Shutdown(); // 关闭应用程序
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
// 读取文件内容
|
2025-05-30 23:31:31 +08:00
|
|
|
|
projectService.LoadLocalProject(filePath);
|
2025-01-05 08:52:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show($"读取文件时发生错误:{ex.Message}");
|
|
|
|
|
|
Shutdown(); // 关闭应用程序
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2025-03-18 21:01:15 +08:00
|
|
|
|
|
2025-01-05 08:52:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|