Пример #1
0
        public static IEnumerable <Error> Validate(this MarkdownDocument doc, string file)
        {
            var descendants = doc.Descendants().OfType <LinkInline>();

            var exception = doc.GetAttachedException();

            if (exception != null)
            {
                yield return(new Error
                {
                    File = file,
                    Message = "Unexpected error occurred while parsing. Please log an issue to https://github.com/madskristensen/MarkdownEditor/issues Reason: " + exception,
                    Line = 0,
                    Column = 0,
                    ErrorCode = "MK0000",
                    Fatal = true,
                    Span = new Span(doc.Span.Start, doc.Span.Length)
                });
            }

            foreach (var link in descendants)
            {
                if (!IsUrlValid(file, link.Url))
                {
                    yield return(LinkError.Create(file, link));
                }
            }
        }
Пример #2
0
 public static void AssertError(this LinkError error)
 {
     if (error == LinkError.Success)
     {
         return;
     }
     throw new LinkException(error);
 }
        public static byte[] LinkError(LinkError code)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteByte((byte)code);
            byte[] buf = packet.ToLinkPacket(LinkMsg.MSG_LINK_ERROR);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
 private void UpdateRetryCount()
 {
     if (_retryBeforeDisconnect > 0)
     {
         _retryBeforeDisconnect -= 1;
     }
     if (_retryBeforeDisconnect == 0)
     {
         LinkError?.Invoke(this, new LinkErrorEventArgs("Too many packets lost"));
     }
 }
 private void EventLoopSafe()
 {
     try
     {
         EventLoop();
     }
     catch (Exception ex)
     {
         _log.Error("exception in event loop thread.", ex);
         LinkError?.Invoke(this, new LinkErrorEventArgs("unexpected error in event loop: " + ex));
     }
     _eventLoopThread = null;
 }
 private void CommunicationLoopSafe()
 {
     try
     {
         CommunicationLoop();
     }
     catch (Exception ex)
     {
         _log.Error("exception in communication loop thread.", ex);
         LinkError?.Invoke(this, new LinkErrorEventArgs("unexpected error in communication loop: " + ex));
     }
     _communicationThread = null;
 }
Пример #7
0
 public LinkException(LinkError error, string message) : base(message) => ErrorCode = error;
Пример #8
0
 public LinkException(LinkError error) : this(error, GetMessage(error))
 {
 }
Пример #9
0
 public LinkException(LinkError error) : base(_GetMessage(error)) => error = _error;
        private void CommunicationLoop()
        {
            _retryBeforeDisconnect = NumberOfRetries;
            _emptyCounter          = 0;
            _waitTime = 0;

            var emptyMessage = new CrtpMessage(0xff, new byte[0]);
            var outMessage   = emptyMessage;

            // Try up to 10 times to enable the safelink mode
            TryEnableSafeLink();

            _comStarted.Set();
            _log.Info("Communication with crazyfly started.");

            while (_isRunning)
            {
                CrtpResponse response = null;
                try
                {
                    response = Send(outMessage);
                }
                catch (Exception ex)
                {
                    _log.Error("error sending message", ex);
                    LinkError?.Invoke(this, new LinkErrorEventArgs("failed to send: " + ex));
                }

                // Analyse the in data packet ...
                if (response == null)
                {
                    _log.Info("Dongle reported ACK status == None");
                    continue;
                }

                TrackLinkQuality(response);
                if (!response.Ack)
                {
                    UpdateRetryCount();
                    if (_retryBeforeDisconnect > 0)
                    {
                        continue;
                    }
                    // else try a next packet to send.
                }
                _retryBeforeDisconnect = NumberOfRetries;

                // after we managed to send the message, set the next one to the ping message again.
                outMessage = emptyMessage;

                if (response.HasContent)
                {
                    _waitTime     = 0;
                    _emptyCounter = 0;
                    lock (_lock)
                    {
                        _log.Debug($"incoming queue count: {_incoming.Count}; enqueue for {response.Content.Port} / {response.Content.Channel}");
                        _incoming.Enqueue(response.Content);
                        while (_incoming.Count > _maxInqueue)
                        {
                            // dequue old messages which are not processed and therefore stale.
                            var old = _incoming.Dequeue();
                            _log.Warn($"Too many old message not processed, drop for port: {old.Port}.");
                        }
                        _waitForInqueue.Set();
                    }
                }
                else
                {
                    _emptyCounter += 1;
                    if (_emptyCounter > 10)
                    {
                        _emptyCounter = 10;
                        // Relaxation time if the last 10 packet where empty
                        _waitTime = 10;
                    }
                    else
                    {
                        // send more ack messages to get more responses and don't wait for
                        // user out messages; start waiting only after 10 empty messages received.
                        _waitTime = 0;
                    }
                }

                _waitForOutqueue.Wait(_waitTime);
                lock (_lock)
                {
                    if (_outgoing.Count > 0)
                    {
                        outMessage = _outgoing.Dequeue();
                    }

                    if (_outgoing.Count == 0)
                    {
                        _waitForOutqueue.Reset();
                    }
                }
            }
            _log.Debug("send loop ended");
        }