mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-09 01:16:34 +08:00
重新设计了项目的保存文件结构
This commit is contained in:
69
Workbench/Themes/DynamicCompilerView.xaml
Normal file
69
Workbench/Themes/DynamicCompilerView.xaml
Normal file
@@ -0,0 +1,69 @@
|
||||
<Window x:Class="Serein.Workbench.Themes.DynamicCompilerView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:Serein.Workbench.Themes"
|
||||
mc:Ignorable="d"
|
||||
xmlns:avalonEdit="http://icsharpcode.net/sharpdevelop/avalonedit"
|
||||
Title="动态编译器" Height="600" Width="800">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="150"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 上方DLL引用部分 -->
|
||||
<Grid Grid.Row="0" Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<StackPanel Grid.Row="0" Orientation="Horizontal" Margin="0,0,0,5">
|
||||
<Button x:Name="btnAdd" Content="添加引用" Click="btnAdd_Click" Width="100" Margin="0,0,10,0"/>
|
||||
<Button x:Name="btnBatchAdd" Content="批量添加" Click="btnBatchAdd_Click" Width="100" Margin="0,0,10,0"/>
|
||||
<Button x:Name="btnRemove" Content="删除引用" Click="btnRemove_Click" Width="100"/>
|
||||
</StackPanel>
|
||||
|
||||
<ListBox x:Name="lstReferences" Grid.Row="1"
|
||||
MouseDoubleClick="lstReferences_MouseDoubleClick" MaxHeight="150"/>
|
||||
</Grid>
|
||||
|
||||
<!-- 中间代码编辑器部分 -->
|
||||
<avalonEdit:TextEditor Grid.Row="1"
|
||||
x:Name="codeEditor"
|
||||
FontFamily="Consolas"
|
||||
FontSize="12"
|
||||
SyntaxHighlighting="C#"
|
||||
ShowLineNumbers="True"
|
||||
Margin="10"/>
|
||||
|
||||
<!-- 下方编译结果部分 -->
|
||||
<Grid Grid.Row="2" Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Orientation="Horizontal"
|
||||
HorizontalAlignment="Left"
|
||||
>
|
||||
<TextBlock Text="程序集名称:" Width="70" Margin="10,0,5,0"/>
|
||||
<TextBox x:Name="textboxAssemblyName" Text="FlowLibrary" Width="150" Margin="10,0,10,0"/>
|
||||
<Button x:Name="btnCompile"
|
||||
Content="编译"
|
||||
Click="btnCompile_Click"
|
||||
/>
|
||||
</StackPanel>
|
||||
|
||||
|
||||
<TextBox x:Name="txtErrors"
|
||||
Grid.Row="1"
|
||||
IsReadOnly="True"
|
||||
TextWrapping="Wrap"
|
||||
VerticalScrollBarVisibility="Auto"
|
||||
Background="LightYellow"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Window>
|
||||
150
Workbench/Themes/DynamicCompilerView.xaml.cs
Normal file
150
Workbench/Themes/DynamicCompilerView.xaml.cs
Normal file
@@ -0,0 +1,150 @@
|
||||
using Microsoft.Win32;
|
||||
using Serein.NodeFlow.Tool;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Serein.Workbench.Themes
|
||||
{
|
||||
/// <summary>
|
||||
/// DynamicCompilerApp.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class DynamicCompilerView : Window
|
||||
{
|
||||
private static int count = 1;
|
||||
private readonly DynamicCompiler _compiler;
|
||||
/// <summary>
|
||||
/// 脚本代码
|
||||
/// </summary>
|
||||
public string ScriptCode { get => codeEditor.Text; set => codeEditor.Text = value; }
|
||||
/// <summary>
|
||||
/// 编译成功回调
|
||||
/// </summary>
|
||||
public Action<Assembly> OnCompileComplete { get; set; }
|
||||
public DynamicCompilerView()
|
||||
{
|
||||
InitializeComponent();
|
||||
textboxAssemblyName.Text = $"FlowLibrary{count}";
|
||||
_compiler = new DynamicCompiler();
|
||||
// 初始化代码编辑器
|
||||
//codeEditor.Text =
|
||||
}
|
||||
|
||||
private void btnAdd_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var openFileDialog = new Microsoft.Win32.OpenFileDialog
|
||||
{
|
||||
Filter = "DLL文件|*.dll|所有文件|*.*",
|
||||
Title = "选择要引用的DLL文件"
|
||||
};
|
||||
|
||||
if (openFileDialog.ShowDialog() == true)
|
||||
{
|
||||
try
|
||||
{
|
||||
_compiler.AddReference(openFileDialog.FileName);
|
||||
lstReferences.Items.Add(openFileDialog.FileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Windows.MessageBox.Show($"添加引用失败:{ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void btnBatchAdd_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
using (var folderDialog = new FolderBrowserDialog())
|
||||
{
|
||||
folderDialog.Description = "选择包含DLL文件的文件夹";
|
||||
if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
string[] dllFiles = Directory.GetFiles(folderDialog.SelectedPath, "*.dll", SearchOption.AllDirectories);
|
||||
int successCount = 0;
|
||||
int failCount = 0;
|
||||
|
||||
foreach (string dllFile in dllFiles)
|
||||
{
|
||||
try
|
||||
{
|
||||
_compiler.AddReference(dllFile);
|
||||
lstReferences.Items.Add(dllFile);
|
||||
successCount++;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
failCount++;
|
||||
System.Diagnostics.Debug.WriteLine($"添加引用失败 {dllFile}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
System.Windows.MessageBox.Show($"批量添加完成!\n成功:{successCount}个\n失败:{failCount}个",
|
||||
"批量添加结果",
|
||||
MessageBoxButton.OK,
|
||||
failCount > 0 ? MessageBoxImage.Warning : MessageBoxImage.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Windows.MessageBox.Show($"批量添加过程中发生错误:{ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void btnRemove_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (lstReferences.SelectedItem != null)
|
||||
{
|
||||
lstReferences.Items.Remove(lstReferences.SelectedItem);
|
||||
}
|
||||
}
|
||||
|
||||
private void lstReferences_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
||||
{
|
||||
if (lstReferences.SelectedItem != null)
|
||||
{
|
||||
System.Windows.MessageBox.Show(lstReferences.SelectedItem.ToString(), "引用路径", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
|
||||
private void btnCompile_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
txtErrors.Clear();
|
||||
string code = codeEditor.Text;
|
||||
Assembly assembly = _compiler.Compile(code, textboxAssemblyName.Text);
|
||||
|
||||
|
||||
|
||||
if (assembly != null)
|
||||
{
|
||||
txtErrors.Text = "编译成功!";
|
||||
txtErrors.Background = System.Windows.Media.Brushes.LightGreen;
|
||||
OnCompileComplete.Invoke(assembly);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
txtErrors.Text = $"编译错误:\n{ex.Message}";
|
||||
txtErrors.Background = System.Windows.Media.Brushes.LightPink;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,8 @@
|
||||
|
||||
<converters:InvertableBooleanToVisibilityConverter x:Key="InvertedBoolConverter"/>
|
||||
<converters:EnumToBooleanConverter x:Key="EnumToBooleanConverter"/>
|
||||
|
||||
<local:DescriptionOrNameConverter x:Key="DescOrNameConverter"/>
|
||||
|
||||
<Style TargetType="{x:Type local:MethodDetailsControl}">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
@@ -66,7 +67,6 @@
|
||||
</Setter>
|
||||
</MultiDataTrigger>
|
||||
|
||||
|
||||
<!--显示Action节点方法入参名称-->
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
@@ -75,7 +75,16 @@
|
||||
<Setter Property="ContentTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<TextBlock Grid.Column="0" MinWidth="50" Text="{Binding Name}"/>
|
||||
|
||||
<TextBlock Grid.Column="0" MinWidth="50">
|
||||
<TextBlock.Text>
|
||||
<MultiBinding Converter="{StaticResource DescOrNameConverter}">
|
||||
<Binding Path="Description"/>
|
||||
<Binding Path="Name"/>
|
||||
</MultiBinding>
|
||||
</TextBlock.Text>
|
||||
</TextBlock>
|
||||
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
@@ -89,7 +98,16 @@
|
||||
<Setter Property="ContentTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<TextBlock Grid.Column="0" MinWidth="50" Text="{Binding Name}"/>
|
||||
|
||||
<TextBlock Grid.Column="0" MinWidth="50">
|
||||
<TextBlock.Text>
|
||||
<MultiBinding Converter="{StaticResource DescOrNameConverter}">
|
||||
<Binding Path="Description"/>
|
||||
<Binding Path="Name"/>
|
||||
</MultiBinding>
|
||||
</TextBlock.Text>
|
||||
</TextBlock>
|
||||
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
@@ -169,7 +187,7 @@
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBox Grid.Column="0" MinWidth="50" Text="{Binding DataValue, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"/>
|
||||
<TextBox Grid.Column="0" MinWidth="50" Text="{Binding DataValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
|
||||
@@ -9,6 +9,23 @@ using System.Windows.Input;
|
||||
|
||||
namespace Serein.Workbench.Themes
|
||||
{
|
||||
|
||||
public class DescriptionOrNameConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
string description = values[0] as string;
|
||||
string name = values[1] as string;
|
||||
return string.IsNullOrWhiteSpace(description) ? name : description;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class MultiConditionConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
|
||||
Reference in New Issue
Block a user