Ver a proveniência

更新redis控件数据缓存

样式分支
fyf há 2 anos
ascendente
cometimento
ca90514165
11 ficheiros alterados com 119 adições e 134 eliminações
  1. +7
    -14
      BPASmartClient.DATABUS/Class_DataBus.cs
  2. +3
    -7
      BPASmartClient.SCADAControl/CustomerControls/Silos.xaml.cs
  3. +8
    -20
      BPASmartClient.SCADAControl/CustomerControls/SwitchButton.cs
  4. +3
    -7
      BPASmartClient.SCADAControl/CustomerControls/TheButton.xaml.cs
  5. +3
    -5
      BPASmartClient.SCADAControl/CustomerControls/TheDataGrid.xaml.cs
  6. +3
    -5
      BPASmartClient.SCADAControl/CustomerControls/TheListBox.xaml.cs
  7. +66
    -11
      BPASmartClient.SCADAControl/CustomerControls/TheRedis.xaml.cs
  8. +3
    -7
      BPASmartClient.SCADAControl/CustomerControls/TheTextBlock.cs
  9. +8
    -13
      BPASmartClient.SCADAControl/CustomerControls/TheTextBox.cs
  10. +8
    -38
      BPASmartClient.SCADAControl/CustomerControls/TheToggleButton.xaml.cs
  11. +7
    -7
      BeDesignerSCADA/ViewModel/MainViewModel.cs

+ 7
- 14
BPASmartClient.DATABUS/Class_DataBus.cs Ver ficheiro

@@ -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; }
}

}

+ 3
- 7
BPASmartClient.SCADAControl/CustomerControls/Silos.xaml.cs Ver ficheiro

@@ -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]]);
}
}
}


+ 8
- 20
BPASmartClient.SCADAControl/CustomerControls/SwitchButton.cs Ver ficheiro

@@ -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 });
}
}


+ 3
- 7
BPASmartClient.SCADAControl/CustomerControls/TheButton.xaml.cs Ver ficheiro

@@ -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]]);
}
}
}


+ 3
- 5
BPASmartClient.SCADAControl/CustomerControls/TheDataGrid.xaml.cs Ver ficheiro

@@ -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();
}
}
}


+ 3
- 5
BPASmartClient.SCADAControl/CustomerControls/TheListBox.xaml.cs Ver ficheiro

@@ -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();
}
}
}


+ 66
- 11
BPASmartClient.SCADAControl/CustomerControls/TheRedis.xaml.cs Ver ficheiro

@@ -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();



+ 3
- 7
BPASmartClient.SCADAControl/CustomerControls/TheTextBlock.cs Ver ficheiro

@@ -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]]);
}
}
}


+ 8
- 13
BPASmartClient.SCADAControl/CustomerControls/TheTextBox.cs Ver ficheiro

@@ -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]]);
}
}
}


+ 8
- 38
BPASmartClient.SCADAControl/CustomerControls/TheToggleButton.xaml.cs Ver ficheiro

@@ -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)
{

}
}
}

+ 7
- 7
BeDesignerSCADA/ViewModel/MainViewModel.cs Ver ficheiro

@@ -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>
/// 修改属性后


Carregando…
Cancelar
Guardar