ソースを参照

1

样式分支
fyf 2年前
コミット
53ca3adaab
7個のファイルの変更186行の追加46行の削除
  1. +1
    -0
      BPASmartClient.Compiler/BPASmartClient.Compiler.csproj
  2. +59
    -15
      BPASmartClient.Compiler/CSharpConfig.cs
  3. +38
    -12
      BPASmartClient.SCADAControl/CustomerControls/TheAPI.xaml.cs
  4. +54
    -6
      BPASmartClient.SCADAControl/CustomerControls/TheDataGrid.xaml.cs
  5. +31
    -13
      BPASmartClient.SCADAControl/Themes/Generic.xaml
  6. +1
    -0
      BeDesignerSCADA/Controls/MainCanvasPanel.xaml
  7. +2
    -0
      BeDesignerSCADA/MainWindow.xaml

+ 1
- 0
BPASmartClient.Compiler/BPASmartClient.Compiler.csproj ファイルの表示

@@ -13,6 +13,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="ServiceStack.Redis" Version="6.3.0" />
<PackageReference Include="StackExchange.Redis" Version="2.6.66" />
<PackageReference Include="Vse.Web.Serialization.ControlledSerializationJsonConverter" Version="1.0.4" />
</ItemGroup>

<ItemGroup>


+ 59
- 15
BPASmartClient.Compiler/CSharpConfig.cs ファイルの表示

@@ -9,6 +9,10 @@ using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Runtime;
using System.Runtime.CompilerServices;

namespace BPASmartClient.Compiler
{
@@ -36,6 +40,8 @@ namespace BPASmartClient.Compiler

}



public object RunCSharp(string code,object[] objValue,string error = "")
{
object strretu = string.Empty;
@@ -43,23 +49,63 @@ namespace BPASmartClient.Compiler
{
string funName = "main";
StringBuilder builder = new StringBuilder();
//builder.Append("using System;\n");
//builder.Append("using System.Linq;\n");
builder.Append("using Newtonsoft.Json;\n");
builder.Append("using Newtonsoft.Json.Linq;\n");
//builder.Append("using System.IO;\n");
//builder.Append("using System.Runtime;\n");
//builder.Append("using System.Text;\n");
builder.Append("using System.Collections.Generic;\n");
builder.Append("namespace YF \n{\n class CSharpConfigRun\n");
builder.Append(" {\n");
builder.Append(code);
builder.Append(" }\n}\n");



//1.添加要引用的程序集
string output = Path.GetTempFileName();
string assemblyName = Path.GetFileName(output);
var refPaths = new[] {
Assembly.GetExecutingAssembly().Location,
typeof(object).GetTypeInfo().Assembly.Location,
Path.Combine(Path.GetDirectoryName(typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly.Location), "System.dll"),
Path.Combine(Path.GetDirectoryName(typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly.Location), "System.Collections.dll"),
Path.Combine(Path.GetDirectoryName(typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly.Location), "System.Threading.dll"),
Path.Combine(Path.GetDirectoryName(typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly.Location), "System.Runtime.dll"),
Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Newtonsoft.Json.dll"),
typeof(DynamicAttribute).GetTypeInfo().Assembly.Location,
};
MetadataReference[] references = refPaths.Select(r => MetadataReference.CreateFromFile(r)).ToArray();

List<MetadataReference> refs = new List<MetadataReference>() {
MetadataReference.CreateFromFile (typeof (object).Assembly.Location),
MetadataReference.CreateFromFile (typeof (List<int>).Assembly.Location),
MetadataReference.CreateFromFile (typeof (ASCIIEncoding).Assembly.Location),
MetadataReference.CreateFromFile (typeof (JsonConvert).Assembly.Location),
MetadataReference.CreateFromFile (typeof (JObject).Assembly.Location),
MetadataReference.CreateFromFile (typeof (Object).Assembly.Location),
MetadataReference.CreateFromFile (typeof (JContainer).Assembly.Location),
MetadataReference.CreateFromFile (typeof (JToken).Assembly.Location),
MetadataReference.CreateFromFile (typeof (Enumerable).Assembly.Location),
};
//2.需要编辑的C#代码
SyntaxTree tree = CSharpSyntaxTree.ParseText(builder.ToString());
var compilation =
CSharpCompilation.Create("YF")
.AddReferences(
MetadataReference.CreateFromFile(
typeof(object).Assembly.Location)
)
.AddSyntaxTrees(tree)
.WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));

//3.生成C#编译
var compilation = CSharpCompilation.Create(Guid.NewGuid().ToString() + ".dll")
.WithOptions(new CSharpCompilationOptions(
Microsoft.CodeAnalysis.OutputKind.DynamicallyLinkedLibrary
,
usings: null,
optimizationLevel: OptimizationLevel.Debug, // TODO
checkOverflow: false, // TODO
allowUnsafe: true, // TODO
platform: Platform.AnyCpu,
warningLevel: 4,
xmlReferenceResolver: null
))
.AddReferences(references)
.AddSyntaxTrees(tree);

//var emitResult = compilation.Emit(output);
EmitResult emitResult;
byte[] dllBytes;
using (var stream = new MemoryStream())
@@ -67,15 +113,13 @@ namespace BPASmartClient.Compiler
emitResult = compilation.Emit(stream);
dllBytes = stream.ToArray();
}

if (emitResult.Success)
{

// Assembly assembly = Assembly.LoadFrom("d:\\test.dll");
Assembly assembly = Assembly.Load(dllBytes);
var obj = assembly.CreateInstance("YF.CSharpConfigRun");
var method = obj.GetType().GetMethod("main",new Type[] { typeof(string) });
strretu = method.Invoke(obj,objValue);
}




+ 38
- 12
BPASmartClient.SCADAControl/CustomerControls/TheAPI.xaml.cs ファイルの表示

@@ -4,8 +4,10 @@ using BPASmartClient.DATABUS;
using BPASmartClient.MessageName.EnumHelp;
using BPASmartClient.SCADAControl;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using StackExchange.Redis;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
@@ -94,7 +96,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls
DispatcherTimer timer = new DispatcherTimer();
public void Register()
{
timer.Interval = TimeSpan.FromSeconds(TimeCount);
timer.Interval = TimeSpan.FromMilliseconds(TimeCount);
timer.Tick += Timer_Tick;
timer.Start();

@@ -118,7 +120,28 @@ namespace BPASmartClient.SCADAControl.CustomerControls
if (!string.IsNullOrEmpty(DataSouceInformation))
{
Direction = 1;
FDataSouce = HttpRequestHelper.HttpGetRequest(DataSouceInformation);
string returndata=string.Empty;
string obj_data= HttpRequestHelper.HttpGetRequest(DataSouceInformation);
Dictionary<string, object> obj = JsonConvert.DeserializeObject<Dictionary<string, object>>(obj_data);
if (obj.ContainsKey("data"))
{
returndata = obj_data.ToString();
} else
{
foreach (var item in obj)
{
if(item.Value is JObject)
{
Dictionary<string, object> itemkey = JsonConvert.DeserializeObject<Dictionary<string, object>>(item.Value.ToString());
if (itemkey.ContainsKey("data"))
{
returndata = item.Value.ToString();
}
}
}
}
//List<Dictionary<string, object>> obj2 = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(obj1["data"].ToString());
FDataSouce = returndata;
}
break;
case InterfaceModeEnum.PUT:
@@ -206,7 +229,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls
set { SetValue(TimeCountProperty,value); }
}
public static readonly DependencyProperty TimeCountProperty =
DependencyProperty.Register("TimeCount",typeof(int),typeof(TheAPI),new PropertyMetadata(5));
DependencyProperty.Register("TimeCount",typeof(int),typeof(TheAPI),new PropertyMetadata(2000));
[Category("数据绑定-数据来源")]
public InterfaceModeEnum InterfaceMode
{
@@ -231,15 +254,15 @@ namespace BPASmartClient.SCADAControl.CustomerControls
set { SetValue(DataSouceInformationProperty,value); }
}
public static readonly DependencyProperty DataSouceInformationProperty =
DependencyProperty.Register("DataSouceInformation",typeof(string),typeof(TheAPI),new PropertyMetadata("http://localhost:9092/api/User/UsersTestSwagger"));
[Category("数据绑定-数据来源")]
public string DeviceName
{
get { return (string)GetValue(DeviceNameProperty); }
set { SetValue(DeviceNameProperty,value); }
}
public static readonly DependencyProperty DeviceNameProperty =
DependencyProperty.Register("DeviceName",typeof(string),typeof(TheAPI),new PropertyMetadata(string.Empty));
DependencyProperty.Register("DataSouceInformation",typeof(string),typeof(TheAPI),new PropertyMetadata("http://datav.dev1.com/api/Alarm/Query"));
//[Category("数据绑定-数据来源")]
//public string DeviceName
//{
// get { return (string)GetValue(DeviceNameProperty); }
// set { SetValue(DeviceNameProperty,value); }
//}
//public static readonly DependencyProperty DeviceNameProperty =
// DependencyProperty.Register("DeviceName",typeof(string),typeof(TheAPI),new PropertyMetadata(string.Empty));
[Category("数据绑定")]
public string FDataSouce
{
@@ -289,5 +312,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls




}
}



+ 54
- 6
BPASmartClient.SCADAControl/CustomerControls/TheDataGrid.xaml.cs ファイルの表示

@@ -8,6 +8,7 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -35,8 +36,10 @@ namespace BPASmartClient.SCADAControl.CustomerControls
ResourceDictionary languageResDic = new ResourceDictionary();
languageResDic.Source = new Uri(@"/BPASmartClient.SCADAControl;component/Themes/Generic.xaml",UriKind.RelativeOrAbsolute);
this.Resources.MergedDictionaries.Add(languageResDic);
MinWidth = 100;
MinHeight = 100;
//MinWidth = 100;
//MinHeight = 100;
//Width = 100;
//Height = 100;
}

public DataSouceModel ItemsString
@@ -70,11 +73,13 @@ namespace BPASmartClient.SCADAControl.CustomerControls
/// </summary>
public void Register()
{

timer.Interval = TimeSpan.FromMilliseconds(TimeCount);
timer.Tick += Timer_Tick; ;
timer.Start();
if (DataSouceType == DataTypeEnum.API接口)
{
timer.Interval = TimeSpan.FromMilliseconds(TimeCount);
timer.Tick += Timer_Tick; ;
timer.Start();
}
}

private void Timer_Tick(object? sender,EventArgs e)
@@ -168,6 +173,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls
{
try
{
//Dictionary<string, object> keys= JsonConvert.DeserializeObject<Dictionary<string, object>>(GenerateData);
//List<Dictionary<string, object>> obj2 = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(keys["data"].ToString());
ItemsString = JsonConvert.DeserializeObject<DataSouceModel>(GenerateData);
// 运行时进行项目绑定
Binding binding = new Binding();
@@ -182,6 +189,47 @@ namespace BPASmartClient.SCADAControl.CustomerControls
}
}

public DataTable ListToDataTable(List<Dictionary<string, object>> arrayList)
{
DataTable dataTable = new DataTable(); //实例化
DataTable result;
try
{
if (arrayList.Count > 0)
{
foreach (Dictionary<string, object> dictionary in arrayList)
{
if (dictionary.Keys.Count<string>() == 0)
{
result = dataTable;
return result;
}
//在第一次循环时确定datatable的列名,后续循环无需再更改
if (dataTable.Columns.Count == 0)
{
//此处仅考虑一层json字符串的形式,多层结构需要深入得到叶子节点的key
foreach (string current in dictionary.Keys)
{
dataTable.Columns.Add(current);//, dictionary[current].GetType());
}
}
//每次循环增加datatable的Rows
DataRow dataRow = dataTable.NewRow();
foreach (string current in dictionary.Keys)
{
dataRow[current] = dictionary[current];
}
dataTable.Rows.Add(dataRow); //循环添加行到DataTable中
}
}
}
catch
{
}
result = dataTable;
return result;
}
#endregion




+ 31
- 13
BPASmartClient.SCADAControl/Themes/Generic.xaml ファイルの表示

@@ -295,6 +295,9 @@
<Style.Setters>
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="../Images/button2.png" />
@@ -305,7 +308,7 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ctrl:TheButton}">
<Border x:Name="BD" Cursor="Hand">
<Border x:Name="BD" Cursor="Hand" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
<StackPanel
HorizontalAlignment="Center"
Cursor="Hand"
@@ -315,19 +318,21 @@
Margin="10,0,10,0"
VerticalAlignment="Center"
Cursor="Hand"
FontSize="14"
FontSize="{TemplateBinding FontSize}"
FontWeight="{TemplateBinding FontWeight}"
FontFamily="{TemplateBinding FontFamily}"
Foreground="{TemplateBinding Foreground}"
Text="{TemplateBinding Content}" />
</StackPanel>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<!--<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="BD" Property="Background" >
<Setter.Value>
<ImageBrush ImageSource="../Images/button2.png" />
</Setter.Value>
</Setter>
<!--<Setter TargetName="textBlock" Property="Foreground" Value="{TemplateBinding Foreground}" />-->
--><!--<Setter TargetName="textBlock" Property="Foreground" Value="{TemplateBinding Foreground}" />--><!--
</Trigger>
<Trigger Property="IsMouseOver" Value="False">
<Setter TargetName="BD" Property="Background" >
@@ -335,8 +340,8 @@
<ImageBrush ImageSource="../Images/button2.png" />
</Setter.Value>
</Setter>
<!--<Setter TargetName="textBlock" Property="Foreground" Value="{TemplateBinding Foreground}" />-->
</Trigger>
--><!--<Setter TargetName="textBlock" Property="Foreground" Value="{TemplateBinding Foreground}" />--><!--
</Trigger>-->
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="textBlock" Property="Foreground" Value="{DynamicResource ButtonUnSelectForeground}" />
</Trigger>
@@ -351,12 +356,20 @@
<Style.Setters>
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="../Images/button2.png" />
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="{DynamicResource ButtonSelectForeground}" />
<Setter Property="Height" Value="25" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ctrl:TheToggleButton}">
<Border x:Name="BD" Cursor="Hand">
<Border x:Name="BD" Cursor="Hand" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
<StackPanel
HorizontalAlignment="Center"
Cursor="Hand"
@@ -366,8 +379,10 @@
Margin="10,0,10,0"
VerticalAlignment="Center"
Cursor="Hand"
FontSize="14"
Foreground="{DynamicResource ButtonSelectForeground}"
FontSize="{TemplateBinding FontSize}"
FontWeight="{TemplateBinding FontWeight}"
FontFamily="{TemplateBinding FontFamily}"
Foreground="{TemplateBinding Foreground}"
Text="{TemplateBinding Content}" />
</StackPanel>
</Border>
@@ -399,7 +414,7 @@
</Style>

<Style TargetType="{x:Type ctrl:TheTextBox}">
<Setter Property="BorderBrush" Value="{x:Static Themes1:ClassicBorderDecorator.ClassicBorderBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource borderBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Padding" Value="0" />
<Setter Property="Foreground" Value="{DynamicResource foreground}" />
@@ -418,9 +433,10 @@
<ControlTemplate TargetType="{x:Type TextBox}">
<Themes1:ClassicBorderDecorator
x:Name="Bd"
BorderBrush="{DynamicResource borderBrush}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderStyle="None"
BorderThickness="1">
BorderThickness="{TemplateBinding BorderThickness}">
<ScrollViewer x:Name="PART_ContentHost" />
</Themes1:ClassicBorderDecorator>
<ControlTemplate.Triggers>
@@ -1969,8 +1985,10 @@
x:Name="Bd"
Height="35"
Margin="5"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
Padding="{TemplateBinding Padding}"
BorderThickness="1"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="2">
<ContentPresenter
x:Name="Content"


+ 1
- 0
BeDesignerSCADA/Controls/MainCanvasPanel.xaml ファイルの表示

@@ -228,6 +228,7 @@
<mypro:PropertyDefinition DisplayName="左边距" Category="基本属性" DisplayOrder="4" Name="(Canvas.Left)"/>
<mypro:PropertyDefinition DisplayName="上边距" Category="基本属性" DisplayOrder="4" Name="(Canvas.Top)"/>

<mypro:PropertyDefinition DisplayName="数据来源类型" Category="数据绑定模块" DisplayOrder="0" Name="DataSouceType"/>
<mypro:PropertyDefinition DisplayName="设备名称" Category="数据绑定模块" DisplayOrder="0" Name="DeviceName"/>
<mypro:PropertyDefinition DisplayName="接口类型" Category="数据绑定模块" DisplayOrder="1" Name="InterfaceMode"/>
<mypro:PropertyDefinition DisplayName="接口参数" Category="数据绑定模块" DisplayOrder="2" Name="InterfaceParameters"/>


+ 2
- 0
BeDesignerSCADA/MainWindow.xaml ファイルの表示

@@ -231,6 +231,8 @@
<mypro:PropertyDefinition DisplayName="左边距" Category="基本属性" DisplayOrder="4" Name="(Canvas.Left)"/>
<mypro:PropertyDefinition DisplayName="上边距" Category="基本属性" DisplayOrder="4" Name="(Canvas.Top)"/>


<mypro:PropertyDefinition DisplayName="数据来源类型" Category="数据绑定模块" DisplayOrder="0" Name="DataSouceType"/>
<mypro:PropertyDefinition DisplayName="设备名称" Category="数据绑定模块" DisplayOrder="0" Name="DeviceName"/>
<mypro:PropertyDefinition DisplayName="接口类型" Category="数据绑定模块" DisplayOrder="1" Name="InterfaceMode"/>
<mypro:PropertyDefinition DisplayName="接口参数" Category="数据绑定模块" DisplayOrder="2" Name="InterfaceParameters"/>


読み込み中…
キャンセル
保存