// throws Exception public int getNumberOfAvailableUpdates() { string jsonStr = new RestClient().getMethod(server, "/patches.json"); JSONArray updates = new JSONArray(jsonStr); return updates.Length(); }
private static List<Fixture> ConvertJsonArrayToFixtureList(JSONArray jsonArray) { var list = new List<Fixture>(); var length = jsonArray.Length(); for (var i = 0; i < length; i++) { var jsonObject = jsonArray.OptJSONObject(i); if (jsonObject == null) continue; var fixture = new Fixture { AwayTeam = jsonObject.GetString("awayTeam"), HomeTeam = jsonObject.GetString("homeTeam"), Date = DateHelper.ParseUtcDate(jsonObject.GetString("date")) }; list.Add(fixture); } return list; }
/// <exception cref="System.Exception"></exception> public virtual void TestRemoteConflictResolution() { // Create a document with two conflicting edits. Document doc = database.CreateDocument(); SavedRevision rev1 = doc.CreateRevision().Save(); SavedRevision rev2a = CreateRevisionWithRandomProps(rev1, false); SavedRevision rev2b = CreateRevisionWithRandomProps(rev1, true); // make sure we can query the db to get the conflict Query allDocsQuery = database.CreateAllDocumentsQuery(); allDocsQuery.SetAllDocsMode(Query.AllDocsMode.OnlyConflicts); QueryEnumerator rows = allDocsQuery.Run(); bool foundDoc = false; NUnit.Framework.Assert.AreEqual(1, rows.GetCount()); for (IEnumerator<QueryRow> it = rows; it.HasNext(); ) { QueryRow row = it.Next(); if (row.GetDocument().GetId().Equals(doc.GetId())) { foundDoc = true; } } NUnit.Framework.Assert.IsTrue(foundDoc); // Push the conflicts to the remote DB. Replication push = database.CreatePushReplication(GetReplicationURL()); RunReplication(push); NUnit.Framework.Assert.IsNull(push.GetLastError()); // Prepare a bulk docs request to resolve the conflict remotely. First, advance rev 2a. JSONObject rev3aBody = new JSONObject(); rev3aBody.Put("_id", doc.GetId()); rev3aBody.Put("_rev", rev2a.GetId()); // Then, delete rev 2b. JSONObject rev3bBody = new JSONObject(); rev3bBody.Put("_id", doc.GetId()); rev3bBody.Put("_rev", rev2b.GetId()); rev3bBody.Put("_deleted", true); // Combine into one _bulk_docs request. JSONObject requestBody = new JSONObject(); requestBody.Put("docs", new JSONArray(Arrays.AsList(rev3aBody, rev3bBody))); // Make the _bulk_docs request. HttpClient client = new DefaultHttpClient(); string bulkDocsUrl = GetReplicationURL().ToExternalForm() + "/_bulk_docs"; HttpPost request = new HttpPost(bulkDocsUrl); request.SetHeader("Content-Type", "application/json"); string json = requestBody.ToString(); request.SetEntity(new StringEntity(json)); HttpResponse response = client.Execute(request); // Check the response to make sure everything worked as it should. NUnit.Framework.Assert.AreEqual(201, response.GetStatusLine().GetStatusCode()); string rawResponse = IOUtils.ToString(response.GetEntity().GetContent()); JSONArray resultArray = new JSONArray(rawResponse); NUnit.Framework.Assert.AreEqual(2, resultArray.Length()); for (int i = 0; i < resultArray.Length(); i++) { NUnit.Framework.Assert.IsTrue(((JSONObject)resultArray.Get(i)).IsNull("error")); } WorkaroundSyncGatewayRaceCondition(); // Pull the remote changes. Replication pull = database.CreatePullReplication(GetReplicationURL()); RunReplication(pull); NUnit.Framework.Assert.IsNull(pull.GetLastError()); // Make sure the conflict was resolved locally. NUnit.Framework.Assert.AreEqual(1, doc.GetConflictingRevisions().Count); }
public static byte[] DeserializeSystemByteArray(JSONArray jsonArray) { var result = new byte[jsonArray.Length()]; for (var i = 0; i < result.Length; i++) { result[i] = (byte)jsonArray.OptInt(i); } return result; }
public static Guid[] DeserializeSystemGuidArray(JSONArray jsonArray) { var result = new Guid[jsonArray.Length()]; for (var i = 0; i < result.Length; i++) { result[i] = new Guid(jsonArray.OptString(i)); } return result; }
public static short[] DeserializeSystemInt16Array(JSONArray jsonArray) { var result = new short[jsonArray.Length()]; for (var i = 0; i < result.Length; i++) { result[i] = (short)jsonArray.OptInt(i); } return result; }
public static decimal[] DeserializeSystemDecimalArray(JSONArray jsonArray) { var result = new decimal[jsonArray.Length()]; for (var i = 0; i < result.Length; i++) { result[i] = (decimal)jsonArray.OptLong(i); } return result; }
public static double[] DeserializeSystemDoubleArray(JSONArray jsonArray) { var result = new double[jsonArray.Length()]; for (var i = 0; i < result.Length; i++) { result[i] = jsonArray.OptDouble(i); } return result; }
public List<String[]> contactRequest(String token) { /* stops working after the first 10 because REST api limit */ String output = httpRequest(token,"https://www.yammer.com/api/v1/users.json"); if (output != "") { JSONArray jObject = new JSONArray (output); // json List<String[]> ppl = new List<String[]> (); //int c = 0; JSONObject data, tmp; String[] items; String uid,fname,lname,email,phone="",org,profilepicture,miniprofilepicture; //maybe use less memory because im using heaps apparently for (int i = 0; i < jObject.Length (); i++) { //if(i < 8){//limit for now data = jObject.GetJSONObject (i); // get data object uid = data.GetString ("id"); //userdeets = httpRequest (token, "https://www.yammer.com/api/v1/users/" + uid + ".json"); //if (userdeets != "") { //Console.WriteLine (uid); //person = new JSONObject (userdeets); // get data object fname = data.GetString ("first_name"); lname = data.GetString ("last_name"); email = data.GetString ("email"); profilepicture = data.GetString ("mugshot_url_template"); profilepicture = profilepicture.Replace ("{width}x{height}", "300x300"); miniprofilepicture = data.GetString ("mugshot_url"); tmp = data.GetJSONObject ("contact"); phone = tmp.GetString ("phone_numbers"); try{ tmp = new JSONArray (phone).GetJSONObject (0); phone = tmp.GetString ("number"); } catch{ phone = ""; } org = data.GetString ("network_name"); //Console.WriteLine (fname + " : " + lname + " : " + email + " : " + phone + " : " + org + " : " + uid); items = new String[] { fname, lname, email, phone, org, uid, profilepicture, miniprofilepicture }; ppl.Add (items); tmp.Dispose (); data.Dispose (); fname = ""; lname = ""; email = ""; phone = ""; org = ""; uid = ""; profilepicture = ""; //}//individual users //c++; //}//limit }//loop jObject.Dispose(); return ppl; }//get all users return new List<String[]>(); }
public static DateTime[] DeserializeSystemDateTimeArray(JSONArray jsonArray) { var result = new DateTime[jsonArray.Length()]; for (var i = 0; i < result.Length; i++) { result[i] = JsonConvert.ToDateTime(jsonArray.OptString(i)); } return result; }
public static ulong[] DeserializeSystemUInt64Array(JSONArray jsonArray) { var result = new ulong[jsonArray.Length()]; for (var i = 0; i < result.Length; i++) { result[i] = (ulong)jsonArray.OptLong(i); } return result; }
private List<Song> MapSongs(string ret) { var arr = new JSONArray(ret); var list = new List<Song>(); for (var i = 0; i < arr.Length(); i++) { var item = (JSONObject)arr.Get(i); var id = item.GetInt("id"); var name = item.GetString("name"); var relativePath = item.GetString("relativePath"); var artist = item.GetString("artist"); var lenght = this.JsonToTimeSpan(item.GetJSONObject("length")); var lastModified = DateTime.Parse(item.GetString("lastModified")); var fileLenght = item.GetInt("fileLength"); var song = new Song(id, name, relativePath, artist, lenght, lastModified, fileLenght); list.Add(song); } return list; }
public static TimeSpan[] DeserializeSystemTimeSpanArray(JSONArray jsonArray) { var result = new TimeSpan[jsonArray.Length()]; for (var i = 0; i < result.Length; i++) { result[i] = JsonConvert.ToTimeSpan(jsonArray.OptString(i)); } return result; }
public static string[] DeserializeSystemStringArray(JSONArray jsonArray) { var result = new string[jsonArray.Length()]; for (var i = 0; i < result.Length; i++) { result[i] = jsonArray.OptString(i); } return result; }
public static float[] DeserializeSystemSingleArray(JSONArray jsonArray) { var result = new float[jsonArray.Length()]; for (var i = 0; i < result.Length; i++) { result[i] = (float)jsonArray.OptDouble(i); } return result; }
public static bool[] DeserializeSystemBooleanArray(JSONArray jsonArray) { var result = new bool[jsonArray.Length()]; for (var i =0; i<result.Length; i++) { result[i] = jsonArray.OptBoolean(i); } return result; }
private Weather CallbackResponse(string responseObj) { Weather weather = null; Org.Json.JSONObject weatherMain = new Org.Json.JSONObject(responseObj); Org.Json.JSONArray weatherArray = new Org.Json.JSONArray(); weatherArray.Put(weatherMain); for (int i = 0; i < weatherArray.Length(); i++) { try { Org.Json.JSONObject weatherObject = weatherArray.GetJSONObject(i); JSONObject objectLocation = weatherObject.GetJSONObject("location"); JSONObject objectCurrent = weatherObject.GetJSONObject("current"); //JSONObject objectrequest = objectCurrent.GetJSONObject("request"); //"request":{ "type":"City","query":"Tel Aviv-Yafo, Israel","language":"en","unit":"m"} weather = new Weather(); weather.setTemperature(objectCurrent.GetString("temperature")); weather.setDescription(objectCurrent.GetString("weather_descriptions")); weather.setWind_kph(objectCurrent.GetString("wind_speed")); string icon = objectCurrent.GetString("weather_icons"); icon = icon.Replace("[\"" + "https:\\/\\/assets", @"https://assets"); icon = icon.Replace("[", ""); icon = icon.Replace("]", ""); icon = icon.Replace("\"", ""); icon = icon.Replace(@"\/", "//"); icon = icon.Replace(@"\\", "//"); //Android.Net.Uri uri = Android.Net.Uri.Parse(icon); //Android.Net.Uri uri = Android.Net.Uri.Parse(icon); //icon = uri.Path; //icon = uri.AbsolutePath; weather.setPoster(icon); weather.setIs_day(objectCurrent.GetString("is_day").ToString()); weather.setCloud(objectCurrent.GetString("cloudcover")); weather.setLast_update(objectLocation.GetString("localtime")); weather.setCountry(objectLocation.GetString("country")); icon = objectLocation.GetString("name").Trim(); icon = icon.Replace(@"[", ""); icon = icon.Replace("[", ""); icon = icon.Replace(@"]", ""); icon = icon.Replace("]", ""); icon = icon.Replace("\"", ""); icon = icon.Replace("\"", ""); icon = icon.Replace("[\"", ""); //icon = icon.Replace('\'', (char)32); weather.setCity(icon.Trim()); // "type":"City","query":"Tel Aviv-Yafo, Israel" weather.setRegion(objectLocation.GetString("region")); weather.setLocal_time(objectLocation.GetString("localtime")); weather.setTz_id(objectLocation.GetString("timezone_id")); //"localtime_epoch":1583177400,"utc_offset":"2.0" //wind_degree":311,"wind_dir":"NW","pressure":1021,"precip":0,"humidity":60,"cloudcover":7,"feelslike":17 try { //weather.setImageView(Utils.GetImageViewFromhUrl(weather.getPoster())); //weather.setImageView(new ImageView(Application.Context)); //Android.Net.Uri uri = Android.Net.Uri.Parse(weather.getPoster()); //weather.getImageView().SetImageURI(uri); } catch { } if (WeatherList.Count < 4) { WeatherList.Add(weather); } else { WeatherList[currentListIndex] = weather; } } catch (JSONException ex) { MH_Utils.Utils.WriteToLog(ex.Message); //Log.d("Error: ", ex.getMessage()); //ex.printStackTrace(); } } return(weather); }
public static char[] DeserializeSystemCharArray(JSONArray jsonArray) { var result = new char[jsonArray.Length()]; for (var i = 0; i < result.Length; i++) { result[i] = jsonArray.OptString(i)[0]; } return result; }
/// <exception cref="System.Exception"></exception> public virtual void TestRemoteConflictResolution() { // Create a document with two conflicting edits. Document doc = database.CreateDocument(); SavedRevision rev1 = doc.CreateRevision().Save(); SavedRevision rev2a = rev1.CreateRevision().Save(); SavedRevision rev2b = rev1.CreateRevision().Save(true); // Push the conflicts to the remote DB. Replication push = database.CreatePushReplication(GetReplicationURL()); RunReplication(push); // Prepare a bulk docs request to resolve the conflict remotely. First, advance rev 2a. JSONObject rev3aBody = new JSONObject(); rev3aBody.Put("_id", doc.GetId()); rev3aBody.Put("_rev", rev2a.GetId()); // Then, delete rev 2b. JSONObject rev3bBody = new JSONObject(); rev3bBody.Put("_id", doc.GetId()); rev3bBody.Put("_rev", rev2b.GetId()); rev3bBody.Put("_deleted", true); // Combine into one _bulk_docs request. JSONObject requestBody = new JSONObject(); requestBody.Put("docs", new JSONArray(Arrays.AsList(rev3aBody, rev3bBody))); // Make the _bulk_docs request. HttpClient client = new DefaultHttpClient(); string bulkDocsUrl = GetReplicationURL().ToExternalForm() + "/_bulk_docs"; HttpPost request = new HttpPost(bulkDocsUrl); request.SetHeader("Content-Type", "application/json"); string json = requestBody.ToString(); request.SetEntity(new StringEntity(json)); HttpResponse response = client.Execute(request); // Check the response to make sure everything worked as it should. NUnit.Framework.Assert.AreEqual(201, response.GetStatusLine().GetStatusCode()); string rawResponse = IOUtils.ToString(response.GetEntity().GetContent()); JSONArray resultArray = new JSONArray(rawResponse); NUnit.Framework.Assert.AreEqual(2, resultArray.Length()); for (int i = 0; i < resultArray.Length(); i++) { NUnit.Framework.Assert.IsTrue(((JSONObject)resultArray.Get(i)).IsNull("error")); } WorkaroundSyncGatewayRaceCondition(); // Pull the remote changes. Replication pull = database.CreatePullReplication(GetReplicationURL()); RunReplication(pull); // Make sure the conflict was resolved locally. NUnit.Framework.Assert.AreEqual(1, doc.GetConflictingRevisions().Count); }