private string _PatternToFind = "APP_PARAM_APPFLAG_SENSORS_"; // Pattern to use to detect sensors group #endregion Fields #region Constructors // Constructor ---------------------------------------------------------------------------- /// <summary> /// Try to read "AppConfig.h" for getting current flags enabled /// </summary> public CommandActiveSensorsFlag() { List<string> Buffer = null; TextFile AppConfigFile = new TextFile(); // First step : Read "../AppConfig.h" //Buffer = AppConfigFile.Load("../AppConfig.h"); if (Buffer == null) { // Buffer = AppConfigFile.Load(); } if(Buffer == null) return; // Extratct data from buffer Extract(Buffer); }
/// <summary> /// Write the current data stored into this object into a specific file /// </summary> /// <param name="Filename">Name of the file to use for storing data</param> /// <returns>True if the file has been written, false otherwise</returns> public bool WriteFile(String OutputFilename, String PatternFilename) { bool Ret = false; String ReadPatternLine = null; String CheckPatternLine = null; int CurrentLoop = -1; List<String> PatternBlock = null; if ((OutputFilename != null) && (PatternFilename != null) && (_Items.Count() > 0)) { // Create the output file and open the pattern file TextFile PatternFile = new TextFile(PatternFilename); _File = new TextFile(); if (_File != null) { for (int i = 1; i <= PatternFile.GetSize(); i++) { // Check all line to change patterns into real value ReadPatternLine = PatternFile.GetLine(i); if (ReadPatternLine != null) { // Check line to remove unused char CheckPatternLine = ReadPatternLine; CheckPatternLine = CheckPatternLine.Replace("\t", ""); if (CheckPatternLine == "// LoopID = 'LOOPID'") { // Create the pattern block PatternBlock = new List<string>(); CurrentLoop++; // Update the current LoopID _File.AddLine(ReadPatternLine.Replace("'LOOPID'", CurrentLoop.ToString())); } if(CheckPatternLine == "// StructuredFileLoopEnd") { if((PatternBlock != null) && (PatternBlock.Count() > 1)) { // Extact values ordered by GID List<StructValueList> KeyValues = ExtractValues(CurrentLoop); if (KeyValues != null) { int PatternIterator = 1; // The first line contains the LOOPID // Check all items and write only items from current Loop foreach (StructValueList Values in KeyValues) { // Create pattern line if (PatternIterator >= PatternBlock.Count()) PatternIterator = 1; // The first line contains the LOOPID string ExportLine = PatternBlock[PatternIterator]; // We have found value for the current GID, we split it to add them to the specific loop string[] KeyToAdd = Values.KeyList.Split('|'); string[] ValueToAdd = Values.ValueList.Split('|'); // Change the 'PATTERN_COUNTER' value ExportLine = ExportLine.Replace("'PATTERN_COUNTER'", Values.CaseID.ToString()); // Write values into final string for (int j = 0; j < KeyToAdd.Length; j++) { ExportLine = ExportLine.Replace("'" + KeyToAdd[j] + "'", ValueToAdd[j]); } // Write final line _File.AddLine(ExportLine); } } } // Clear PatternBlock PatternBlock = null; } if (PatternBlock == null) { foreach(StructuredFileKey PatternKey in _Items) { if(PatternKey.GetLoopID() == -1) { ReadPatternLine = ReadPatternLine.Replace("'" + PatternKey.GetName() + "'", PatternKey.GetValue()); } } _File.AddLine(ReadPatternLine); } else { // We are reading a pattern block, we add this line into PatternBlock PatternBlock.Add(ReadPatternLine); } } } } } _File.Save(OutputFilename); return (Ret); }
/// <summary> /// Open an existing Structured file by using the filename /// </summary> /// <param name="Pathname"></param> public StructuredFile(String Pathname) { _File = new TextFile(Pathname); }
// Constructeur --------------------------------------------------------------------------- /// <summary> /// Open an existing Structured file by openning a dialog box /// </summary> public StructuredFile() { _File = new TextFile(); _File.Load(); }
// Public --------------------------------------------------------------------------------- public void Parse(String PatternFilename) { List<String> PatternLine = null; List<String> PatternLoop = null; List<String> LineToCheck = null; List<String> LoopToCheck = null; String CurrentLine, TestLine, ResultPattern, ResultValue; int iCurrentLine = 0, PatternLen = 0, iterator = 0, PatternLoopInitialValue = 0; TextFile PatternFile = new TextFile(PatternFilename); if ((_File == null) || (null == PatternFile)) return; // Clear unused data PatternFile.RemoveUnusedLine(); _File.RemoveUnusedLine(); // Search for Loops for (iCurrentLine = 1; iCurrentLine <= PatternFile.GetSize(); iCurrentLine++) { // Read the current line from patter file CurrentLine = PatternFile.GetLine(iCurrentLine); // Search for inital tag if (CurrentLine == "// StructuredFileLoopBegin") { // Read the next line iCurrentLine++; CurrentLine = PatternFile.GetLine(iCurrentLine); PatternLen = 0; if (PatternLoop == null) PatternLoopInitialValue = 0; else PatternLoopInitialValue = PatternLoop.Count(); // Search for final tag into Pattern File while ((CurrentLine != "// StructuredFileLoopEnd") && (iCurrentLine <= PatternFile.GetSize())) { if (PatternLoop == null) PatternLoop = new List<string>(); if (LoopToCheck == null) LoopToCheck = new List<string>(); // Check equivalent line into _File TestLine = _File.GetLine(iCurrentLine); // Add lines into the loop checker (if TestLine is valid) if (TestLine != "// StructuredFileLoopEnd") { PatternLoop.Add(CurrentLine); LoopToCheck.Add(TestLine); if(CurrentLine != "// LoopID = 'LOOPID'") // This line is not included into the pattern PatternLen++; // Remove added line (for current file) _File.RemoveLine(iCurrentLine); } // Remove added line (for pattern file) PatternFile.RemoveLine(iCurrentLine); CurrentLine = PatternFile.GetLine(iCurrentLine); } iterator = PatternLoopInitialValue + 1; // Initial value is computed before adding the first LoopPattern value CurrentLine = _File.GetLine(iCurrentLine); // Search for final tag into current File while ((CurrentLine != "// StructuredFileLoopEnd") && (iCurrentLine <= _File.GetSize())) { // Add lines to the loop checker PatternLoop.Add(PatternLoop[iterator].ToString()); LoopToCheck.Add(_File.GetLine(iCurrentLine)); // Remove added lines _File.RemoveLine(iCurrentLine); CurrentLine = _File.GetLine(iCurrentLine); iterator++; if (iterator > PatternLoopInitialValue + PatternLen) iterator = PatternLoopInitialValue + 1; } } } // Clear unchanged line between the Pattern File and currentFile for (int i = 1; i <= _File.GetSize(); i++) { if (PatternFile.GetLine(i) != _File.GetLine(i)) { if (PatternLine == null) PatternLine = new List<string>(); if (LineToCheck == null) LineToCheck = new List<string>(); // Add line we have to compare PatternLine.Add(PatternFile.GetLine(i)); LineToCheck.Add(_File.GetLine(i)); } } // Create the result list for non-loop values if (PatternLine != null) { if (_Items == null) _Items = new List<StructuredFileKey>(); // Lecture ligne a ligne et sauvegarde des infos for (iCurrentLine = 0; iCurrentLine < PatternLine.Count(); iCurrentLine++) { int iCurrentPatternChar = 0, iCurrentValueChar = 0; // Traitement de la ligne en cours for (iCurrentValueChar = 0; iCurrentValueChar < LineToCheck[iCurrentLine].Length; iCurrentValueChar++) { // Si nous n'avons pas d'overflow if (iCurrentPatternChar < PatternLine[iCurrentLine].Length) { if (PatternLine[iCurrentLine].Substring(iCurrentPatternChar, 1) != LineToCheck[iCurrentLine].Substring(iCurrentValueChar, 1)) { iCurrentPatternChar++; iCurrentValueChar++; int iStartPatternChar = iCurrentPatternChar; // Des que nous voyons une difference dans les lignes // On recherche la fin du pattern while ((iCurrentPatternChar < PatternLine[iCurrentLine].Length) && (PatternLine[iCurrentLine].Substring(iCurrentPatternChar, 1) != "'")) { iCurrentPatternChar++; } ResultPattern = PatternLine[iCurrentLine].Substring(iStartPatternChar, iCurrentPatternChar - iStartPatternChar); // Read the next char to get the end of pattern block iCurrentPatternChar++; if (iCurrentPatternChar < PatternLine[iCurrentLine].Length) { int iFirstChar = iCurrentValueChar - 1; string sLastChar = PatternLine[iCurrentLine].Substring(iCurrentPatternChar, 1); // Lecture de la valeur reelle dans la liste LineToCheck while ((iCurrentValueChar < LineToCheck[iCurrentLine].Length) && (LineToCheck[iCurrentLine].Substring(iCurrentValueChar, 1) != sLastChar)) { iCurrentValueChar++; } // if the correct kay has been found if (LineToCheck[iCurrentLine].Substring(iCurrentValueChar, 1) == sLastChar) { ResultValue = LineToCheck[iCurrentLine].Substring(iFirstChar, iCurrentValueChar - iFirstChar); _Items.Add(new StructuredFileKey(-1, iCurrentLine, ResultPattern, ResultValue)); } } } } // Incremente la valeur pour suivre iCurrentValueChar iCurrentPatternChar++; } } } // Create result list for loop values if (PatternLoop != null) { int CurrentLoopID = -1; if (_Items == null) _Items = new List<StructuredFileKey>(); // Lecture ligne a ligne et sauvegarde des infos for (iCurrentLine = 0; iCurrentLine < PatternLoop.Count(); iCurrentLine++) { if (PatternLoop[iCurrentLine] == "// LoopID = 'LOOPID'") { CurrentLoopID = int.Parse(LoopToCheck[iCurrentLine].Substring("// LoopID = ".Length)); } else if (PatternLoop[iCurrentLine] == "// StructuredFileLoopEnd") { CurrentLoopID = -1; } else { int iCurrentPatternChar = 0, iCurrentValueChar = 0; // Traitement de la ligne en cours for (iCurrentValueChar = 0; iCurrentValueChar < LoopToCheck[iCurrentLine].Length; iCurrentValueChar++) { // Si nous n'avons pas d'overflow if (iCurrentPatternChar < PatternLoop[iCurrentLine].Length) { if (PatternLoop[iCurrentLine].Substring(iCurrentPatternChar, 1) != LoopToCheck[iCurrentLine].Substring(iCurrentValueChar, 1)) { iCurrentPatternChar++; iCurrentValueChar++; int iStartPatternChar = iCurrentPatternChar; // Des que nous voyons une difference dans les lignes // On recherche la fin du pattern while ((iCurrentPatternChar < PatternLoop[iCurrentLine].Length) && (PatternLoop[iCurrentLine].Substring(iCurrentPatternChar, 1) != "'")) { iCurrentPatternChar++; } ResultPattern = PatternLoop[iCurrentLine].Substring(iStartPatternChar, iCurrentPatternChar - iStartPatternChar); // Read the next char to get the end of pattern block iCurrentPatternChar++; if (iCurrentPatternChar < PatternLoop[iCurrentLine].Length) { int iFirstChar = iCurrentValueChar - 1; string sLastChar = PatternLoop[iCurrentLine].Substring(iCurrentPatternChar, 1); // Lecture de la valeur reelle dans la liste LineToCheck while ((iCurrentValueChar < LoopToCheck[iCurrentLine].Length) && (LoopToCheck[iCurrentLine].Substring(iCurrentValueChar, 1) != sLastChar)) { iCurrentValueChar++; } if (iCurrentValueChar < LoopToCheck[iCurrentLine].Length) { // if the correct key has been found if (LoopToCheck[iCurrentLine].Substring(iCurrentValueChar, 1) == sLastChar) { ResultValue = LoopToCheck[iCurrentLine].Substring(iFirstChar, iCurrentValueChar - iFirstChar); _Items.Add(new StructuredFileKey(CurrentLoopID, iCurrentLine, ResultPattern, ResultValue)); } } else { _Items.Add(new StructuredFileKey(CurrentLoopID, iCurrentLine, ResultPattern, "\t")); } } } } // Incremente la valeur pour suivre iCurrentValueChar iCurrentPatternChar++; } } } } return; }
/// <summary> /// Write the current data stored into this object into a specific file /// </summary> /// <param name="Filename">Name of the file to use for storing data</param> /// <returns>True if the file has been written, false otherwise</returns> public bool WriteFile(String OutputFilename, String PatternFilename) { bool Ret = false; String ReadPatternLine = null; String CheckPatternLine = null; int CurrentLoop = -1; List <String> PatternBlock = null; if ((OutputFilename != null) && (PatternFilename != null) && (_Items.Count() > 0)) { // Create the output file and open the pattern file TextFile PatternFile = new TextFile(PatternFilename); _File = new TextFile(); if (_File != null) { for (int i = 1; i <= PatternFile.GetSize(); i++) { // Check all line to change patterns into real value ReadPatternLine = PatternFile.GetLine(i); if (ReadPatternLine != null) { // Check line to remove unused char CheckPatternLine = ReadPatternLine; CheckPatternLine = CheckPatternLine.Replace("\t", ""); if (CheckPatternLine == "// LoopID = 'LOOPID'") { // Create the pattern block PatternBlock = new List <string>(); CurrentLoop++; // Update the current LoopID _File.AddLine(ReadPatternLine.Replace("'LOOPID'", CurrentLoop.ToString())); } if (CheckPatternLine == "// StructuredFileLoopEnd") { if ((PatternBlock != null) && (PatternBlock.Count() > 1)) { // Extact values ordered by GID List <StructValueList> KeyValues = ExtractValues(CurrentLoop); if (KeyValues != null) { int PatternIterator = 1; // The first line contains the LOOPID // Check all items and write only items from current Loop foreach (StructValueList Values in KeyValues) { // Create pattern line if (PatternIterator >= PatternBlock.Count()) { PatternIterator = 1; // The first line contains the LOOPID } string ExportLine = PatternBlock[PatternIterator]; // We have found value for the current GID, we split it to add them to the specific loop string[] KeyToAdd = Values.KeyList.Split('|'); string[] ValueToAdd = Values.ValueList.Split('|'); // Change the 'PATTERN_COUNTER' value ExportLine = ExportLine.Replace("'PATTERN_COUNTER'", Values.CaseID.ToString()); // Write values into final string for (int j = 0; j < KeyToAdd.Length; j++) { ExportLine = ExportLine.Replace("'" + KeyToAdd[j] + "'", ValueToAdd[j]); } // Write final line _File.AddLine(ExportLine); } } } // Clear PatternBlock PatternBlock = null; } if (PatternBlock == null) { foreach (StructuredFileKey PatternKey in _Items) { if (PatternKey.GetLoopID() == -1) { ReadPatternLine = ReadPatternLine.Replace("'" + PatternKey.GetName() + "'", PatternKey.GetValue()); } } _File.AddLine(ReadPatternLine); } else { // We are reading a pattern block, we add this line into PatternBlock PatternBlock.Add(ReadPatternLine); } } } } } _File.Save(OutputFilename); return(Ret); }
// Public --------------------------------------------------------------------------------- public void Parse(String PatternFilename) { List <String> PatternLine = null; List <String> PatternLoop = null; List <String> LineToCheck = null; List <String> LoopToCheck = null; String CurrentLine, TestLine, ResultPattern, ResultValue; int iCurrentLine = 0, PatternLen = 0, iterator = 0, PatternLoopInitialValue = 0; TextFile PatternFile = new TextFile(PatternFilename); if ((_File == null) || (null == PatternFile)) { return; } // Clear unused data PatternFile.RemoveUnusedLine(); _File.RemoveUnusedLine(); // Search for Loops for (iCurrentLine = 1; iCurrentLine <= PatternFile.GetSize(); iCurrentLine++) { // Read the current line from patter file CurrentLine = PatternFile.GetLine(iCurrentLine); // Search for inital tag if (CurrentLine == "// StructuredFileLoopBegin") { // Read the next line iCurrentLine++; CurrentLine = PatternFile.GetLine(iCurrentLine); PatternLen = 0; if (PatternLoop == null) { PatternLoopInitialValue = 0; } else { PatternLoopInitialValue = PatternLoop.Count(); } // Search for final tag into Pattern File while ((CurrentLine != "// StructuredFileLoopEnd") && (iCurrentLine <= PatternFile.GetSize())) { if (PatternLoop == null) { PatternLoop = new List <string>(); } if (LoopToCheck == null) { LoopToCheck = new List <string>(); } // Check equivalent line into _File TestLine = _File.GetLine(iCurrentLine); // Add lines into the loop checker (if TestLine is valid) if (TestLine != "// StructuredFileLoopEnd") { PatternLoop.Add(CurrentLine); LoopToCheck.Add(TestLine); if (CurrentLine != "// LoopID = 'LOOPID'") // This line is not included into the pattern { PatternLen++; } // Remove added line (for current file) _File.RemoveLine(iCurrentLine); } // Remove added line (for pattern file) PatternFile.RemoveLine(iCurrentLine); CurrentLine = PatternFile.GetLine(iCurrentLine); } iterator = PatternLoopInitialValue + 1; // Initial value is computed before adding the first LoopPattern value CurrentLine = _File.GetLine(iCurrentLine); // Search for final tag into current File while ((CurrentLine != "// StructuredFileLoopEnd") && (iCurrentLine <= _File.GetSize())) { // Add lines to the loop checker PatternLoop.Add(PatternLoop[iterator].ToString()); LoopToCheck.Add(_File.GetLine(iCurrentLine)); // Remove added lines _File.RemoveLine(iCurrentLine); CurrentLine = _File.GetLine(iCurrentLine); iterator++; if (iterator > PatternLoopInitialValue + PatternLen) { iterator = PatternLoopInitialValue + 1; } } } } // Clear unchanged line between the Pattern File and currentFile for (int i = 1; i <= _File.GetSize(); i++) { if (PatternFile.GetLine(i) != _File.GetLine(i)) { if (PatternLine == null) { PatternLine = new List <string>(); } if (LineToCheck == null) { LineToCheck = new List <string>(); } // Add line we have to compare PatternLine.Add(PatternFile.GetLine(i)); LineToCheck.Add(_File.GetLine(i)); } } // Create the result list for non-loop values if (PatternLine != null) { if (_Items == null) { _Items = new List <StructuredFileKey>(); } // Lecture ligne a ligne et sauvegarde des infos for (iCurrentLine = 0; iCurrentLine < PatternLine.Count(); iCurrentLine++) { int iCurrentPatternChar = 0, iCurrentValueChar = 0; // Traitement de la ligne en cours for (iCurrentValueChar = 0; iCurrentValueChar < LineToCheck[iCurrentLine].Length; iCurrentValueChar++) { // Si nous n'avons pas d'overflow if (iCurrentPatternChar < PatternLine[iCurrentLine].Length) { if (PatternLine[iCurrentLine].Substring(iCurrentPatternChar, 1) != LineToCheck[iCurrentLine].Substring(iCurrentValueChar, 1)) { iCurrentPatternChar++; iCurrentValueChar++; int iStartPatternChar = iCurrentPatternChar; // Des que nous voyons une difference dans les lignes // On recherche la fin du pattern while ((iCurrentPatternChar < PatternLine[iCurrentLine].Length) && (PatternLine[iCurrentLine].Substring(iCurrentPatternChar, 1) != "'")) { iCurrentPatternChar++; } ResultPattern = PatternLine[iCurrentLine].Substring(iStartPatternChar, iCurrentPatternChar - iStartPatternChar); // Read the next char to get the end of pattern block iCurrentPatternChar++; if (iCurrentPatternChar < PatternLine[iCurrentLine].Length) { int iFirstChar = iCurrentValueChar - 1; string sLastChar = PatternLine[iCurrentLine].Substring(iCurrentPatternChar, 1); // Lecture de la valeur reelle dans la liste LineToCheck while ((iCurrentValueChar < LineToCheck[iCurrentLine].Length) && (LineToCheck[iCurrentLine].Substring(iCurrentValueChar, 1) != sLastChar)) { iCurrentValueChar++; } // if the correct kay has been found if (LineToCheck[iCurrentLine].Substring(iCurrentValueChar, 1) == sLastChar) { ResultValue = LineToCheck[iCurrentLine].Substring(iFirstChar, iCurrentValueChar - iFirstChar); _Items.Add(new StructuredFileKey(-1, iCurrentLine, ResultPattern, ResultValue)); } } } } // Incremente la valeur pour suivre iCurrentValueChar iCurrentPatternChar++; } } } // Create result list for loop values if (PatternLoop != null) { int CurrentLoopID = -1; if (_Items == null) { _Items = new List <StructuredFileKey>(); } // Lecture ligne a ligne et sauvegarde des infos for (iCurrentLine = 0; iCurrentLine < PatternLoop.Count(); iCurrentLine++) { if (PatternLoop[iCurrentLine] == "// LoopID = 'LOOPID'") { CurrentLoopID = int.Parse(LoopToCheck[iCurrentLine].Substring("// LoopID = ".Length)); } else if (PatternLoop[iCurrentLine] == "// StructuredFileLoopEnd") { CurrentLoopID = -1; } else { int iCurrentPatternChar = 0, iCurrentValueChar = 0; // Traitement de la ligne en cours for (iCurrentValueChar = 0; iCurrentValueChar < LoopToCheck[iCurrentLine].Length; iCurrentValueChar++) { // Si nous n'avons pas d'overflow if (iCurrentPatternChar < PatternLoop[iCurrentLine].Length) { if (PatternLoop[iCurrentLine].Substring(iCurrentPatternChar, 1) != LoopToCheck[iCurrentLine].Substring(iCurrentValueChar, 1)) { iCurrentPatternChar++; iCurrentValueChar++; int iStartPatternChar = iCurrentPatternChar; // Des que nous voyons une difference dans les lignes // On recherche la fin du pattern while ((iCurrentPatternChar < PatternLoop[iCurrentLine].Length) && (PatternLoop[iCurrentLine].Substring(iCurrentPatternChar, 1) != "'")) { iCurrentPatternChar++; } ResultPattern = PatternLoop[iCurrentLine].Substring(iStartPatternChar, iCurrentPatternChar - iStartPatternChar); // Read the next char to get the end of pattern block iCurrentPatternChar++; if (iCurrentPatternChar < PatternLoop[iCurrentLine].Length) { int iFirstChar = iCurrentValueChar - 1; string sLastChar = PatternLoop[iCurrentLine].Substring(iCurrentPatternChar, 1); // Lecture de la valeur reelle dans la liste LineToCheck while ((iCurrentValueChar < LoopToCheck[iCurrentLine].Length) && (LoopToCheck[iCurrentLine].Substring(iCurrentValueChar, 1) != sLastChar)) { iCurrentValueChar++; } if (iCurrentValueChar < LoopToCheck[iCurrentLine].Length) { // if the correct key has been found if (LoopToCheck[iCurrentLine].Substring(iCurrentValueChar, 1) == sLastChar) { ResultValue = LoopToCheck[iCurrentLine].Substring(iFirstChar, iCurrentValueChar - iFirstChar); _Items.Add(new StructuredFileKey(CurrentLoopID, iCurrentLine, ResultPattern, ResultValue)); } } else { _Items.Add(new StructuredFileKey(CurrentLoopID, iCurrentLine, ResultPattern, "\t")); } } } } // Incremente la valeur pour suivre iCurrentValueChar iCurrentPatternChar++; } } } } return; }
/// <summary> /// Open an existing Structured file by using the filename /// </summary> /// <param name="Pathname"></param> public StructuredFile(String Pathname) { _File = new TextFile(Pathname); }
// Constructeur --------------------------------------------------------------------------- /// <summary> /// Open an existing Structured file by openning a dialog box /// </summary> public StructuredFile() { _File = new TextFile(); _File.Load(); }