private void AddFaultCode(string faultcode) { if (gridControl1.DataSource == null) { DataTable dtn = new DataTable(); dtn.Columns.Add("Code"); dtn.Columns.Add("Description"); gridControl1.DataSource = dtn; } DataTable dt = (DataTable)gridControl1.DataSource; bool _found = false; foreach (DataRow dr in dt.Rows) { if (dr["Code"] != DBNull.Value) { if (dr["Code"].ToString() == faultcode) { _found = true; } } } if (!_found) { if (mDTCDescriptionDict.ContainsKey(faultcode)) { DTCDescription dtc = mDTCDescriptionDict[faultcode]; dt.Rows.Add(faultcode, dtc.Description); } else { logger.Debug("Warning: dtc not found (" + faultcode + ")"); } } }
// Load known dts codes from XML file private void LoadDTCDescriptions() { // Create the XmlSchemaSet class. XmlSchemaSet sc = new XmlSchemaSet(); // Add the schema to the collection. sc.Add("", "DTCDescription.xsd"); XmlReaderSettings reader_settings = new XmlReaderSettings(); reader_settings.ValidationType = ValidationType.Schema; reader_settings.Schemas = sc; reader_settings.ValidationEventHandler += new ValidationEventHandler(DTCDescriptionsValidationEventHandler); string path = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); string[] dtc_files = Directory.GetFiles(path + "\\", "DTC_*.xml"); // sort file list on alfabetic order Array.Sort(dtc_files); mDTCDescriptionDict = new Dictionary <string, DTCDescription>(); foreach (string file in dtc_files) { XmlReader reader = XmlReader.Create(file, reader_settings); XmlDocument doc = new XmlDocument(); string error_message; try { // parsing the xml, warnings/errors are generated in this step doc.Load(reader); XmlNode dtcdescriptions = doc.DocumentElement; foreach (XmlNode dtcdescription_node in dtcdescriptions.SelectNodes("dtcdescription")) { DTCDescription dtc = new DTCDescription(dtcdescription_node); if (dtc.IsComplete() && !mDTCDescriptionDict.ContainsKey(dtc.Code)) { mDTCDescriptionDict.Add(dtc.Code, dtc); } else { error_message = dtc.Description + " <-> " + mDTCDescriptionDict[dtc.Code].Description; logger.Debug("Warning: double code: " + dtc.Code + " >> " + error_message); } } } catch (Exception ex) { // TODO: Second time the parsing error is logged logger.Debug(ex.Message); } } }
// Load known dts codes from XML file private void LoadDTCDescriptions() { // Create the XmlSchemaSet class. XmlSchemaSet sc = new XmlSchemaSet(); // Add the schema to the collection. sc.Add("", "DTCDescription.xsd"); XmlReaderSettings reader_settings = new XmlReaderSettings(); reader_settings.ValidationType = ValidationType.Schema; reader_settings.Schemas = sc; reader_settings.ValidationEventHandler += new ValidationEventHandler(DTCDescriptionsValidationEventHandler); string path = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); string[] dtc_files = Directory.GetFiles(path+"\\", "DTC_*.xml"); mDTCDescriptionDict = new Dictionary<string, DTCDescription>(); foreach (string file in dtc_files) { XmlReader reader = XmlReader.Create(file, reader_settings); XmlDocument doc = new XmlDocument(); string error_message; try { // parsing the xml, warnings/errors are generated in this step doc.Load(reader); XmlNode dtcdescriptions = doc.DocumentElement; foreach (XmlNode dtcdescription_node in dtcdescriptions.SelectNodes("dtcdescription")) { DTCDescription dtc = new DTCDescription(dtcdescription_node); if (dtc.IsComplete() && !mDTCDescriptionDict.ContainsKey(dtc.Code)) { mDTCDescriptionDict.Add(dtc.Code, dtc); } else { error_message = dtc.Description + " <-> " + mDTCDescriptionDict[dtc.Code].Description; logger.Debug("Warning: double code: " + dtc.Code + " >> " + error_message); } } } catch (Exception ex) { // TODO: Second time the parsing error is logged logger.Debug(ex.Message); } } }