#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.Generic;
using System.Runtime.Serialization;
#endregion
namespace Technosoftware.DaAeHdaClient
{
///
/// The default class used to instantiate server objects.
///
[Serializable]
public class OpcFactory : IOpcFactory, ISerializable, ICloneable
{
#region Class Names
///
/// A set of names for fields used in serialization.
///
private class Names
{
internal const string SystemType = "SystemType";
}
#endregion
#region Constructors, Destructor, Initialization
///
/// Initializes the object with the type of the servers it can instantiate.
///
/// The System.Type of the server object that the factory can create.
public OpcFactory(Type systemType)
{
SystemType = systemType;
}
///
/// Maybe overridden to release unmanaged resources.
///
public virtual void Dispose()
{
// do nothing.
}
///
/// Construct a server by de-serializing its OpcUrl from the stream.
///
protected OpcFactory(SerializationInfo info, StreamingContext context)
{
SystemType = (Type)info.GetValue(Names.SystemType, typeof(Type));
}
#endregion
#region Properties
///
/// The system type used to instantiate the remote server object.
///
protected Type SystemType { get; set; }
///
/// Can be used to force OPC DA 2.0 even if OPC DA 3.0 server features are available
///
public bool ForceDa20Usage { get; set; }
///
/// List of supported OPC specifications
///
public IList SupportedSpecifications { get; set; }
#endregion
#region ISerializable
///
/// Serializes a server into a stream.
///
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue(Names.SystemType, SystemType);
}
#endregion
#region ICloneable
///
/// Returns a clone of the factory.
///
public virtual object Clone()
{
return MemberwiseClone();
}
#endregion
#region IOpcFactory
///
/// Creates a new instance of the server.
///
public virtual IOpcServer CreateInstance(OpcUrl url, OpcConnectData connectData)
{
var server = (IOpcServer)Activator.CreateInstance(SystemType, new object[] { url, connectData });
return server;
}
#endregion
}
}