当前位置: 首页>>代码示例>>C#>>正文


C# JsonReader.ContainsKey方法代码示例

本文整理汇总了C#中JsonFx.Json.JsonReader.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.ContainsKey方法的具体用法?C# JsonReader.ContainsKey怎么用?C# JsonReader.ContainsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonFx.Json.JsonReader的用法示例。


在下文中一共展示了JsonReader.ContainsKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AccountLogin

        // Logging an account in
        public void AccountLogin(object password)
        {
            App.Popups.ShowInfo("ScrollsPost Login", "Logging in, this will only take a second...");

            WebClient wc = new WebClient();

            try {
                NameValueCollection form = new NameValueCollection();
                form["email"] = config.GetString("email");
                form["password"] = (String) password;
                form["id"] = App.MyProfile.ProfileInfo.id;
                form["uid"] = App.MyProfile.ProfileInfo.userUuid;
                form["name"] = App.MyProfile.ProfileInfo.name;

                byte[] bytes = wc.UploadValues(new Uri(mod.apiURL + "/v1/user"), "PUT", form);
                Dictionary<String, object> result = new JsonReader().Read<Dictionary<String, object>>(Encoding.UTF8.GetString(bytes));

                // Failed to login
                if( result.ContainsKey("errors") ) {
                    Dictionary<String, object> errors = (Dictionary<String, object>) result["errors"];
                    if( errors.ContainsKey("password") ) {
                        ShowAuthPassword(false, "<color=red>Password " + ((String[]) errors["password"])[0] + "</color>");
                    } else if( errors.ContainsKey("email") ) {
                        ShowAuthEmail("<color=red>Email " + ((String[]) errors["email"])[0] + "</color>");
                    }

                    // Save our keys so we don't store passwords
                } else {
                    App.Popups.ShowOk(this, "done", "Logged In!", "You're now logged into your ScrollsPost.com account!\n\nYour collection will automatically sync to ScrollsPost now, will let you know when the initial sync has finished in-game.", "Ok");

                    config.Add("user-id", (String) result["user_id"]);
                    config.Add("api-key", (String) result["api_key"]);
                    config.Remove("email");
                    config.Remove("last-card-sync");

                    if( result.ContainsKey("verif_key") ) {
                        config.Add("verif-key", (String) result["verif_key"]);
                    }

                    //if( config.ContainsKey("verif-key") ) {
                    //    verifier = new AccountVerifier(config);
                    //}

                    App.Communicator.sendRequest(new LibraryViewMessage());
                }

            } catch ( WebException we ) {
                App.Popups.ShowOk(this, "fail", "HTTP Error", "Unable to login due to an HTTP error.\nContact [email protected] for help.\n\n" + we.Message, "Ok");
                mod.WriteLog("Failed to register", we);
            }
        }
开发者ID:noHero123,项目名称:ScrollsPost,代码行数:52,代码来源:ConfigGUI.cs

示例2: Upload

        public Dictionary<String, object> Upload(String path)
        {
            // Setup
            String boundary = String.Format("---------------------------{0}", (int)mod.TimeSinceEpoch());
            byte[] boundaryBytes = Encoding.ASCII.GetBytes(String.Format("\r\n--{0}\r\n", boundary));

            HttpWebRequest wr = (HttpWebRequest) WebRequest.Create(mod.apiURL + "/v1/replays");
            wr.Method = "POST";
            wr.ContentType = String.Format("multipart/form-data; boundary={0}", boundary);

            // Start the boundary off
            using( Stream stream = wr.GetRequestStream() ) {
                stream.Write(boundaryBytes, 0, boundaryBytes.Length);

                // File info
                String field = String.Format("Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\nContent-Type: {2}\r\n\r\n", "replay", Path.GetFileName(path), "text/plain");
                byte[] bytes = Encoding.UTF8.GetBytes(field);

                stream.Write(bytes, 0, bytes.Length);

                // Write the file
                bytes = File.ReadAllBytes(path);
                stream.Write(bytes, 0, bytes.Length);

                bytes = Encoding.ASCII.GetBytes(String.Format("\r\n--{0}--\r\n", boundary));
                stream.Write(bytes, 0, bytes.Length);
            }

            try {
                using( WebResponse wres = wr.GetResponse() ) {
                    using( StreamReader rs = new StreamReader(wres.GetResponseStream()) ) {
                        String contents = rs.ReadToEnd();
                        Dictionary<String, object> response = new JsonReader().Read<Dictionary<String, object>>(contents);

                        if( response.ContainsKey("url") ) {
                            mod.SendMessage(String.Format("Finished uploading replay to ScrollsPost. Can be found at {0}, or by typing /sp and going to Replay List.", (response["url"] as String).Replace("scrollspost/", "scrollspost.com/")));
                            LogUploaded(path);
                        } else if( response["error"].Equals("game_too_short") ) {
                            mod.SendMessage("Replay rejected as it was too short, must go beyond 1 round to be uploaded.");
                        } else {
                            mod.SendMessage(String.Format("Error while uploading replay ({0}), please contact us for more info at [email protected]", response["error"]));
                            LogNotUploaded(path);
                        }

                        return response;
                    }
                }

            } catch ( WebException we ) {
                LogNotUploaded(path);

                Console.WriteLine("**** ERROR {0}", we.ToString());
                mod.SendMessage(String.Format("We had an HTTP error while uploading replay {0}, contact us at [email protected] for help.", Path.GetFileName(path)));
                mod.WriteLog("Failed to sync collection", we);

                Dictionary<String, object> response = new Dictionary<String, object>();
                response["error"] = we.ToString();

                return response;
            }
        }
开发者ID:Tomseibert,项目名称:ScrollsPost,代码行数:61,代码来源:ReplayLogger.cs


注:本文中的JsonFx.Json.JsonReader.ContainsKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。