using System.Collections.Generic; namespace DTS.Common.Classes.TMAT { /// /// this class handles a TMATS template in only one file /// public class TmtSingleFile : TmtBase { /// /// reads all lines from the file in the given location and prepare to update values /// /// public TmtSingleFile(string templateLocation) { if (System.IO.File.Exists(templateLocation)) { _allLines.AddRange(System.IO.File.ReadAllLines(templateLocation)); } } /// /// updates the files in the file with a given value /// public override void UpdateValue(TMTChannelKeysEx key, string value, int channelNumber) { var pattern = TMTKey.GetKey(key); for (var i = 0; i < _allLines.Count; i++) { if (_allLines[i].Contains(pattern)) { _allLines[i] = _allLines[i].Replace(pattern, value); } } } /// /// updates the fields in the file with a given value /// /// /// public override void UpdateValue(TMTGlobalKeys key, string value) { var pattern = TMTKey.GetKey(key); for (int i = 0; i < _allLines.Count; i++) { if (_allLines[i].Contains(pattern)) { _allLines[i] = _allLines[i].Replace(pattern, value); } } } /// /// updates the files in the file with the given value /// /// /// /// public override void UpdateValue(TMTChannelKeys key, string value, int channelNumber) { var pattern = TMTKey.GetKey(key, channelNumber); for (int i = 0; i < _allLines.Count; i++) { if (_allLines[i].Contains(pattern)) { _allLines[i] = _allLines[i].Replace(pattern, value); } } } /// /// all lines in the TMT file /// private readonly List _allLines = new List(); /// /// returns all lines in the TMT file /// /// public override string[] GetAllLines() { return _allLines.ToArray(); } } }