|
|
@@ -27,7 +27,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls |
|
|
|
/// <summary> |
|
|
|
/// TheRedis.xaml 的交互逻辑 |
|
|
|
/// </summary> |
|
|
|
public partial class TheRedis :UserControl, IExecutable, IDisposable |
|
|
|
public partial class TheRedis : UserControl, IExecutable, IDisposable |
|
|
|
{ |
|
|
|
Image imageZC = null; |
|
|
|
Image imageYC = null; |
|
|
@@ -41,7 +41,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls |
|
|
|
Height = 40; |
|
|
|
this.SizeChanged += TheRedis_SizeChanged; |
|
|
|
} |
|
|
|
private void TheRedis_SizeChanged(object sender,SizeChangedEventArgs e) |
|
|
|
private void TheRedis_SizeChanged(object sender, SizeChangedEventArgs e) |
|
|
|
{ |
|
|
|
if (textBlock == null) |
|
|
|
{ |
|
|
@@ -84,7 +84,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls |
|
|
|
{ |
|
|
|
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++) |
|
|
|
{ |
|
|
|
DependencyObject child = VisualTreeHelper.GetChild(depObj,i); |
|
|
|
DependencyObject child = VisualTreeHelper.GetChild(depObj, i); |
|
|
|
if (child != null && child is T) |
|
|
|
{ |
|
|
|
yield return (T)child; |
|
|
@@ -108,7 +108,6 @@ namespace BPASmartClient.SCADAControl.CustomerControls |
|
|
|
if (IsExecuteState) |
|
|
|
{ |
|
|
|
Register(); |
|
|
|
//Style = null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@@ -135,73 +134,90 @@ namespace BPASmartClient.SCADAControl.CustomerControls |
|
|
|
timer.Start(); |
|
|
|
|
|
|
|
} |
|
|
|
Task<bool> isSuccess; |
|
|
|
private async void Timer_Tick(object sender,EventArgs e) |
|
|
|
private async void Timer_Tick(object sender, EventArgs e) |
|
|
|
{ |
|
|
|
Config.GetInstance().RunJsScipt(TikcExecute); |
|
|
|
if (fRedisClient._connection != null && fRedisClient._connection.IsConnected) |
|
|
|
|
|
|
|
if (TestData) |
|
|
|
{ |
|
|
|
Direction = 1; |
|
|
|
keyValuePairs1.Clear(); |
|
|
|
for (int i = 0; i < 20; i++) |
|
|
|
{ |
|
|
|
Random ran = new Random(); |
|
|
|
int n = ran.Next(0, 100); |
|
|
|
keyValuePairs1[i.ToString()] = "10." + n; |
|
|
|
} |
|
|
|
Class_DataBus.GetInstance().Dic_RedisData["Test"] = keyValuePairs1; |
|
|
|
Class_DataBus.GetInstance().Dic_RedisDataBinding = JsonConvert.DeserializeObject<Dictionary<string, object>>(JsonConvert.SerializeObject(Class_DataBus.GetInstance().Dic_RedisData)); |
|
|
|
Class_DataBus.GetInstance().refreshDataAction("Test"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Direction = 0; |
|
|
|
try |
|
|
|
if (fRedisClient._connection != null && fRedisClient._connection.IsConnected) |
|
|
|
{ |
|
|
|
if (!string.IsNullOrEmpty(DataSouceInformation)) |
|
|
|
fRedisClient.Connect(DataSouceInformation); |
|
|
|
Direction = 1; |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
else |
|
|
|
{ |
|
|
|
Direction = 2; |
|
|
|
Direction = 0; |
|
|
|
try |
|
|
|
{ |
|
|
|
if (!string.IsNullOrEmpty(DataSouceInformation)) |
|
|
|
fRedisClient.Connect(DataSouceInformation); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
Direction = 2; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (Direction == 1) //定时读取数据 |
|
|
|
{ |
|
|
|
try |
|
|
|
if (Direction == 1) //定时读取数据 |
|
|
|
{ |
|
|
|
if (!string.IsNullOrEmpty(DeviceName)) |
|
|
|
try |
|
|
|
{ |
|
|
|
RedisValue obj = fRedisClient.RedisGet(DeviceName); |
|
|
|
List<ReeisDataModel> str = JsonConvert.DeserializeObject<List<ReeisDataModel>>(obj.ToString()); |
|
|
|
Dictionary<string, object> keyValues = new Dictionary<string, object>(); |
|
|
|
Dictionary<string, string> keyValuesType = new Dictionary<string, string>(); |
|
|
|
str?.ForEach(jon => |
|
|
|
if (!string.IsNullOrEmpty(DeviceName)) |
|
|
|
{ |
|
|
|
keyValues[jon.VarName] = GetValuesType(jon.DataType, jon.VarVaule); |
|
|
|
keyValuesType[jon.VarName] = jon.DataType.ToString(); |
|
|
|
}); |
|
|
|
Class_DataBus.GetInstance().Dic_RedisData[DeviceName] = keyValues; |
|
|
|
Class_DataBus.GetInstance().Dic_RedisDataBinding = JsonConvert.DeserializeObject<Dictionary<string, object>>(JsonConvert.SerializeObject(Class_DataBus.GetInstance().Dic_RedisData)); |
|
|
|
Class_DataBus.GetInstance().Dic_RedisDataType[DeviceName] = keyValuesType; |
|
|
|
Class_DataBus.GetInstance().refreshDataAction(DeviceName); |
|
|
|
if (PropertyChange != null) PropertyChange(this,null); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
fRedisClient.GetKeys()?.ToList().ForEach(par => { |
|
|
|
//所有变量集合 |
|
|
|
//PublishInfo |
|
|
|
List<ReeisDataModel> str = JsonConvert.DeserializeObject<List<ReeisDataModel>>(par.Value); |
|
|
|
Dictionary<string,object> keyValues = new Dictionary<string,object>(); |
|
|
|
RedisValue obj = fRedisClient.RedisGet(DeviceName); |
|
|
|
List<ReeisDataModel> str = JsonConvert.DeserializeObject<List<ReeisDataModel>>(obj.ToString()); |
|
|
|
Dictionary<string, object> keyValues = new Dictionary<string, object>(); |
|
|
|
Dictionary<string, string> keyValuesType = new Dictionary<string, string>(); |
|
|
|
str?.ForEach(jon => |
|
|
|
{ |
|
|
|
keyValues[jon.VarName] = GetValuesType(jon.DataType, jon.VarVaule); |
|
|
|
keyValuesType[jon.VarName] = jon.DataType.ToString(); |
|
|
|
keyValuesType[jon.VarName] = jon.DataType.ToString(); |
|
|
|
}); |
|
|
|
Class_DataBus.GetInstance().Dic_RedisData[par.Key] = keyValues; |
|
|
|
Class_DataBus.GetInstance().Dic_RedisData[DeviceName] = keyValues; |
|
|
|
Class_DataBus.GetInstance().Dic_RedisDataBinding = JsonConvert.DeserializeObject<Dictionary<string, object>>(JsonConvert.SerializeObject(Class_DataBus.GetInstance().Dic_RedisData)); |
|
|
|
Class_DataBus.GetInstance().Dic_RedisDataType[par.Key] = keyValuesType; |
|
|
|
Class_DataBus.GetInstance().refreshDataAction(par.Key); |
|
|
|
Class_DataBus.GetInstance().Dic_RedisDataType[DeviceName] = keyValuesType; |
|
|
|
Class_DataBus.GetInstance().refreshDataAction(DeviceName); |
|
|
|
if (PropertyChange != null) PropertyChange(this, null); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
fRedisClient.GetKeys()?.ToList().ForEach(par => |
|
|
|
{ |
|
|
|
//所有变量集合 |
|
|
|
//PublishInfo |
|
|
|
List<ReeisDataModel> str = JsonConvert.DeserializeObject<List<ReeisDataModel>>(par.Value); |
|
|
|
Dictionary<string, object> keyValues = new Dictionary<string, object>(); |
|
|
|
Dictionary<string, string> keyValuesType = new Dictionary<string, string>(); |
|
|
|
str?.ForEach(jon => |
|
|
|
{ |
|
|
|
keyValues[jon.VarName] = GetValuesType(jon.DataType, jon.VarVaule); |
|
|
|
keyValuesType[jon.VarName] = jon.DataType.ToString(); |
|
|
|
}); |
|
|
|
Class_DataBus.GetInstance().Dic_RedisData[par.Key] = keyValues; |
|
|
|
Class_DataBus.GetInstance().Dic_RedisDataBinding = JsonConvert.DeserializeObject<Dictionary<string, object>>(JsonConvert.SerializeObject(Class_DataBus.GetInstance().Dic_RedisData)); |
|
|
|
Class_DataBus.GetInstance().Dic_RedisDataType[par.Key] = keyValuesType; |
|
|
|
Class_DataBus.GetInstance().refreshDataAction(par.Key); |
|
|
|
|
|
|
|
}); |
|
|
|
if (PropertyChange != null) PropertyChange(this,null); |
|
|
|
}); |
|
|
|
if (PropertyChange != null) PropertyChange(this, null); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@@ -212,7 +228,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls |
|
|
|
/// <param name="eData"></param> |
|
|
|
/// <param name="Value"></param> |
|
|
|
/// <returns></returns> |
|
|
|
public object GetValuesType(EDataType eData,string Value) |
|
|
|
public object GetValuesType(EDataType eData, string Value) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
@@ -265,16 +281,36 @@ namespace BPASmartClient.SCADAControl.CustomerControls |
|
|
|
} |
|
|
|
|
|
|
|
#region 属性 |
|
|
|
public bool TestData |
|
|
|
{ |
|
|
|
get { return (bool)GetValue(TestDataProperty); } |
|
|
|
set { SetValue(TestDataProperty, value); } |
|
|
|
} |
|
|
|
public static readonly DependencyProperty TestDataProperty = |
|
|
|
DependencyProperty.Register("TestData", typeof(bool), typeof(TheRedis), |
|
|
|
new PropertyMetadata(false, new PropertyChangedCallback(OnTestDataPropertyChanged))); |
|
|
|
private static void OnTestDataPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
|
|
|
{ |
|
|
|
(d as TheRedis)?.RefreshTest(); |
|
|
|
} |
|
|
|
#region MyRegion |
|
|
|
Dictionary<string, object> keyValuePairs1 = new Dictionary<string, object>(); |
|
|
|
#endregion |
|
|
|
public void RefreshTest() |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
[Category("值设定")] |
|
|
|
public int Direction |
|
|
|
{ |
|
|
|
get { return (int)GetValue(DirectionProperty); } |
|
|
|
set { SetValue(DirectionProperty,value); } |
|
|
|
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) |
|
|
|
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(); |
|
|
|
} |
|
|
@@ -318,10 +354,10 @@ namespace BPASmartClient.SCADAControl.CustomerControls |
|
|
|
public string TikcExecute |
|
|
|
{ |
|
|
|
get { return (string)GetValue(TikcExecuteProperty); } |
|
|
|
set { SetValue(TikcExecuteProperty,value); } |
|
|
|
set { SetValue(TikcExecuteProperty, value); } |
|
|
|
} |
|
|
|
public static readonly DependencyProperty TikcExecuteProperty = |
|
|
|
DependencyProperty.Register("TikcExecute",typeof(string),typeof(TheRedis),new PropertyMetadata(string.Empty)); |
|
|
|
DependencyProperty.Register("TikcExecute", typeof(string), typeof(TheRedis), new PropertyMetadata(string.Empty)); |
|
|
|
#endregion |
|
|
|
|
|
|
|
#region 数据绑定模块 |
|
|
@@ -330,43 +366,43 @@ namespace BPASmartClient.SCADAControl.CustomerControls |
|
|
|
public int TimeCount |
|
|
|
{ |
|
|
|
get { return (int)GetValue(TimeCountProperty); } |
|
|
|
set { SetValue(TimeCountProperty,value); } |
|
|
|
set { SetValue(TimeCountProperty, value); } |
|
|
|
} |
|
|
|
public static readonly DependencyProperty TimeCountProperty = |
|
|
|
DependencyProperty.Register("TimeCount",typeof(int),typeof(TheRedis),new PropertyMetadata(100)); |
|
|
|
DependencyProperty.Register("TimeCount", typeof(int), typeof(TheRedis), new PropertyMetadata(100)); |
|
|
|
[Category("数据绑定-数据来源")] |
|
|
|
public string DataSouceInformation |
|
|
|
{ |
|
|
|
get { return (string)GetValue(DataSouceInformationProperty); } |
|
|
|
set { SetValue(DataSouceInformationProperty,value); } |
|
|
|
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")); |
|
|
|
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); } |
|
|
|
set { SetValue(DeviceNameProperty, value); } |
|
|
|
} |
|
|
|
public static readonly DependencyProperty DeviceNameProperty = |
|
|
|
DependencyProperty.Register("DeviceName",typeof(string),typeof(TheRedis),new PropertyMetadata(string.Empty)); |
|
|
|
DependencyProperty.Register("DeviceName", typeof(string), typeof(TheRedis), new PropertyMetadata(string.Empty)); |
|
|
|
[Category("数据绑定")] |
|
|
|
public string FDataSouce |
|
|
|
{ |
|
|
|
get { return (string)GetValue(FDataSouceProperty); } |
|
|
|
set { SetValue(FDataSouceProperty,value); } |
|
|
|
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(); |
|
|
|
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 }); |
|
|
|
|
|
|
|
GenerateData = (string)CSharpConfig.GetInstance().RunCSharp(Code, new object[] { FDataSouce }); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
@@ -379,10 +415,10 @@ namespace BPASmartClient.SCADAControl.CustomerControls |
|
|
|
public string Code |
|
|
|
{ |
|
|
|
get { return (string)GetValue(CodeProperty); } |
|
|
|
set { SetValue(CodeProperty,value); } |
|
|
|
set { SetValue(CodeProperty, value); } |
|
|
|
} |
|
|
|
public static readonly DependencyProperty CodeProperty = |
|
|
|
DependencyProperty.Register("Code",typeof(string),typeof(TheRedis),new PropertyMetadata(_code)); |
|
|
|
DependencyProperty.Register("Code", typeof(string), typeof(TheRedis), new PropertyMetadata(_code)); |
|
|
|
[Category("数据绑定")] |
|
|
|
public bool IsRun |
|
|
|
{ |
|
|
@@ -407,10 +443,10 @@ namespace BPASmartClient.SCADAControl.CustomerControls |
|
|
|
public string GenerateData |
|
|
|
{ |
|
|
|
get { return (string)GetValue(GenerateDataProperty); } |
|
|
|
set { SetValue(GenerateDataProperty,value); } |
|
|
|
set { SetValue(GenerateDataProperty, value); } |
|
|
|
} |
|
|
|
public static readonly DependencyProperty GenerateDataProperty = |
|
|
|
DependencyProperty.Register("GenerateData",typeof(string),typeof(TheRedis),new PropertyMetadata(string.Empty)); |
|
|
|
DependencyProperty.Register("GenerateData", typeof(string), typeof(TheRedis), new PropertyMetadata(string.Empty)); |
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
|
|