提交 48746dbb 编写于 作者: H Huajiang Wei

add script editor

上级 b3056caf
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
\ No newline at end of file
<Application x:Class="DemoScriptEditor.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DemoScriptEditor"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace DemoScriptEditor
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoScriptEditor
{
class ConsoleItem
{
public DateTime Time { get; set; }
public string Text { get; set; }
}
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{692B38FD-DD40-4DAE-858C-5966C50E7D3D}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>DemoScriptEditor</RootNamespace>
<AssemblyName>DemoScriptEditor</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="ConsoleItem.cs" />
<Compile Include="LogStatement.cs" />
<Compile Include="Persistance.cs" />
<Compile Include="Script.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ExecutionEngine\ExecutionEngine.csproj">
<Project>{86044555-48e3-4128-92ee-59f55f9d8b53}</Project>
<Name>ExecutionEngine</Name>
</ProjectReference>
<ProjectReference Include="..\FontAwesome.WPF\FontAwesome.WPF.csproj">
<Project>{7006ac9f-d218-4d7b-98eb-5d2d91f69c57}</Project>
<Name>FontAwesome.WPF</Name>
</ProjectReference>
<ProjectReference Include="..\ScratchEditor\ScriptEditor.csproj">
<Project>{801cfd14-89d2-4b1e-9332-b22ec959baba}</Project>
<Name>ScriptEditor</Name>
</ProjectReference>
<ProjectReference Include="..\ScriptEngine\ScriptEngine.csproj">
<Project>{9efe2134-8015-4957-a9e1-f7d2fbb4cda7}</Project>
<Name>ScriptEngine</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using ScratchNet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoScriptEditor
{
public delegate void OutWriteLine(object obj, params object[] param);
public class LogStatement : Statement, Execution2
{
public LogStatement()
{
Message = new Literal() { Raw = "Log Text" };
}
public Expression Message { get; set; }
public string ReturnType
{
get { return "void"; }
}
public Completion Execute(ExecutionEnvironment enviroment)
{
return Completion.Void;
}
public Descriptor Descriptor
{
get
{
Descriptor desc = new Descriptor();
desc.Add(new TextItemDescriptor(this, "Console.WriteLine("));
desc.Add(new ExpressionDescriptor(this, "Message", "string|number|boolean") { IsOnlyNumberAllowed = false });
desc.Add(new TextItemDescriptor(this, ")"));
return desc;
}
}
public string Type
{
get
{
return "MoveStatement";
}
}
public BlockDescriptor BlockDescriptor
{
get { return null; }
}
public bool IsClosing
{
get { return false; }
}
public static OutWriteLine WriteLine { get; set; }
//execution
object logValue = null;
public ExecutionEnvironment StartCall(ExecutionEnvironment e)
{
return e;
}
public Completion EndCall(ExecutionEnvironment e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.WriteLine(DateTime.Now + ":" + DateTime.Now.Millisecond + " " + logValue);
Console.ForegroundColor = ConsoleColor.White;
if (WriteLine != null)
{
WriteLine(logValue);
}
return Completion.Void;
}
public bool PopStack(out object execution, out ExecutionCallback callback, ExecutionEnvironment e)
{
execution = Message;
callback = Callback;
return false;
}
Nullable<DateTime> Callback(object value, object exception, ExecutionEnvironment e)
{
logValue = value;
return null;
}
public bool HandleException(object exception)
{
throw new NotImplementedException();
}
}
}
<Window xmlns:ScratchNet="clr-namespace:ScratchNet;assembly=DemoScriptEditor" x:Class="DemoScriptEditor.MainWindow"
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:DemoScriptEditor"
xmlns:editor="clr-namespace:ScratchNet;assembly=ScriptEditor"
mc:Ignorable="d" WindowState="Maximized"
xmlns:fa="http://schemas.fontawesome.io/icons/"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<Button Margin="5" Grid.Column="2" Click="OnNew" Name="ButtonNew">
<Button.Template>
<ControlTemplate>
<fa:FontAwesome Name="StartIcon" FontSize="25" Foreground="Green" Icon="NewspaperOutlined"/>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="StartIcon" Property="Foreground" Value="Gray"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
<Button Margin="5" Grid.Column="2" Click="OnOpen" Name="ButtonOpen" IsEnabled="True">
<Button.Template>
<ControlTemplate>
<fa:FontAwesome Name="StartIcon" FontSize="25" Foreground="Green" Icon="FolderOpenOutlined"/>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="StartIcon" Property="Foreground" Value="Gray"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
<Button Margin="5" Grid.Column="2" Click="OnSave" Name="ButtonSave" IsEnabled="False">
<Button.Template>
<ControlTemplate>
<fa:FontAwesome Name="StartIcon" FontSize="25" Foreground="Green" Icon="Save"/>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="StartIcon" Property="Foreground" Value="Gray"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
<Button Margin="5" Grid.Column="2" Click="OnStartRun" Name="ButtonStart" IsEnabled="False">
<Button.Template>
<ControlTemplate>
<fa:FontAwesome Name="StartIcon" FontSize="25" Foreground="Green" Icon="Play"/>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="StartIcon" Property="Foreground" Value="Gray"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
<Button Margin="5" Grid.Column="3" Click="OnStopRun" Name="ButtonStop" IsEnabled="False">
<Button.Template>
<ControlTemplate>
<fa:FontAwesome Name="Icon" FontSize="25" Foreground="DarkRed" Icon="Stop"/>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Icon" Property="Foreground" Value="Gray"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</StackPanel>
<GridSplitter Height="5" Background="Black" Grid.Row="2" VerticalAlignment="Center" IsEnabled="True"
ResizeBehavior="PreviousAndNext" ResizeDirection="Rows" ShowsPreview="True"/>
<editor:GraphicScriptEditor Grid.Row="1" Name="Editor"/>
<DataGrid Grid.Row="3" Height="150" IsReadOnly="True" Name="ConsoleList" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Time" Binding="{Binding Path=Time}" Width="150"/>
<DataGridTextColumn Header="Text" Binding="{Binding Path=Text}" Width="*"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
using Microsoft.Win32;
using ScratchNet;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.InteropServices;
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.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace DemoScriptEditor
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
[DllImport("kernel32.dll")]
public static extern Boolean AllocConsole();
[DllImport("kernel32.dll")]
public static extern Boolean FreeConsole();
ObservableCollection<ConsoleItem> consoles = new ObservableCollection<ConsoleItem>();
public MainWindow()
{
AllocConsole();
InitializeComponent();
Editor.IsEnabled = false;
List<ScriptStepGroup> toolbar = new List<ScriptStepGroup>();
toolbar.Add(new ScriptStepGroup()
{
Name = "Logic",
Types = new List<object>(){
new CompareExpression(),
new LogicExpression(),
new NotExpression()
}
});
toolbar.Add(new ScriptStepGroup()
{
Name = "Number",
Types = new List<object>(){
new BinaryExpression(),
new ConditionalExpression(),
new RandomExpression()
}
});
toolbar.Add(new ScriptStepGroup()
{
Name = "Flow",
Types = new List<object>(){
new IfStatement(),
new IfStatement(){Alternate=new BlockStatement()},
new ForStatement(),
new WhileStatement(),
new BreakStatement(),
new ContinueStatement(),
new ReturnStatement(),
new TryStatement()
}
});
toolbar.Add(new ScriptStepGroup()
{
Name = "Console",
Types = new List<object>(){
new LogStatement()
}
});
/*
toolbar.Add(new ScriptStepGroup()
{
Name = "Event",
Types = new List<object>(){
//new StartEventHandler(),
}
});*/
toolbar.Add(new ScriptStepGroup()
{
Name = "Variable",
Types = new List<object>(){
"CreateVariable",
new AssignmentStatement(),
}
});
toolbar.Add(new ScriptStepGroup()
{
Name = "Function",
Types = new List<object>(){
"CreateFunction"
}
});
Editor.SetToolBar(toolbar);
LogStatement.WriteLine = WriteLineFunc;
ConsoleList.ItemsSource = consoles;
}
void WriteLineFunc(object obj, params object[] param)
{
Dispatcher.InvokeAsync(() =>
{
string text = string.Format(obj + "", param);
consoles.Insert(0, new ConsoleItem() { Time = DateTime.Now, Text = text });
});
}
ExecutionEngine engine;
private void OnStartRun(object sender, RoutedEventArgs e)
{
consoles.Clear();
foreach(var func in Editor.Script.Functions)
{
if("main".Equals(func.Format, StringComparison.OrdinalIgnoreCase))
{
if (engine != null)
{
engine.Stop();
engine = null;
}
engine = new ExecutionEngine();
engine.AddInstance(new Instance(Editor.Script));
engine.Start();
engine.RunFunction(func);
Console.WriteLine("Start run");
return;
}
}
MessageBox.Show(this, "找不到main主方法", "无法运行", MessageBoxButton.OK, MessageBoxImage.Warning);
}
private void OnStopRun(object sender, RoutedEventArgs e)
{
if (engine != null)
{
engine.Stop();
engine = null;
}
}
public string File { get; set; }
private void OnOpen(object sender, RoutedEventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.DefaultExt = ".xml";
dlg.Filter = "XML Files (*.xml)|*.xml|All Files (*.*)|*.*";
dlg.Multiselect = false;
dlg.InitialDirectory = System.IO.Directory.GetCurrentDirectory();
ButtonOpen.IsEnabled = false;
ButtonSave.IsEnabled = false;
ButtonStart.IsEnabled = false;
ButtonStop.IsEnabled = false;
Nullable<bool> result = dlg.ShowDialog();
if (result == true)
{
Editor.Script = null;
Editor.IsEnabled = false;
File = dlg.FileName;
Script script = Serialization.Load(File);
Editor.Script = script;
Editor.IsEnabled = true;
ButtonStart.IsEnabled = true;
ButtonStop.IsEnabled = true;
}
ButtonOpen.IsEnabled = true;
ButtonSave.IsEnabled = true;
}
private void OnSave(object sender, RoutedEventArgs e)
{
ButtonOpen.IsEnabled = false;
ButtonSave.IsEnabled = false;
if (string.IsNullOrEmpty(File))
{
SaveFileDialog dlg = new SaveFileDialog();
dlg.DefaultExt = ".xml";
dlg.Filter = "XML Files (*.xml)|*.xml|All Files (*.*)|*.*";
//dlg.Multiselect = false;
dlg.InitialDirectory = System.IO.Directory.GetCurrentDirectory();
Nullable<bool> result = dlg.ShowDialog();
if (result != true)
{
ButtonOpen.IsEnabled = true;
ButtonSave.IsEnabled = true;
return;
}
File = dlg.FileName;
}
Serialization.Save((Script)Editor.Script, File);
ButtonOpen.IsEnabled = true;
ButtonSave.IsEnabled = true;
}
private void OnNew(object sender, RoutedEventArgs e)
{
Editor.Script = new Script();
Editor.IsEnabled = true;
ButtonOpen.IsEnabled = true;
ButtonSave.IsEnabled = true;
ButtonStart.IsEnabled = true;
ButtonStop.IsEnabled = true;
}
}
}
此差异已折叠。
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("DemoScriptEditor")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HP Inc.")]
[assembly: AssemblyProduct("DemoScriptEditor")]
[assembly: AssemblyCopyright("Copyright © HP Inc. 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace DemoScriptEditor.Properties
{
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DemoScriptEditor.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace DemoScriptEditor.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
}
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
\ No newline at end of file
using ScratchNet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoScriptEditor
{
public class Script : Class
{
public Script()
{
Positions = new Dictionary<object, System.Windows.Point>();
Variables = new List<Variable>();
Functions = new List<Function>();
Handlers = new List<ScratchNet.EventHandler>();
Expressions = new List<Expression>();
BlockStatements = new List<BlockStatement>();
}
public Dictionary<object, System.Windows.Point> Positions
{
get;
set;
}
public List<Variable> Variables
{
get;
set;
}
public List<Function> Functions
{
get;
set;
}
public List<ScratchNet.EventHandler> Handlers
{
get;
set;
}
public List<ScratchNet.Expression> Expressions
{
get;
set;
}
public List<BlockStatement> BlockStatements
{
get;
set;
}
public string Name => "Script";
}
}
......@@ -118,6 +118,21 @@ namespace ScratchNet
}
}
}
public void RunFunction(Function function)
{
Lock();
foreach (Instance inst in Instances)
{
foreach (var func in inst.Class.Functions)
{
if (func.Equals(function))
{
Threads.Add(new RunThread(inst, func, BaseEnvironment));
}
}
}
UnLock();
}
public void SendEvent(Event e)
{
Lock();
......
......@@ -13,6 +13,18 @@ namespace ScratchNet
public bool IsStarted { get; internal set; }
public bool IsCompleted { get; internal set; }
Stack<ExecStackItem> Stacks { get; set; }
public RunThread(Instance instance, Function fun, ExecutionEnvironment environment)
{
Instance = instance;
IsStarted = false;
IsCompleted = false;
Stacks = new Stack<ExecStackItem>();
Execution2 exe = fun as Execution2;
Environment = new ExecutionEnvironment(environment, instance);
ExecutionEnvironment env = exe.StartCall(Environment);
Stacks.Push(new ExecStackItem(exe, FinishCallback, env, Environment));
}
public RunThread(Instance instance, EventHandler fun, Event e, ExecutionEnvironment environment)
{
Instance = instance;
......
......@@ -2,6 +2,7 @@
this is a visual programming editor like google blocky and scratch, but implemented by WPF and dotnet. I want to develop a visual programming editor like scratch, but which will be more powerful, and has modern programming feature, like local variable, expandsibility. And I plan to enable it to control the robot toy like Lego Mindstorm EV3.
currently we wrote this prototype, and achieved the basic function, visualization and execution.
currently we wrote this prototype, and achieved the basic function, visualization and execution.
<Img src="PrintScreen.PNG"/>
![ScreenShot](PrintScreen.PNG)
![ScreenShot](PrintScreen2.PNG)
......@@ -640,9 +640,10 @@ namespace ScratchNet
{
FunctionControl ectrl = new FunctionControl();
ectrl.Function = fc;
ScriptBoard.Children.Add(ectrl);
Canvas.SetLeft(ectrl, pt.X);
Canvas.SetTop(ectrl, pt.Y);
ScriptBoard.Children.Add(ectrl);
}
private bool DropFunction(Function fc, Point pt)
{
......
......@@ -8,7 +8,7 @@
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ScratchEditor</RootNamespace>
<AssemblyName>ScratchEditor</AssemblyName>
<AssemblyName>ScriptEditor</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
......

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
# Visual Studio Version 16
VisualStudioVersion = 16.0.29728.190
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScratchNet", "ScratchNet\ScratchNet.csproj", "{79F40D09-D4EE-469F-883D-0D471E22AE20}"
EndProject
......@@ -13,7 +13,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExecutionEngine", "Executio
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScratchControl", "ScratchControl\ScratchControl.csproj", "{E1C33987-94F5-472F-B191-8CBEDDEE5D99}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScratchEditor", "ScratchEditor\ScratchEditor.csproj", "{801CFD14-89D2-4B1E-9332-B22EC959BABA}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScriptEditor", "ScratchEditor\ScriptEditor.csproj", "{801CFD14-89D2-4B1E-9332-B22EC959BABA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{574786AA-DCD3-435B-8411-3C0850428F93}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "demo", "demo", "{98B9AB53-DABC-4E87-B63B-BFFB0B7BAB81}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "improve", "improve", "{CE3FE9EE-1EC5-4CAB-990F-27F21F2586FD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DemoScriptEditor", "DemoScriptEditor\DemoScriptEditor.csproj", "{692B38FD-DD40-4DAE-858C-5966C50E7D3D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......@@ -45,8 +53,24 @@ Global
{801CFD14-89D2-4B1E-9332-B22EC959BABA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{801CFD14-89D2-4B1E-9332-B22EC959BABA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{801CFD14-89D2-4B1E-9332-B22EC959BABA}.Release|Any CPU.Build.0 = Release|Any CPU
{692B38FD-DD40-4DAE-858C-5966C50E7D3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{692B38FD-DD40-4DAE-858C-5966C50E7D3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{692B38FD-DD40-4DAE-858C-5966C50E7D3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{692B38FD-DD40-4DAE-858C-5966C50E7D3D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{79F40D09-D4EE-469F-883D-0D471E22AE20} = {98B9AB53-DABC-4E87-B63B-BFFB0B7BAB81}
{9EFE2134-8015-4957-A9E1-F7D2FBB4CDA7} = {574786AA-DCD3-435B-8411-3C0850428F93}
{7006AC9F-D218-4D7B-98EB-5D2D91F69C57} = {574786AA-DCD3-435B-8411-3C0850428F93}
{86044555-48E3-4128-92EE-59F55F9D8B53} = {574786AA-DCD3-435B-8411-3C0850428F93}
{E1C33987-94F5-472F-B191-8CBEDDEE5D99} = {CE3FE9EE-1EC5-4CAB-990F-27F21F2586FD}
{801CFD14-89D2-4B1E-9332-B22EC959BABA} = {574786AA-DCD3-435B-8411-3C0850428F93}
{692B38FD-DD40-4DAE-858C-5966C50E7D3D} = {98B9AB53-DABC-4E87-B63B-BFFB0B7BAB81}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0BD434C9-8675-4D9D-B905-6C481145EB9A}
EndGlobalSection
EndGlobal
......@@ -6,7 +6,7 @@
xmlns:lclz="clr-namespace:ScratchNet.localization"
x:Class="ScratchNet.MainWindow"
FontSize="12" WindowState="Maximized"
xmlns:gui="clr-namespace:ScratchNet;assembly=ScratchEditor"
xmlns:gui="clr-namespace:ScratchNet;assembly=ScriptEditor"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
</Window.Resources>
......
......@@ -192,9 +192,9 @@
<Project>{7006ac9f-d218-4d7b-98eb-5d2d91f69c57}</Project>
<Name>FontAwesome.WPF</Name>
</ProjectReference>
<ProjectReference Include="..\ScratchEditor\ScratchEditor.csproj">
<ProjectReference Include="..\ScratchEditor\ScriptEditor.csproj">
<Project>{801cfd14-89d2-4b1e-9332-b22ec959baba}</Project>
<Name>ScratchEditor</Name>
<Name>ScriptEditor</Name>
</ProjectReference>
<ProjectReference Include="..\ScriptEngine\ScriptEngine.csproj">
<Project>{9efe2134-8015-4957-a9e1-f7d2fbb4cda7}</Project>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册