Implement DocumentWriter, control elements, and tests.

This commit is contained in:
Daniel Kraus
2015-07-25 14:33:48 +02:00
parent 659713abe3
commit 9df937138d
22 changed files with 722 additions and 151 deletions

View File

@ -0,0 +1,45 @@
/* ControlElementBase.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.Collections.Generic;
namespace zaaReloaded2.Controller.Elements
{
/// <summary>
/// Base class for control elements that control e.g. the working
/// set of time points in a Formatter object.
/// </summary>
public abstract class ControlElementBase : ElementBase
{
/// <summary>
/// Gets a list of child elements, all of which must be derived
/// from FormatElementBase.
/// </summary>
public IList<FormatElementBase> FormatElements { get; private set; }
public ControlElementBase() { }
public ControlElementBase(IList<FormatElementBase> formatElements)
{
FormatElements = formatElements;
}
public ControlElementBase(FormatElementBase formatElement)
: this(new List<FormatElementBase>() { formatElement })
{ }
}
}

View File

@ -34,7 +34,7 @@ namespace zaaReloaded2.Controller.Elements
public override void Run(Formatter.Formatter formatter)
{
formatter.WriteToDocument(Text);
formatter.Write(Text);
}
/// <summary>

View File

@ -0,0 +1,27 @@
/* FormatElementBase.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.
*/
namespace zaaReloaded2.Controller.Elements
{
/// <summary>
/// Base class for elements that perform actual formatting.
/// </summary>
public abstract class FormatElementBase : ElementBase
{
}
}

View File

@ -31,7 +31,7 @@ namespace zaaReloaded2.Controller.Elements
/// to a Word document.
/// </summary>
[Serializable]
class Items : ElementBase
class Items : FormatElementBase
{
#region ElementBase implementation
@ -55,15 +55,13 @@ namespace zaaReloaded2.Controller.Elements
{
if (!String.IsNullOrEmpty(_caption))
{
formatter.Document.Range().InsertAfter(
String.Format("{0}: ", _caption)
);
formatter.Write(String.Format("{0}: ", _caption));
};
foreach (ItemFormatter i in items)
{
if (_needComma)
{
formatter.Document.Range().InsertAfter(", ");
formatter.Write(", ");
}
else
{
@ -71,6 +69,7 @@ namespace zaaReloaded2.Controller.Elements
}
i.WriteToDocument(formatter);
}
formatter.Write("\r");
}
}

View File

@ -0,0 +1,43 @@
/* SelectEachDay.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.Controller.Elements
{
class SelectEachDay : ControlElementBase
{
public override string Label
{
get { return "Jeden Tag auswählen"; }
}
public override void Run(Formatter.Formatter formatter)
{
formatter.ProcessEachDay(this);
}
public SelectEachDay() : base() { }
public SelectEachDay(FormatElementBase formatElement)
: base(formatElement)
{ }
}
}

View File

@ -26,7 +26,7 @@ namespace zaaReloaded2.Controller.Elements
/// Selects the time points of the first day in a given Formatter
/// object.
/// </summary>
class SelectFirstDay : ElementBase
class SelectFirstDay : ControlElementBase
{
public override string Label
{
@ -35,7 +35,13 @@ namespace zaaReloaded2.Controller.Elements
public override void Run(Formatter.Formatter formatter)
{
formatter.SelectFirstDay();
formatter.ProcessFirstDay(this);
}
public SelectFirstDay() : base() { }
public SelectFirstDay(FormatElementBase formatElement)
: base(formatElement)
{ }
}
}

View File

@ -27,7 +27,7 @@ namespace zaaReloaded2.Controller.Elements
/// Selects the time points of the last day in a given Formatter
/// object.
/// </summary>
class SelectLastDay : ElementBase
class SelectLastDay : ControlElementBase
{
public override string Label
{
@ -36,7 +36,13 @@ namespace zaaReloaded2.Controller.Elements
public override void Run(Formatter.Formatter formatter)
{
formatter.SelectLastDay();
formatter.ProcessLastDay(this);
}
public SelectLastDay() : base() { }
public SelectLastDay(FormatElementBase formatElement)
: base(formatElement)
{ }
}
}