本文整理汇总了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);
}
}
示例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;
}
}