using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTS.SensorDB.TSF { /// /// handles the module information section of a TSF /// public class TSFModuleInformationSection { private const string SECTION_START_HEADER = "---- Start Module Information ----"; private const string COLUMN_HEADER = "rack,module,trigmode,trigchan,trigdir,triglevel,moduletype"; private const string SECTION_END_HEADER = "---- End Module Information ----"; /// /// reads the section from a TSF /// assumes currentline is the start of the section /// /// /// /// /// /// public void ReadFrom(List lines, ref int currentLine, ref List errors, TSFSystemDescription system, TSFRackInformationSection rackSection) { if (currentLine == lines.Count) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_UNEXPECTED_EOF, currentLine)); return; } string sectionHeader = lines[currentLine++]; if (sectionHeader != SECTION_START_HEADER) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.MODULEINFORMATIONSECTION_BADHEADER, currentLine, sectionHeader)); return; } if (currentLine == lines.Count) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_UNEXPECTED_EOF, currentLine)); return; } string columnHeader = lines[currentLine++]; if (columnHeader != COLUMN_HEADER) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.MODULEINFORMATIONSECTION_BADCOLUMHEADER, currentLine, columnHeader)); return; } var invariant = System.Globalization.CultureInfo.InvariantCulture; bool done = false; while (!done) { if (currentLine == lines.Count) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_UNEXPECTED_EOF, currentLine)); return; } string line = lines[currentLine++]; if (!line.Contains("End Module Information")) { string[] tokens = line.Split(new char[] { ',' }); if (tokens.Length < 7) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_SKIPPING_MODULE_TOO_FEW_TOKENS, currentLine)); continue; } int r; try { r = int.Parse(tokens[0], invariant); } catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_MODULE_INVALID_RACK_FIELD, currentLine, tokens[0])); continue; } int m; try { m = int.Parse(tokens[1], invariant); } catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_MODULE_INVALID_MODULE_FIELD, currentLine, tokens[1])); continue; } int trigMode; try { trigMode = int.Parse(tokens[2], invariant); } catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_MODULE_INVALID_TRIGGERMODE_FIELD, currentLine, tokens[2])); continue; } int trigChan; try { trigChan = int.Parse(tokens[3], invariant); } catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_MODULE_INVALID_TRIGGERCHAN_FIELD, currentLine, tokens[3])); continue; } int trigDir; try { trigDir = int.Parse(tokens[4], invariant); } catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_MODULE_INVALID_TRIGGERDIR_FIELD, currentLine, tokens[4])); continue; } double trigLevel; try { trigLevel = double.Parse(tokens[5], invariant); } catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_MODULE_INVALID_TRIGGERLEVEL_FIELD, currentLine, tokens[5])); continue; } int moduleType; try { moduleType = int.Parse(tokens[6], invariant); } catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_MODULE_INVALID_MODULETYPE_FIELD, currentLine, tokens[6])); continue; } //var rackHW = system.HWRack[r]; bool bFound = false; foreach (var curRack in rackSection.Racks) { if (curRack.Number == r) { curRack.SetModule(m, trigMode, trigChan, trigDir, trigLevel, moduleType); bFound = true; break; } } if (!bFound) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_MODULE_SKIPPED_RACKNOTFOUND, currentLine)); continue; } } else { done = true; } } } } }