/// <summary>
            /// Create new instance of <see cref="MetaDataState"/>
            /// </summary>
            /// <param name="dataSetWriter"></param>
            public MetaDataState(DataSetWriterDataType dataSetWriter)
            {
                DataSetWriter = dataSetWriter;
                LastSendTime  = DateTime.MinValue;

                BrokerDataSetWriterTransportDataType transport =
                    ExtensionObject.ToEncodeable(DataSetWriter.TransportSettings)
                    as BrokerDataSetWriterTransportDataType;

                MetaDataUpdateTime = transport?.MetaDataUpdateTime ?? 0;
            }
Пример #2
0
        /// <summary>
        /// Creates a PubSubConfiguration object for MQTT & Json programmatically.
        /// </summary>
        /// <returns></returns>
        private static PubSubConfigurationDataType CreatePublisherConfiguration_MqttJson(string urlAddress)
        {
            // Define a PubSub connection with PublisherId 100
            PubSubConnectionDataType pubSubConnection1 = new PubSubConnectionDataType();

            pubSubConnection1.Name                = "Publisher Connection3 MQTT Json";
            pubSubConnection1.Enabled             = true;
            pubSubConnection1.PublisherId         = (UInt16)2;
            pubSubConnection1.TransportProfileUri = Profiles.PubSubMqttJsonTransport;
            NetworkAddressUrlDataType address = new NetworkAddressUrlDataType();

            // Specify the local Network interface name to be used
            // e.g. address.NetworkInterface = "Ethernet";
            // Leave empty to publish on all available local interfaces.
            address.NetworkInterface = String.Empty;
            address.Url = urlAddress;
            pubSubConnection1.Address = new ExtensionObject(address);

            // Configure the mqtt specific configuration with the MQTTbroker
            ITransportProtocolConfiguration mqttConfiguration = new MqttClientProtocolConfiguration(version: EnumMqttProtocolVersion.V500);

            pubSubConnection1.ConnectionProperties = mqttConfiguration.ConnectionProperties;

            string brokerQueueName = "Json_WriterGroup_1";
            string brokerMetaData  = "$Metadata";

            #region Define WriterGroup1 - Json

            WriterGroupDataType writerGroup1 = new WriterGroupDataType();
            writerGroup1.Name                  = "WriterGroup 1";
            writerGroup1.Enabled               = true;
            writerGroup1.WriterGroupId         = 1;
            writerGroup1.PublishingInterval    = 5000;
            writerGroup1.KeepAliveTime         = 5000;
            writerGroup1.MaxNetworkMessageSize = 1500;

            JsonWriterGroupMessageDataType jsonMessageSettings = new JsonWriterGroupMessageDataType()
            {
                NetworkMessageContentMask = (uint)(JsonNetworkMessageContentMask.NetworkMessageHeader
                                                   | JsonNetworkMessageContentMask.DataSetMessageHeader
                                                   | JsonNetworkMessageContentMask.PublisherId
                                                   | JsonNetworkMessageContentMask.DataSetClassId
                                                   | JsonNetworkMessageContentMask.ReplyTo)
            };

            writerGroup1.MessageSettings   = new ExtensionObject(jsonMessageSettings);
            writerGroup1.TransportSettings = new ExtensionObject(new BrokerWriterGroupTransportDataType()
            {
                QueueName = brokerQueueName,
            }
                                                                 );

            // Define DataSetWriter 'Simple' Variant encoding
            DataSetWriterDataType dataSetWriter1 = new DataSetWriterDataType();
            dataSetWriter1.Name                    = "Writer Variant Encoding";
            dataSetWriter1.DataSetWriterId         = 1;
            dataSetWriter1.Enabled                 = true;
            dataSetWriter1.DataSetFieldContentMask = 0;// Variant encoding;
            dataSetWriter1.DataSetName             = "Simple";
            dataSetWriter1.KeyFrameCount           = 1;

            JsonDataSetWriterMessageDataType jsonDataSetWriterMessage = new JsonDataSetWriterMessageDataType()
            {
                DataSetMessageContentMask = (uint)(JsonDataSetMessageContentMask.DataSetWriterId
                                                   | JsonDataSetMessageContentMask.MetaDataVersion
                                                   | JsonDataSetMessageContentMask.SequenceNumber
                                                   | JsonDataSetMessageContentMask.Status
                                                   | JsonDataSetMessageContentMask.Timestamp),
            };

            dataSetWriter1.MessageSettings = new ExtensionObject(jsonDataSetWriterMessage);

            BrokerDataSetWriterTransportDataType jsonDataSetWriterTransport = new BrokerDataSetWriterTransportDataType()
            {
                QueueName          = brokerQueueName,
                MetaDataQueueName  = $"{brokerQueueName}/{brokerMetaData}",
                MetaDataUpdateTime = 10000
            };
            dataSetWriter1.TransportSettings = new ExtensionObject(jsonDataSetWriterTransport);

            writerGroup1.DataSetWriters.Add(dataSetWriter1);

            // Define DataSetWriter 'Simple' - Variant encoding
            DataSetWriterDataType dataSetWriter2 = new DataSetWriterDataType();
            dataSetWriter2.Name                    = "Writer RawData Encoding";
            dataSetWriter2.DataSetWriterId         = 2;
            dataSetWriter2.Enabled                 = true;
            dataSetWriter2.DataSetFieldContentMask = (uint)DataSetFieldContentMask.RawData;
            dataSetWriter2.DataSetName             = "AllTypes";
            dataSetWriter2.KeyFrameCount           = 1;

            jsonDataSetWriterMessage = new JsonDataSetWriterMessageDataType()
            {
                DataSetMessageContentMask = (uint)(JsonDataSetMessageContentMask.DataSetWriterId
                                                   | JsonDataSetMessageContentMask.SequenceNumber
                                                   | JsonDataSetMessageContentMask.Status
                                                   | JsonDataSetMessageContentMask.Timestamp),
            };
            dataSetWriter2.MessageSettings   = new ExtensionObject(jsonDataSetWriterMessage);
            dataSetWriter2.TransportSettings = new ExtensionObject(jsonDataSetWriterTransport);
            writerGroup1.DataSetWriters.Add(dataSetWriter2);

            pubSubConnection1.WriterGroups.Add(writerGroup1);
            #endregion

            // Define PublishedDataSet Simple
            PublishedDataSetDataType publishedDataSetSimple = CreatePublishedDataSetSimple();

            // Define PublishedDataSet AllTypes
            PublishedDataSetDataType publishedDataSetAllTypes = CreatePublishedDataSetAllTypes();

            //create  the PubSub configuration root object
            PubSubConfigurationDataType pubSubConfiguration = new PubSubConfigurationDataType();
            pubSubConfiguration.Connections = new PubSubConnectionDataTypeCollection()
            {
                pubSubConnection1
            };
            pubSubConfiguration.PublishedDataSets = new PublishedDataSetDataTypeCollection()
            {
                publishedDataSetSimple, publishedDataSetAllTypes
            };

            return(pubSubConfiguration);
        }
Пример #3
0
        /// <summary>
        /// Creates a PubSubConfiguration object for MQTT & UADP programmatically.
        /// </summary>
        /// <returns></returns>
        private static PubSubConfigurationDataType CreatePublisherConfiguration_MqttUadp(string urlAddress)
        {
            // Define a PubSub connection with PublisherId 3
            PubSubConnectionDataType pubSubConnection1 = new PubSubConnectionDataType();

            pubSubConnection1.Name                = "Publisher Connection MQTT UADP";
            pubSubConnection1.Enabled             = true;
            pubSubConnection1.PublisherId         = (UInt16)3;
            pubSubConnection1.TransportProfileUri = Profiles.PubSubMqttUadpTransport;
            NetworkAddressUrlDataType address = new NetworkAddressUrlDataType();

            // Specify the local Network interface name to be used
            // e.g. address.NetworkInterface = "Ethernet";
            // Leave empty to publish on all available local interfaces.
            address.NetworkInterface = String.Empty;
            address.Url = urlAddress;
            pubSubConnection1.Address = new ExtensionObject(address);

            // Configure the mqtt specific configuration with the MQTTbroker
            ITransportProtocolConfiguration mqttConfiguration = new MqttClientProtocolConfiguration(version: EnumMqttProtocolVersion.V500);

            pubSubConnection1.ConnectionProperties = mqttConfiguration.ConnectionProperties;

            string brokerQueueName = "Uadp_WriterGroup_1";
            string brokerMetaData  = "$Metadata";

            #region Define WriterGroup1
            WriterGroupDataType writerGroup1 = new WriterGroupDataType();
            writerGroup1.Name                  = "WriterGroup 1";
            writerGroup1.Enabled               = true;
            writerGroup1.WriterGroupId         = 1;
            writerGroup1.PublishingInterval    = 5000;
            writerGroup1.KeepAliveTime         = 5000;
            writerGroup1.MaxNetworkMessageSize = 1500;
            writerGroup1.HeaderLayoutUri       = "UADP-Cyclic-Fixed";
            UadpWriterGroupMessageDataType uadpMessageSettings = new UadpWriterGroupMessageDataType()
            {
                DataSetOrdering           = DataSetOrderingType.AscendingWriterId,
                GroupVersion              = 0,
                NetworkMessageContentMask = (uint)(UadpNetworkMessageContentMask.PublisherId
                                                   | UadpNetworkMessageContentMask.GroupHeader
                                                   | UadpNetworkMessageContentMask.WriterGroupId
                                                   | UadpNetworkMessageContentMask.PayloadHeader
                                                   | UadpNetworkMessageContentMask.GroupVersion
                                                   | UadpNetworkMessageContentMask.NetworkMessageNumber
                                                   | UadpNetworkMessageContentMask.SequenceNumber)
            };

            writerGroup1.MessageSettings = new ExtensionObject(uadpMessageSettings);
            // initialize Broker transport settings
            writerGroup1.TransportSettings = new ExtensionObject(new BrokerWriterGroupTransportDataType()
            {
                QueueName = brokerQueueName,
            });

            // Define DataSetWriter 'Simple'
            DataSetWriterDataType dataSetWriter1 = new DataSetWriterDataType();
            dataSetWriter1.Name                    = "Writer 1";
            dataSetWriter1.DataSetWriterId         = 1;
            dataSetWriter1.Enabled                 = true;
            dataSetWriter1.DataSetFieldContentMask = (uint)DataSetFieldContentMask.RawData;
            dataSetWriter1.DataSetName             = "Simple";
            dataSetWriter1.KeyFrameCount           = 1;
            UadpDataSetWriterMessageDataType uadpDataSetWriterMessage = new UadpDataSetWriterMessageDataType()
            {
                ConfiguredSize            = 32,
                DataSetOffset             = 15,
                NetworkMessageNumber      = 1,
                DataSetMessageContentMask = (uint)(UadpDataSetMessageContentMask.Status | UadpDataSetMessageContentMask.SequenceNumber),
            };

            dataSetWriter1.MessageSettings = new ExtensionObject(uadpDataSetWriterMessage);
            BrokerDataSetWriterTransportDataType uadpDataSetWriterTransport = new BrokerDataSetWriterTransportDataType()
            {
                QueueName          = brokerQueueName,
                MetaDataQueueName  = $"{brokerQueueName}/{brokerMetaData}",
                MetaDataUpdateTime = 60000
            };
            dataSetWriter1.TransportSettings = new ExtensionObject(uadpDataSetWriterTransport);


            writerGroup1.DataSetWriters.Add(dataSetWriter1);

            // Define DataSetWriter 'AllTypes'
            DataSetWriterDataType dataSetWriter2 = new DataSetWriterDataType();
            dataSetWriter2.Name                    = "Writer 2";
            dataSetWriter2.DataSetWriterId         = 2;
            dataSetWriter2.Enabled                 = true;
            dataSetWriter2.DataSetFieldContentMask = (uint)DataSetFieldContentMask.RawData;
            dataSetWriter2.DataSetName             = "AllTypes";
            dataSetWriter2.KeyFrameCount           = 1;
            uadpDataSetWriterMessage               = new UadpDataSetWriterMessageDataType()
            {
                ConfiguredSize            = 32,
                DataSetOffset             = 47,
                NetworkMessageNumber      = 1,
                DataSetMessageContentMask = (uint)(UadpDataSetMessageContentMask.Status | UadpDataSetMessageContentMask.SequenceNumber),
            };

            dataSetWriter2.MessageSettings = new ExtensionObject(uadpDataSetWriterMessage);

            dataSetWriter2.TransportSettings = new ExtensionObject(uadpDataSetWriterTransport);
            writerGroup1.DataSetWriters.Add(dataSetWriter2);

            pubSubConnection1.WriterGroups.Add(writerGroup1);
            #endregion

            //  Define PublishedDataSet Simple
            PublishedDataSetDataType publishedDataSetSimple = CreatePublishedDataSetSimple();

            // Define PublishedDataSet AllTypes
            PublishedDataSetDataType publishedDataSetAllTypes = CreatePublishedDataSetAllTypes();

            //create  the PubSub configuration root object
            PubSubConfigurationDataType pubSubConfiguration = new PubSubConfigurationDataType();
            pubSubConfiguration.Connections = new PubSubConnectionDataTypeCollection()
            {
                pubSubConnection1
            };
            pubSubConfiguration.PublishedDataSets = new PublishedDataSetDataTypeCollection()
            {
                publishedDataSetSimple, publishedDataSetAllTypes
            };

            return(pubSubConfiguration);
        }