예제 #1
0
파일: Symbol.cs 프로젝트: ykebaili/Timos
 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");
            }

            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);
        }
예제 #3
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);
        }