#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
{
///
/// The description of an item aggregate supported by the server.
///
[Serializable]
public class TsCHdaAggregateCollection : ICloneable, ICollection
{
#region Fields
private TsCHdaAggregate[] hdaAggregates_ = new TsCHdaAggregate[0];
#endregion
#region Constructors, Destructor, Initialization
///
/// Creates an empty collection.
///
public TsCHdaAggregateCollection()
{
// do nothing.
}
///
/// Initializes the object with any Aggregates contained in the collection.
///
/// A collection containing aggregate descriptions.
public TsCHdaAggregateCollection(ICollection collection)
{
Init(collection);
}
#endregion
#region Properties
///
/// Returns the aggregate at the specified index.
///
public TsCHdaAggregate this[int index]
{
get => hdaAggregates_[index];
set => hdaAggregates_[index] = value;
}
#endregion
#region Public Methods
///
/// Returns the first aggregate with the specified id.
///
public TsCHdaAggregate Find(int id)
{
foreach (var aggregate in hdaAggregates_)
{
if (aggregate.Id == id)
{
return aggregate;
}
}
return null;
}
///
/// Initializes the object with any aggregates contained in the collection.
///
/// A collection containing aggregate descriptions.
public void Init(ICollection collection)
{
Clear();
if (collection != null)
{
var aggregates = new ArrayList(collection.Count);
foreach (var value in collection)
{
if (value.GetType() == typeof(TsCHdaAggregate))
{
aggregates.Add(OpcConvert.Clone(value));
}
}
hdaAggregates_ = (TsCHdaAggregate[])aggregates.ToArray(typeof(TsCHdaAggregate));
}
}
///
/// Removes all aggregates in the collection.
///
public void Clear()
{
hdaAggregates_ = new TsCHdaAggregate[0];
}
#endregion
#region ICloneable Members
///
/// Creates a deep copy of the object.
///
public virtual object Clone()
{
return new TsCHdaAggregateCollection(this);
}
#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 => hdaAggregates_?.Length ?? 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)
{
hdaAggregates_?.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(TsCHdaAggregate[] 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 hdaAggregates_.GetEnumerator();
}
#endregion
}
}