Beispiel #1
0
        private void ReadPayload()
        {
            lock (_msg.SyncLock)
            {
                if (!_msg.PayloadRead)
                {
                    int pos = ReadVariableHeader();

                    var nameArray = new AutoExpandingArray();
                    while (pos < _msg.MsgBuffer.Length)
                    {
                        string topicName = Frame.DecodeString(_msg.MsgBuffer, ref pos);
                        nameArray.Add(topicName);
                    }

                    _topicNames = new string[nameArray.Count];
                    for (int i = 0; i < nameArray.Count; i++)
                    {
                        _topicNames[i] = (string)nameArray.GetAt(i);
                    }

                    _msg.PayloadRead = true;
                }
            }
        }
        protected override void OnPublishReceived(MqttNetEventArgs args)
        {
            bool handled = false;
            lock (_subscriptionClients)
            {
                // Send to subscriber clients first
#if !(MF_FRAMEWORK_VERSION_V4_3 || MF_FRAMEWORK_VERSION_V4_2 || WINDOWS_PHONE)
                Parallel.For(0, _subscriptionClients.Count, i =>
#else
                for (int i = 0; i < _subscriptionClients.Count; i++)
#endif
                {
                    var client = (SubscriptionClient)_subscriptionClients.GetAt(i);
                    try
                    {
                        bool clientHandled = client.NotifyPublishReceived(args.Message as MqttPublishMessage);
                        handled = handled | clientHandled;
                    }
                    catch (Exception ex)
                    {
                        Logger.LogException("Protocol", LogLevel.Error, "Exception occured while sending publish event to subscriber.", ex);
                    }
                }