mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-07 02:00:50 +08:00
C# 脚本模块正式发布
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
using AIStudio.Wpf.Script.Core.Models;
|
||||
using AIStudio.Wpf.Script.Core.ViewModels;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AIStudio.Wpf.Script.ViewModels
|
||||
{
|
||||
public class ColorBoxCollectorScriptViewModel : RoslynScriptViewModel
|
||||
{
|
||||
public ColorBoxCollectorScriptViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public ColorBoxCollectorScriptViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public ColorBoxCollectorScriptViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
}
|
||||
|
||||
public ColorBoxCollectorScriptViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void InitNew()
|
||||
{
|
||||
base.InitNew();
|
||||
|
||||
ItemWidth = 230;
|
||||
ItemHeight = 76;
|
||||
Code = @"using System;
|
||||
using System.Collections.Generic;
|
||||
using AIStudio.Wpf.Script.Core.Models;
|
||||
using System.Windows.Media;
|
||||
using System.Linq;
|
||||
|
||||
namespace AIStudio.Wpf.CSharpScript
|
||||
{
|
||||
public class ColorBoxFactory
|
||||
{
|
||||
private List<ColorBoxModel> ItemsSource { get; set;} = new List<ColorBoxModel>();
|
||||
public ColorBoxModel Input {private get; set;}
|
||||
public int Count{ get; private set;}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
if (Input != null)
|
||||
{
|
||||
ItemsSource.Add(Input);
|
||||
Input = null;
|
||||
Console.WriteLine($""收集到{Input.Text}号Box"");
|
||||
}
|
||||
|
||||
Count = ItemsSource.Count;
|
||||
}
|
||||
}
|
||||
}";
|
||||
}
|
||||
|
||||
private List<ColorBoxModel> _itemsSource;
|
||||
public List<ColorBoxModel> ItemsSource
|
||||
{
|
||||
get
|
||||
{
|
||||
return _itemsSource;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _itemsSource, value);
|
||||
}
|
||||
}
|
||||
|
||||
public ColorBoxModel Tag { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
using AIStudio.Wpf.Script.Core.Models;
|
||||
using AIStudio.Wpf.Script.Core.ViewModels;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AIStudio.Wpf.Script.ViewModels
|
||||
{
|
||||
public class ColorBoxFactoryScriptViewModel : RoslynScriptViewModel
|
||||
{
|
||||
public ColorBoxFactoryScriptViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public ColorBoxFactoryScriptViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public ColorBoxFactoryScriptViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
}
|
||||
|
||||
public ColorBoxFactoryScriptViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void InitNew()
|
||||
{
|
||||
base.InitNew();
|
||||
|
||||
ItemWidth = 230;
|
||||
ItemHeight = 230;
|
||||
Code = @"using System;
|
||||
using System.Collections.Generic;
|
||||
using AIStudio.Wpf.Script.Core.Models;
|
||||
using System.Windows.Media;
|
||||
using System.Linq;
|
||||
|
||||
namespace AIStudio.Wpf.CSharpScript
|
||||
{
|
||||
public class ColorBoxFactory
|
||||
{
|
||||
public int Count{private get;set;} = 100;
|
||||
private List<ColorBoxModel> ItemsSource { get; set;} = new List<ColorBoxModel>();
|
||||
public ColorBoxModel Output {get;private set;}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
if (ItemsSource.Count == 0)
|
||||
{
|
||||
Random random = new Random();
|
||||
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
var sharpindex = random.Next(0, 8);
|
||||
if (sharpindex == 7)
|
||||
{
|
||||
sharpindex = 0;
|
||||
}
|
||||
|
||||
var colorindex = random.Next(0, 8);
|
||||
if (colorindex == 7)
|
||||
{
|
||||
colorindex = 0;
|
||||
}
|
||||
string sharp = ColorBoxModel.SettingSharps[sharpindex];
|
||||
Color color = ColorBoxModel.SettingColors[colorindex];
|
||||
|
||||
ColorBoxModel colorBoxModel = new ColorBoxModel(i.ToString(), sharp, color);
|
||||
ItemsSource.Add(colorBoxModel);
|
||||
}
|
||||
Console.WriteLine($""初始化完成,一共初始化Box{Count}个"");
|
||||
}
|
||||
else if (Output == null)
|
||||
{
|
||||
Output = ItemsSource.FirstOrDefault();
|
||||
ItemsSource.RemoveAt(0);
|
||||
Console.WriteLine($""装配{Output.Text}号Box"");
|
||||
}
|
||||
}
|
||||
}
|
||||
}";
|
||||
}
|
||||
|
||||
private List<ColorBoxModel> _itemsSource;
|
||||
public List<ColorBoxModel> ItemsSource
|
||||
{
|
||||
get
|
||||
{
|
||||
return _itemsSource;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _itemsSource, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
using AIStudio.Wpf.Script.Core.Models;
|
||||
using AIStudio.Wpf.Script.Core.ViewModels;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AIStudio.Wpf.Script.ViewModels
|
||||
{
|
||||
public class ColorBoxIfScriptViewModel : RoslynScriptViewModel
|
||||
{
|
||||
public ColorBoxIfScriptViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public ColorBoxIfScriptViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public ColorBoxIfScriptViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
}
|
||||
|
||||
public ColorBoxIfScriptViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void InitNew()
|
||||
{
|
||||
base.InitNew();
|
||||
|
||||
ItemWidth = 80;
|
||||
ItemHeight = 80;
|
||||
Text = "均衡分配器";
|
||||
Code = @"using System;
|
||||
using System.Collections.Generic;
|
||||
using AIStudio.Wpf.Script.Core.Models;
|
||||
using System.Windows.Media;
|
||||
using System.Linq;
|
||||
|
||||
namespace AIStudio.Wpf.CSharpScript
|
||||
{
|
||||
public class ColorBoxIfScript
|
||||
{
|
||||
public int Count1 {private get;set;}
|
||||
public int Count2 {private get;set;}
|
||||
public ColorBoxModel Input {private get; set;}
|
||||
public ColorBoxModel Output1 {get;private set;}
|
||||
public ColorBoxModel Output2 {get;private set;}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
if (Input != null)
|
||||
{
|
||||
Console.WriteLine($""等待均衡负载{Input.Text}号Box"");
|
||||
if (Count1 <= Count2)
|
||||
{
|
||||
if (Output1 == null)
|
||||
{
|
||||
Output1 = Input;
|
||||
Input = null;
|
||||
Console.WriteLine($""{Output1.Text}号Box均衡负载完毕,送往1号出口"");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Output2 == null)
|
||||
{
|
||||
Output2 = Input;
|
||||
Input = null;
|
||||
Console.WriteLine($""{Output2.Text}号Box均衡负载完毕,送往2号出口"");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}";
|
||||
}
|
||||
|
||||
private List<ColorBoxModel> _itemsSource;
|
||||
public List<ColorBoxModel> ItemsSource
|
||||
{
|
||||
get
|
||||
{
|
||||
return _itemsSource;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _itemsSource, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
using AIStudio.Wpf.Script.Core.ViewModels;
|
||||
|
||||
namespace AIStudio.Wpf.Script.ViewModels
|
||||
{
|
||||
public class ColorBoxSwitchScriptViewModel : RoslynScriptViewModel
|
||||
{
|
||||
public ColorBoxSwitchScriptViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public ColorBoxSwitchScriptViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public ColorBoxSwitchScriptViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
}
|
||||
|
||||
public ColorBoxSwitchScriptViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void InitNew()
|
||||
{
|
||||
base.InitNew();
|
||||
|
||||
Text = "ColorBox分配器";
|
||||
ItemWidth = 100;
|
||||
ItemHeight = 230;
|
||||
Code = @"using AIStudio.Wpf.Script.Core.Models;
|
||||
using System;
|
||||
|
||||
namespace AIStudio.Wpf.CSharpScript
|
||||
{
|
||||
public class ColorBoxSwitch
|
||||
{
|
||||
public bool Mode { private get; set; }
|
||||
public string Description { get; private set; }
|
||||
public ColorBoxModel Input { private get; set; }
|
||||
public ColorBoxModel Output1 { get; private set; }
|
||||
public ColorBoxModel Output2 { get; private set; }
|
||||
public ColorBoxModel Output3 { get; private set; }
|
||||
public ColorBoxModel Output4 { get; private set; }
|
||||
public ColorBoxModel Output5 { get; private set; }
|
||||
public ColorBoxModel Output6 { get; private set; }
|
||||
public ColorBoxModel Output7 { get; private set; }
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
if (Input == null)
|
||||
return;
|
||||
|
||||
if (Mode == false)
|
||||
{
|
||||
Console.WriteLine($""正在使用按颜色分配,等待分配{Input.Text}号Box"");
|
||||
Description = ""欢迎来到AIStudio Diagream Box装配工厂,正在使用按颜色分配Box"";
|
||||
switch (Input.Color.ToString())
|
||||
{
|
||||
case ""#FFFF0000"":
|
||||
if (Output1 == null)
|
||||
{
|
||||
Output1 = Input;
|
||||
Input = null;
|
||||
Console.WriteLine($""{Output1.Text}号Box分配完毕,送往1号出口"");
|
||||
}
|
||||
break;
|
||||
case ""#FFFFA500"":
|
||||
if (Output2 == null)
|
||||
{
|
||||
Output2 = Input;
|
||||
Input = null;
|
||||
Console.WriteLine($""{Output2.Text}号Box分配完毕,送往2号出口"");
|
||||
}
|
||||
break;
|
||||
case ""#FFFFFF00"":
|
||||
if (Output3 == null)
|
||||
{
|
||||
Output3 = Input;
|
||||
Input = null;
|
||||
Console.WriteLine($""{Output3.Text}号Box分配完毕,送往3号出口"");
|
||||
}
|
||||
break;
|
||||
case ""#FF008000"":
|
||||
if (Output4 == null)
|
||||
{
|
||||
Output4 = Input;
|
||||
Input = null;
|
||||
Console.WriteLine($""{Output4.Text}号Box分配完毕,送往4号出口"");
|
||||
}
|
||||
break;
|
||||
case ""#FF00FFFF"":
|
||||
if (Output5 == null)
|
||||
{
|
||||
Output5 = Input;
|
||||
Input = null;
|
||||
Console.WriteLine($""{Output5.Text}号Box分配完毕,送往5号出口"");
|
||||
}
|
||||
break;
|
||||
case ""#FF0000FF"":
|
||||
if (Output6 == null)
|
||||
{
|
||||
Output6 = Input;
|
||||
Input = null;
|
||||
Console.WriteLine($""{Output6.Text}号Box分配完毕,送往6号出口"");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (Output7 == null)
|
||||
{
|
||||
Output7 = Input;
|
||||
Input = null;
|
||||
Console.WriteLine($""{Output7.Text}号Box分配完毕,送往7号出口"");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($""正在使用按形状分配,等待分配{Input.Text}号Box"");
|
||||
Description = ""欢迎来到AIStudio Diagream Box装配工厂,正在使用按形状分配Box"";
|
||||
switch (Input.Path)
|
||||
{
|
||||
case ""M 10,20 A 20,20 0 1 1 50,20 A 20,20 0 1 1 10,20"":
|
||||
if (Output1 == null)
|
||||
{
|
||||
Output1 = Input;
|
||||
Input = null;
|
||||
Console.WriteLine($""{Output1.Text}号Box分配完毕,送往1号出口"");
|
||||
}
|
||||
break;
|
||||
case ""M1,21H23L12,2"":
|
||||
if (Output2 == null)
|
||||
{
|
||||
Output2 = Input;
|
||||
Input = null;
|
||||
Console.WriteLine($""{Output2.Text}号Box分配完毕,送往2号出口"");
|
||||
}
|
||||
break;
|
||||
case ""M3,3V21H21V3"":
|
||||
if (Output3 == null)
|
||||
{
|
||||
Output3 = Input;
|
||||
Input = null;
|
||||
Console.WriteLine($""{Output3.Text}号Box分配完毕,送往3号出口"");
|
||||
}
|
||||
break;
|
||||
case ""M 0,20 L 30 0 L 60,20 L 30,40 Z"":
|
||||
if (Output4 == null)
|
||||
{
|
||||
Output4 = Input;
|
||||
Input = null;
|
||||
Console.WriteLine($""{Output4.Text}号Box分配完毕,送往4号出口"");
|
||||
}
|
||||
break;
|
||||
case ""M 0 0 H 60 L 50 40 H 10 Z"":
|
||||
if (Output5 == null)
|
||||
{
|
||||
Output5 = Input;
|
||||
Input = null;
|
||||
Console.WriteLine($""{Output5.Text}号Box分配完毕,送往5号出口"");
|
||||
}
|
||||
break;
|
||||
case ""M 9,2 11,7 17,7 12,10 14,15 9,12 4,15 6,10 1,7 7,7 Z"":
|
||||
if (Output6 == null)
|
||||
{
|
||||
Output6 = Input;
|
||||
Input = null;
|
||||
Console.WriteLine($""{Output6.Text}号Box分配完毕,送往6号出口"");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (Output7 == null)
|
||||
{
|
||||
Output7 = Input;
|
||||
Input = null;
|
||||
Console.WriteLine($""{Output7.Text}号Box分配完毕,送往7号出口"");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user