Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

多脚本任务管理 #3

Merged
merged 10 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ BenchmarkDotNet.Artifacts/
project.lock.json
project.fragment.lock.json
artifacts/

# StyleCop
StyleCopReport.xml

Expand Down Expand Up @@ -337,4 +336,5 @@ ASALocalRun/
.localhistory/

# BeatPulse healthcheck temp database
healthchecksdb
healthchecksdb
/src/.paket/.store/paket/8.0.3/paket/8.0.3/tools/netcoreapp2.1/any/de/FSharp.Core.resources.dll
11 changes: 7 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,14 @@ else:

### Python的版本支持

底层用的是`IronPython`,由于到目前为之,`IronPython 3.x`尚未成熟,故这里`IronPython`的版本是`2.7.11`。
底层用的是`IronPython`,<del>由于到目前为之,`IronPython 3.x`尚未成熟,故这里`IronPython`的版本是`2.7.11`。</del>

这意味着:
- 只能使用 **Python2.x** 的语法和特性
- 如果要写中文,应该指定文件编码 `# -*- coding: UTF-8 -*-`
<del>这意味着:</del>
- <del>只能使用 **Python2.x** 的语法和特性</del>
- <del>如果要写中文,应该指定文件编码 `# -*- coding: UTF-8 -*-`</del>


从0.4.0开始,使用`IronPython 3.4.1`

### 自定义模块的检索路径

Expand Down
997 changes: 500 additions & 497 deletions src/.paket/Paket.Restore.targets

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/S7SvrSim.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "S7SvrSim", "S7SvrSim\S7SvrS
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2952E6D1-2B99-46A8-8E2B-5A14CB67F6F1}"
ProjectSection(SolutionItems) = preProject
..\.gitignore = ..\.gitignore
paket.dependencies = paket.dependencies
..\Readme.md = ..\Readme.md
EndProjectSection
Expand Down
23 changes: 5 additions & 18 deletions src/S7SvrSim/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using S7Server.Simulator.ViewModels;
using S7Svr.Simulator.MessageHandlers;
using S7Svr.Simulator.ViewModels;
using S7SvrSim;
using S7SvrSim.Services;
using S7SvrSim.ViewModels;
using System;
Expand Down Expand Up @@ -47,27 +48,13 @@ public App()
}
})
.ConfigureServices((ctx, services) => {
this.ConfigureServices(ctx, services);
services.AddS7CoreServices();
})
.Build();
this.ServiceProvider = this._host.Services;
this.ServiceProvider.RegisterViews();
}

private void ConfigureServices(HostBuilderContext ctx, IServiceCollection services)
{
services.AddMediatR(typeof(MessageNotificationHandler).Assembly);
services.AddSingleton<RunningSnap7ServerVM>();
services.AddSingleton<OperationVM>();
services.AddSingleton<ConfigSnap7ServerVM>();
services.AddSingleton<PyScriptRunner>();
services.AddSingleton<ConfigPyEngineVM>();
services.AddSingleton<MsgLoggerVM>();
services.AddSingleton<MainWindow>();
services.AddSingleton<IS7ServerService, S7ServerService>();
services.AddSingleton<IS7DataBlockService, S7DataBlockService>();
services.AddSingleton<IS7MBService, S7MBService>();
services.AddSingleton<MainVM>();
}

private void Application_Startup(object sender, StartupEventArgs e)
{
Expand All @@ -80,7 +67,7 @@ private void Application_Startup(object sender, StartupEventArgs e)
var config = sp.GetRequiredService<IConfiguration>();
var logger = sp.GetRequiredService<ILogger<App>>();
}
var mainWin = this.ServiceProvider.GetRequiredService<MainWindow>();
var mainWin = new MainWindow();
mainWin.Show();
_ = Task.Run(async () =>
{
Expand All @@ -101,7 +88,7 @@ protected override void OnExit(ExitEventArgs e)
var lieftime = _host.Services.GetRequiredService<IHostApplicationLifetime>();
lieftime.StopApplication();
}
base.OnExit(e);
Environment.Exit(0);
}


Expand Down
71 changes: 71 additions & 0 deletions src/S7SvrSim/Exts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using S7Server.Simulator.ViewModels;
using S7Svr.Simulator.MessageHandlers;
using S7Svr.Simulator.ViewModels;
using S7Svr.Simulator;
using S7SvrSim.Services;
using S7SvrSim.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Splat;
using S7SvrSim.ViewModels.Rw;
using S7SvrSim.UserControls.Rws;
using S7SvrSim.UserControls;

namespace S7SvrSim
{
internal static class Exts
{
public static IServiceCollection AddS7CoreServices(this IServiceCollection services)
{
services.AddMediatR(typeof(MessageNotificationHandler).Assembly);
services.AddSingleton<PyScriptRunner>();
services.AddSingleton<IS7ServerService, S7ServerService>();
services.AddSingleton<IS7DataBlockService, S7DataBlockService>();
services.AddSingleton<IS7MBService, S7MBService>();

return services;
}


public static void RegisterViews(this IServiceProvider sp)
{
Locator.CurrentMutable.RegisterLazySingletonEx<MsgLoggerVM>(sp);

Locator.CurrentMutable.RegisterLazySingletonEx<ConfigPyEngineVM>(sp);
Locator.CurrentMutable.RegisterLazySingletonEx<ConfigSnap7ServerVM>(sp);

Locator.CurrentMutable.RegisterLazySingletonEx<RunningSnap7ServerVM>(sp);
Locator.CurrentMutable.RegisterLazySingletonEx<RwTargetVM>(sp);
Locator.CurrentMutable.RegisterLazySingletonEx<OperationVM>(sp);
Locator.CurrentMutable.RegisterLazySingletonEx<MainVM>(sp);

Locator.CurrentMutable.RegisterLazySingletonEx<RwBitVM>(sp);
Locator.CurrentMutable.RegisterLazySingletonEx<RwByteVM>(sp);
Locator.CurrentMutable.RegisterLazySingletonEx<RwShortVM>(sp);
Locator.CurrentMutable.RegisterLazySingletonEx<RwUInt32VM>(sp);
Locator.CurrentMutable.RegisterLazySingletonEx<RwUInt64VM>(sp);
Locator.CurrentMutable.RegisterLazySingletonEx<RwRealVM>(sp);
Locator.CurrentMutable.RegisterLazySingletonEx<RwStringVM>(sp);

Locator.CurrentMutable.RegisterLazySingletonEx<ScriptTaskWindowVM>(sp);


Locator.CurrentMutable.Register<IViewFor<RwBitVM>, BitOpsView>();
Locator.CurrentMutable.Register<IViewFor<RwByteVM>, ByteOpsView>();
Locator.CurrentMutable.Register<IViewFor<RwShortVM>, ShortOpsView>();
Locator.CurrentMutable.Register<IViewFor<RwUInt32VM>, UInt32OpsView>();
Locator.CurrentMutable.Register<IViewFor<RwUInt64VM>, UInt64OpsView>();
Locator.CurrentMutable.Register<IViewFor<RwRealVM>, RealOpsView>();
Locator.CurrentMutable.Register<IViewFor<RwStringVM>, StringOpsView>();
//Locator.CurrentMutable.Register<IViewFor<ScriptTaskWindowVM>, ScriptTaskWindow>();



}
}
}
3 changes: 3 additions & 0 deletions src/S7SvrSim/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ReactiveUI />
</Weavers>
26 changes: 26 additions & 0 deletions src/S7SvrSim/FodyWeavers.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="ReactiveUI" minOccurs="0" maxOccurs="1" type="xs:anyType" />
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
4 changes: 4 additions & 0 deletions src/S7SvrSim/GlboalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
global using ReactiveUI;
global using System.Reactive.Disposables;
global using System.Reactive;
global using S7SvrSim.Shared.Utils;
53 changes: 15 additions & 38 deletions src/S7SvrSim/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
xmlns:uc="clr-namespace:S7Svr.Simulator.UserControls"
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:viewmodels="clr-namespace:S7Svr.Simulator.ViewModels"
xmlns:usercontrols="clr-namespace:S7SvrSim.UserControls"
xmlns:usercontrols="clr-namespace:S7SvrSim.UserControls" xmlns:scripting="clr-namespace:S7SvrSim.UserControls.Scripting"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=viewmodels:MainVM}"
Title="Siemens PLC 通讯模拟器"
Expand All @@ -30,7 +30,7 @@
<Style TargetType="TextBlock" BasedOn="{StaticResource MaterialDesignTextBlock}">
</Style>
</TabControl.Resources>
<TabItem Header="DB配置">
<TabItem Header="配置">
<TabItem.Resources>
<Style TargetType="Grid" >
<Setter Property="Margin" Value="4,8,4,4"></Setter>
Expand All @@ -51,7 +51,7 @@


<Label Content="IP Address" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Column="0" ></Label>
<TextBox Text="{Binding ConfigVM.IpAddress.Value}"
<TextBox Text="{Binding ConfigVM.IpAddress}"
Width="100" VerticalAlignment="Center" Grid.Row="0" Grid.Column="1" />
<Button Content="启动" Command="{Binding CmdStartServer}"
Width="100" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="0" Grid.Column="2"/>
Expand All @@ -65,10 +65,10 @@
<DataGrid.Style>
<Style TargetType="DataGrid" BasedOn="{StaticResource MaterialDesignDataGrid}">
<Style.Triggers>
<DataTrigger Binding="{Binding RunningVM.RunningStatus.Value}" Value="True">
<DataTrigger Binding="{Binding RunningVM.RunningStatus}" Value="True">
<Setter Property="IsEnabled" Value="False"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding RunningVM.RunningStatus.Value}" Value="False">
<DataTrigger Binding="{Binding RunningVM.RunningStatus}" Value="False">
<Setter Property="IsEnabled" Value="True"></Setter>
</DataTrigger>
</Style.Triggers>
Expand All @@ -80,11 +80,11 @@

</Grid>
</TabItem>
<TabItem Header="DB命令">
<TabItem Header="命令">

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
Expand All @@ -94,13 +94,13 @@
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>

<Label Content="IpAddress" Grid.Row="0" Grid.Column="0" ></Label>
<TextBlock Text="{Binding ConfigVM.IpAddress.Value}" Grid.Row="0" Grid.Column="1"></TextBlock>
<Label Content="IpAddress" Margin="0,4,0,4" Grid.Row="0" Grid.Column="0" ></Label>
<TextBlock Text="{Binding ConfigVM.IpAddress}" Margin="0,4,0,4" Grid.Row="0" Grid.Column="1"></TextBlock>

<uc:OperationsCtrl DataContext="{Binding OperationVM}" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" ></uc:OperationsCtrl>

<ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2">
<ItemsControl ItemsSource="{Binding RunningVM.RunningsItems}">
<!--<ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2">
<HeaderedItemsControl Header="运行" ItemsSource="{Binding RunningVM.RunningsItems}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Expander >
Expand All @@ -114,37 +114,14 @@
</Expander>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</HeaderedItemsControl>
</ScrollViewer>-->

</Grid>
</TabItem>

<TabItem Header="PyEngine" DataContext="{Binding ConfigPyEngineVM}">
<GroupBox>
<GroupBox.Header>Search Paths</GroupBox.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="200"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition Height="32"></RowDefinition>
</Grid.RowDefinitions>
<ItemsControl ItemsSource="{Binding PyEngineSearchPaths}" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding .}" IsReadOnly="True" ></TextBox>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Button Command="{Binding CmdSelectModulePath}" Content="选择路径" Grid.Row="1" Grid.Column="0" ></Button>
<TextBox Text="{Binding SelectedModulePath.Value}" VerticalAlignment="Stretch" TextAlignment="Justify" Grid.Row="1" Grid.Column="1"></TextBox>
<Button Content="提交" Command="{Binding CmdSubmitSelectPath}" Grid.Row="1" Grid.Column="2" ></Button>
</Grid>
</GroupBox>
<TabItem Header="脚本">
<scripting:ConfigPyEngineView></scripting:ConfigPyEngineView>
</TabItem>
</TabControl>

Expand Down
26 changes: 23 additions & 3 deletions src/S7SvrSim/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using S7Svr.Simulator.ViewModels;
using Splat;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -19,14 +20,33 @@ namespace S7Svr.Simulator
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
public partial class MainWindow : Window, IViewFor<MainVM>
{

public MainWindow(MainVM vm)
public MainWindow()
{
InitializeComponent();
this.DataContext = vm;

this.WhenActivated(d => {
this.ViewModel = Locator.Current.GetRequiredService<MainVM>();
this.DataContext = this.ViewModel;
});
}

#region
public MainVM ViewModel
{
get { return (MainVM)GetValue(ViewModelProperty); }
set { SetValue(ViewModelProperty, value); }
}

object IViewFor.ViewModel { get => this.ViewModel; set => this.ViewModel = (MainVM)value; }

// Using a DependencyProperty as the backing store for ViewModel. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ViewModelProperty =
DependencyProperty.Register("ViewModel", typeof(MainVM), typeof(MainWindow), new PropertyMetadata(null));


#endregion
}
}
Loading