Example #1
0
        private JsonObject DeserializeObject(int depth)
        {
            JsonObject dictionary = new JsonObject();

            while (MoveNextNonEmptyChar() && (_current == '"' || _current == '\''))
            {
                string memberName = DeserializeString();
                if (memberName == string.Empty ||
                    !MoveNextNonEmptyChar() ||
                    _current != ':' ||
                    !MoveNextNonEmptyChar() ||
                    _current == '}' || _current == ',')
                {
                    break;
                }

                object propVal = DeserializeNext(depth);
                dictionary.Add(memberName, propVal);

                if (!MoveNextNonEmptyChar() || _current != ',')
                {
                    break;
                }
            }
            if (_current == '}')
            {
                return(dictionary);
            }
            if (_index >= _length)
            {
                throw new JsonException("UnexpectedTermination", _index);
            }
            throw new JsonException("InvalideObject", _index);
        }
Example #2
0
        public void Start(IEnumerable arguments, Dictionary preferences, IEnumerable extensions, Dictionary capabilities, string profile, bool persistant)
        {
            this.Arguments    = arguments;
            this.Preferences  = preferences;
            this.Extensions   = extensions;
            this.Capabilities = capabilities;
            this.Profile      = profile;
            this.Persistant   = persistant;

            string debugAddress;

            if (capabilities.TryGetValue("debuggerAddress", out debugAddress))
            {
                _endpoint = EndPointExt.Parse(debugAddress);
                return;
            }

            _endpoint = EndPointExt.Create(IPAddress.Loopback, false);

            Thread thread = new Thread(RunStart);

            thread.Start();
            thread.Join();
            if (_exception != null)
            {
                throw _exception;
            }
        }
Example #3
0
 public void ShouldProcessDictionary() {
     //Dictionary
     var dict = new Selenium.Dictionary();
     dict.Add("a", 987);
     var resDict = (Dictionary)driver.ExecuteScript("return arguments[0];", dict);
     CollectionAssert.AreEquivalent(dict, resDict);
 }
Example #4
0
        public void ShouldProcessDictionary()
        {
            //Dictionary
            var dict = new Selenium.Dictionary();

            dict.Add("a", 987);
            var resDict = (Dictionary)driver.ExecuteScript("return arguments[0];", dict);

            CollectionAssert.AreEquivalent(dict, resDict);
        }
Example #5
0
        /// <summary>
        /// Parses a collection of key/value.
        /// </summary>
        /// <returns>Json object</returns>
        private static JsonObject ParseObject(byte[] data, ref int index, int depth)
        {
            if (depth-- < 0)
            {
                throw new JsonException(E_DepthLimitExceeded, data, index);
            }

            JsonObject members = new JsonObject();
            int        c       = -1;

            while (++index < data.Length)
            {
                c = PeekChar(data, ref index);
                if (c == '}')
                {
                    return(members);
                }

                string key = ParseQuotedString(data, ref index);

                index++;
                c = PeekChar(data, ref index);
                if (c != ':' || key.Length == 0)
                {
                    break;
                }

                index++;
                object value = ParseNext(data, ref index, depth);
                members.Add(key, value);

                index++;
                c = PeekChar(data, ref index);
                if (c != ',')
                {
                    break;
                }
            }
            if (c == '}')
            {
                return(members);
            }
            if (index >= data.Length)
            {
                throw new JsonException(E_UnexpectedTermination, data, index);
            }
            throw new JsonException(E_InvalidObject, data, index);
        }
Example #6
0
        private void WriteDictionary(int depth, JsonObject dict)
        {
            if (depth-- < 0)
            {
                throw new JsonException(E_DepthLimitExceeded, _buffer, _length);
            }

            WriteByte((byte)'{');
            int len_start = _length;

            foreach (JsonObjectItem item in dict)
            {
                if (_length > len_start)
                {
                    WriteByte((byte)',');
                }
                WriteQuotedString(item.Key.ToString()); //item Key
                WriteByte((byte)':');
                Write(depth, item.Value);               //item Value
            }
            WriteByte((byte)'}');
        }
Example #7
0
        private void SerializeDictionary(JsonObject dict, int depth)
        {
            if (++depth > DEPTH_MAX)
            {
                throw new JsonException("DepthLimitExceeded");
            }

            WriteByte((byte)'{');

            int i = 0;

            foreach (JsonObjectItem item in dict)
            {
                if (i++ > 0)
                {
                    WriteByte((byte)',');
                }
                SerializeString(item.key);          //item name
                WriteByte((byte)':');
                SerializeObject(item.value, depth); //item value
            }
            WriteByte((byte)'}');
        }
Example #8
0
        public void Start(IEnumerable arguments, Dictionary preferences, IEnumerable extensions, Dictionary capabilities, string profile, bool persistant) {
            this.Arguments = arguments;
            this.Preferences = preferences;
            this.Extensions = extensions;
            this.Capabilities = capabilities;
            this.Profile = profile;
            this.Persistant = persistant;

            string debugAddress;
            if (capabilities.TryGetValue("debuggerAddress", out debugAddress)) {
                _endpoint = EndPointExt.Parse(debugAddress);
                return;
            }

            _endpoint = EndPointExt.Create(IPAddress.Loopback, false);

            Thread thread = new Thread(RunStart);
            thread.Start();
            thread.Join();
            if (_exception != null)
                throw _exception;
        }
Example #9
0
        private void Write(int depth, object obj)
        {
            if (obj == null)
            {
                WriteLiteral("null");
                return;
            }

            Type objType = obj.GetType();

            switch (Type.GetTypeCode(objType))
            {
            case TypeCode.Int16:
            case TypeCode.Int32:
            case TypeCode.Int64:
            case TypeCode.UInt16:
            case TypeCode.UInt32:
            case TypeCode.UInt64:
                WriteNumber((IConvertible)obj);
                return;

            case TypeCode.Double:
            case TypeCode.Decimal:
            case TypeCode.Single:
                WriteNumber((IFormattable)obj);
                return;

            case TypeCode.String:
                WriteQuotedString((string)obj);
                return;

            case TypeCode.Char:
                WriteQuotedString((char)obj);
                return;

            case TypeCode.Boolean:
                WriteBool((bool)obj);
                return;

            case TypeCode.DBNull:
                WriteLiteral("null");
                return;

            case TypeCode.DateTime:
                WriteDateTime((System.DateTime)obj);
                return;
            }

            if (objType.IsArray)
            {
                Type eleType = objType.GetElementType();
                switch (Type.GetTypeCode(eleType))
                {
                case TypeCode.Int16:
                case TypeCode.Int32:
                case TypeCode.Int64:
                case TypeCode.UInt16:
                case TypeCode.UInt32:
                case TypeCode.UInt64:
                    WriteArray(depth, (IConvertible[])obj, WriteNumber);
                    return;

                case TypeCode.Double:
                case TypeCode.Decimal:
                case TypeCode.Single:
                    WriteArray(depth, (IFormattable[])obj, WriteNumber);
                    return;

                case TypeCode.String:
                    WriteArray(depth, (string[])obj, WriteQuotedString);
                    return;

                case TypeCode.Char:
                    WriteArray(depth, (char[])obj, WriteQuotedString);
                    return;

                case TypeCode.Boolean:
                    WriteArray(depth, (bool[])obj, WriteBool);
                    return;

                case TypeCode.DBNull:
                    WriteLiteral("null");
                    return;

                case TypeCode.DateTime:
                    WriteArray(depth, (DateTime[])obj, WriteDateTime);
                    return;
                }

                IConvertible[] arrConv = obj as IConvertible[];
                if (arrConv != null)
                {
                    WriteArray(depth, arrConv, WriteNumber);
                    return;
                }
            }

            JsonObject objDict = obj as JsonObject;

            if (objDict != null)
            {
                WriteDictionary(depth, objDict);
                return;
            }

            JsonArray objList = obj as JsonArray;

            if (objList != null)
            {
                WriteArray(depth, objList);
                return;
            }

            IJsonObject objObj = obj as IJsonObject;

            if (objObj != null)
            {
                var ocdict = objObj.SerializeJson();
                WriteDictionary(depth, ocdict);
                return;
            }

            IEnumerable objEnum = obj as IEnumerable;

            if (objEnum != null && objType.IsSerializable)
            {
                WriteEnumerable(depth, objEnum);
                return;
            }

            IJsonBinary objBinary = obj as IJsonBinary;

            if (objBinary != null)
            {
                WriteBinary(objBinary);
                return;
            }

            Bitmap objBitmap = obj as Bitmap;

            if (objBitmap != null)
            {
                WriteImage(objBitmap);
                return;
            }

            throw new JsonException(string.Format("Object of type {0} is not serializable.", objType.Name));
        }
Example #10
0
        private JsonObject DeserializeObject(int depth) {
            JsonObject dictionary = new JsonObject();
            while (MoveNextNonEmptyChar() && (_current == '"' || _current == '\'')) {

                string memberName = DeserializeString();
                if (memberName == string.Empty
                    || !MoveNextNonEmptyChar()
                    || _current != ':'
                    || !MoveNextNonEmptyChar()
                    || _current == '}' || _current == ',')
                    break;

                object propVal = DeserializeNext(depth);
                dictionary.Add(memberName, propVal);

                if (!MoveNextNonEmptyChar() || _current != ',')
                    break;
            }
            if (_current == '}')
                return dictionary;
            if (_index >= _length)
                throw new JsonException("UnexpectedTermination", _index);
            throw new JsonException("InvalideObject", _index);
        }
Example #11
0
        private void SerializeObject(object obj, int depth)
        {
            if (obj == null)
            {
                WriteBytes("null"); return;
            }

            Type t = obj.GetType();

            switch (Type.GetTypeCode(t))
            {
            case TypeCode.Int16:
            case TypeCode.Int32:
            case TypeCode.Int64:
            case TypeCode.UInt16:
            case TypeCode.UInt32:
            case TypeCode.UInt64:
                SerializeConvertible((IConvertible)obj); return;

            case TypeCode.Double:
            case TypeCode.Decimal:
            case TypeCode.Single:
                SerializeFloat((IFormattable)obj); return;

            case TypeCode.String:
                SerializeString((string)obj); return;

            case TypeCode.Char:
                SerializeCharacter((char)obj); return;

            case TypeCode.Boolean:
                SerializeBool((bool)obj); return;

            case TypeCode.DBNull:
                WriteBytes("null"); return;

            case TypeCode.DateTime:
                SerializeDateTime((System.DateTime)obj); return;
            }

            if (t.IsArray)
            {
                Type te = t.GetElementType();
                switch (Type.GetTypeCode(te))
                {
                case TypeCode.Int16:
                case TypeCode.Int32:
                case TypeCode.Int64:
                case TypeCode.UInt16:
                case TypeCode.UInt32:
                case TypeCode.UInt64:
                    SerializeArray((IConvertible[])obj, SerializeConvertible); return;

                case TypeCode.Double:
                case TypeCode.Decimal:
                case TypeCode.Single:
                    SerializeArray((IFormattable[])obj, SerializeFloat); return;

                case TypeCode.String:
                    SerializeArray((string[])obj, SerializeString); return;

                case TypeCode.Char:
                    SerializeArray((char[])obj, SerializeCharacter); return;

                case TypeCode.Boolean:
                    SerializeArray((bool[])obj, SerializeBool); return;

                case TypeCode.DBNull:
                    WriteBytes("null"); return;

                case TypeCode.DateTime:
                    SerializeArray((DateTime[])obj, SerializeDateTime); return;
                }

                IConvertible[] arrConv = obj as IConvertible[];
                if (arrConv != null)
                {
                    SerializeArray(arrConv, SerializeConvertible); return;
                }
            }

            JsonObject objDict = obj as JsonObject;

            if (objDict != null)
            {
                SerializeDictionary(objDict, depth); return;
            }

            JsonArray objList = obj as JsonArray;

            if (objList != null)
            {
                SerializeArray(objList, depth); return;
            }

            IJsonObject objObj = obj as IJsonObject;

            if (objObj != null)
            {
                var ocdict = objObj.SerializeJson();
                SerializeDictionary(ocdict, depth); return;
            }

            IEnumerable objEnum = obj as IEnumerable;

            if (objEnum != null && t.IsSerializable)
            {
                SerializeEnumerable(objEnum, depth); return;
            }

            IJsonBinary objBinary = obj as IJsonBinary;

            if (objBinary != null)
            {
                SerializeBinary(objBinary); return;
            }

            throw new JsonException(string.Format(
                                        "Object of type {0} is not serializable\n{1}{0}"
                                        , t.Name, this.DebugValue));
        }