public void OnDownloadCompleted(object sender, DownloadStringCompletedEventArgs e) { AddLogEntry("Download async completed"); WebClient DownloadClient = CurrentDownload; DatabaseOperation Operation = CurrentOperation; CurrentDownload = null; CurrentOperation = null; if (DownloadClient != null) { foreach (KeyValuePair <string, KeyValuePair <DatabaseOperation, WebClient> > Entry in DownloadClientTable) { if (DownloadClient == Entry.Value.Value) { DownloadClientTable.Remove(Entry.Key); AddLogEntry("Request withdrawn"); break; } } AddLogEntry($"Request {Operation.Name} completed"); List <IDictionary <string, object> > RequestResult = new List <IDictionary <string, object> >(); try { string Content = e.Result; RequestResult = ParseResponse(Content); } catch (Exception ex) { AddLogEntry(ex.Message); } RequestResultTable.Add(Operation, RequestResult); AddLogEntry($"Request {Operation.Name} result available"); Operation.Callback?.Invoke(this, new CompletionEventArgs(Operation)); } if (DownloadClientTable.Count > 0) { Windows.UI.Xaml.Window.Current.Dispatcher.BeginInvoke(PopRequest); } }
private void StartRequest(DatabaseOperation operation) { if (DebugLog) { operation.DebugStart(); } string AddressString = operation.RequestString(QueryScriptPath); if (!DownloadClientTable.ContainsKey(AddressString)) { DownloadClientTable.Add(AddressString, new KeyValuePair <DatabaseOperation, WebClient>(operation, new WebClient())); AddLogEntry($"{operation.TypeName} added"); if (DownloadClientTable.Count == 1) { PopRequest(); } } else { AddLogEntry($"An identical {operation.TypeName} request is already queued"); } }