Beispiel #1
0
        async void PollingThread()
        {
            try
            {
                while (run)
                {
                    var s = await api.TagList();

                    var lines = s.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var line in lines)
                    {
                        if (line == ProtocolMessages.NoTags)
                        {
                            continue;
                        }
                        if (TagParser.TryParse(line, out var t))
                        {
                            tags.OnNext(t);
                        }
                        else
                        {
                            unparsedMessages.OnNext(line);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("{ex}", ex);
            }
        }
Beispiel #2
0
        async void PollingThread()
        {
            var lastHeartbeat = DateTime.UtcNow;

            while (run)
            {
                try
                {
                    var s = await api.TagList();

                    var lines = s.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var line in lines)
                    {
                        if (line == ProtocolMessages.NoTags)
                        {
                            continue;
                        }
                        if (TagParser.TryParse(line, out var t))
                        {
                            t.DiscoveryTime = t.LastSeenTime = DateTime.UtcNow;
                            inventoryResults.Enqueue(t);
                        }
                        else
                        {
                            unparsedMessages.OnNext(line);
                        }
                    }
                    if (DateTime.UtcNow - lastHeartbeat > TimeSpan.FromSeconds(1))
                    {
                        inventoryResults.Enqueue(null);
                        lastHeartbeat = DateTime.UtcNow;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Warning(ex, "TagPoller stopped");
                    errors.OnNext(ex);
                }
            }
        }