133 lines
3.6 KiB
C#
133 lines
3.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SCMA.AdapterCom
|
|
{
|
|
// Oggetto SEMPLICE x definizione data item... con MTC verrà fatta conversione 1:1 ai dataitem di tipo MTC (con relative estensioni)
|
|
public class SimpleDataItem
|
|
{
|
|
/// <summary>
|
|
/// The name of the data item
|
|
/// </summary>
|
|
protected String mName;
|
|
|
|
/// <summary>
|
|
/// The value of the data item, can be any type.
|
|
/// </summary>
|
|
protected object mValue = "UNAVAILABLE";
|
|
|
|
/// <summary>
|
|
/// A flag to indicate if the data item's value has changed since it
|
|
/// has last been set.
|
|
/// </summary>
|
|
protected bool mChanged = true;
|
|
|
|
/// <summary>
|
|
/// An indicator that this data item must be sent on a separate line.
|
|
/// This is done for all data items that are more complex than simple
|
|
/// Key|Value pairs.
|
|
/// </summary>
|
|
protected bool mNewLine = false;
|
|
|
|
/// <summary>
|
|
/// Optional device prefix.
|
|
/// </summary>
|
|
public string DevicePrefix = null;
|
|
|
|
/// <summary>
|
|
/// Create a new data item
|
|
/// </summary>
|
|
/// <param name="name">The name of the data item</param>
|
|
public SimpleDataItem(String name)
|
|
{
|
|
mName = name;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get and set the Value property. This will check if the value has changed
|
|
/// and set the changed flag appropriately. Automatically boxes types so will
|
|
/// work for any data.
|
|
/// </summary>
|
|
public object Value
|
|
{
|
|
set
|
|
{
|
|
if (!mValue.Equals(value))
|
|
{
|
|
mValue = value;
|
|
mChanged = true;
|
|
}
|
|
}
|
|
get { return mValue; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Make this data item unavailable.
|
|
/// </summary>
|
|
public virtual void Unavailable() { Value = "UNAVAILABLE"; }
|
|
|
|
/// <summary>
|
|
/// Checks if the data item is unavailable.
|
|
/// </summary>
|
|
/// <returns>true if Unavailable</returns>
|
|
public bool IsUnavailable() { return mValue.Equals("UNAVAILABLE"); }
|
|
|
|
/// <summary>
|
|
/// Getter for the mChanged property.
|
|
/// </summary>
|
|
public bool Changed { get { return mChanged; } }
|
|
/// <summary>
|
|
/// Getter for the mNewLine property.
|
|
/// </summary>
|
|
public bool NewLine { get { return mNewLine; } }
|
|
|
|
public void ForceChanged()
|
|
{
|
|
mChanged = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Simple string representation with pipe delim.
|
|
/// </summary>
|
|
/// <returns>A text representation</returns>
|
|
public override string ToString()
|
|
{
|
|
if (DevicePrefix == null)
|
|
return mName + "|" + mValue;
|
|
else
|
|
return DevicePrefix + ":" + mName + "|" + mValue;
|
|
}
|
|
|
|
/// <summary>
|
|
/// These methods are mainly for conditions. They allow for
|
|
/// mark and sweep of the condition activations.
|
|
/// </summary>
|
|
public virtual void Begin() { }
|
|
public virtual void Prepare() { }
|
|
|
|
/// <summary>
|
|
/// Reset the Changed flag.
|
|
/// </summary>
|
|
public virtual void Cleanup() { mChanged = false; }
|
|
|
|
/// <summary>
|
|
/// Get a list of all the changed data items. Since this is a
|
|
/// single value, just return a list with one item if it has
|
|
/// changed
|
|
/// </summary>
|
|
/// <param name="onlyChanged">true means to return this data item regardless of the
|
|
/// changed flag. This is used to send initial data back to a new client.</param>
|
|
/// <returns>The changed data item</returns>
|
|
public virtual List<SimpleDataItem> ItemList(bool all = false)
|
|
{
|
|
List<SimpleDataItem> list = new List<SimpleDataItem>();
|
|
if (all || mChanged)
|
|
list.Add(this);
|
|
return list;
|
|
}
|
|
}
|
|
}
|