109 lines
3.1 KiB
C#
Executable File
109 lines
3.1 KiB
C#
Executable File
/* TimePointFormatter.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.LabModel;
|
|
|
|
namespace zaaReloaded2.Formatter
|
|
{
|
|
/// <summary>
|
|
/// Creates a list of ItemFormatter objects from a TimePoint.
|
|
/// </summary>
|
|
public class TimePointFormatter
|
|
{
|
|
#region Properties
|
|
|
|
/// <summary>
|
|
/// Gets the time stamp of the <see cref="TimePoint"/> from which this
|
|
/// TimePointFormatter was built.
|
|
/// </summary>
|
|
public DateTime TimeStamp { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Gets a dictionary of ItemFormatter objects that wrap LabItems.
|
|
/// The QualifiedName of each LabItem is used as key.
|
|
/// </summary>
|
|
public IItemFormatterDictionary ItemFormatters { get; private set; }
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Creates a new TimePointFormatter object using a given
|
|
/// <paramref name="timePoint"/>.
|
|
/// </summary>
|
|
/// <param name="timePoint">TimePoint whose LabItems will be
|
|
/// used to create ItemFormatter objects.</param>
|
|
public TimePointFormatter(TimePoint timePoint, ReferenceStyle referenceStyle)
|
|
{
|
|
TimeStamp = timePoint.TimeStamp;
|
|
ItemFormatters = new ItemFormatterDictionary();
|
|
foreach (LabItem item in timePoint.Items.Values)
|
|
{
|
|
ItemFormatters[item.QualifiedName] = new ItemFormatter(item, referenceStyle);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
public bool ContainsItem(string itemName)
|
|
{
|
|
return ItemFormatters.ContainsKey(itemName);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a header text line with the time point's date.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string GetDateHeader()
|
|
{
|
|
return FormatHeader(TimeStamp.ToShortDateString());
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Creates a header text line with the time point's date
|
|
/// and time.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string GetDateAndTimeHeader()
|
|
{
|
|
return FormatHeader(TimeStamp.ToString());
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Private methods
|
|
|
|
string FormatHeader(string text)
|
|
{
|
|
return String.Format("{0}{1}:{2}",
|
|
Environment.NewLine,
|
|
text,
|
|
Environment.NewLine
|
|
);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |