コード例 #1
0
 internal void Validate(bool condition, string message)
 {
     if (condition)
     {
         throw MibException.Create(message, this);
     }
 }
コード例 #2
0
        /// <summary>
        /// Creates a <see cref="MibException"/> with a specific <see cref="Symbol"/>.
        /// </summary>
        /// <param name="message">Message</param>
        /// <param name="symbol">Symbol</param>
        /// <returns></returns>
        public static MibException Create(string message, Symbol symbol)
        {
            if (symbol == null)
            {
                throw new ArgumentNullException("symbol");
            }

            if (String.IsNullOrEmpty(message))
            {
                message = "Unknown MIB Exception";
            }

            message = String.Format(
                "{0} (file: \"{1}\"; row: {2}; column: {3})",
                message,
                symbol.File,
                symbol.Row + 1,
                symbol.Column + 1);

            MibException ex = new MibException(message)
            {
                Symbol = symbol
            };

            return(ex);
        }
コード例 #3
0
 internal void Assert(bool condition, string message)
 {
     if (!condition)
     {
         throw MibException.Create(message, this);
     }
 }
コード例 #4
0
        /// <summary>
        /// Creates a <see cref="MibException"/> with a specific <see cref="Symbol"/>.
        /// </summary>
        /// <param name="message">Message</param>
        /// <param name="symbol">Symbol</param>
        /// <returns></returns>
        public static MibException Create(string message, Symbol symbol)
        {
            if (symbol == null)
            {
                throw new ArgumentNullException("symbol");
            }

            MibException ex = new MibException(message + ". Wrong entity, " + symbol + " in file \"" + symbol.File + "\". row: " + (symbol.Row + 1).ToString(CultureInfo.InvariantCulture) + "; column: " + (symbol.Column + 1).ToString(CultureInfo.InvariantCulture))
            {
                Symbol = symbol
            };

            return(ex);
        }
コード例 #5
0
        internal void ParseOidValue(out string parent, out uint value)
        {
            parent = null;
            value  = 0;
            Symbol previous = null;

            Symbol temp = NextNonEOLSymbol;

            temp.Expect(Symbol.OpenBracket);
            StringBuilder longParent = new StringBuilder();

            temp = NextNonEOLSymbol;
            longParent.Append(temp);

            while ((temp = NextNonEOLSymbol) != null)
            {
                if (temp == Symbol.OpenParentheses)
                {
                    longParent.Append(temp);
                    temp = NextNonEOLSymbol;
                    bool succeed = UInt32.TryParse(temp.ToString(), out value);
                    temp.Validate(!succeed, "not a decimal");
                    longParent.Append(temp);
                    temp = NextNonEOLSymbol;
                    temp.Expect(Symbol.CloseParentheses);
                    longParent.Append(temp);
                    continue;
                }

                if (temp == Symbol.CloseBracket)
                {
                    parent = longParent.ToString();
                    return;
                }

                bool succeeded = UInt32.TryParse(temp.ToString(), out value);
                if (succeeded)
                {
                    // numerical way
                    while ((temp = NextNonEOLSymbol) != Symbol.CloseBracket)
                    {
                        longParent.Append(".").Append(value);
                        succeeded = UInt32.TryParse(temp.ToString(), out value);
                        temp.Validate(!succeeded, "not a decimal");
                    }

                    temp.Expect(Symbol.CloseBracket);
                    parent = longParent.ToString();
                    return;
                }

                longParent.Append(".");
                longParent.Append(temp);
                temp = NextNonEOLSymbol;
                temp.Expect(Symbol.OpenParentheses);
                longParent.Append(temp);
                temp      = NextNonEOLSymbol;
                succeeded = UInt32.TryParse(temp.ToString(), out value);
                temp.Validate(!succeeded, "not a decimal");
                longParent.Append(temp);
                temp = NextNonEOLSymbol;
                temp.Expect(Symbol.CloseParentheses);
                longParent.Append(temp);
                previous = temp;
            }

            throw MibException.Create("end of file reached", previous);
        }
コード例 #6
0
ファイル: MibException.cs プロジェクト: xxjeng/nuxleus
        /// <summary>
        /// Creates a <see cref="MibException"/> with a specific <see cref="Symbol"/>.
        /// </summary>
        /// <param name="message">Message</param>
        /// <param name="symbol">Symbol</param>
        /// <returns></returns>
        public static MibException Create(string message, Symbol symbol)
        {
            if (symbol == null)
            {
                throw new ArgumentNullException("symbol");
            }

            MibException ex = new MibException(message + ". Wrong entity, " + symbol + " in file \"" + symbol.File + "\". row: " + (symbol.Row + 1).ToString(CultureInfo.InvariantCulture) + "; column: " + (symbol.Column + 1).ToString(CultureInfo.InvariantCulture)) { Symbol = symbol };
            return ex;
        }
コード例 #7
0
        public static void ParseOidValue(ISymbolEnumerator symbols, out string parent, out uint value)
        {
            parent = null;
            value  = 0;

            Symbol current = symbols.NextNonEOLSymbol();

            current.Expect(Symbol.OpenBracket);

            Symbol        previous   = null;
            StringBuilder longParent = new StringBuilder();

            current = symbols.NextNonEOLSymbol();
            longParent.Append(current);

            while ((current = symbols.NextNonEOLSymbol()) != null)
            {
                bool succeeded;

                if (current == Symbol.OpenParentheses)
                {
                    longParent.Append(current);

                    current   = symbols.NextNonEOLSymbol();
                    succeeded = UInt32.TryParse(current.ToString(), out value);
                    current.Assert(succeeded, "not a decimal");
                    longParent.Append(current);
                    current = symbols.NextNonEOLSymbol();
                    current.Expect(Symbol.CloseParentheses);
                    longParent.Append(current);
                    continue;
                }

                if (current == Symbol.CloseBracket)
                {
                    parent = longParent.ToString();
                    return;
                }

                succeeded = UInt32.TryParse(current.ToString(), out value);
                if (succeeded)
                {
                    // numerical way
                    while ((current = symbols.NextNonEOLSymbol()) != Symbol.CloseBracket)
                    {
                        longParent.Append(".").Append(value);
                        succeeded = UInt32.TryParse(current.ToString(), out value);
                        current.Assert(succeeded, "not a decimal");
                    }

                    current.Expect(Symbol.CloseBracket);
                    parent = longParent.ToString();
                    return;
                }

                longParent.Append(".");
                longParent.Append(current);
                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.OpenParentheses);
                longParent.Append(current);
                current   = symbols.NextNonEOLSymbol();
                succeeded = UInt32.TryParse(current.ToString(), out value);
                current.Assert(succeeded, "not a decimal");
                longParent.Append(current);
                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.CloseParentheses);
                longParent.Append(current);
                previous = current;
            }

            throw MibException.Create("end of file reached", previous);
        }
コード例 #8
0
ファイル: MibException.cs プロジェクト: plocklsh/lwip
        /// <summary>
        /// Creates a <see cref="MibException"/> with a specific <see cref="Symbol"/>.
        /// </summary>
        /// <param name="message">Message</param>
        /// <param name="symbol">Symbol</param>
        /// <returns></returns>
        public static MibException Create(string message, Symbol symbol)
        {
            if (symbol == null)
            {
                throw new ArgumentNullException("symbol");
            }

            if (String.IsNullOrEmpty(message))
            {
                message = "Unknown MIB Exception";
            }

            message = String.Format(
                "{0} (file: \"{1}\"; row: {2}; column: {3})",
                message,
                symbol.File,
                symbol.Row + 1,
                symbol.Column + 1);

            MibException ex = new MibException(message) { Symbol = symbol };
            return ex;
        }