/// <summary>
        ///  Initializes a new instance of the <see cref="UaPubSubApplication"/> class.
        /// </summary>
        /// <param name="dataStore"> The current implementation of <see cref="IUaPubSubDataStore"/> used by this instance of pub sub application</param>
        /// <param name="applicationId"> The application id for instance.</param>
        private UaPubSubApplication(IUaPubSubDataStore dataStore = null, string applicationId = null)
        {
            m_uaPubSubConnections = new List <IUaPubSubConnection>();

            if (dataStore != null)
            {
                m_dataStore = dataStore;
            }
            else
            {
                m_dataStore = new UaPubSubDataStore();
            }

            if (!String.IsNullOrEmpty(applicationId))
            {
                ApplicationId = applicationId;
            }
            else
            {
                ApplicationId = $"opcua:{System.Net.Dns.GetHostName()}:{new Random().Next().ToString("D10")}";
            }

            m_dataCollector        = new DataCollector(m_dataStore);
            m_uaPubSubConfigurator = new UaPubSubConfigurator();
            m_uaPubSubConfigurator.ConnectionAdded         += UaPubSubConfigurator_ConnectionAdded;
            m_uaPubSubConfigurator.ConnectionRemoved       += UaPubSubConfigurator_ConnectionRemoved;
            m_uaPubSubConfigurator.PublishedDataSetAdded   += UaPubSubConfigurator_PublishedDataSetAdded;
            m_uaPubSubConfigurator.PublishedDataSetRemoved += UaPubSubConfigurator_PublishedDataSetRemoved;

            Utils.Trace("An instance of UaPubSubApplication was created.");
        }
        /// <summary>
        /// Creates a new <see cref="UaPubSubApplication"/> by loading the configuration parameters from the
        /// specified <see cref="PubSubConfigurationDataType"/> parameter.
        /// </summary>
        /// <param name="pubSubConfiguration">The configuration object.</param>
        /// <param name="dataStore"> The current implementation of <see cref="IUaPubSubDataStore"/> used by this instance of pub sub application</param>
        /// <returns>New instance of <see cref="UaPubSubApplication"/></returns>
        public static UaPubSubApplication Create(PubSubConfigurationDataType pubSubConfiguration = null,
                                                 IUaPubSubDataStore dataStore = null)
        {
            // if no argument received, start with empty configuration
            if (pubSubConfiguration == null)
            {
                pubSubConfiguration = new PubSubConfigurationDataType();
            }

            UaPubSubApplication uaPubSubApplication = new UaPubSubApplication(dataStore);

            uaPubSubApplication.m_uaPubSubConfigurator.LoadConfiguration(pubSubConfiguration);
            return(uaPubSubApplication);
        }
        /// <summary>
        /// Creates a new <see cref="UaPubSubApplication"/> by loading the configuration parameters from the specified path.
        /// </summary>
        /// <param name="configFilePath">The path of the configuration path.</param>
        /// <param name="dataStore"> The current implementation of <see cref="IUaPubSubDataStore"/> used by this instance of pub sub application</param>
        /// <returns>New instance of <see cref="UaPubSubApplication"/></returns>
        public static UaPubSubApplication Create(string configFilePath, IUaPubSubDataStore dataStore = null)
        {
            // validate input argument
            if (configFilePath == null)
            {
                throw new ArgumentException(nameof(configFilePath));
            }
            if (!File.Exists(configFilePath))
            {
                throw new ArgumentException("The specified file {0} does not exist", configFilePath);
            }
            PubSubConfigurationDataType pubSubConfiguration = UaPubSubConfigurationHelper.LoadConfiguration(configFilePath);

            return(Create(pubSubConfiguration, dataStore));
        }
 /// <summary>
 ///  Initializes a new instance of the <see cref="UaPubSubApplication"/> class.
 /// </summary>
 /// <param name="dataStore"> The current implementation of <see cref="IUaPubSubDataStore"/> used by this instance of pub sub application</param>
 private UaPubSubApplication(IUaPubSubDataStore dataStore = null)
 {
     m_uaPubSubConnections = new List <IUaPubSubConnection>();
     if (dataStore != null)
     {
         m_dataStore = dataStore;
     }
     else
     {
         m_dataStore = new UaPubSubDataStore();
     }
     m_dataCollector        = new DataCollector(m_dataStore);
     m_uaPubSubConfigurator = new UaPubSubConfigurator();
     m_uaPubSubConfigurator.ConnectionAdded         += UaPubSubConfigurator_ConnectionAdded;
     m_uaPubSubConfigurator.ConnectionRemoved       += UaPubSubConfigurator_ConnectionRemoved;
     m_uaPubSubConfigurator.PublishedDataSetAdded   += UaPubSubConfigurator_PublishedDataSetAdded;
     m_uaPubSubConfigurator.PublishedDataSetRemoved += UaPubSubConfigurator_PublishedDataSetRemoved;
 }
 /// <summary>
 /// Create new instance of <see cref="DataCollector"/>.
 /// </summary>
 /// <param name="dataStore">Reference to the <see cref="IUaPubSubDataStore"/> that will be used to collect data.</param>
 public DataCollector(IUaPubSubDataStore dataStore)
 {
     m_dataStore = dataStore;
     m_publishedDataSetsByName = new Dictionary <string, PublishedDataSetDataType>();
 }
 /// <summary>
 /// Creates a new <see cref="UaPubSubApplication"/> and associates it with a custom implementation of <see cref="IUaPubSubDataStore"/>.
 /// </summary>
 /// <param name="dataStore"> The current implementation of <see cref="IUaPubSubDataStore"/> used by this instance of pub sub application</param>
 /// <returns>New instance of <see cref="UaPubSubApplication"/></returns>
 public static UaPubSubApplication Create(IUaPubSubDataStore dataStore)
 {
     return(Create(new PubSubConfigurationDataType(), dataStore));
 }
Exemple #7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="pubSubApplication"></param>
 public PublishedValuesWrites(UaPubSubApplication uaPubSubApplication)
 {
     m_publishedDataSets = uaPubSubApplication.UaPubSubConfigurator.PubSubConfiguration.PublishedDataSets;
     m_dataStore         = uaPubSubApplication.DataStore;
 }