整理IoManager.cs格式
This commit is contained in:
auvkk 2023-12-15 10:10:23 +08:00
parent 027726a932
commit e4a31589da
1 changed files with 149 additions and 149 deletions

View File

@ -16,39 +16,39 @@ namespace MECF.Framework.Common.IOCore
{
public class IoManager : Singleton<IoManager>, IIoBuffer
{
private Dictionary<string, DIAccessor> _diMap = new Dictionary<string, DIAccessor>();
private Dictionary<string, DIAccessor> _diMap = new();
private Dictionary<string, DOAccessor> _doMap = new Dictionary<string, DOAccessor>();
private Dictionary<string, DOAccessor> _doMap = new();
private Dictionary<string, AIAccessor> _aiMap = new Dictionary<string, AIAccessor>();
private Dictionary<string, AIAccessor> _aiMap = new();
private Dictionary<string, AOAccessor> _aoMap = new Dictionary<string, AOAccessor>();
private Dictionary<string, AOAccessor> _aoMap = new();
private Dictionary<string, Dictionary<int, bool[]>> _diBuffer = new Dictionary<string, Dictionary<int, bool[]>>();
private Dictionary<string, Dictionary<int, bool[]>> _diBuffer = new();
private Dictionary<string, Dictionary<int, bool[]>> _doBuffer = new Dictionary<string, Dictionary<int, bool[]>>();
private Dictionary<string, Dictionary<int, bool[]>> _doBuffer = new();
private Dictionary<string, Dictionary<int, short[]>> _aiBufferShort = new Dictionary<string, Dictionary<int, short[]>>();
private Dictionary<string, Dictionary<int, short[]>> _aiBufferShort = new();
private Dictionary<string, Dictionary<int, short[]>> _aoBufferShort = new Dictionary<string, Dictionary<int, short[]>>();
private Dictionary<string, Dictionary<int, short[]>> _aoBufferShort = new();
private Dictionary<string, Dictionary<int, float[]>> _aiBufferFloat = new Dictionary<string, Dictionary<int, float[]>>();
private Dictionary<string, Dictionary<int, float[]>> _aiBufferFloat = new();
private Dictionary<string, Dictionary<int, float[]>> _aoBufferFloat = new Dictionary<string, Dictionary<int, float[]>>();
private Dictionary<string, Dictionary<int, float[]>> _aoBufferFloat = new();
private Dictionary<string, Dictionary<int, Type>> _aiBufferType = new Dictionary<string, Dictionary<int, Type>>();
private Dictionary<string, Dictionary<int, Type>> _aiBufferType = new();
private Dictionary<string, Dictionary<int, Type>> _aoBufferType = new Dictionary<string, Dictionary<int, Type>>();
private Dictionary<string, Dictionary<int, Type>> _aoBufferType = new();
private Dictionary<string, List<DIAccessor>> _diList = new Dictionary<string, List<DIAccessor>>();
private Dictionary<string, List<DIAccessor>> _diList = new();
private Dictionary<string, List<DOAccessor>> _doList = new Dictionary<string, List<DOAccessor>>();
private Dictionary<string, List<DOAccessor>> _doList = new();
private Dictionary<string, List<AIAccessor>> _aiList = new Dictionary<string, List<AIAccessor>>();
private Dictionary<string, List<AIAccessor>> _aiList = new();
private Dictionary<string, List<AOAccessor>> _aoList = new Dictionary<string, List<AOAccessor>>();
private Dictionary<string, List<AOAccessor>> _aoList = new();
private Dictionary<string, List<NotifiableIoItem>> _ioItemList = new Dictionary<string, List<NotifiableIoItem>>();
private Dictionary<string, List<NotifiableIoItem>> _ioItemList = new();
private PeriodicJob _monitorThread;
@ -96,23 +96,23 @@ namespace MECF.Framework.Common.IOCore
}
public List<DIAccessor> GetDIList(string source)
{
return _diList.ContainsKey(source) ? _diList[source] : null;
}
{
return _diList.TryGetValue(source, out var value) ? value : null;
}
public List<DOAccessor> GetDOList(string source)
{
return _doList.ContainsKey(source) ? _doList[source] : null;
return _doList.TryGetValue(source, out var value) ? value : null;
}
public List<AIAccessor> GetAIList(string source)
{
return _aiList.ContainsKey(source) ? _aiList[source] : null;
return _aiList.TryGetValue(source, out var value) ? value : null;
}
public List<AOAccessor> GetAOList(string source)
{
return _aoList.ContainsKey(source) ? _aoList[source] : null;
return _aoList.TryGetValue(source, out var value) ? value : null;
}
public IoManager()
@ -120,7 +120,7 @@ namespace MECF.Framework.Common.IOCore
OP.Subscribe("System.SetDoValue", InvokeSetDo);
OP.Subscribe("System.SetAoValue", InvokeSetAo);
OP.Subscribe("System.SetAoValueFloat", InvokeSetAoFloat);
OP.Subscribe("System.SetDoValueWithPrivoder", InvokeSetDoWithPrivoder);
OP.Subscribe("System.SetDoValueWithPrivoder", InvokeSetDoWithProvider);
OP.Subscribe("System.SetAoValueWithPrivoder", InvokeSetAoWithPrivoder);
OP.Subscribe("System.SetAiBuffer", InvokeSetAiBuffer);
OP.Subscribe("System.SetDiBuffer", InvokeSetDiBuffer);
@ -128,14 +128,14 @@ namespace MECF.Framework.Common.IOCore
private bool InvokeSetDo(string arg1, object[] args)
{
string text = (string)args[0];
bool flag = (bool)args[1];
var text = (string)args[0];
var flag = (bool)args[1];
if (!CanSetDo(text, flag, out var reason))
{
EV.PostWarningLog("System", $"Can not set DO {text} to {flag}, {reason}");
return false;
}
DOAccessor iO = GetIO<DOAccessor>(text);
var iO = GetIO<DOAccessor>(text);
if (iO == null)
{
EV.PostWarningLog("System", $"Can not set DO {text} to {flag}, not defined do");
@ -152,9 +152,9 @@ namespace MECF.Framework.Common.IOCore
private bool InvokeSetAo(string arg1, object[] args)
{
string text = (string)args[0];
short num = (short)args[1];
AOAccessor iO = GetIO<AOAccessor>(text);
var text = (string)args[0];
var num = (short)args[1];
var iO = GetIO<AOAccessor>(text);
if (iO == null)
{
EV.PostWarningLog("System", $"Can not set AO {text} to {num}, not defined do");
@ -167,9 +167,9 @@ namespace MECF.Framework.Common.IOCore
private bool InvokeSetAoFloat(string arg1, object[] args)
{
string text = (string)args[0];
float num = (float)args[1];
AOAccessor iO = GetIO<AOAccessor>(text);
var text = (string)args[0];
var num = (float)args[1];
var iO = GetIO<AOAccessor>(text);
if (iO == null)
{
EV.PostWarningLog("System", $"Can not set AO {text} to {num}, not defined");
@ -180,24 +180,24 @@ namespace MECF.Framework.Common.IOCore
return true;
}
private bool InvokeSetDoWithPrivoder(string arg1, object[] args)
private bool InvokeSetDoWithProvider(string arg1, object[] args)
{
string text = (string)args[0];
int num = (int)args[1];
string name = (string)args[2];
bool flag = (bool)args[3];
var text = (string)args[0];
var num = (int)args[1];
var name = (string)args[2];
var flag = (bool)args[3];
if (!CanSetDo(name, flag, out var reason))
{
EV.PostWarningLog("System", $"Can not set DO {text}.{name} to {flag}, {reason}");
return false;
}
List<DOAccessor> dOList = GetDOList(text);
var dOList = GetDOList(text);
if (dOList == null)
{
EV.PostWarningLog("System", $"Can not set DO {text}.{name} to {flag}, {reason}");
return false;
}
DOAccessor dOAccessor = dOList.FirstOrDefault((DOAccessor x) => x.Name == name);
var dOAccessor = dOList.FirstOrDefault((DOAccessor x) => x.Name == name);
if (dOAccessor == null)
{
EV.PostWarningLog("System", $"Can not set DO {text}.{name} to {flag}, {reason}");
@ -214,36 +214,36 @@ namespace MECF.Framework.Common.IOCore
private bool InvokeSetAiBuffer(string arg1, object[] args)
{
string source = (string)args[0];
int offset = (int)args[1];
short[] buffer = (short[])args[2];
var source = (string)args[0];
var offset = (int)args[1];
var buffer = (short[])args[2];
SetAiBuffer(source, offset, buffer);
return true;
}
private bool InvokeSetDiBuffer(string arg1, object[] args)
{
string source = (string)args[0];
int offset = (int)args[1];
bool[] buffer = (bool[])args[2];
var source = (string)args[0];
var offset = (int)args[1];
var buffer = (bool[])args[2];
SetDiBuffer(source, offset, buffer);
return true;
}
private bool InvokeSetAoWithPrivoder(string arg1, object[] args)
{
string text = (string)args[0];
int num = (int)args[1];
string name = (string)args[2];
float num2 = (float)args[3];
string text2 = "";
List<AOAccessor> aOList = GetAOList(text);
var text = (string)args[0];
var num = (int)args[1];
var name = (string)args[2];
var num2 = (float)args[3];
var text2 = "";
var aOList = GetAOList(text);
if (aOList == null)
{
EV.PostWarningLog("System", $"Can not set AO {text}.{name} to {num2}, {text2}");
return false;
}
AOAccessor aOAccessor = aOList.FirstOrDefault((AOAccessor x) => x.Name == name);
var aOAccessor = aOList.FirstOrDefault((AOAccessor x) => x.Name == name);
if (aOAccessor == null)
{
EV.PostWarningLog("System", $"Can not set AO {text}.{name} to {num2}, {text2}");
@ -256,75 +256,75 @@ namespace MECF.Framework.Common.IOCore
public T GetIO<T>(string name) where T : class
{
if (typeof(T) == typeof(DIAccessor) && _diMap.ContainsKey(name))
if (typeof(T) == typeof(DIAccessor) && _diMap.TryGetValue(name, out var value))
{
return _diMap[name] as T;
return value as T;
}
if (typeof(T) == typeof(DOAccessor) && _doMap.ContainsKey(name))
if (typeof(T) == typeof(DOAccessor) && _doMap.TryGetValue(name, out var value1))
{
return _doMap[name] as T;
return value1 as T;
}
if (typeof(T) == typeof(AIAccessor) && _aiMap.ContainsKey(name))
if (typeof(T) == typeof(AIAccessor) && _aiMap.TryGetValue(name, out var value2))
{
return _aiMap[name] as T;
return value2 as T;
}
if (typeof(T) == typeof(AOAccessor) && _aoMap.ContainsKey(name))
if (typeof(T) == typeof(AOAccessor) && _aoMap.TryGetValue(name, out var value3))
{
return _aoMap[name] as T;
return value3 as T;
}
return null;
}
public Dictionary<int, bool[]> GetDiBuffer(string source)
{
if (_diBuffer.ContainsKey(source))
if (_diBuffer.TryGetValue(source, out var buffer))
{
return _diBuffer[source];
return buffer;
}
return null;
}
public Dictionary<int, bool[]> GetDoBuffer(string source)
{
if (_doBuffer.ContainsKey(source))
if (_doBuffer.TryGetValue(source, out var buffer))
{
return _doBuffer[source];
return buffer;
}
return null;
}
public Dictionary<int, short[]> GetAiBuffer(string source)
{
if (_aiBufferShort.ContainsKey(source))
if (_aiBufferShort.TryGetValue(source, out var buffer))
{
return _aiBufferShort[source];
return buffer;
}
return null;
}
public Dictionary<int, float[]> GetAoBufferFloat(string source)
{
if (_aoBufferFloat.ContainsKey(source))
if (_aoBufferFloat.TryGetValue(source, out var f))
{
return _aoBufferFloat[source];
return f;
}
return null;
}
public Dictionary<int, float[]> GetAiBufferFloat(string source)
{
if (_aiBufferFloat.ContainsKey(source))
if (_aiBufferFloat.TryGetValue(source, out var f))
{
return _aiBufferFloat[source];
return f;
}
return null;
}
public Dictionary<int, short[]> GetAoBuffer(string source)
{
if (_aoBufferShort.ContainsKey(source))
if (_aoBufferShort.TryGetValue(source, out var buffer))
{
return _aoBufferShort[source];
return buffer;
}
return null;
}
@ -333,7 +333,7 @@ namespace MECF.Framework.Common.IOCore
{
if (_diBuffer.ContainsKey(source) && _diBuffer[source].ContainsKey(offset))
{
for (int i = 0; i < buffer.Length && i < _diBuffer[source][offset].Length; i++)
for (var i = 0; i < buffer.Length && i < _diBuffer[source][offset].Length; i++)
{
_diBuffer[source][offset][i] = buffer[i];
}
@ -344,7 +344,7 @@ namespace MECF.Framework.Common.IOCore
{
if (_aiBufferShort.ContainsKey(source) && _aiBufferShort[source].ContainsKey(offset))
{
for (int i = 0; i < buffer.Length && i < _aiBufferShort[source][offset].Length; i++)
for (var i = 0; i < buffer.Length && i < _aiBufferShort[source][offset].Length; i++)
{
_aiBufferShort[source][offset][i + skipSize] = buffer[i];
}
@ -355,7 +355,7 @@ namespace MECF.Framework.Common.IOCore
{
if (_aiBufferFloat.ContainsKey(source) && _aiBufferFloat[source].ContainsKey(offset))
{
for (int i = 0; i < buffer.Length && i < _aiBufferFloat[source][offset].Length; i++)
for (var i = 0; i < buffer.Length && i < _aiBufferFloat[source][offset].Length; i++)
{
_aiBufferFloat[source][offset][i + skipSize] = buffer[i];
}
@ -366,7 +366,7 @@ namespace MECF.Framework.Common.IOCore
{
if (_doBuffer.ContainsKey(source) && _doBuffer[source].ContainsKey(offset))
{
for (int i = 0; i < buffer.Length && i < _doBuffer[source][offset].Length; i++)
for (var i = 0; i < buffer.Length && i < _doBuffer[source][offset].Length; i++)
{
_doBuffer[source][offset][i] = buffer[i];
}
@ -377,7 +377,7 @@ namespace MECF.Framework.Common.IOCore
{
if (_aoBufferShort.ContainsKey(source) && _aoBufferShort[source].ContainsKey(offset))
{
for (int i = 0; i < buffer.Length && i < _aoBufferShort[source][offset].Length; i++)
for (var i = 0; i < buffer.Length && i < _aoBufferShort[source][offset].Length; i++)
{
_aoBufferShort[source][offset][i] = buffer[i];
}
@ -388,7 +388,7 @@ namespace MECF.Framework.Common.IOCore
{
if (_aoBufferFloat.ContainsKey(source) && _aoBufferFloat[source].ContainsKey(offset))
{
for (int i = 0; i < buffer.Length && i < _aoBufferFloat[source][offset].Length; i++)
for (var i = 0; i < buffer.Length && i < _aoBufferFloat[source][offset].Length; i++)
{
_aoBufferFloat[source][offset][i] = buffer[i];
}
@ -399,7 +399,7 @@ namespace MECF.Framework.Common.IOCore
{
if (_aoBufferShort.ContainsKey(source) && _aoBufferShort[source].ContainsKey(offset) && _aoBufferShort[source][offset].Length > bufferStartIndex)
{
for (int i = 0; i < buffer.Length && bufferStartIndex + i < _aoBufferShort[source][offset].Length; i++)
for (var i = 0; i < buffer.Length && bufferStartIndex + i < _aoBufferShort[source][offset].Length; i++)
{
_aoBufferShort[source][offset][bufferStartIndex + i] = buffer[i];
}
@ -408,7 +408,7 @@ namespace MECF.Framework.Common.IOCore
public void SetBufferBlock(string provider, List<IoBlockItem> lstBlocks)
{
foreach (IoBlockItem lstBlock in lstBlocks)
foreach (var lstBlock in lstBlocks)
{
switch (lstBlock.Type)
{
@ -466,10 +466,10 @@ namespace MECF.Framework.Common.IOCore
private List<NotifiableIoItem> SubscribeDiData()
{
List<NotifiableIoItem> list = new List<NotifiableIoItem>();
foreach (KeyValuePair<string, DIAccessor> item2 in _diMap)
var list = new List<NotifiableIoItem>();
foreach (var item2 in _diMap)
{
NotifiableIoItem item = new NotifiableIoItem
var item = new NotifiableIoItem
{
Address = item2.Value.Addr,
Name = item2.Value.Name,
@ -488,10 +488,10 @@ namespace MECF.Framework.Common.IOCore
private List<NotifiableIoItem> SubscribeDoData()
{
List<NotifiableIoItem> list = new List<NotifiableIoItem>();
foreach (KeyValuePair<string, DOAccessor> item2 in _doMap)
var list = new List<NotifiableIoItem>();
foreach (var item2 in _doMap)
{
NotifiableIoItem item = new NotifiableIoItem
var item = new NotifiableIoItem
{
Address = item2.Value.Addr,
Name = item2.Value.Name,
@ -510,10 +510,10 @@ namespace MECF.Framework.Common.IOCore
private List<NotifiableIoItem> SubscribeAiData()
{
List<NotifiableIoItem> list = new List<NotifiableIoItem>();
foreach (KeyValuePair<string, AIAccessor> item2 in _aiMap)
var list = new List<NotifiableIoItem>();
foreach (var item2 in _aiMap)
{
NotifiableIoItem item = new NotifiableIoItem
var item = new NotifiableIoItem
{
Address = item2.Value.Addr,
Name = item2.Value.Name,
@ -533,10 +533,10 @@ namespace MECF.Framework.Common.IOCore
private List<NotifiableIoItem> SubscribeAoData()
{
List<NotifiableIoItem> list = new List<NotifiableIoItem>();
foreach (KeyValuePair<string, AOAccessor> item2 in _aoMap)
var list = new List<NotifiableIoItem>();
foreach (var item2 in _aoMap)
{
NotifiableIoItem item = new NotifiableIoItem
var item = new NotifiableIoItem
{
Address = item2.Value.Addr,
Name = item2.Value.Name,
@ -557,8 +557,8 @@ namespace MECF.Framework.Common.IOCore
public void SetIoMap(string provider, int blockOffset, List<DIAccessor> ioList)
{
SubscribeIoItemList(provider);
bool flag = SC.GetConfigItem("System.IsIgnoreSaveDB")?.BoolValue ?? false;
foreach (DIAccessor accessor in ioList)
var flag = SC.GetConfigItem("System.IsIgnoreSaveDB")?.BoolValue ?? false;
foreach (var accessor in ioList)
{
accessor.Provider = provider;
accessor.BlockOffset = blockOffset;
@ -589,8 +589,8 @@ namespace MECF.Framework.Common.IOCore
public void SetIoMap(string provider, int blockOffset, List<DOAccessor> ioList)
{
SubscribeIoItemList(provider);
bool flag = SC.GetConfigItem("System.IsIgnoreSaveDB")?.BoolValue ?? false;
foreach (DOAccessor accessor in ioList)
var flag = SC.GetConfigItem("System.IsIgnoreSaveDB")?.BoolValue ?? false;
foreach (var accessor in ioList)
{
accessor.Provider = provider;
accessor.BlockOffset = blockOffset;
@ -621,8 +621,8 @@ namespace MECF.Framework.Common.IOCore
public void SetIoMap(string provider, int blockOffset, List<AIAccessor> ioList)
{
SubscribeIoItemList(provider);
bool flag = SC.GetConfigItem("System.IsIgnoreSaveDB")?.BoolValue ?? false;
foreach (AIAccessor accessor in ioList)
var flag = SC.GetConfigItem("System.IsIgnoreSaveDB")?.BoolValue ?? false;
foreach (var accessor in ioList)
{
accessor.Provider = provider;
accessor.BlockOffset = blockOffset;
@ -653,8 +653,8 @@ namespace MECF.Framework.Common.IOCore
public void SetIoMap(string provider, int blockOffset, List<AOAccessor> ioList)
{
SubscribeIoItemList(provider);
bool flag = SC.GetConfigItem("System.IsIgnoreSaveDB")?.BoolValue ?? false;
foreach (AOAccessor accessor in ioList)
var flag = SC.GetConfigItem("System.IsIgnoreSaveDB")?.BoolValue ?? false;
foreach (var accessor in ioList)
{
accessor.Provider = provider;
accessor.BlockOffset = blockOffset;
@ -685,27 +685,27 @@ namespace MECF.Framework.Common.IOCore
public void SetIoMap(string provider, int blockOffset, string xmlPathFile, string module = "")
{
SubscribeIoItemList(provider);
XmlDocument xmlDocument = new XmlDocument();
var xmlDocument = new XmlDocument();
xmlDocument.Load(xmlPathFile);
XmlNodeList xmlNodeList = xmlDocument.SelectNodes("IO_DEFINE/Dig_In/DI_ITEM");
bool flag = SC.GetConfigItem("System.IsIgnoreSaveDB")?.BoolValue ?? false;
List<DIAccessor> list = new List<DIAccessor>();
foreach (object item in xmlNodeList)
var xmlNodeList = xmlDocument.SelectNodes("IO_DEFINE/Dig_In/DI_ITEM");
var flag = SC.GetConfigItem("System.IsIgnoreSaveDB")?.BoolValue ?? false;
var list = new List<DIAccessor>();
foreach (var item in xmlNodeList)
{
if (!(item is XmlElement xmlElement))
{
continue;
}
string attribute = xmlElement.GetAttribute("Index");
string text = xmlElement.GetAttribute("BufferOffset");
var attribute = xmlElement.GetAttribute("Index");
var text = xmlElement.GetAttribute("BufferOffset");
if (string.IsNullOrEmpty(text))
{
text = attribute;
}
string attribute2 = xmlElement.GetAttribute("Name");
string attribute3 = xmlElement.GetAttribute("Addr");
string attribute4 = xmlElement.GetAttribute("Description");
bool visible = true;
var attribute2 = xmlElement.GetAttribute("Name");
var attribute3 = xmlElement.GetAttribute("Addr");
var attribute4 = xmlElement.GetAttribute("Description");
var visible = true;
if (xmlElement.HasAttribute("Visible"))
{
visible = Convert.ToBoolean(xmlElement.GetAttribute("Visible"));
@ -717,7 +717,7 @@ namespace MECF.Framework.Common.IOCore
attribute2 = attribute2.Trim();
attribute = attribute.Trim();
text = text.Trim();
string text2 = (string.IsNullOrEmpty(module) ? attribute2 : (module + "." + attribute2));
var text2 = (string.IsNullOrEmpty(module) ? attribute2 : (module + "." + attribute2));
if (!int.TryParse(attribute, out var result) || !int.TryParse(text, out var result2))
{
continue;
@ -730,7 +730,7 @@ namespace MECF.Framework.Common.IOCore
{
throw new Exception("Not defined DI buffer from IO provider, " + provider);
}
DIAccessor diAccessor = new DIAccessor(text2, result2, _diBuffer[provider][blockOffset], _diBuffer[provider][blockOffset]);
var diAccessor = new DIAccessor(text2, result2, _diBuffer[provider][blockOffset], _diBuffer[provider][blockOffset]);
diAccessor.IoTableIndex = result;
diAccessor.Addr = attribute3;
diAccessor.Provider = provider;
@ -760,23 +760,23 @@ namespace MECF.Framework.Common.IOCore
DATA.Subscribe("IO." + text2, () => diAccessor.Value);
}
}
XmlNodeList xmlNodeList2 = xmlDocument.SelectNodes("IO_DEFINE/Dig_Out/DO_ITEM");
foreach (object item2 in xmlNodeList2)
var xmlNodeList2 = xmlDocument.SelectNodes("IO_DEFINE/Dig_Out/DO_ITEM");
foreach (var item2 in xmlNodeList2)
{
if (!(item2 is XmlElement xmlElement2))
{
continue;
}
string attribute5 = xmlElement2.GetAttribute("Index");
string text3 = xmlElement2.GetAttribute("BufferOffset");
var attribute5 = xmlElement2.GetAttribute("Index");
var text3 = xmlElement2.GetAttribute("BufferOffset");
if (string.IsNullOrEmpty(text3))
{
text3 = attribute5;
}
string attribute6 = xmlElement2.GetAttribute("Name");
string attribute7 = xmlElement2.GetAttribute("Addr");
string attribute8 = xmlElement2.GetAttribute("Description");
bool visible2 = true;
var attribute6 = xmlElement2.GetAttribute("Name");
var attribute7 = xmlElement2.GetAttribute("Addr");
var attribute8 = xmlElement2.GetAttribute("Description");
var visible2 = true;
if (xmlElement2.HasAttribute("Visible"))
{
visible2 = Convert.ToBoolean(xmlElement2.GetAttribute("Visible"));
@ -788,7 +788,7 @@ namespace MECF.Framework.Common.IOCore
attribute6 = attribute6.Trim();
attribute5 = attribute5.Trim();
text3 = text3.Trim();
string text4 = (string.IsNullOrEmpty(module) ? attribute6 : (module + "." + attribute6));
var text4 = (string.IsNullOrEmpty(module) ? attribute6 : (module + "." + attribute6));
if (!int.TryParse(attribute5, out var result3) || !int.TryParse(text3, out var result4))
{
continue;
@ -797,7 +797,7 @@ namespace MECF.Framework.Common.IOCore
{
throw new Exception("Not defined DO buffer from IO provider, " + provider);
}
DOAccessor doAccessor = new DOAccessor(text4, result4, _doBuffer[provider][blockOffset]);
var doAccessor = new DOAccessor(text4, result4, _doBuffer[provider][blockOffset]);
_doMap[text4] = doAccessor;
doAccessor.IoTableIndex = result3;
doAccessor.Addr = attribute7;
@ -826,23 +826,23 @@ namespace MECF.Framework.Common.IOCore
DATA.Subscribe("IO." + text4, () => doAccessor.Value);
}
}
XmlNodeList xmlNodeList3 = xmlDocument.SelectNodes("IO_DEFINE/Ana_Out/AO_ITEM");
foreach (object item3 in xmlNodeList3)
var xmlNodeList3 = xmlDocument.SelectNodes("IO_DEFINE/Ana_Out/AO_ITEM");
foreach (var item3 in xmlNodeList3)
{
if (!(item3 is XmlElement xmlElement3))
{
continue;
}
string attribute9 = xmlElement3.GetAttribute("Index");
string text5 = xmlElement3.GetAttribute("BufferOffset");
var attribute9 = xmlElement3.GetAttribute("Index");
var text5 = xmlElement3.GetAttribute("BufferOffset");
if (string.IsNullOrEmpty(text5))
{
text5 = attribute9;
}
string attribute10 = xmlElement3.GetAttribute("Name");
string attribute11 = xmlElement3.GetAttribute("Addr");
string attribute12 = xmlElement3.GetAttribute("Description");
bool visible3 = true;
var attribute10 = xmlElement3.GetAttribute("Name");
var attribute11 = xmlElement3.GetAttribute("Addr");
var attribute12 = xmlElement3.GetAttribute("Description");
var visible3 = true;
if (xmlElement3.HasAttribute("Visible"))
{
visible3 = Convert.ToBoolean(xmlElement3.GetAttribute("Visible"));
@ -854,7 +854,7 @@ namespace MECF.Framework.Common.IOCore
attribute10 = attribute10.Trim();
attribute9 = attribute9.Trim();
text5 = text5.Trim();
string text6 = (string.IsNullOrEmpty(module) ? attribute10 : (module + "." + attribute10));
var text6 = (string.IsNullOrEmpty(module) ? attribute10 : (module + "." + attribute10));
if (!int.TryParse(attribute9, out var result5) || !int.TryParse(text5, out var result6))
{
continue;
@ -863,7 +863,7 @@ namespace MECF.Framework.Common.IOCore
{
throw new Exception("Not defined AO buffer from IO provider, " + provider);
}
AOAccessor aoAccessor = new AOAccessor(text6, result6, _aoBufferShort[provider][blockOffset], _aoBufferFloat[provider][blockOffset]);
var aoAccessor = new AOAccessor(text6, result6, _aoBufferShort[provider][blockOffset], _aoBufferFloat[provider][blockOffset]);
_aoMap[text6] = aoAccessor;
aoAccessor.IoTableIndex = result5;
aoAccessor.Addr = attribute11;
@ -900,23 +900,23 @@ namespace MECF.Framework.Common.IOCore
DATA.Subscribe("IO." + text6, () => aoAccessor.Value);
}
}
XmlNodeList xmlNodeList4 = xmlDocument.SelectNodes("IO_DEFINE/Ana_In/AI_ITEM");
foreach (object item4 in xmlNodeList4)
var xmlNodeList4 = xmlDocument.SelectNodes("IO_DEFINE/Ana_In/AI_ITEM");
foreach (var item4 in xmlNodeList4)
{
if (!(item4 is XmlElement xmlElement4))
{
continue;
}
string attribute13 = xmlElement4.GetAttribute("Index");
string text7 = xmlElement4.GetAttribute("BufferOffset");
var attribute13 = xmlElement4.GetAttribute("Index");
var text7 = xmlElement4.GetAttribute("BufferOffset");
if (string.IsNullOrEmpty(text7))
{
text7 = attribute13;
}
string attribute14 = xmlElement4.GetAttribute("Name");
string attribute15 = xmlElement4.GetAttribute("Addr");
string attribute16 = xmlElement4.GetAttribute("Description");
bool visible4 = true;
var attribute14 = xmlElement4.GetAttribute("Name");
var attribute15 = xmlElement4.GetAttribute("Addr");
var attribute16 = xmlElement4.GetAttribute("Description");
var visible4 = true;
if (xmlElement4.HasAttribute("Visible"))
{
visible4 = Convert.ToBoolean(xmlElement4.GetAttribute("Visible"));
@ -928,7 +928,7 @@ namespace MECF.Framework.Common.IOCore
attribute14 = attribute14.Trim();
attribute13 = attribute13.Trim();
text7 = text7.Trim();
string text8 = (string.IsNullOrEmpty(module) ? attribute14 : (module + "." + attribute14));
var text8 = (string.IsNullOrEmpty(module) ? attribute14 : (module + "." + attribute14));
if (!int.TryParse(attribute13, out var result7) || !int.TryParse(text7, out var result8))
{
continue;
@ -937,7 +937,7 @@ namespace MECF.Framework.Common.IOCore
{
throw new Exception("Not defined AI buffer from IO provider, " + provider);
}
AIAccessor aiAccessor = new AIAccessor(text8, result8, _aiBufferShort[provider][blockOffset], _aiBufferFloat[provider][blockOffset]);
var aiAccessor = new AIAccessor(text8, result8, _aiBufferShort[provider][blockOffset], _aiBufferFloat[provider][blockOffset]);
_aiMap[text8] = aiAccessor;
aiAccessor.IoTableIndex = result7;
aiAccessor.Addr = attribute15;
@ -978,7 +978,7 @@ namespace MECF.Framework.Common.IOCore
public void SetIoMap(string provider, Dictionary<int, string> ioMappingPathFile)
{
foreach (KeyValuePair<int, string> item in ioMappingPathFile)
foreach (var item in ioMappingPathFile)
{
SetIoMap(provider, item.Key, item.Value);
}
@ -999,25 +999,25 @@ namespace MECF.Framework.Common.IOCore
private void SubscribeIoItemList(string provider)
{
string diKey = provider + ".DIItemList";
var diKey = provider + ".DIItemList";
if (!_ioItemList.ContainsKey(diKey))
{
_ioItemList[diKey] = new List<NotifiableIoItem>();
DATA.Subscribe(diKey, () => _ioItemList[diKey]);
}
string doKey = provider + ".DOItemList";
var doKey = provider + ".DOItemList";
if (!_ioItemList.ContainsKey(doKey))
{
_ioItemList[doKey] = new List<NotifiableIoItem>();
DATA.Subscribe(doKey, () => _ioItemList[doKey]);
}
string aiKey = provider + ".AIItemList";
var aiKey = provider + ".AIItemList";
if (!_ioItemList.ContainsKey(aiKey))
{
_ioItemList[aiKey] = new List<NotifiableIoItem>();
DATA.Subscribe(aiKey, () => _ioItemList[aiKey]);
}
string aoKey = provider + ".AOItemList";
var aoKey = provider + ".AOItemList";
if (!_ioItemList.ContainsKey(aoKey))
{
_ioItemList[aoKey] = new List<NotifiableIoItem>();