Ver código fonte

增加redis变量绑定

样式分支
fyf 2 anos atrás
pai
commit
726f751ecb
15 arquivos alterados com 757 adições e 3 exclusões
  1. +2
    -0
      BPASmartClient.Compiler/BPASmartClient.Compiler.csproj
  2. +68
    -0
      BPASmartClient.Compiler/FJson.cs
  3. +170
    -0
      BPASmartClient.Compiler/FRedisClient.cs
  4. +69
    -0
      BPASmartClient.Compiler/RedisHelper.cs
  5. +4
    -0
      BPASmartClient.MessageName/EnumHelp/DataTypeEnum.cs
  6. +10
    -0
      BPASmartClient.SCADAControl/BPASmartClient.SCADAControl.csproj
  7. +55
    -2
      BPASmartClient.SCADAControl/CustomerControls/Silos.xaml.cs
  8. +15
    -0
      BPASmartClient.SCADAControl/CustomerControls/TheRedis.xaml
  9. +346
    -0
      BPASmartClient.SCADAControl/CustomerControls/TheRedis.xaml.cs
  10. BIN
     
  11. BIN
     
  12. BIN
     
  13. +16
    -0
      BPASmartClient.SCADAControl/Themes/Generic.xaml
  14. +1
    -1
      SCADA.Test/MainWindow.xaml.cs
  15. +1
    -0
      SCADA.Test/SCADA.Test.csproj

+ 2
- 0
BPASmartClient.Compiler/BPASmartClient.Compiler.csproj Ver arquivo

@@ -10,6 +10,8 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="ServiceStack.Redis" Version="6.3.0" />
<PackageReference Include="StackExchange.Redis" Version="2.6.66" />
</ItemGroup>

<ItemGroup>


+ 68
- 0
BPASmartClient.Compiler/FJson.cs Ver arquivo

@@ -0,0 +1,68 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.Compiler
{
public class FJson<T> where T : class, new()
{
private static string path
{
get
{
Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"AccessFile\\JSON"));
return AppDomain.CurrentDomain.BaseDirectory + "AccessFile\\JSON\\" + typeof(T).Name + ".json";
}
}

public static T Data
{
get;
set;
} = new T();


public static void Save()
{
string contents = JsonConvert.SerializeObject(Data);
File.WriteAllText(path,contents);
}

public static void Read()
{
if (File.Exists(path))
{
T val = JsonConvert.DeserializeObject<T>(File.ReadAllText(path));
if (val != null)
{
Data = val;
}
}
}

public static void SaveInterface()
{
JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings();
jsonSerializerSettings.TypeNameHandling = TypeNameHandling.Objects;
string contents = JsonConvert.SerializeObject(Data,Formatting.Indented,jsonSerializerSettings);
File.WriteAllText(path,contents);
}

public static void ReadInterface()
{
if (File.Exists(path))
{
JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings();
jsonSerializerSettings.TypeNameHandling = TypeNameHandling.Objects;
T val = JsonConvert.DeserializeObject<T>(File.ReadAllText(path),jsonSerializerSettings);
if (val != null)
{
Data = val;
}
}
}
}
}

+ 170
- 0
BPASmartClient.Compiler/FRedisClient.cs Ver arquivo

@@ -0,0 +1,170 @@
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace BPASmartClient.Compiler
{
public class FRedisClient
{
#region 单例模式
//private static FRedisClient instance = null;
//public static FRedisClient Instance()
//{
// if (instance == null) instance = new FRedisClient();
// return instance;
//}
#endregion

#region 变量
/// <summary>
/// IP地址
/// </summary>
public string redisconnection = "124.222.238.75:16000,password=123456";
/// <summary>
/// redis 连接状态
/// </summary>
public ConnectionMultiplexer _connection = null;
/// <summary>
/// 数据存储位置
/// </summary>
public IDatabase _database = null;
/// <summary>
/// 通道建立连接
/// </summary>
public ISubscriber subscibe = null;
#endregion

#region 外部访问
/// <summary>
/// 委托出去
/// </summary>
public Action<string,string> LogMeaage = null;
#endregion

public void Connect()
{
_connection = ConnectionMultiplexer.Connect(ConfigurationOptions.Parse(redisconnection));
_database = _connection.GetDatabase(0);//默认使用db0
subscibe = _connection.GetSubscriber();
}
public void Connect(string connection)
{
_connection = ConnectionMultiplexer.Connect(ConfigurationOptions.Parse(connection));
if (connection.Contains("defaultDatabase="))
{
string[] str=connection.Split(',');
string stro = str.ToList().Find(s => s.Contains("defaultDatabase="));
int dbi = 0;
try
{
dbi=int.Parse(stro.Replace("defaultDatabase=",""));
}
catch (Exception ex)
{

throw;
}
_database = _connection.GetDatabase(dbi);//默认使用db0
}
else
{
_database = _connection.GetDatabase();//默认使用db0
}
subscibe = _connection.GetSubscriber();
}

/// <summary>
/// 获取设备列表
/// </summary>
/// <returns></returns>
public Dictionary<string,string> GetKeys()
{
Dictionary<string,string> keys = new Dictionary<string,string>();
foreach (var endPoint in _connection.GetEndPoints())
{
//获取指定服务器
var server = _connection.GetServer(endPoint);
//在指定服务器上使用 keys 或者 scan 命令来遍历key
foreach (var key in server.Keys(0,"设备列表:*"))
{
//获取key对于的值
var val = _database.StringGet(key);
Console.WriteLine($"key: {key}, value: {val}");
keys[key] = val;
}
}
return keys;
}

/// <summary>
/// 订阅通道消息
/// </summary>
public void SubscribeChanne(string channelname)
{
if (subscibe == null) return;
subscibe.Subscribe(channelname,(channel,message) =>
{
MessageLog(channel,message);
});
}

/// <summary>
/// 发布通道消息
/// </summary>
public void PublishChanne(string channelname,string value)
{
if (subscibe == null) return;
subscibe.Publish(channelname,value);
}

/// <summary>
/// 获取 key 值
/// </summary>
public RedisValue RedisGet(string key,string hashField = "")
{
if (_database == null) return new RedisValue();
RedisValue result;
if (string.IsNullOrEmpty(hashField))
{
result = _database.StringGet(key);
}
else
{
result = _database.HashGet(key,hashField);
}
return result;
//MessageLog(key,result);
}
/// <summary>
/// 设置 redis 的值
/// </summary>
public bool RedisSet(string key,string hashField,string value)
{
bool result;
if (string.IsNullOrEmpty(hashField))
{
result = _database.StringSet(key,value);
}
else
{
result = _database.HashSet(key,hashField,value);
}
return result;
}

/// <summary>
/// 消息打印
/// </summary>
private void MessageLog(string key,string msg)
{
if (LogMeaage != null)
{
LogMeaage.Invoke(key,msg);
}
}
}
}

+ 69
- 0
BPASmartClient.Compiler/RedisHelper.cs Ver arquivo

@@ -0,0 +1,69 @@
using ServiceStack.Redis;
using System.Diagnostics;

namespace BPASmartClient.Compiler
{
public class RedisHelper
{

private volatile static RedisHelper _Instance;
public static RedisHelper GetInstance => _Instance ?? (_Instance = new RedisHelper());
private RedisHelper() { }
RedisClient client;

public async Task<bool> ConnectAsync(string redisconnection)
{
return await Task.Factory.StartNew(new Func<bool>(() =>
{
if (client == null)
{
//"124.222.238.75:16000,password=123456";
client = new RedisClient("124.222.238.75",16000,"123456",1);
client.ConnectTimeout = 5000;
Stopwatch sw = new Stopwatch();
sw.Start();
while (!client.IsSocketConnected())
{
if (sw.ElapsedMilliseconds >= client.ConnectTimeout) break;
Thread.Sleep(1000);
}
string status = client.IsSocketConnected() ? "成功" : "失败";
}
return client.IsSocketConnected();
}));

}

/// <summary>
/// 清除所有redis 数据
/// </summary>
public void FlushDb()
{
client?.FlushDb();
}

/// <summary>
/// 设置值
/// </summary>
/// <typeparam name="TValue"></typeparam>
/// <param name="key"></param>
/// <param name="value"></param>
public void SetValue<TValue>(string key,TValue value)
{
var res = client?.Set<TValue>(key,value);
}

/// <summary>
/// 获取值
/// </summary>
/// <typeparam name="TResult"></typeparam>
/// <param name="key"></param>
/// <returns></returns>
public TResult GetValue<TResult>(string key)
{
if (client == null) return default(TResult);
return client.Get<TResult>(key);
}

}
}

+ 4
- 0
BPASmartClient.MessageName/EnumHelp/DataTypeEnum.cs Ver arquivo

@@ -20,6 +20,10 @@ namespace BPASmartClient.MessageName.EnumHelp
/// </summary>
MQTT,
/// <summary>
/// Redis拉取数据
/// </summary>
Redis,
/// <summary>
/// 本地数据推送
/// </summary>
本地源,


+ 10
- 0
BPASmartClient.SCADAControl/BPASmartClient.SCADAControl.csproj Ver arquivo

@@ -12,6 +12,9 @@
<None Remove="Images\biogebj.png" />
<None Remove="Images\bj.png" />
<None Remove="Images\databj.png" />
<None Remove="Images\redis.png" />
<None Remove="Images\redisrun.png" />
<None Remove="Images\redisstop.png" />
<None Remove="Images\State0.png" />
<None Remove="Images\State1.png" />
<None Remove="Images\State11.png" />
@@ -29,7 +32,9 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BPASmart.Model\BPASmart.Model.csproj" />
<ProjectReference Include="..\BPASmartClient.Compiler\BPASmartClient.Compiler.csproj" />
<ProjectReference Include="..\BPASmartClient.DATABUS\BPASmartClient.DATABUS.csproj" />
<ProjectReference Include="..\BPASmartClient.MessageCommunication\BPASmartClient.MessageCommunication.csproj" />
<ProjectReference Include="..\BPASmartClient.MessageName\BPASmartClient.MessageName.csproj" />
</ItemGroup>
@@ -47,6 +52,11 @@
<Resource Include="Fonts\ds-digib.ttf" />
<Resource Include="Images\bj.png" />
<Resource Include="Images\databj.png" />
<Resource Include="Images\redis.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Images\redisrun.png" />
<Resource Include="Images\redisstop.png" />
<Resource Include="Images\State0.png" />
<Resource Include="Images\State1.png" />
<Resource Include="Images\State11.png" />


+ 55
- 2
BPASmartClient.SCADAControl/CustomerControls/Silos.xaml.cs Ver arquivo

@@ -1,4 +1,5 @@
using BPASmartClient.Compiler;
using BPASmartClient.DATABUS;
using BPASmartClient.MessageCommunication;
using BPASmartClient.MessageCommunication.MsgControl;
using BPASmartClient.MessageName;
@@ -26,6 +27,7 @@ using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace BPASmartClient.SCADAControl.CustomerControls
{
@@ -33,7 +35,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls
/// Silos.xaml 的交互逻辑
/// 物料仓
/// </summary>
public partial class Silos :UserControl, IExecutable
public partial class Silos :UserControl, IExecutable, IDisposable
{
#region 临时变量
TextBlock textBlockCLKZ = null;
@@ -341,6 +343,22 @@ namespace BPASmartClient.SCADAControl.CustomerControls
}
public static readonly DependencyProperty DataSouceInformationProperty =
DependencyProperty.Register("DataSouceInformation",typeof(string),typeof(Silos),new PropertyMetadata(string.Empty));
[Category("数据绑定-数据来源")]
public string DeviceName
{
get { return (string)GetValue(DeviceNameProperty); }
set { SetValue(DeviceNameProperty,value); }
}
public static readonly DependencyProperty DeviceNameProperty =
DependencyProperty.Register("DeviceName",typeof(string),typeof(Silos),new PropertyMetadata(string.Empty));
[Category("数据绑定-数据来源")]
public string DeviceValuleName
{
get { return (string)GetValue(DeviceValuleNameProperty); }
set { SetValue(DeviceValuleNameProperty,value); }
}
public static readonly DependencyProperty DeviceValuleNameProperty =
DependencyProperty.Register("DeviceValuleName",typeof(string),typeof(Silos),new PropertyMetadata(string.Empty));

[Category("数据绑定")]
public string FDataSouce
@@ -369,7 +387,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls

}
}
public static string _code = " public string main(string message) \n { \n //请在此填写你的代码\n\n return message; \n }\n";
public static string _code = "public string main(string message) \n{ \n //请在此填写你的代码\n\n return message; \n}\n";
[Category("数据绑定")]
public string Code
{
@@ -386,6 +404,11 @@ namespace BPASmartClient.SCADAControl.CustomerControls
}
public static readonly DependencyProperty GenerateDataProperty =
DependencyProperty.Register("GenerateData",typeof(string),typeof(Silos),new PropertyMetadata(string.Empty));
public void RefreshData()
{
;
}

#endregion

#region 发送事件名称集合
@@ -486,6 +509,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls
#endregion

#region 运行事件
DispatcherTimer timer = new DispatcherTimer();
List<string> MessageNameL = null;
public void Register()
{
@@ -500,6 +524,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls

}
}

if (!string.IsNullOrEmpty(EventSendNameListStr))
{
try
@@ -520,7 +545,30 @@ namespace BPASmartClient.SCADAControl.CustomerControls
MessageNameL = MessageNameNew;
}

timer.Interval = TimeSpan.FromMilliseconds(50);
timer.Tick += Timer_Tick; ;
timer.Start();

}

private void Timer_Tick(object? sender,EventArgs e)
{
try
{
if (!string.IsNullOrEmpty(DeviceName) && !string.IsNullOrEmpty(DeviceValuleName))
{
if (Class_DataBus.GetInstance().Dic_DeviceData.ContainsKey(DeviceValuleName))
{
textBlockTitle.Text= Class_DataBus.GetInstance().Dic_DeviceData[DeviceValuleName].ToString();
}
}
}
catch (Exception ex)
{

}
}

/// <summary>
/// 统一事件消息处理中心
/// </summary>
@@ -564,6 +612,11 @@ namespace BPASmartClient.SCADAControl.CustomerControls
#endregion

#region 发送消息事件
public void Dispose()
{
timer.Stop();
}

/// <summary>
/// 按钮按下
/// </summary>


+ 15
- 0
BPASmartClient.SCADAControl/CustomerControls/TheRedis.xaml Ver arquivo

@@ -0,0 +1,15 @@
<UserControl x:Class="BPASmartClient.SCADAControl.CustomerControls.TheRedis"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BPASmartClient.SCADAControl.CustomerControls"
mc:Ignorable="d"
d:DesignHeight="40" d:DesignWidth="40" >
<Grid>
<Image Source="../Images/redis.png" Tag="正常" Visibility="Visible"/>
<Image Source="../Images/redisrun.png" Tag="运行" Visibility="Collapsed"/>
<Image Source="../Images/redisstop.png" Tag="故障" Visibility="Collapsed"/>
<TextBlock HorizontalAlignment="Center" Tag="显示文字" VerticalAlignment="Bottom" Foreground="#FF02F9FF" Margin="0,0,0,-8">未运行</TextBlock>
</Grid>
</UserControl>

+ 346
- 0
BPASmartClient.SCADAControl/CustomerControls/TheRedis.xaml.cs Ver arquivo

@@ -0,0 +1,346 @@
using BPASmart.Model;
using BPASmartClient.Compiler;
using BPASmartClient.DATABUS;
using BPASmartClient.MessageName.EnumHelp;
using BPASmartClient.SCADAControl;
using Newtonsoft.Json;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
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;
using System.Windows.Threading;

namespace BPASmartClient.SCADAControl.CustomerControls
{
/// <summary>
/// TheRedis.xaml 的交互逻辑
/// </summary>
public partial class TheRedis :UserControl, IExecutable, IDisposable
{
Image imageZC = null;
Image imageYC = null;
Image imageGZ = null;
TextBlock textBlock = null;
FRedisClient fRedisClient = new FRedisClient();
public TheRedis()
{
InitializeComponent();
Width = 40;
Height = 40;
this.SizeChanged += TheRedis_SizeChanged;
}
private void TheRedis_SizeChanged(object sender,SizeChangedEventArgs e)
{
if (textBlock == null)
{
foreach (Image tb in FindVisualChildren<Image>(this))
{
// do something with tb here
if (tb.Tag != null)
{
if (tb.Tag.ToString() == "正常")
{
imageZC = tb;
}

if (tb.Tag.ToString() == "运行")
{
imageYC = tb;
}

if (tb.Tag.ToString() == "故障")
{
imageGZ = tb;
}
}
}

foreach (TextBlock tb in FindVisualChildren<TextBlock>(this))
{
// do something with tb here
if (tb.Tag != null)
{
if (tb.Tag.ToString() == "显示文字")
{
textBlock = tb;
}
}
}
}
}
public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
{
if (depObj != null)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(depObj,i);
if (child != null && child is T)
{
yield return (T)child;
}

foreach (T childOfChild in FindVisualChildren<T>(child))
{
yield return childOfChild;
}
}
}
}
public string ControlType => "控件";
private bool isExecuteState;
public bool IsExecuteState
{
get { return isExecuteState; }
set
{
isExecuteState = value;
if (IsExecuteState)
{
Register();
Style = null;
}
}
}

DispatcherTimer timer = new DispatcherTimer();
public void Register()
{
if (Direction == 0)
{
try
{
if (!string.IsNullOrEmpty(DataSouceInformation))
fRedisClient.Connect(DataSouceInformation);

}
catch (Exception ex)
{
Direction = 2;
}
}
timer.Interval = TimeSpan.FromSeconds(Interval);
timer.Tick += Timer_Tick;
timer.Start();

}
Task<bool> isSuccess;
private async void Timer_Tick(object sender,EventArgs e)
{
Config.GetInstance().RunJsScipt(TikcExecute);
if (fRedisClient._connection != null && fRedisClient._connection.IsConnected)
{
Direction = 1;
}
else
{
Direction = 0;
try
{
if (!string.IsNullOrEmpty(DataSouceInformation))
fRedisClient.Connect(DataSouceInformation);
}
catch (Exception ex)
{
Direction = 2;
}
}
if (Direction == 1) //定时读取数据
{
RedisValue obj = fRedisClient.RedisGet(DeviceName);
FDataSouce = obj.ToString();
List<ReeisDataModel> str = JsonConvert.DeserializeObject<List<ReeisDataModel>>(FDataSouce);
str?.ForEach(par =>
{
Class_DataBus.GetInstance().Dic_DeviceData[par.VarName] = par.VarVaule;
});
}
}

public void Start() => timer.Start();
public void Stop() => timer.Stop();

public void Dispose()
{
timer.Stop();
}

#region 属性
/// <summary>
/// 时间间隔
/// </summary>
[Category("值设定")]
public int Interval
{
get { return (int)GetValue(IntervalProperty); }
set { SetValue(IntervalProperty,value); }
}
public static readonly DependencyProperty IntervalProperty =
DependencyProperty.Register("Interval",typeof(int),typeof(TheRedis),new PropertyMetadata(1));
[Category("值设定")]
public int Direction
{
get { return (int)GetValue(DirectionProperty); }
set { SetValue(DirectionProperty,value); }
}
public static readonly DependencyProperty DirectionProperty =
DependencyProperty.Register("Direction",typeof(int),typeof(TheRedis),
new PropertyMetadata(0,new PropertyChangedCallback(OnPropertyChanged)));
private static void OnPropertyChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)
{
(d as TheRedis)?.Refresh();
}
public void Refresh()
{
if (textBlock != null)
{
if (Direction == 1)
{
imageZC.Visibility = Visibility.Collapsed;
imageYC.Visibility = Visibility.Visible;
imageGZ.Visibility = Visibility.Collapsed;
textBlock.Visibility = Visibility.Visible;
textBlock.Text = "运行中";
textBlock.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#FF2077EC"));
}
else if (Direction == 2)
{
imageZC.Visibility = Visibility.Collapsed;
imageYC.Visibility = Visibility.Collapsed;
imageGZ.Visibility = Visibility.Visible;
textBlock.Visibility = Visibility.Visible;
textBlock.Text = "故障";
textBlock.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#FFFF0202"));
}
else
{
imageZC.Visibility = Visibility.Visible;
imageYC.Visibility = Visibility.Collapsed;
imageGZ.Visibility = Visibility.Collapsed;
textBlock.Visibility = Visibility.Visible;
textBlock.Text = "未运行";
textBlock.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#FF02F9FF"));
}
}
}
/// <summary>
/// 执行内容
/// </summary>
[Category("事件")]
public string TikcExecute
{
get { return (string)GetValue(TikcExecuteProperty); }
set { SetValue(TikcExecuteProperty,value); }
}
public static readonly DependencyProperty TikcExecuteProperty =
DependencyProperty.Register("TikcExecute",typeof(string),typeof(TheRedis),new PropertyMetadata(string.Empty));
#endregion

#region 数据绑定模块
public event EventHandler PropertyChange; //声明一个事件
[Category("数据绑定-数据来源")]
public DataTypeEnum DataSouceType
{
get { return (DataTypeEnum)GetValue(DataSouceTypeProperty); }
set { SetValue(DataSouceTypeProperty,value); }
}
public static readonly DependencyProperty DataSouceTypeProperty =
DependencyProperty.Register("DataSouceType",typeof(DataTypeEnum),typeof(TheRedis),new PropertyMetadata(DataTypeEnum.静态数据));
[Category("数据绑定-数据来源")]
public int TimeCount
{
get { return (int)GetValue(TimeCountProperty); }
set { SetValue(TimeCountProperty,value); }
}
public static readonly DependencyProperty TimeCountProperty =
DependencyProperty.Register("TimeCount",typeof(int),typeof(TheRedis),new PropertyMetadata(5));
[Category("数据绑定-数据来源")]
public string DataSouceInformation
{
get { return (string)GetValue(DataSouceInformationProperty); }
set { SetValue(DataSouceInformationProperty,value); }
}
public static readonly DependencyProperty DataSouceInformationProperty =
DependencyProperty.Register("DataSouceInformation",typeof(string),typeof(TheRedis),new PropertyMetadata("124.222.238.75:16000,password=123456,defaultDatabase=1"));
[Category("数据绑定-数据来源")]
public string DeviceName
{
get { return (string)GetValue(DeviceNameProperty); }
set { SetValue(DeviceNameProperty,value); }
}
public static readonly DependencyProperty DeviceNameProperty =
DependencyProperty.Register("DeviceName",typeof(string),typeof(TheRedis),new PropertyMetadata(string.Empty));
[Category("数据绑定-数据来源")]
public string DeviceValuleName
{
get { return (string)GetValue(DeviceValuleNameProperty); }
set { SetValue(DeviceValuleNameProperty,value); }
}
public static readonly DependencyProperty DeviceValuleNameProperty =
DependencyProperty.Register("DeviceValuleName",typeof(string),typeof(TheRedis),new PropertyMetadata(string.Empty));

[Category("数据绑定")]
public string FDataSouce
{
get { return (string)GetValue(FDataSouceProperty); }
set { SetValue(FDataSouceProperty,value); }
}
public static readonly DependencyProperty FDataSouceProperty =
DependencyProperty.Register("FDataSouce",typeof(string),typeof(TheRedis),new PropertyMetadata(string.Empty,new PropertyChangedCallback(onFDataSouceChanged)));
private static void onFDataSouceChanged(DependencyObject d,DependencyPropertyChangedEventArgs e) => (d as TheRedis)?.DataSouceRefresh();
public void DataSouceRefresh()
{
try
{
if (!string.IsNullOrEmpty(FDataSouce))
{
GenerateData = (string)CSharpConfig.GetInstance().RunCSharp(Code,new object[] { FDataSouce });
if (PropertyChange != null)
{
PropertyChange(this,null);
}
}
}
catch (Exception ex)
{

}
}
public static string _code = "public string main(string message) \n{ \n //请在此填写你的代码\n\n return message; \n}\n";
[Category("数据绑定")]
public string Code
{
get { return (string)GetValue(CodeProperty); }
set { SetValue(CodeProperty,value); }
}
public static readonly DependencyProperty CodeProperty =
DependencyProperty.Register("Code",typeof(string),typeof(TheRedis),new PropertyMetadata(_code));
[Category("数据绑定")]
public string GenerateData
{
get { return (string)GetValue(GenerateDataProperty); }
set { SetValue(GenerateDataProperty,value); }
}
public static readonly DependencyProperty GenerateDataProperty =
DependencyProperty.Register("GenerateData",typeof(string),typeof(TheRedis),new PropertyMetadata(string.Empty));
public void RefreshData()
{
;
}
#endregion


}
}




+ 16
- 0
BPASmartClient.SCADAControl/Themes/Generic.xaml Ver arquivo

@@ -231,6 +231,22 @@
</Setter>
</Style>

<!--<Style TargetType="{x:Type ctrl:TheRedis}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ctrl:TheRedis}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid>
<Image Source="../Images/redis.png"/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>-->

<Style TargetType="ComboBox" x:Key="DesignComboBox">
<Setter Property="Focusable" Value="False" />
<Setter Property="Template">


+ 1
- 1
SCADA.Test/MainWindow.xaml.cs Ver arquivo

@@ -45,7 +45,7 @@ namespace SCADA.Test
{
InitializeComponent();

RedisHelper.GetInstance.ConnectAsync(String.Empty);

string _code = " public string main(string message) \n { \n //请在此填写你的代码\n\n return message; \n }\n";
string GenerateData = (string)CSharpConfig.GetInstance().RunCSharp(_code,new object[] { "ERERERERE" });


+ 1
- 0
SCADA.Test/SCADA.Test.csproj Ver arquivo

@@ -12,6 +12,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BPASmart.Model\BPASmart.Model.csproj" />
<ProjectReference Include="..\BPASmartClient.Compiler\BPASmartClient.Compiler.csproj" />
<ProjectReference Include="..\BPASmartClient.MessageCommunication\BPASmartClient.MessageCommunication.csproj" />
<ProjectReference Include="..\BPASmartClient.MessageName\BPASmartClient.MessageName.csproj" />


Carregando…
Cancelar
Salvar