@@ -26,9 +26,14 @@ namespace BPASmartClient.DATABUS | |||
#region 实时数据->大数据量 | |||
/// <summary> | |||
/// 设备数据 | |||
/// 缓存Redis数据 | |||
/// </summary> | |||
public ConcurrentDictionary<string, Dictionary<string,DeviceDataModel>> Dic_DeviceData = new ConcurrentDictionary<string,Dictionary<string,DeviceDataModel>>(); | |||
public ConcurrentDictionary<string, Dictionary<string, object>> Dic_RedisData = new ConcurrentDictionary<string, Dictionary<string, object>>(); | |||
/// <summary> | |||
/// 缓存Redis数据相关类型 | |||
/// </summary> | |||
public ConcurrentDictionary<string, Dictionary<string, string>> Dic_RedisDataType = new ConcurrentDictionary<string, Dictionary<string, string>>(); | |||
/// <summary> | |||
/// API数据 | |||
/// </summary> | |||
@@ -36,19 +41,7 @@ namespace BPASmartClient.DATABUS | |||
#endregion | |||
#region 配置数据 | |||
//Json<CommunicationPar>.Read(); | |||
#endregion | |||
} | |||
public class DeviceDataModel | |||
{ | |||
public string VarName { get; set; } | |||
public string VarVaule { get; set; } | |||
public string DataType { get; set; } | |||
} | |||
} |
@@ -505,14 +505,10 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
string[] str= item.Value.Replace("{Binding ","").Replace("}","").Split("."); | |||
if (str.Length > 1) | |||
{ | |||
if (Class_DataBus.GetInstance().Dic_DeviceData.ContainsKey(str[0])) | |||
if (Class_DataBus.GetInstance().Dic_RedisData.ContainsKey(str[0])) | |||
{ | |||
Dictionary<string,DeviceDataModel> b= Class_DataBus.GetInstance().Dic_DeviceData[str[0]]; | |||
if (b!=null && b.ContainsKey(str[1])) | |||
{ | |||
object _value = b[str[1]].VarVaule; | |||
this.GetType().GetProperty(item.Key).SetValue(this,_value); | |||
} | |||
Dictionary<string, object> b= Class_DataBus.GetInstance().Dic_RedisData[str[0]]; | |||
if (b!=null && b.ContainsKey(str[1])) this.GetType().GetProperty(item.Key).SetValue(this, b[str[1]]); | |||
} | |||
} | |||
} | |||
@@ -201,24 +201,12 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
string[] str = item.Value.Replace("{Binding ","").Replace("}","").Split("."); | |||
if (str.Length > 1) | |||
{ | |||
if (Class_DataBus.GetInstance().Dic_DeviceData.ContainsKey(str[0])) | |||
if (Class_DataBus.GetInstance().Dic_RedisData.ContainsKey(str[0])) | |||
{ | |||
Dictionary<string,DeviceDataModel> b = Class_DataBus.GetInstance().Dic_DeviceData[str[0]]; | |||
Dictionary<string,object> b = Class_DataBus.GetInstance().Dic_RedisData[str[0]]; | |||
if (b != null && b.ContainsKey(str[1])) | |||
{ | |||
object _value = b[str[1]].VarVaule; | |||
bool _checked = false; | |||
try | |||
{ | |||
_checked = bool.Parse(_value.ToString()); | |||
} | |||
catch (Exception ex) | |||
{ | |||
_checked = false; | |||
} | |||
EDataType eDataType = (EDataType)Enum.Parse(typeof(EDataType),b[str[1]].DataType); | |||
SendText = JsonConvert.SerializeObject(new PublishModel { DeviceName = str[0],VarName = str[1],Value = _checked.ToString(),DataType = eDataType }); | |||
this.GetType().GetProperty("IsChecked").SetValue(this,_checked); | |||
this.GetType().GetProperty("IsChecked").SetValue(this, b[str[1]]); | |||
} | |||
} | |||
} | |||
@@ -239,13 +227,13 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
string[] str = item.Value.Replace("{Binding ","").Replace("}","").Split("."); | |||
if (str.Length > 1) | |||
{ | |||
if (Class_DataBus.GetInstance().Dic_DeviceData.ContainsKey(str[0])) | |||
if (Class_DataBus.GetInstance().Dic_RedisData.ContainsKey(str[0]))//包含设备名称 | |||
{ | |||
Dictionary<string,DeviceDataModel> b = Class_DataBus.GetInstance().Dic_DeviceData[str[0]]; | |||
if (b != null && b.ContainsKey(str[1])) | |||
Dictionary<string,string> blx = Class_DataBus.GetInstance().Dic_RedisDataType[str[0]]; | |||
if (blx != null && blx.ContainsKey(str[1])) | |||
{ | |||
object _value = b[str[1]].VarVaule; | |||
EDataType eDataType = (EDataType)Enum.Parse(typeof(EDataType),b[str[1]].DataType); | |||
EDataType eDataType = (EDataType)Enum.Parse(typeof(EDataType), blx[str[1]]); | |||
SendText = JsonConvert.SerializeObject(new PublishModel { DeviceName = str[0],VarName = str[1],Value = this.IsChecked.ToString(),DataType = eDataType }); | |||
} | |||
} | |||
@@ -121,14 +121,10 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
string[] str = item.Value.Replace("{Binding ","").Replace("}","").Split("."); | |||
if (str.Length > 1) | |||
{ | |||
if (Class_DataBus.GetInstance().Dic_DeviceData.ContainsKey(str[0])) | |||
if (Class_DataBus.GetInstance().Dic_RedisData.ContainsKey(str[0])) | |||
{ | |||
Dictionary<string,DeviceDataModel> b = Class_DataBus.GetInstance().Dic_DeviceData[str[0]]; | |||
if (b != null && b.ContainsKey(str[1])) | |||
{ | |||
object _value = b[str[1]].VarVaule; | |||
this.GetType().GetProperty(item.Key).SetValue(this,_value); | |||
} | |||
Dictionary<string, object> b = Class_DataBus.GetInstance().Dic_RedisData[str[0]]; | |||
if (b != null && b.ContainsKey(str[1])) this.GetType().GetProperty(item.Key).SetValue(this, b[str[1]]); | |||
} | |||
} | |||
} | |||
@@ -128,13 +128,11 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
string[] str = DataSouceInformation.Replace("{Binding ", "").Replace("}", "").Split("."); | |||
if (str.Length > 1) | |||
{ | |||
if (Class_DataBus.GetInstance().Dic_DeviceData.ContainsKey(str[0])) | |||
if (Class_DataBus.GetInstance().Dic_RedisData.ContainsKey(str[0])) | |||
{ | |||
Dictionary<string, DeviceDataModel> b = Class_DataBus.GetInstance().Dic_DeviceData[str[0]]; | |||
Dictionary<string, object> b = Class_DataBus.GetInstance().Dic_RedisData[str[0]]; | |||
if (b != null && b.ContainsKey(str[1])) | |||
{ | |||
FDataSouce = b[str[1]].VarVaule; | |||
} | |||
FDataSouce = b[str[1]].ToString(); | |||
} | |||
} | |||
} | |||
@@ -256,13 +256,11 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
string[] str = DataSouceInformation.Replace("{Binding ", "").Replace("}", "").Split("."); | |||
if (str.Length > 1) | |||
{ | |||
if (Class_DataBus.GetInstance().Dic_DeviceData.ContainsKey(str[0])) | |||
if (Class_DataBus.GetInstance().Dic_RedisData.ContainsKey(str[0])) | |||
{ | |||
Dictionary<string, DeviceDataModel> b = Class_DataBus.GetInstance().Dic_DeviceData[str[0]]; | |||
Dictionary<string, object> b = Class_DataBus.GetInstance().Dic_RedisData[str[0]]; | |||
if (b != null && b.ContainsKey(str[1])) | |||
{ | |||
FDataSouce = b[str[1]].VarVaule; | |||
} | |||
FDataSouce = b[str[1]].ToString(); | |||
} | |||
} | |||
} | |||
@@ -163,26 +163,34 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
if (!string.IsNullOrEmpty(DeviceName)) | |||
{ | |||
RedisValue obj = fRedisClient.RedisGet(DeviceName); | |||
List<DeviceDataModel> str = JsonConvert.DeserializeObject<List<DeviceDataModel>>(obj.ToString()); | |||
Dictionary<string,DeviceDataModel> keys = new Dictionary<string,DeviceDataModel>(); | |||
str?.ForEach(par => | |||
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 => | |||
{ | |||
keys[par.VarName] = par; | |||
keyValues[jon.VarName] = GetValuesType(jon.DataType, jon.VarVaule); | |||
keyValuesType[jon.VarName] = jon.DataType.ToString(); | |||
}); | |||
Class_DataBus.GetInstance().Dic_DeviceData[DeviceName] = keys; | |||
Class_DataBus.GetInstance().Dic_RedisData[DeviceName] = keyValues; | |||
Class_DataBus.GetInstance().Dic_RedisDataType[DeviceName] = keyValuesType; | |||
if (PropertyChange != null) PropertyChange(this,null); | |||
} | |||
else | |||
{ | |||
fRedisClient.GetKeys()?.ToList().ForEach(par => { | |||
List<DeviceDataModel> str = JsonConvert.DeserializeObject<List<DeviceDataModel>>(par.Value); | |||
Dictionary<string,DeviceDataModel> keys = new Dictionary<string,DeviceDataModel>(); | |||
str?.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 => | |||
{ | |||
keys[par.VarName] = par; | |||
keyValues[jon.VarName] = GetValuesType(jon.DataType, jon.VarVaule); | |||
keyValuesType[jon.VarName] = jon.DataType.ToString(); | |||
}); | |||
Class_DataBus.GetInstance().Dic_DeviceData[par.Key] = keys; | |||
Class_DataBus.GetInstance().Dic_RedisData[par.Key] = keyValues; | |||
Class_DataBus.GetInstance().Dic_RedisDataType[par.Key] = keyValuesType; | |||
}); | |||
if (PropertyChange != null) PropertyChange(this,null); | |||
} | |||
@@ -194,6 +202,53 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
} | |||
} | |||
/// <summary> | |||
/// 根据变量获取变量实际值 | |||
/// </summary> | |||
/// <param name="eData"></param> | |||
/// <param name="Value"></param> | |||
/// <returns></returns> | |||
public object GetValuesType(EDataType eData,string Value) | |||
{ | |||
try | |||
{ | |||
if (!string.IsNullOrEmpty(Value)) | |||
{ | |||
switch (eData) | |||
{ | |||
case EDataType.Bool: | |||
return Convert.ToBoolean(Value); | |||
break; | |||
case EDataType.Byte: | |||
return Convert.ToByte(Value); | |||
break; | |||
case EDataType.Int: | |||
return Convert.ToInt16(Value); | |||
break; | |||
case EDataType.Word: | |||
return Convert.ToUInt16(Value); | |||
break; | |||
case EDataType.Dint: | |||
return Convert.ToInt32(Value); | |||
break; | |||
case EDataType.Dword: | |||
return Convert.ToUInt32(Value); | |||
break; | |||
case EDataType.Float: | |||
return Convert.ToSingle(Value); | |||
break; | |||
default: | |||
break; | |||
} | |||
} | |||
return null; | |||
} | |||
catch (Exception ex) | |||
{ | |||
return null; | |||
} | |||
} | |||
public void Start() => timer.Start(); | |||
public void Stop() => timer.Stop(); | |||
@@ -121,14 +121,10 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
string[] str = item.Value.Replace("{Binding ","").Replace("}","").Split("."); | |||
if (str.Length > 1) | |||
{ | |||
if (Class_DataBus.GetInstance().Dic_DeviceData.ContainsKey(str[0])) | |||
if (Class_DataBus.GetInstance().Dic_RedisData.ContainsKey(str[0])) | |||
{ | |||
Dictionary<string,DeviceDataModel> b = Class_DataBus.GetInstance().Dic_DeviceData[str[0]]; | |||
if (b != null && b.ContainsKey(str[1])) | |||
{ | |||
object _value = b[str[1]].VarVaule; | |||
this.GetType().GetProperty(item.Key).SetValue(this,_value); | |||
} | |||
Dictionary<string, object> b = Class_DataBus.GetInstance().Dic_RedisData[str[0]]; | |||
if (b != null && b.ContainsKey(str[1])) this.GetType().GetProperty(item.Key).SetValue(this, b[str[1]]); | |||
} | |||
} | |||
} | |||
@@ -71,14 +71,13 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
string[] str = item.Value.Replace("{Binding ","").Replace("}","").Split("."); | |||
if (str.Length > 1) | |||
{ | |||
if (Class_DataBus.GetInstance().Dic_DeviceData.ContainsKey(str[0])) | |||
if (Class_DataBus.GetInstance().Dic_RedisData.ContainsKey(str[0])) | |||
{ | |||
Dictionary<string,DeviceDataModel> b = Class_DataBus.GetInstance().Dic_DeviceData[str[0]]; | |||
if (b != null && b.ContainsKey(str[1])) | |||
Dictionary<string, string> blx = Class_DataBus.GetInstance().Dic_RedisDataType[str[0]]; | |||
if (blx != null && blx.ContainsKey(str[1])) | |||
{ | |||
object _value = b[str[1]].VarVaule; | |||
EDataType eDataType = (EDataType)Enum.Parse(typeof(EDataType),b[str[1]].DataType); | |||
SendText = JsonConvert.SerializeObject(new PublishModel { DeviceName = str[0],VarName = str[1],Value = Text,DataType = eDataType }); | |||
EDataType eDataType = (EDataType)Enum.Parse(typeof(EDataType), blx[str[1]]); | |||
SendText = JsonConvert.SerializeObject(new PublishModel { DeviceName = str[0], VarName = str[1], Value = Text, DataType = eDataType }); | |||
} | |||
} | |||
} | |||
@@ -180,14 +179,10 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
string[] str = item.Value.Replace("{Binding ","").Replace("}","").Split("."); | |||
if (str.Length > 1) | |||
{ | |||
if (Class_DataBus.GetInstance().Dic_DeviceData.ContainsKey(str[0])) | |||
if (Class_DataBus.GetInstance().Dic_RedisData.ContainsKey(str[0])) | |||
{ | |||
Dictionary<string,DeviceDataModel> b = Class_DataBus.GetInstance().Dic_DeviceData[str[0]]; | |||
if (b != null && b.ContainsKey(str[1])) | |||
{ | |||
object _value = b[str[1]].VarVaule; | |||
this.GetType().GetProperty(item.Key).SetValue(this,_value); | |||
} | |||
Dictionary<string, object> b = Class_DataBus.GetInstance().Dic_RedisData[str[0]]; | |||
if (b != null && b.ContainsKey(str[1])) this.GetType().GetProperty(item.Key).SetValue(this, b[str[1]]); | |||
} | |||
} | |||
} | |||
@@ -134,8 +134,6 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
timer.Start(); | |||
} | |||
Click += TheToggleButton_Click; | |||
Checked += TheCheckBox_Checked; | |||
Unchecked += TheCheckBox_Unchecked; | |||
} | |||
@@ -155,26 +153,10 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
string[] str = item.Value.Replace("{Binding ","").Replace("}","").Split("."); | |||
if (str.Length > 1) | |||
{ | |||
if (Class_DataBus.GetInstance().Dic_DeviceData.ContainsKey(str[0])) | |||
if (Class_DataBus.GetInstance().Dic_RedisData.ContainsKey(str[0])) | |||
{ | |||
Dictionary<string,DeviceDataModel> b = Class_DataBus.GetInstance().Dic_DeviceData[str[0]]; | |||
if (b != null && b.ContainsKey(str[1])) | |||
{ | |||
object _value = b[str[1]].VarVaule; | |||
bool _checked = false; | |||
try | |||
{ | |||
_checked = bool.Parse(_value.ToString()); | |||
} | |||
catch (Exception ex) | |||
{ | |||
_checked = false; | |||
} | |||
EDataType eDataType = (EDataType)Enum.Parse(typeof(EDataType),b[str[1]].DataType); | |||
SendText = JsonConvert.SerializeObject(new PublishModel { DeviceName = str[0],VarName = str[1],Value = _checked.ToString(),DataType = eDataType }); | |||
this.GetType().GetProperty("IsChecked").SetValue(this,_checked); | |||
} | |||
Dictionary<string, object> b = Class_DataBus.GetInstance().Dic_RedisData[str[0]]; | |||
if (b != null && b.ContainsKey(str[1])) this.GetType().GetProperty("IsChecked").SetValue(this, b[str[1]]); | |||
} | |||
} | |||
} | |||
@@ -194,14 +176,13 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
string[] str = item.Value.Replace("{Binding ","").Replace("}","").Split("."); | |||
if (str.Length > 1) | |||
{ | |||
if (Class_DataBus.GetInstance().Dic_DeviceData.ContainsKey(str[0])) | |||
if (Class_DataBus.GetInstance().Dic_RedisData.ContainsKey(str[0])) | |||
{ | |||
Dictionary<string,DeviceDataModel> b = Class_DataBus.GetInstance().Dic_DeviceData[str[0]]; | |||
if (b != null && b.ContainsKey(str[1])) | |||
Dictionary<string, string> blx = Class_DataBus.GetInstance().Dic_RedisDataType[str[0]]; | |||
if (blx != null && blx.ContainsKey(str[1])) | |||
{ | |||
object _value = b[str[1]].VarVaule; | |||
EDataType eDataType = (EDataType)Enum.Parse(typeof(EDataType),b[str[1]].DataType); | |||
SendText = JsonConvert.SerializeObject(new PublishModel { DeviceName = str[0],VarName = str[1],Value = "False",DataType = eDataType }); | |||
EDataType eDataType = (EDataType)Enum.Parse(typeof(EDataType), blx[str[1]]); | |||
SendText = JsonConvert.SerializeObject(new PublishModel { DeviceName = str[0], VarName = str[1], Value = IsChecked.ToString(), DataType = eDataType }); | |||
} | |||
} | |||
} | |||
@@ -210,16 +191,5 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
else Config.GetInstance().RunJsScipt(UnCheckedExec); | |||
timer.Start(); | |||
} | |||
private void TheCheckBox_Unchecked(object sender, RoutedEventArgs e) | |||
{ | |||
} | |||
private void TheCheckBox_Checked(object sender, RoutedEventArgs e) | |||
{ | |||
} | |||
} | |||
} |
@@ -297,13 +297,13 @@ namespace BeDesignerSCADA.ViewModel | |||
/// <param name="e"></param> | |||
private void Executable_PropertyChange(object? sender,EventArgs e) | |||
{ | |||
System.Windows.Controls.Control content = CanSelectedItem as System.Windows.Controls.Control; | |||
System.Reflection.PropertyInfo info = content.GetType().GetProperty("GenerateData"); | |||
var propName = info?.GetValue(content,null); | |||
PropeObject.GetType().GetProperty("数据结果").SetValue(PropeObject,propName); | |||
DevNameList = new System.Collections.ObjectModel.ObservableCollection<string>(); | |||
DevValueList = new System.Collections.ObjectModel.ObservableCollection<string>(); | |||
Class_DataBus.GetInstance().Dic_DeviceData.Keys?.ToList().ForEach(key => { DevNameList.Add(key); }); | |||
//System.Windows.Controls.Control content = CanSelectedItem as System.Windows.Controls.Control; | |||
//System.Reflection.PropertyInfo info = content.GetType().GetProperty("GenerateData"); | |||
//var propName = info?.GetValue(content,null); | |||
//PropeObject.GetType().GetProperty("数据结果").SetValue(PropeObject,propName); | |||
//DevNameList = new System.Collections.ObjectModel.ObservableCollection<string>(); | |||
//DevValueList = new System.Collections.ObjectModel.ObservableCollection<string>(); | |||
//Class_DataBus.GetInstance().Dic_DeviceData.Keys?.ToList().ForEach(key => { DevNameList.Add(key); }); | |||
} | |||
/// <summary> | |||
/// 修改属性后 | |||