#region Copyright (c) 2011-2023 Technosoftware GmbH. All rights reserved
//-----------------------------------------------------------------------------
// Copyright (c) 2011-2023 Technosoftware GmbH. All rights reserved
// Web: https://www.technosoftware.com
//
// The source code in this file is covered under a dual-license scenario:
// - Owner of a purchased license: SCLA 1.0
// - GPL V3: everybody else
//
// SCLA license terms accompanied with this source code.
// See SCLA 1.0: https://technosoftware.com/license/Source_Code_License_Agreement.pdf
//
// GNU General Public License as published by the Free Software Foundation;
// version 3 of the License are accompanied with this source code.
// See https://technosoftware.com/license/GPLv3License.txt
//
// This source code is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.
//-----------------------------------------------------------------------------
#endregion Copyright (c) 2011-2023 Technosoftware GmbH. All rights reserved
#region Using Directives
using System;
using System.Collections;
#endregion
namespace Technosoftware.DaAeHdaClient.Hda
{
///
/// A collection of item attribute values passed to write or returned from a read operation.
///
[Serializable]
public class TsCHdaItemAttributeCollection : OpcItem, IOpcResult, ITsCHdaActualTime, IList
{
#region Fields
private DateTime startTime_ = DateTime.MinValue;
private DateTime endTime_ = DateTime.MinValue;
private ArrayList attributes_ = new ArrayList();
private OpcResult result_ = OpcResult.S_OK;
#endregion
#region Constructors, Destructor, Initialization
///
/// Initializes object with the default values.
///
public TsCHdaItemAttributeCollection() { }
///
/// Initializes object with the specified ItemIdentifier object.
///
public TsCHdaItemAttributeCollection(OpcItem item) : base(item) { }
///
/// Initializes object with the specified ItemAttributeCollection object.
///
public TsCHdaItemAttributeCollection(TsCHdaItemAttributeCollection item)
: base(item)
{
attributes_ = new ArrayList(item.attributes_.Count);
foreach (TsCHdaAttributeValueCollection value in item.attributes_)
{
if (value != null)
{
attributes_.Add(value.Clone());
}
}
}
#endregion
#region Properties
///
/// Accessor for elements in the collection.
///
public TsCHdaAttributeValueCollection this[int index]
{
get => (TsCHdaAttributeValueCollection)attributes_[index];
set => attributes_[index] = value;
}
#endregion
#region IOpcResult Members
///
/// The error id for the result of an operation on an item.
///
public OpcResult Result
{
get => result_;
set => result_ = value;
}
///
/// Vendor specific diagnostic information (not the localized error text).
///
public string DiagnosticInfo { get; set; }
#endregion
#region IActualTime Members
///
/// The actual start time used by a server while processing a request.
/// The ApplicationInstance.TimeAsUtc property defines
/// the time format (UTC or local time).
///
public DateTime StartTime
{
get => startTime_;
set => startTime_ = value;
}
///
/// The actual end time used by a server while processing a request.
/// The ApplicationInstance.TimeAsUtc property defines
/// the time format (UTC or local time).
///
public DateTime EndTime
{
get => endTime_;
set => endTime_ = value;
}
#endregion
#region ICloneable Members
///
/// Creates a deep copy of the object.
///
public override object Clone()
{
var collection = (TsCHdaItemAttributeCollection)base.Clone();
collection.attributes_ = new ArrayList(attributes_.Count);
foreach (TsCHdaAttributeValueCollection value in attributes_)
{
collection.attributes_.Add(value.Clone());
}
return collection;
}
#endregion
#region ICollection Members
///
/// Indicates whether access to the ICollection is synchronized (thread-safe).
///
public bool IsSynchronized => false;
///
/// Gets the number of objects in the collection.
///
public int Count => attributes_?.Count ?? 0;
///
/// Copies the objects to an Array, starting at a the specified index.
///
/// The one-dimensional Array that is the destination for the objects.
/// The zero-based index in the Array at which copying begins.
public void CopyTo(Array array, int index)
{
attributes_?.CopyTo(array, index);
}
///
/// Copies the objects to an Array, starting at a the specified index.
///
/// The one-dimensional Array that is the destination for the objects.
/// The zero-based index in the Array at which copying begins.
public void CopyTo(TsCHdaAttributeValueCollection[] array, int index)
{
CopyTo((Array)array, index);
}
///
/// Indicates whether access to the ICollection is synchronized (thread-safe).
///
public object SyncRoot => this;
#endregion
#region IEnumerable Members
///
/// Returns an enumerator that can iterate through a collection.
///
/// An IEnumerator that can be used to iterate through the collection.
public IEnumerator GetEnumerator()
{
return attributes_.GetEnumerator();
}
#endregion
#region IList Members
///
/// Gets a value indicating whether the IList is read-only.
///
public bool IsReadOnly => false;
///
/// Gets or sets the element at the specified index.
///
object IList.this[int index]
{
get => attributes_[index];
set
{
if (!(value is TsCHdaAttributeValueCollection))
{
throw new ArgumentException("May only add AttributeValueCollection objects into the collection.");
}
attributes_[index] = value;
}
}
///
/// Removes the IList item at the specified index.
///
/// The zero-based index of the item to remove.
public void RemoveAt(int index)
{
attributes_.RemoveAt(index);
}
///
/// Inserts an item to the IList at the specified position.
///
/// The zero-based index at which value should be inserted.
/// The Object to insert into the IList.
public void Insert(int index, object value)
{
if (!(value is TsCHdaAttributeValueCollection))
{
throw new ArgumentException("May only add AttributeValueCollection objects into the collection.");
}
attributes_.Insert(index, value);
}
///
/// Removes the first occurrence of a specific object from the IList.
///
/// The Object to remove from the IList.
public void Remove(object value)
{
attributes_.Remove(value);
}
///
/// Determines whether the IList contains a specific value.
///
/// The Object to locate in the IList.
/// true if the Object is found in the IList; otherwise, false.
public bool Contains(object value)
{
return attributes_.Contains(value);
}
///
/// Removes all items from the IList.
///
public void Clear()
{
attributes_.Clear();
}
///
/// Determines the index of a specific item in the IList.
///
/// The Object to locate in the IList.
/// The index of value if found in the list; otherwise, -1.
public int IndexOf(object value)
{
return attributes_.IndexOf(value);
}
///
/// Adds an item to the IList.
///
/// The Object to add to the IList.
/// The position into which the new element was inserted.
public int Add(object value)
{
if (!(value is TsCHdaAttributeValueCollection))
{
throw new ArgumentException("May only add AttributeValueCollection objects into the collection.");
}
return attributes_.Add(value);
}
///
/// Indicates whether the IList has a fixed size.
///
public bool IsFixedSize => false;
///
/// Inserts an item to the IList at the specified position.
///
/// The zero-based index at which value should be inserted.
/// The Object to insert into the IList.
public void Insert(int index, TsCHdaAttributeValueCollection value)
{
Insert(index, (object)value);
}
///
/// Removes the first occurrence of a specific object from the IList.
///
/// The Object to remove from the IList.
public void Remove(TsCHdaAttributeValueCollection value)
{
Remove((object)value);
}
///
/// Determines whether the IList contains a specific value.
///
/// The Object to locate in the IList.
/// true if the Object is found in the IList; otherwise, false.
public bool Contains(TsCHdaAttributeValueCollection value)
{
return Contains((object)value);
}
///
/// Determines the index of a specific item in the IList.
///
/// The Object to locate in the IList.
/// The index of value if found in the list; otherwise, -1.
public int IndexOf(TsCHdaAttributeValueCollection value)
{
return IndexOf((object)value);
}
///
/// Adds an item to the IList.
///
/// The Object to add to the IList.
/// The position into which the new element was inserted.
public int Add(TsCHdaAttributeValueCollection value)
{
return Add((object)value);
}
#endregion
}
}