Ejemplo n.º 1
0
        private void PopRequest()
        {
            try
            {
                foreach (KeyValuePair <string, KeyValuePair <DatabaseOperation, WebClient> > Entry in DownloadClientTable)
                {
                    string            BaseUrl        = UrlTools.GetBaseUrl();
                    string            AddressString  = $"{BaseUrl}/{Entry.Key}";
                    DatabaseOperation Operation      = Entry.Value.Key;
                    WebClient         DownloadClient = Entry.Value.Value;

                    AddLogEntry("Request started");
                    AddLogEntry($"Address: {AddressString}");

                    CurrentDownload  = DownloadClient;
                    CurrentOperation = Operation;

                    Uri UriAddress = new Uri(AddressString, UriKind.Relative);
                    DownloadClient.DownloadStringCompleted += OnDownloadCompleted;
                    DownloadClient.DownloadStringAsync(UriAddress);

                    AddLogEntry("Download async started");
                    return;
                }

                AddLogEntry("No more request");
            }
            catch (Exception e)
            {
                AddLogEntry(e.Message);
            }
        }
Ejemplo n.º 2
0
        public List <IDictionary <string, string> > ProcessMultipleResponse(DatabaseOperation operation, List <string> keyList)
        {
            List <IDictionary <string, string> > Result = null;

            if (RequestResultTable.ContainsKey(operation))
            {
                List <IDictionary <string, object> > ResultList = RequestResultTable[operation];
                RequestResultTable.Remove(operation);

                foreach (IDictionary <string, object> Item in ResultList)
                {
                    IDictionary <string, string> ResultLine = null;
                    foreach (string Key in keyList)
                    {
                        if (Item.ContainsKey(Key) && (ResultLine == null || !ResultLine.ContainsKey(Key)) && Item[Key] is string)
                        {
                            if (ResultLine == null)
                            {
                                ResultLine = new Dictionary <string, string>();
                                if (Result == null)
                                {
                                    Result = new List <IDictionary <string, string> >();
                                }

                                Result.Add(ResultLine);
                            }

                            ResultLine.Add(Key, Item[Key] as string);
                        }
                    }
                }
            }

            return(Result);
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        public void DebugWriteState()
        {
            foreach (KeyValuePair <DatabaseOperation, List <IDictionary <string, object> > > ResultEntry in RequestResultTable)
            {
                DatabaseOperation Operation = ResultEntry.Key;
                List <IDictionary <string, object> > ResultList = ResultEntry.Value;
                AddLogEntry($"Operation: {Operation.Name}, {ResultList.Count} entries");

                for (int i = 0; i < ResultList.Count; i++)
                {
                    IDictionary <string, object> Item = ResultList[i];
                    AddLogEntry($"#{i}, {Item.Count} keys");

                    foreach (KeyValuePair <string, object> Entry in Item)
                    {
                        AddLogEntry($"{Entry.Key} -> {Entry.Value}");
                    }
                }
            }
        }
Ejemplo n.º 5
0
        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");
            }
        }
Ejemplo n.º 6
0
 public CompletionEventArgs(DatabaseOperation operation)
 {
     Operation = operation;
 }