///
/// Copyright (c) 2018 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using TBF.Rig.Generic;
namespace TBF.Rig.Output.DataStorage.UniDataStorageWriter
{
///
/// Provides factory services for the
/// component.
///
///
/// The factory is responsible for creating runtime
/// instances and their corresponding
/// configuration objects.
///
/// The concrete storage technology is not selected by the factory.
/// Technology-specific writer selection is performed later by
/// according to the active configuration.
///
/// Consequently, database write modes such as INSERT, UPDATE and
/// stored procedure execution do not require separate component
/// factories.
///
public class Factory : IComponentFactory
{
///
/// Gets the component class name used by the TBF component framework.
///
///
/// The namespace prefix is removed for backward compatibility with
/// existing component configurations.
///
public string ClassName
{
get { return GetType().Namespace.Substring(8); }
}
///
/// Returns the component class name.
///
///
/// The value of .
///
public override string ToString()
{
return ClassName;
}
///
/// Creates a default runtime instance of the
/// component.
///
///
/// A new configured with a default
/// instance.
///
///
/// The dummy component is primarily used by the component framework
/// for discovery and configuration purposes.
///
public IComponent DummyComponent()
{
return new Writer(
new WriterCfg("UniDataStorageWriter", this));
}
///
/// Creates a runtime from an existing
/// component configuration.
///
///
/// Component configuration expected to be a
/// instance.
///
///
/// Collection of already created components supplied by the
/// component framework.
///
///
/// A new instance using the supplied configuration.
///
///
/// Thrown when is not a valid
/// instance.
///
///
/// The collection is currently not
/// required by , but remains part of the factory
/// contract defined by .
///
public IComponent GetComponent(
IComponentCfg cfg,
IList components)
{
WriterCfg writerCfg = cfg as WriterCfg;
if (writerCfg == null)
{
throw new ArgumentException(
"Invalid config for UniDataStorageWriter");
}
return new Writer(writerCfg);
}
///
/// Creates the default configuration for the
/// component.
///
///
/// A new default instance.
///
public IComponentCfg DefaultConfig()
{
return new WriterCfg(
"UniDataStorageWriter",
this);
}
///
/// Creates a instance from a persisted
/// component database entity.
///
///
/// Persisted component entity containing serialized configuration data.
///
///
/// Deserialized component configuration compatible with
/// .
///
///
/// Configuration deserialization is delegated to
/// .
///
public IComponentCfg CmpntCfgFromCmpntEntity(
Config.Entities.Component component)
{
return ComponentCfgBase.CreateFromDbEntity(
WriterCfg.Serializer,
component,
this);
}
}
}