private void FinishedRemoteIndexRequest(object sender, DownloadStringCompletedEventArgs e) { if (e.Error == null) { IndexResultInternal nextIndexResultInternal = indexInternalConverter.ConvertJsonToObject(e.Result); if (nextIndexResultInternal == null) { OnIndexCompleted(new DataEventArgs <IndexResult>(new Exception("Error deserializing index response from server:" + e.Result))); } else { List <JsonObjectResult> jsonIndex = new List <JsonObjectResult>(); foreach (string json in nextIndexResultInternal.index) { // note that null objects will be added if they fail to deserialize JsonObjectResult jsonObject = jsonObjectConverter.ConvertJsonToObject(json); jsonIndex.Add(jsonObject); } IndexResult nextIndexResult = new IndexResult(nextIndexResultInternal.current, jsonIndex); OnIndexPartialCompleted(new DataEventArgs <IndexResult>(nextIndexResult)); if (indexRequest.result == null) { indexRequest.result = nextIndexResult; } // accummulate changes in index, which is our deserialization of the first response if (indexRequest.result != nextIndexResult) { indexRequest.result.index.AddRange(nextIndexResult.index); } // more to come? if (nextIndexResultInternal.mark != null) { StartRemoteIndexRequest(nextIndexResultInternal.mark); return; } // upcall that we are all done OnIndexCompleted(new DataEventArgs <IndexResult>(indexRequest.result)); } } else { OnIndexCompleted(new DataEventArgs <IndexResult>(e.Error)); } // note that the pointer to the indexResult will remain valid as long as the user holds on to it indexRequest = null; }
private void FinishedRemoteIndexRequest(object sender, DownloadStringCompletedEventArgs e) { if (e.Error == null) { IndexResultInternal nextIndexResultInternal = indexInternalConverter.ConvertJsonToObject(e.Result); if (nextIndexResultInternal == null) OnIndexCompleted(new DataEventArgs<IndexResult>(new Exception("Error deserializing index response from server:" + e.Result))); else { List<JsonObjectResult> jsonIndex = new List<JsonObjectResult>(); foreach (string json in nextIndexResultInternal.index) { // note that null objects will be added if they fail to deserialize JsonObjectResult jsonObject = jsonObjectConverter.ConvertJsonToObject(json); jsonIndex.Add(jsonObject); } IndexResult nextIndexResult = new IndexResult(nextIndexResultInternal.current, jsonIndex); OnIndexPartialCompleted(new DataEventArgs<IndexResult>(nextIndexResult)); if (indexRequest.result == null) indexRequest.result = nextIndexResult; // accummulate changes in index, which is our deserialization of the first response if (indexRequest.result != nextIndexResult) indexRequest.result.index.AddRange(nextIndexResult.index); // more to come? if (nextIndexResultInternal.mark != null) { StartRemoteIndexRequest(nextIndexResultInternal.mark); return; } // upcall that we are all done OnIndexCompleted(new DataEventArgs<IndexResult>(indexRequest.result)); } } else { OnIndexCompleted(new DataEventArgs<IndexResult>(e.Error)); } // note that the pointer to the indexResult will remain valid as long as the user holds on to it indexRequest = null; }