예제 #1
0
        public bool TryRead(string json, out object result)
        {
            result = null;
            object obj;

            if (!SimpleJson.TryDeserializeObject(json, out obj))
            {
                return(false);
            }

            if (obj is JsonObject)
            {
                if (TryParseGeometry((JsonObject)obj, out result))
                {
                    return(true);
                }
                if (TryParseFeature((JsonObject)obj, out result))
                {
                    return(true);
                }
                if (TryParseFeatureCollection((JsonObject)obj, out result))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #2
0
파일: Form1.cs 프로젝트: laenion/desura-app
        private void readLineAndProcess(MemoryMappedViewAccessor accessor, int row)
        {
            accessor.ReadArray <byte>(12 + (row * _BlockSize), _Buffer, 0, _BlockSize);

            if (_Buffer[0] == 0)
            {
                _MissingItems.Add(row);
                return;
            }

            var str = System.Text.Encoding.Default.GetString(_Buffer);

            int index = str.IndexOf('\0');

            if (index >= 0)
            {
                str = str.Remove(index);
            }

            dynamic obj;

            if (SimpleJson.TryDeserializeObject(str, out obj))
            {
                Action action = () => NewRow(obj);
                BeginInvoke(action);
            }
            else
            {
                _MissingItems.Add(row);
            }
        }
예제 #3
0
        public static bool TryParseAsObjectList(string value, out List <object?>?list)
        {
            if (SimpleJson.TryDeserializeObject(value, out object?obj))
            {
                list = (List <object?>?)obj;
                return(true);
            }

            list = null;
            return(false);
        }
예제 #4
0
        static void appServer_NewMessageReceived(WebSocketSession session, string message)
        {
            JsonObject Answer = new JsonObject();

            Console.WriteLine(message);

            object BUF;

            if (SimpleJson.TryDeserializeObject(message, out BUF))
            {
                JsonObject Message = (JsonObject)BUF;

                switch (Message["type"].ToString())
                {
                case "join":
                    Answer.Add("type", "registered");
                    Answer.Add("player_name", Message["name"].ToString());
                    //int j1 = 0;
                    //Console.Write("PlayerID: ");
                    //int.TryParse(Console.ReadLine(), out j1);
                    //Answer.Add("player_id",j1);
                    Answer.Add("player_id", player_count++);
                    Answer.Add("content_pack", "dev-pack");
                    break;

                case "new_game":
                    Answer.Add("type", "game_created");
                    Answer.Add("game_id", "bullshit");
                    break;

                case "request_pack_list":
                    Answer.Add("type", "pack_list");
                    Answer.Add("packs", new string[] { "dev-pack" });
                    break;

                case "start":
                    Answer.Add("type", "next");
                    Answer.Add("player_id", 0);
                    break;

                case "move_request":
                    Answer.Add("type", "move");
                    Answer.Add("player_id", Convert.ToInt32(Message["player_id"]));
                    Answer.Add("location_id", Convert.ToInt32(Message["location_id"]));
                    break;

                default:
                    break;
                }
            }
            Console.WriteLine(SimpleJson.SerializeObject(Answer));
            session.Send(SimpleJson.SerializeObject(Answer));
        }
예제 #5
0
        private IEnumerator ProcessMatchResponse <JSONRESPONSE, USERRESPONSEDELEGATETYPE>(UnityWebRequest client, NetworkMatch.InternalResponseDelegate <JSONRESPONSE, USERRESPONSEDELEGATETYPE> internalCallback, USERRESPONSEDELEGATETYPE userCallback) where JSONRESPONSE : Response, new()
        {
            yield return(client.SendWebRequest());

            JSONRESPONSE jsonInterface = Activator.CreateInstance <JSONRESPONSE>();

            if (!client.isNetworkError && !client.isHttpError)
            {
                object obj;
                if (SimpleJson.TryDeserializeObject(client.downloadHandler.text, out obj))
                {
                    IDictionary <string, object> dictionary = obj as IDictionary <string, object>;
                    if (dictionary != null)
                    {
                        try
                        {
                            jsonInterface.Parse(obj);
                        }
                        catch (FormatException ex)
                        {
                            jsonInterface.SetFailure(UnityString.Format("FormatException:[{0}] ", new object[]
                            {
                                ex.ToString()
                            }));
                        }
                    }
                }
            }
            else
            {
                jsonInterface.SetFailure(UnityString.Format("Request error:[{0}] Raw response:[{1}]", new object[]
                {
                    client.error,
                    client.downloadHandler.text
                }));
            }
            client.Dispose();
            internalCallback(jsonInterface, userCallback);
            yield break;
        }
예제 #6
0
        private static bool AddScopedRegistryIfNeeded()
        {
            // Load packages.json
            string packageManifestPath = Application.dataPath.Replace("/Assets", "/Packages/manifest.json");
            string packageManifestJSON = File.ReadAllText(packageManifestPath);

            // Deserialize
            SimpleJson.TryDeserializeObject(packageManifestJSON, out object packageManifestObject);
            JsonObject packageManifest = packageManifestObject as JsonObject;

            if (packageManifest == null)
            {
                Debug.LogError("Normcore Package Manager: Failed to read project package manifest. Unable to add Normcore.");
                return(false);
            }


            // Create scoped registries array if needed
            packageManifest.TryGetValue("scopedRegistries", out object scopedRegistriesObject);
            JsonArray scopedRegistries = scopedRegistriesObject as JsonArray;

            if (scopedRegistries == null)
            {
                packageManifest["scopedRegistries"] = scopedRegistries = new JsonArray();
            }

            // Check for Normal registry
            bool normalRegistryFound = scopedRegistries.Any(registryObject => {
                JsonObject registry = registryObject as JsonObject;
                if (registry == null)
                {
                    return(false);
                }

                return(registry.TryGetValue("url", out object registryURL) && (registryURL as string) == __registryURL);
            });

            if (normalRegistryFound)
            {
                if (__debugLogging)
                {
                    Debug.Log("Normcore Package Manager: Found Normal registry");
                }
                return(true);
            }

            // Add Normal registry
            JsonObject normalRegistry = new JsonObject();

            normalRegistry["name"]   = "Normal";
            normalRegistry["url"]    = __registryURL;
            normalRegistry["scopes"] = new JsonArray {
                "com.normalvr", "io.normcore"
            };
            scopedRegistries.Add(normalRegistry);

            // Serialize and save
            string packageManifestJSONUpdated = SimpleJson.SerializeObject(packageManifest);

            File.WriteAllText(packageManifestPath, packageManifestJSONUpdated);
            if (__debugLogging)
            {
                Debug.Log("Normcore Package Manager: Added Normal registry");
            }

            return(true);
        }
예제 #7
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            // http://stackoverflow.com/questions/32788409/c-sharp-httpwebrequest-the-underlying-connection-was-closed-an-unexpected-error
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            var client = new RestClient("https://" + strServer);

            Debug.WriteLine(client.BaseUrl.Port + "\n" + ServicePointManager.SecurityProtocol.ToString());

            Method httpMeth = Method.PUT;               // default HTTP method

            if (strMethod == "GET")
            {
                httpMeth = Method.GET;
            }
            if (strMethod == "POST")
            {
                httpMeth = Method.POST;
            }
            if (strMethod == "PATCH")
            {
                httpMeth = Method.PATCH;
            }
            if (strMethod == "DELETE")
            {
                httpMeth = Method.DELETE;
            }

            // Create request based on the resource and method
            var request = new RestRequest(strResource, httpMeth);

            request.AddHeader("Content-Type", "application/json");

            // If we haven't logged-in yet:
            if (strXAuthToken == "")
            {
                // create a dictionary containing name/value pairs
                Dictionary_NVP credentials = new Dictionary_NVP(2);
                credentials.Add("userid", strUserID);
                credentials.Add("password", strPassword);

                // debug testing: serialize the credentials object and write to VS output window
                string strJsonBody = SimpleJson.SerializeObject(credentials);
                //Debug.WriteLine(strJsonBody);

                // automatically serializes the credentials object and adds to the request body
                request.AddJsonBody(credentials);

                strJsonBody = SimpleJson.SerializeObject(authentication_json());
                Debug.WriteLine(strJsonBody);
                request.AddJsonBody(authentication_json());
            }
            else
            {
                // easily add HTTP Headers
                request.AddHeader("X-Auth-Token", strXAuthToken);
                //request.RequestFormat = DataFormat.Json;
                request.AddJsonBody(authentication_json());
            }

            // add files to upload (works with compatible verbs)
            if (strFileName != "")
            {
                request.AddFile("file", strFileName);
            }

            // execute the request
            IRestResponse response = client.Execute(request);
            var           content  = response.Content;  // raw content as string

            Debug.WriteLine(content);

            if (content != "")                          // something was returned
            {
                try
                {
                    Dictionary_NVP deserialized_obj = SimpleJson.DeserializeObject <Dictionary_NVP>(content);

                    // check for an error key
                    if (deserialized_obj.ContainsKey("error"))
                    {
                        listResponse.Items.Add(deserialized_obj["error"].ToString());
                    }
                    else
                    {
                        // have you logged in yet, i.e. do we have an empty token?
                        if (strXAuthToken == "")
                        {
                            //strXAuthToken = (string)deserialized_obj["X-Auth-Token"];
                            object obj1;
                            bool   bSuccess = SimpleJson.TryDeserializeObject(content, out obj1);

                            JObject   obj2 = (JObject)JsonConvert.DeserializeObject(content);
                            JProperty abc  = (JProperty)obj2.First;
                            if (abc.Name == "X-Auth-Token")
                            {
                                strXAuthToken = (string)abc.Value;
                            }

                            foreach (string key in deserialized_obj.Keys)
                            {
                                //objArray.Add(key);
                                listResponse.Items.Add("[" + key + "]:  \t" + deserialized_obj[key].ToString());
                            }
                        }
                        else
                        // some other method was invoked, ASSUMES an array of objects (documents / workspaces / folders) are returned
                        {
                            if (deserialized_obj.ContainsKey("data"))
                            {
                                JObject   obj3      = (JObject)JsonConvert.DeserializeObject(content);
                                JProperty data_prop = (JProperty)obj3.First;
                                JArray    data      = (JArray)data_prop.First;
                                Debug.WriteLine("count: " + data.Count);

                                if (data.Count > 0)
                                {
                                    JToken array = data[0];
                                    foreach (string userid in data.Values("userid"))
                                    {
                                        Debug.WriteLine(userid);
                                    }

                                    listResponse.Items.Clear();
                                    foreach (JObject obj in data)
                                    {
                                        JToken token_value;
                                        bool   bSuccess = obj.TryGetValue("name", out token_value);
                                        if (bSuccess)
                                        {
                                            listResponse.Items.Add(String.Format("{0} - {1}", obj["id"].ToString(), token_value.ToString()));
                                        }
                                        else
                                        {
                                            listResponse.Items.Add(String.Format("{0} - {1} - {2}", obj["user_id"], obj["full_name"], obj["email"]));
                                        }
                                    }
                                }
                                else
                                {
                                    listResponse.Items.Clear();
                                    listResponse.Items.Add("data[] == null");
                                }
                            }
                            if (deserialized_obj.ContainsKey("ServerVersion"))
                            {
                                Debug.WriteLine("count: " + deserialized_obj.Count);
                                foreach (KeyValuePair <string, object> kvp in deserialized_obj)
                                {
                                    listResponse.Items.Add(String.Format("{0} - {1}", kvp.Key, kvp.Value));
                                }
                            }
                        } // if (strXAuthToken
                    }     // if (
                }
                catch (SerializationException ex)
                {
                    listResponse.Items.Add(ex.Message + "\t**************\tDid you use the right VERB?\t**************");
                }
                catch (NullReferenceException ex)
                {
                    listResponse.Items.Add(ex.Message);
                }
            }
        }   // void btnExecute_Click
예제 #8
0
        public static object Deserialize(string json)
        {
            object result;

            return(SimpleJson.TryDeserializeObject(json, out result) ? result : null);
        }