Implement Laboratory and TimePoints.

This commit is contained in:
Daniel Kraus
2015-07-11 16:51:02 +02:00
parent 2cf31914dd
commit 07ee4fbf2a
10 changed files with 276 additions and 38 deletions

View File

@ -108,7 +108,7 @@ namespace zaaReloaded2.Importer.ZaaImporter
foreach (Capture itemCapture in m.Groups["items"].Captures)
{
LaurisItem i = new LaurisItem(itemCapture.Value, _parameterDictionary, _unitDictionary);
Items.Add(i.QualifiedName, i);
Items[i.QualifiedName] = i;
}
IsLaurisParagraph = Items.Count > 0;
}

View File

@ -32,12 +32,52 @@ namespace zaaReloaded2.Importer.ZaaImporter
/// </summary>
class LaurisTimePoint : TimePoint
{
#region Static methods
/// <summary>
/// Examines a string and returns true if it resembles
/// a time stamp line in the Lauris output.
/// </summary>
/// <param name="line">Line to examine.</param>
/// <returns>True if line resembles a time stamp line
/// in the Lauris output.</returns>
static public bool IsTimeStampLine(string line)
{
return _timeStampRegex.IsMatch(line);
}
/// <summary>
/// Gets a Regex object that matches a Lauris time stamp
/// line.
/// </summary>
static public Regex TimeStampRegex
{
get
{
return _timeStampRegex;
}
}
#endregion
#region Properties
/// <summary>
/// Gets an array of paragraphs in this LaurisText.
/// </summary>
public string[] Paragraphs { get; private set; }
public string[] Paragraphs
{
[DebuggerStepThrough]
get
{
return _paragraphs;
}
set
{
_paragraphs = value;
ParseParagraphs();
}
}
/// <summary>
/// Is true if the LaurisText has time stamp in the first
@ -62,7 +102,6 @@ namespace zaaReloaded2.Importer.ZaaImporter
Paragraphs = value.Split(
new string[] { Environment.NewLine },
StringSplitOptions.None);
ParseParagraphs();
}
}
}
@ -73,23 +112,35 @@ namespace zaaReloaded2.Importer.ZaaImporter
public LaurisTimePoint() { }
public LaurisTimePoint(string laurisTest)
: this()
{
_parameterDictionary = null;
_unitDictionary = null;
LaurisText = laurisTest;
}
public LaurisTimePoint(
string laurisTest,
string laurisText,
ParameterDictionary parameterDictionary,
UnitDictionary unitDictionary)
: this()
{
_parameterDictionary = parameterDictionary;
_unitDictionary = unitDictionary;
LaurisText = laurisTest;
LaurisText = laurisText;
}
public LaurisTimePoint(string laurisText)
: this(laurisText, null, null)
{ }
public LaurisTimePoint(
string[] paragraphs,
ParameterDictionary parameterDictionary,
UnitDictionary unitDictionary)
: this()
{
_parameterDictionary = parameterDictionary;
_unitDictionary = unitDictionary;
Paragraphs = paragraphs;
}
public LaurisTimePoint(string[] paragraphs)
: this(paragraphs, null, null)
{
}
#endregion
@ -139,7 +190,7 @@ namespace zaaReloaded2.Importer.ZaaImporter
if (Paragraphs.Length == 0)
throw new InvalidOperationException("The time point has no paragraphs.");
Match m = _dateStampRegex.Match(Paragraphs[0]);
Match m = _timeStampRegex.Match(Paragraphs[0]);
bool success = false;
if (m.Success)
{
@ -158,7 +209,7 @@ namespace zaaReloaded2.Importer.ZaaImporter
void AddItems(IItemDictionary items)
{
Items.Merge(items);
}
#endregion
@ -169,8 +220,9 @@ namespace zaaReloaded2.Importer.ZaaImporter
/// A regular expression that matches the time stamp in the first
/// paragraph of a LaurisText.
/// </summary>
static readonly Regex _dateStampRegex = new Regex(
@"^\s*\[?\s*(?<datetime>\d\d\.\d\d\.\d\d\d\d\s+\d\d:\d\d)");
static readonly Regex _timeStampRegex = new Regex(
@"^\s*\(?\s*(?<datetime>\d\d\.\d\d\.\d\d\d\d\s+\d\d:\d\d)");
string[] _paragraphs;
ParameterDictionary _parameterDictionary;
UnitDictionary _unitDictionary;

View File

@ -20,6 +20,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Bovender.Extensions;
using zaaReloaded2.LabModel;
namespace zaaReloaded2.Importer.ZaaImporter
@ -34,21 +35,68 @@ namespace zaaReloaded2.Importer.ZaaImporter
public Laboratory Laboratory
{
[DebuggerStepThrough]
get
{
throw new NotImplementedException();
if (_laboratory == null)
{
_laboratory = new Laboratory();
}
return _laboratory;
}
[DebuggerStepThrough]
set
{
throw new NotImplementedException();
_laboratory = value;
}
}
public void Import(string text)
{
throw new NotImplementedException();
string[] paragraphs = text.Split(
new string[] { Environment.NewLine },
StringSplitOptions.RemoveEmptyEntries);
int i = 0;
int start = 0;
int numParagraphs = paragraphs.Length;
while (i < numParagraphs)
{
// Search for the next occurrence of a time stamp line
while (i < numParagraphs
&& !LaurisTimePoint.IsTimeStampLine(paragraphs[i]))
{
i++;
}
// TODO: Find an alternative to returning in the middle of the method.
if (i >= numParagraphs) return;
if (LaurisTimePoint.IsTimeStampLine(paragraphs[i]))
{
// Remember the time stamp line's index
start = i;
// Seek the next time stamp line
while (i + 1 < numParagraphs
&& !LaurisTimePoint.IsTimeStampLine(paragraphs[i + 1]))
{
i++;
}
}
Laboratory.AddTimePoint(
new LaurisTimePoint(paragraphs.Slice(start, i - start + 1))
);
}
}
#endregion
#region Fields
Laboratory _laboratory;
#endregion
}
}