86 lines
2.8 KiB
C#
86 lines
2.8 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace DTS.Common.Classes.TMAT
|
|
{
|
|
|
|
/// <summary>
|
|
/// this class handles a TMATS template in only one file
|
|
/// </summary>
|
|
public class TmtSingleFile : TmtBase
|
|
{
|
|
/// <summary>
|
|
/// reads all lines from the file in the given location and prepare to update values
|
|
/// </summary>
|
|
/// <param name="templateLocation"></param>
|
|
public TmtSingleFile(string templateLocation)
|
|
{
|
|
if (System.IO.File.Exists(templateLocation))
|
|
{
|
|
_allLines.AddRange(System.IO.File.ReadAllLines(templateLocation));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// updates the files in the file with a given value
|
|
/// </summary>
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// updates the fields in the file with a given value
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <param name="value"></param>
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// updates the files in the file with the given value
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <param name="value"></param>
|
|
/// <param name="channelNumber"></param>
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// all lines in the TMT file
|
|
/// </summary>
|
|
private readonly List<string> _allLines = new List<string>();
|
|
|
|
/// <summary>
|
|
/// returns all lines in the TMT file
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override string[] GetAllLines()
|
|
{
|
|
return _allLines.ToArray();
|
|
}
|
|
}
|
|
|
|
}
|