public SPORTSlave(XmlNode sNode, TreeNode tn) { string strRoutineName = "SPORTSlave"; try { //SetSupportedASDUSizes(); SetSupportedIOASizes(); SetSupportedPortNumber(); //IMP: Use tn when we want to further add child nodes to 'IEC104'. Check if it's null... //Parse n store values... Utils.WriteLine(VerboseLevel.DEBUG, "sNode name: '{0}'", sNode.Name); if (sNode.Attributes != null) { //First set the root element value... try { sType = (SPORTType)Enum.Parse(typeof(SPORTType), sNode.Name); } catch (System.ArgumentException) { Utils.WriteLine(VerboseLevel.WARNING, "Enum argument {0} not supported!!!", sNode.Name); } foreach (XmlAttribute item in sNode.Attributes) { Utils.Write(VerboseLevel.DEBUG, "{0} {1} ", item.Name, item.Value); try { if (this.GetType().GetProperty(item.Name) != null) //Ajay: 03/07/2018 { this.GetType().GetProperty(item.Name).SetValue(this, item.Value); } } catch (System.NullReferenceException) { Utils.WriteLine(VerboseLevel.WARNING, "Field doesn't exist. XML and class fields mismatch!!! key: {0} value:{1}", item.Name, item.Value); } } Utils.Write(VerboseLevel.DEBUG, "\n"); } else if (sNode.NodeType == XmlNodeType.Comment) { isNodeComment = true; comment = sNode.Value; } } catch (Exception ex) { MessageBox.Show(strRoutineName + ": " + "Error: " + ex.Message.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } //Not Used: uciec.lblMain.Text += slaveNum; }
public SPORTSlave(string sSportName, List <KeyValuePair <string, string> > sSportData, TreeNode tn) { string strRoutineName = "SPORTSlave"; try { //SetSupportedASDUSizes(); SetSupportedIOASizes(); SetSupportedPortNumber(); try { sType = (SPORTType)Enum.Parse(typeof(SPORTType), sSportName); } catch (System.ArgumentException) { Utils.WriteLine(VerboseLevel.WARNING, "Enum argument {0} not supported!!!", sSportName); } //Parse n store values... if (sSportData != null && sSportData.Count > 0) { foreach (KeyValuePair <string, string> sSportkp in sSportData) { Utils.Write(VerboseLevel.DEBUG, "{0} {1} ", sSportkp.Key, sSportkp.Value); try { if (this.GetType().GetProperty(sSportkp.Key) != null) { this.GetType().GetProperty(sSportkp.Key).SetValue(this, sSportkp.Value); } } catch (System.NullReferenceException) { Utils.WriteLine(VerboseLevel.WARNING, "Field doesn't exist. XML and class fields mismatch!!! key: {0} value:{1}", sSportkp.Key, sSportkp.Value); } } Utils.Write(VerboseLevel.DEBUG, "\n"); } } catch (Exception ex) { MessageBox.Show(strRoutineName + ": " + "Error: " + ex.Message.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }