private void HandleEedToken(EedToken token)
        {
            var isSevere = token.Severity > 10;

            if (isSevere)
            {
                _foundSevereError = true;
            }

            var error = new AseError
            {
                IsError       = isSevere,
                IsFromServer  = true,
                Message       = token.Message,
                MessageNumber = token.MessageNumber,
                ProcName      = token.ProcedureName,
                State         = token.State,
                TranState     = (int)token.TransactionStatus,
                Status        = (int)token.Status,
                Severity      = token.Severity,
                ServerName    = token.ServerName,
                SqlState      = Encoding.ASCII.GetString(token.SqlState),
                IsFromClient  = false,
                IsInformation = !isSevere,
                IsWarning     = false,
                LineNum       = token.LineNumber
            };

            _allErrors.Add(error);

            // if we have not encountered any data yet, then send messages straight out.
            if (_current == null)
            {
                _eventNotifier?.NotifyInfoMessage(new AseErrorCollection(error), error.Message);
            }
            // else if we have encountered any data, then add the messages to the data reader so that they are returned with data/message order preserved.
            else
            {
                _current.Messages.Add(new MessageResult {
                    Errors = new AseErrorCollection(error), Message = error.Message
                });
            }

            var msgType = isSevere
                ? "ERROR"
                : "INFO ";

            var formatted = $"{msgType} [{token.Severity}] [L:{token.LineNumber}]: {token.Message}";

            if (formatted.EndsWith("\n"))
            {
                Logger.Instance?.Write(formatted);
            }
            else
            {
                Logger.Instance?.WriteLine(formatted);
            }
        }
Example #2
0
        public void Handle(IToken token)
        {
            switch (token)
            {
            case EedToken t:

                var isSevere = t.Severity > 10;

                if (isSevere)
                {
                    _foundSevereError = true;
                }

                var error = new AseError
                {
                    IsError       = isSevere,
                    IsFromServer  = true,
                    Message       = t.Message,
                    MessageNumber = t.MessageNumber,
                    ProcName      = t.ProcedureName,
                    State         = t.State,
                    TranState     = (int)t.TransactionStatus,
                    Status        = (int)t.Status,
                    Severity      = t.Severity,
                    ServerName    = t.ServerName,
                    SqlState      = Encoding.ASCII.GetString(t.SqlState),
                    IsFromClient  = false,
                    IsInformation = !isSevere,
                    IsWarning     = false,
                    LineNum       = t.LineNumber
                };

                _allErrors.Add(error);
                _eventNotifier?.NotifyInfoMessage(new AseErrorCollection(error), error.Message);

                var msgType = isSevere
                        ? "ERROR"
                        : "INFO ";

                var formatted = $"{msgType} [{t.Severity}] [L:{t.LineNumber}]: {t.Message}";

                if (formatted.EndsWith("\n"))
                {
                    Logger.Instance?.Write(formatted);
                }
                else
                {
                    Logger.Instance?.WriteLine(formatted);
                }
                break;

            default:
                return;
            }
        }
Example #3
0
        /// <summary>
        /// Send the messages to the event listener, removing them from the collection as they are sent.
        /// </summary>
        /// <param name="messages">The messages to dispatch.</param>
        private void DispatchMessages(IList <MessageResult> messages)
        {
            while (messages.Count > 0)
            {
                // Grab the next message.
                var message = messages[0];

                // Send the event to any listeners.
                _eventNotifier?.NotifyInfoMessage(message.Errors, message.Message);

                // Remove the message so it can't be processed again.
                messages.RemoveAt(0);
            }
        }
        public void Handle(IToken token)
        {
            switch (token)
            {
            case IFormatToken format:
                ReturnCurrent();
                _current = new TableResult
                {
                    Formats = format.Formats
                };
                _hasSentCurrent = false;
                break;

            case RowToken row:
                _current?.Rows.Add(new RowResult
                {
                    Items = row.Values
                });
                break;

            case DoneToken _:
            case DoneInProcToken _:
            case DoneProcToken _:
                ReturnCurrent();
                break;

            case EedToken t:

                var isSevere = t.Severity > 10;

                if (isSevere)
                {
                    _foundSevereError = true;
                }

                var error = new AseError
                {
                    IsError       = isSevere,
                    IsFromServer  = true,
                    Message       = t.Message,
                    MessageNumber = t.MessageNumber,
                    ProcName      = t.ProcedureName,
                    State         = t.State,
                    TranState     = (int)t.TransactionStatus,
                    Status        = (int)t.Status,
                    Severity      = t.Severity,
                    ServerName    = t.ServerName,
                    SqlState      = Encoding.ASCII.GetString(t.SqlState),
                    IsFromClient  = false,
                    IsInformation = !isSevere,
                    IsWarning     = false,
                    LineNum       = t.LineNumber
                };

                _allErrors.Add(error);

                // if we have not encountered any data yet, then send messages straight out.
                if (_current == null)
                {
                    _eventNotifier?.NotifyInfoMessage(new AseErrorCollection(error), error.Message);
                }
                // else if we have encountered any data, then add the messages to the data reader so that they are returned with data/message order preserved.
                else
                {
                    _current.Messages.Add(new MessageResult {
                        Errors = new AseErrorCollection(error), Message = error.Message
                    });
                }

                var msgType = isSevere
                        ? "ERROR"
                        : "INFO ";

                var formatted = $"{msgType} [{t.Severity}] [L:{t.LineNumber}]: {t.Message}";

                if (formatted.EndsWith("\n"))
                {
                    Logger.Instance?.Write(formatted);
                }
                else
                {
                    Logger.Instance?.WriteLine(formatted);
                }
                break;
            }
        }