Create new namespace zaaReloaded2.Formatter, move settings there.
This commit is contained in:
parent
26766dbf81
commit
e4e7f80ed2
@ -23,7 +23,7 @@ using NUnit.Framework;
|
||||
using Microsoft.Office.Interop.Word;
|
||||
using zaaReloaded2.LabModel;
|
||||
using zaaReloaded2.Formatter;
|
||||
using zaa = zaaReloaded2.Formatter.Elements;
|
||||
using zaa = zaaReloaded2.Controller.Elements;
|
||||
|
||||
namespace Tests.Formatter.Elements
|
||||
{
|
||||
@ -55,9 +55,9 @@ namespace Tests.Formatter.Elements
|
||||
// We do not add a 'Cl' item, and it should not appear in output.
|
||||
lab.AddTimePoint(tp);
|
||||
|
||||
_formatter.ReferenceStyle = ReferenceStyle.IfAbnormal;
|
||||
_formatter.Settings.ReferenceStyle = ReferenceStyle.IfAbnormal;
|
||||
_formatter.Laboratory = lab;
|
||||
_formatter.Elements.Add(new zaa.Items("Na, K, Cl"));
|
||||
_formatter.Settings.Elements.Add(new zaa.Items("Na, K, Cl"));
|
||||
_formatter.Run();
|
||||
Assert.AreEqual("Na 133, K 6 (5)\r", _formatter.Document.Range().Text);
|
||||
}
|
||||
@ -73,9 +73,9 @@ namespace Tests.Formatter.Elements
|
||||
// We do not add a 'Cl' item, and it should not appear in output.
|
||||
lab.AddTimePoint(tp);
|
||||
|
||||
_formatter.ReferenceStyle = ReferenceStyle.IfAbnormal;
|
||||
_formatter.Settings.ReferenceStyle = ReferenceStyle.IfAbnormal;
|
||||
_formatter.Laboratory = lab;
|
||||
_formatter.Elements.Add(new zaa.Items("Klinische Chemie: Na, K, Cl"));
|
||||
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: Na, K, Cl"));
|
||||
_formatter.Run();
|
||||
Assert.AreEqual("Klinische Chemie: Na 133, K 6 (5)\r", _formatter.Document.Range().Text);
|
||||
}
|
||||
@ -91,9 +91,9 @@ namespace Tests.Formatter.Elements
|
||||
// We do not add a 'Cl' item, and it should not appear in output.
|
||||
lab.AddTimePoint(tp);
|
||||
|
||||
_formatter.ReferenceStyle = ReferenceStyle.IfAbnormal;
|
||||
_formatter.Settings.ReferenceStyle = ReferenceStyle.IfAbnormal;
|
||||
_formatter.Laboratory = lab;
|
||||
_formatter.Elements.Add(new zaa.Items("Klinische Chemie: this, does, not, exist"));
|
||||
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: this, does, not, exist"));
|
||||
_formatter.Run();
|
||||
Assert.AreEqual("\r", _formatter.Document.Range().Text);
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ using NUnit.Framework;
|
||||
using f = zaaReloaded2.Formatter;
|
||||
using zaaReloaded2.LabModel;
|
||||
using zaaReloaded2.Importer.ZaaImporter;
|
||||
using zaaReloaded2.Controller.Elements;
|
||||
using Microsoft.Office.Interop.Word;
|
||||
|
||||
namespace Tests.Formatter
|
||||
@ -37,7 +38,7 @@ namespace Tests.Formatter
|
||||
ZaaImporter importer = TestHelpers.ZaaImporterFromResource();
|
||||
f.Formatter formatter = new f.Formatter(document);
|
||||
formatter.Laboratory = importer.Laboratory;
|
||||
formatter.Elements.Add(new f.Elements.Items("Klinische Chemie: Na, K, Cl"));
|
||||
formatter.Settings.Elements.Add(new Items("Klinische Chemie: Na, K, Cl"));
|
||||
formatter.Run();
|
||||
Assert.AreEqual("Klinische Chemie: Na 144 mM, K 4,3 mM\r", document.Range().Text);
|
||||
((_Document)document).Close(WdSaveOptions.wdDoNotSaveChanges);
|
||||
|
@ -22,13 +22,13 @@ using System.Text;
|
||||
using Microsoft.Office.Interop.Word;
|
||||
using zaaReloaded2.LabModel;
|
||||
|
||||
namespace zaaReloaded2.Formatter.Elements
|
||||
namespace zaaReloaded2.Controller.Elements
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for formatting elements.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
abstract class ElementBase
|
||||
public abstract class ElementBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the label for this formatting element.
|
||||
@ -43,6 +43,6 @@ namespace zaaReloaded2.Formatter.Elements
|
||||
/// <param name="formatter">Formatter object that this
|
||||
/// Element belongs to. The Formatter object provides access
|
||||
/// to the current Word document etc.</param>
|
||||
abstract public void Run(Formatter formatter);
|
||||
abstract public void Run(zaaReloaded2.Formatter.Formatter formatter);
|
||||
}
|
||||
}
|
@ -20,16 +20,18 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Office.Interop.Word;
|
||||
using zaaReloaded2.LabModel;
|
||||
using System.Diagnostics;
|
||||
using zaaReloaded2.Formatter;
|
||||
|
||||
namespace zaaReloaded2.Formatter.Elements
|
||||
namespace zaaReloaded2.Controller.Elements
|
||||
{
|
||||
/// <summary>
|
||||
/// This formatting element is concerned with writing <see cref="LabItem"/>s
|
||||
/// to a Word document.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
class Items : ElementBase
|
||||
{
|
||||
#region ElementBase implementation
|
||||
@ -39,7 +41,7 @@ namespace zaaReloaded2.Formatter.Elements
|
||||
get { return Line; }
|
||||
}
|
||||
|
||||
public override void Run(Formatter formatter)
|
||||
public override void Run(zaaReloaded2.Formatter.Formatter formatter)
|
||||
{
|
||||
bool _needComma = false;
|
||||
|
56
zaaReloaded2/Controller/Settings.cs
Executable file
56
zaaReloaded2/Controller/Settings.cs
Executable file
@ -0,0 +1,56 @@
|
||||
/* Settings.cs
|
||||
* part of zaaReloaded2
|
||||
*
|
||||
* Copyright 2015 Daniel Kraus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using zaaReloaded2.Formatter;
|
||||
using zaaReloaded2.Controller.Elements;
|
||||
|
||||
namespace zaaReloaded2.Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds settings related to controlling laboratory output.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class Settings
|
||||
{
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the reference style.
|
||||
/// </summary>
|
||||
public ReferenceStyle ReferenceStyle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of controlling elements.
|
||||
/// </summary>
|
||||
public IList<ElementBase> Elements { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
public Settings()
|
||||
{
|
||||
Elements = new List<ElementBase>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
/* ElementsList.cs
|
||||
* part of zaaReloaded2
|
||||
*
|
||||
* Copyright 2015 Daniel Kraus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace zaaReloaded2.Formatter.Elements
|
||||
{
|
||||
[Serializable]
|
||||
class ElementsList : List<ElementBase>
|
||||
{
|
||||
}
|
||||
}
|
@ -19,37 +19,28 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Office.Interop.Word;
|
||||
using zaaReloaded2.Formatter.Elements;
|
||||
using zaaReloaded2.LabModel;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Office.Interop.Word;
|
||||
using zaaReloaded2.LabModel;
|
||||
using zaaReloaded2.Controller;
|
||||
using zaaReloaded2.Controller.Elements;
|
||||
|
||||
namespace zaaReloaded2.Formatter
|
||||
{
|
||||
/// <summary>
|
||||
/// Formats and writes a <see cref="Laboratory"/> to a Word document.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
class Formatter
|
||||
public class Formatter
|
||||
{
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of formatting elements (derived from
|
||||
/// <see cref="ElementBase"/>).
|
||||
/// </summary>
|
||||
public ElementsList Elements { get; private set; }
|
||||
public Settings Settings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the working Word document.
|
||||
/// </summary>
|
||||
public Document Document { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the style of the normal range reference.
|
||||
/// </summary>
|
||||
public ReferenceStyle ReferenceStyle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="Laboratory"/> that shall be
|
||||
/// formatted.
|
||||
@ -67,7 +58,8 @@ namespace zaaReloaded2.Formatter
|
||||
_timePointFormatters = new TimePointFormatterDictionary();
|
||||
foreach (TimePoint tp in _laboratory.TimePoints.Values)
|
||||
{
|
||||
_timePointFormatters[tp.TimeStamp] = new TimePointFormatter(tp, ReferenceStyle);
|
||||
_timePointFormatters[tp.TimeStamp] =
|
||||
new TimePointFormatter(tp, Settings.ReferenceStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -83,7 +75,7 @@ namespace zaaReloaded2.Formatter
|
||||
|
||||
public Formatter()
|
||||
{
|
||||
Elements = new ElementsList();
|
||||
Settings = new Settings();
|
||||
}
|
||||
|
||||
public Formatter(Document document)
|
||||
@ -104,7 +96,7 @@ namespace zaaReloaded2.Formatter
|
||||
public void Run()
|
||||
{
|
||||
WorkingTimePoints = _timePointFormatters;
|
||||
foreach (ElementBase element in Elements)
|
||||
foreach (ElementBase element in Settings.Elements)
|
||||
{
|
||||
element.Run(this);
|
||||
}
|
||||
|
@ -163,8 +163,8 @@
|
||||
can be found.
|
||||
-->
|
||||
<ItemGroup>
|
||||
<Compile Include="Controller\Settings.cs" />
|
||||
<Compile Include="Thesaurus\ThesaurusBase.cs" />
|
||||
<Compile Include="Formatter\Elements\ElementsList.cs" />
|
||||
<Compile Include="Formatter\IItemFormatterDictionary.cs" />
|
||||
<Compile Include="Formatter\ItemFormatter.cs" />
|
||||
<Compile Include="Formatter\ItemFormatterDictionary.cs" />
|
||||
@ -176,8 +176,8 @@
|
||||
<Compile Include="Thesaurus\LineParser.cs" />
|
||||
<Compile Include="Thesaurus\Parameters.cs" />
|
||||
<Compile Include="Thesaurus\Units.cs" />
|
||||
<Compile Include="Formatter\Elements\ElementBase.cs" />
|
||||
<Compile Include="Formatter\Elements\Items.cs" />
|
||||
<Compile Include="Controller\Elements\ElementBase.cs" />
|
||||
<Compile Include="Controller\Elements\Items.cs" />
|
||||
<Compile Include="Formatter\Formatter.cs" />
|
||||
<Compile Include="Formatter\ReferenceStyle.cs" />
|
||||
<Compile Include="Importer\IImporter.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user