2024-12-20 23:39:29 +08:00
|
|
|
|
using Dm.parser;
|
|
|
|
|
|
using NetTaste;
|
|
|
|
|
|
using Newtonsoft.Json;
|
2024-10-20 12:10:57 +08:00
|
|
|
|
using Serein.Library;
|
2024-12-18 00:05:42 +08:00
|
|
|
|
using Serein.Library.Utils;
|
|
|
|
|
|
using Serein.Library.Utils.SereinExpression;
|
2024-12-20 23:39:29 +08:00
|
|
|
|
using Serein.NodeFlow.Model;
|
|
|
|
|
|
using Serein.Script;
|
2024-12-10 23:58:49 +08:00
|
|
|
|
using System.Diagnostics;
|
2024-11-02 16:48:40 +08:00
|
|
|
|
using System.IO;
|
2024-12-16 00:58:45 +08:00
|
|
|
|
using System.Linq.Expressions;
|
2024-08-05 10:11:58 +08:00
|
|
|
|
using System.Windows;
|
2024-12-18 00:05:42 +08:00
|
|
|
|
using System.Windows.Media.Animation;
|
2024-10-20 12:10:57 +08:00
|
|
|
|
using System.Windows.Threading;
|
2024-08-05 10:11:58 +08:00
|
|
|
|
|
2024-10-15 21:56:09 +08:00
|
|
|
|
namespace Serein.Workbench
|
2024-08-05 10:11:58 +08:00
|
|
|
|
{
|
2024-12-18 00:05:42 +08:00
|
|
|
|
#if DEBUG
|
2024-12-20 23:39:29 +08:00
|
|
|
|
|
2024-12-18 00:05:42 +08:00
|
|
|
|
#endif
|
2024-12-16 00:58:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-08-05 10:11:58 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Interaction logic for App.xaml
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public partial class App : Application
|
|
|
|
|
|
{
|
2024-10-23 19:22:27 +08:00
|
|
|
|
void LoadLocalProject()
|
|
|
|
|
|
{
|
2024-12-12 20:33:08 +08:00
|
|
|
|
|
|
|
|
|
|
#if DEBUG
|
2024-12-12 21:09:29 +08:00
|
|
|
|
if (1 == 1)
|
2024-10-23 19:22:27 +08:00
|
|
|
|
{
|
2024-12-16 00:58:45 +08:00
|
|
|
|
|
2024-12-12 20:33:08 +08:00
|
|
|
|
// 这里是我自己的测试代码,你可以删除
|
2024-10-23 19:22:27 +08:00
|
|
|
|
string filePath;
|
2024-12-09 22:57:06 +08:00
|
|
|
|
filePath = @"C:\Users\Az\source\repos\CLBanyunqiState\CLBanyunqiState\bin\Release\net8.0\PLCproject.dnf";
|
2024-12-16 00:58:45 +08:00
|
|
|
|
filePath = @"C:\Users\Az\source\repos\CLBanyunqiState\CLBanyunqiState\bin\Release\banyunqi\project.dnf";
|
2024-12-23 23:19:10 +08:00
|
|
|
|
filePath = @"C:\Users\Az\source\repos\CLBanyunqiState\CLBanyunqiState\bin\debug\net8.0\project.dnf";
|
2024-10-23 19:22:27 +08:00
|
|
|
|
string content = System.IO.File.ReadAllText(filePath); // 读取整个文件内容
|
|
|
|
|
|
App.FlowProjectData = JsonConvert.DeserializeObject<SereinProjectData>(content);
|
|
|
|
|
|
App.FileDataPath = System.IO.Path.GetDirectoryName(filePath)!; // filePath;//
|
2024-11-02 16:48:40 +08:00
|
|
|
|
var dir = Path.GetDirectoryName(filePath);
|
|
|
|
|
|
//System.IO.Directory.SetCurrentDirectory(dir);
|
2024-10-23 19:22:27 +08:00
|
|
|
|
}
|
2024-10-22 00:13:13 +08:00
|
|
|
|
#endif
|
2024-10-23 19:22:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-14 17:29:28 +08:00
|
|
|
|
public static SereinProjectData? FlowProjectData { get; set; }
|
|
|
|
|
|
public static string FileDataPath { get; set; } = "";
|
2024-08-05 19:43:57 +08:00
|
|
|
|
|
2024-10-14 17:29:28 +08:00
|
|
|
|
public App()
|
|
|
|
|
|
{
|
2024-10-20 12:10:57 +08:00
|
|
|
|
|
2024-10-14 17:29:28 +08:00
|
|
|
|
}
|
2024-08-05 19:43:57 +08:00
|
|
|
|
|
2024-10-14 17:29:28 +08:00
|
|
|
|
protected override void OnExit(ExitEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnExit(e);
|
2024-08-05 10:11:58 +08:00
|
|
|
|
|
2024-10-14 17:29:28 +08:00
|
|
|
|
// 强制关闭所有窗口
|
|
|
|
|
|
foreach (Window window in Windows)
|
|
|
|
|
|
{
|
|
|
|
|
|
window.Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void Application_Startup(object sender, StartupEventArgs e)
|
|
|
|
|
|
{
|
2024-10-20 12:10:57 +08:00
|
|
|
|
Application.Current.Dispatcher.Invoke(() => { });
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-10-14 17:29:28 +08:00
|
|
|
|
// 检查是否传入了参数
|
|
|
|
|
|
if (e.Args.Length == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 获取文件路径
|
|
|
|
|
|
string filePath = e.Args[0];
|
|
|
|
|
|
// 检查文件是否存在
|
|
|
|
|
|
if (!System.IO.File.Exists(filePath))
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show($"文件未找到:{filePath}");
|
|
|
|
|
|
Shutdown(); // 关闭应用程序
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-08-05 10:11:58 +08:00
|
|
|
|
|
2024-10-14 17:29:28 +08:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
// 读取文件内容
|
|
|
|
|
|
string content = System.IO.File.ReadAllText(filePath); // 读取整个文件内容
|
|
|
|
|
|
FlowProjectData = JsonConvert.DeserializeObject<SereinProjectData>(content);
|
|
|
|
|
|
FileDataPath = System.IO.Path.GetDirectoryName(filePath) ?? "";
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show($"读取文件时发生错误:{ex.Message}");
|
|
|
|
|
|
Shutdown(); // 关闭应用程序
|
|
|
|
|
|
}
|
2024-12-10 23:58:49 +08:00
|
|
|
|
|
2024-10-14 17:29:28 +08:00
|
|
|
|
}
|
2024-10-23 19:22:27 +08:00
|
|
|
|
this.LoadLocalProject();
|
2024-10-14 17:29:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-10-23 19:22:27 +08:00
|
|
|
|
}
|
2024-10-14 17:29:28 +08:00
|
|
|
|
|
2024-12-20 23:39:29 +08:00
|
|
|
|
}
|
2024-08-05 10:11:58 +08:00
|
|
|
|
|