Exemple #1
0
 internal void Validate(bool condition, string message)
 {
     if (condition)
     {
         throw MibException.Create(message, this);
     }
 }
Exemple #2
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);
        }