private static async Task OnCompletedRequestAsync(object sender, ClientRequestEventArgs clientRequest) { var content = StringCompressor.CompressString(clientRequest.ResponseContent); var cacheItem = new CacheItem() { Url = clientRequest.Url, Content = content }; using var cacheContext = new CacheContext(); await cacheContext.CacheItems.AddAsync(cacheItem); await cacheContext.SaveChangesAsync(); }
/// <summary> /// Event handler for when the remote clients sent a request for a command to be executed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">Event args.</param> private void server_ClientRequest(object sender, ClientRequestEventArgs e) { // look at the command that should be fulfilled switch ( e.Request ) { case ClientRequest.StartPresentation: this.StartPresentation(); break; case ClientRequest.StopPresentation: this.StopPresentation(); break; case ClientRequest.NextSlide: this.NextSlide(); break; case ClientRequest.PreviousSlide: this.PreviousSlide(); break; } }
private static async Task OnBeforeRequestAsync(object sender, ClientRequestEventArgs e) { var client = sender as Client; var clientRequest = e as ClientRequestEventArgs; using var cacheContext = new CacheContext(); var item = cacheContext .CacheItems .Where(i => i.Url.ToLower() == clientRequest.Url.ToLower()) .Select(i => i.Content); var content = item.FirstOrDefault(); if (content == null) { return; } var contentText = StringCompressor.DecompressString(content); clientRequest.ResponseContent = contentText; }
// methods used to update the UI when retrieving products private void OnSucceededListenerGetProducts(object sender, ClientRequestEventArgs args) { _syncContext.Post(OnSucceedGetProducts, null); }
private async void HttpRestServerForIoTServer_ClientRequestEvent(object sender, ClientRequestEventArgs e) { IO.SimpleHttpServer.Result res = new IO.SimpleHttpServer.Result(); try { if (e.Authorization == AuthorizationType.Basic && e.UserName == HttpServerUserName && e.Password == HttpServerPassword) { if (e.RequestMethod == RequestMethodType.GET) { //.... } else if (e.RequestMethod == RequestMethodType.POST) { if (e.uriString.ToLower() == "/mes/productreport") { await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => MessageList.Items.Add(e.HttpContent)); res = await HttpRestServerForIoTServer.ServerResponse(HTTPStatusCodes.OK, e.OStream, null); } } else { res = await HttpRestServerForIoTServer.ServerResponse(HTTPStatusCodes.Not_Found, e.OStream, null); } } else { res = await HttpRestServerForIoTServer.ServerResponse(HTTPStatusCodes.Unauthorized, e.OStream, null); } } catch (Exception ex) { await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => MessageList.Items.Add("HttpRestServerForIoTServer error: " + ex.Message)); } }
protected virtual void OnCompletedRequest(ClientRequestEventArgs e) { CompletedRequest?.Invoke(this, e); }
async private Task OnCompletedRequestAsync(ClientRequestEventArgs e) { CompletedRequestAsync?.InvokeAsync(this, e); }
protected virtual void OnSuccessRequest(ClientRequestEventArgs e) { SuccessRequest?.Invoke(this, e); }
async private Task OnSuccessRequestAsync(ClientRequestEventArgs e) { SuccessRequestAsync?.InvokeAsync(this, e); }
protected virtual void OnBeforeRequest(ClientRequestEventArgs e) { BeforeRequest?.Invoke(this, e); }
private async Task OnBeforeRequestAsync(ClientRequestEventArgs e) => BeforeRequestAsync?.InvokeAsync(this, e);