public void Init() { for (int i = 0; i < Template.Length; i++) { // add in template characters char ch = Template[i]; if (Elems.ContainsKey(ch)) { Elems[ch]++; } else { Elems.Add(ch, 1); } } // add in pairs for (int i = 0; i < Template.Length - 1; i++) { var key = Template.Substring(i, 2); if (Pairs.ContainsKey(key)) { Pairs[key]++; } else { Pairs.Add(key, 1); } } }
/// <summary> /// Loads the configuration from the XML node. /// </summary> public virtual void LoadFromXml(XmlElement xmlElem) { if (xmlElem == null) { throw new ArgumentNullException(nameof(xmlElem)); } Active = xmlElem.GetAttrAsBool("active"); DataBlock = xmlElem.GetAttrAsEnum("dataBlock", xmlElem.GetAttrAsEnum <DataBlock>("tableType")); Address = xmlElem.GetAttrAsInt("address"); Name = xmlElem.GetAttrAsString("name"); ElemType defaultElemType = DefaultElemType; bool defaultReadOnly = !ReadOnlyEnabled; bool defaultBitMask = !BitMaskEnabled; int maxElemCnt = MaxElemCnt; foreach (XmlElement elemElem in xmlElem.SelectNodes("Elem")) { if (Elems.Count >= maxElemCnt) { break; } ElemConfig elemConfig = CreateElemConfig(); elemConfig.ElemType = elemElem.GetAttrAsEnum("type", defaultElemType); elemConfig.ByteOrder = elemElem.GetAttrAsString("byteOrder"); elemConfig.ReadOnly = elemElem.GetAttrAsBool("readOnly", defaultReadOnly); elemConfig.IsBitMask = elemElem.GetAttrAsBool("isBitMask", defaultBitMask); elemConfig.TagCode = elemElem.GetAttrAsString("tagCode"); elemConfig.Name = elemElem.GetAttrAsString("name"); Elems.Add(elemConfig); } }
/// <summary> /// Loads the group from the XML node. /// </summary> public virtual void LoadFromXml(XmlElement groupElem) { if (groupElem == null) { throw new ArgumentNullException("groupElem"); } Name = groupElem.GetAttribute("name"); Address = (ushort)groupElem.GetAttrAsInt("address"); Active = groupElem.GetAttrAsBool("active", true); XmlNodeList elemNodes = groupElem.SelectNodes("Elem"); int maxElemCnt = MaxElemCnt; ElemType defElemType = DefElemType; foreach (XmlElement elemElem in elemNodes) { if (Elems.Count >= maxElemCnt) { break; } Elem elem = CreateElem(); elem.Name = elemElem.GetAttribute("name"); elem.ElemType = elemElem.GetAttrAsEnum("type", defElemType); if (ByteOrderEnabled) { elem.ByteOrderStr = elemElem.GetAttribute("byteOrder"); elem.ByteOrder = ModbusUtils.ParseByteOrder(elem.ByteOrderStr); } Elems.Add(elem); } }
public void AddFrom(MfModelDicts dict) { foreach (var c in dict.Cates) { if (!Cates.ContainsKey(c.Key)) { Cates.Add(c.Key, c.Value); } } foreach (var c in dict.Elems) { if (!Elems.ContainsKey(c.Key)) { Elems.Add(c.Key, c.Value); } } foreach (var c in dict.Fams) { if (!Fams.ContainsKey(c.Key)) { Fams.Add(c.Key, c.Value); } } foreach (var c in dict.Floors) { if (!Floors.ContainsKey(c.Key)) { Floors.Add(c.Key, c.Value); } } foreach (var c in dict.Mats) { if (!Mats.ContainsKey(c.Key)) { Mats.Add(c.Key, c.Value); } } foreach (var c in dict.Types) { if (!Types.ContainsKey(c.Key)) { Types.Add(c.Key, c.Value); } } foreach (var c in dict.Views) { if (!Views.ContainsKey(c.Key)) { Views.Add(c.Key, c.Value); } } }
public void PairInsertion() { NewPairs = new Dictionary <string, long>(); foreach (var pair in Pairs) { char ch = Converter[pair.Key][0]; if (Elems.ContainsKey(ch)) { Elems[ch] += pair.Value; } else { Elems.Add(ch, pair.Value); } AddNewPair($"{pair.Key[0]}{ch}", pair.Value); AddNewPair($"{ch}{pair.Key[1]}", pair.Value); } Pairs = NewPairs; }
/// <summary> /// Copies the group properties from the source group. /// </summary> public virtual void CopyFrom(ElemGroup srcGroup) { if (srcGroup == null) { throw new ArgumentNullException("srcGroup"); } Name = srcGroup.Name; Address = srcGroup.Address; Active = srcGroup.Active; StartKPTagInd = srcGroup.StartKPTagInd; StartSignal = srcGroup.StartSignal; Elems.Clear(); foreach (Elem srcElem in srcGroup.Elems) { Elem destElem = CreateElem(); destElem.Name = srcElem.Name; destElem.ElemType = srcElem.ElemType; destElem.ByteOrder = srcElem.ByteOrder; // copy the array reference destElem.ByteOrderStr = srcElem.ByteOrderStr; Elems.Add(destElem); } }