Beispiel #1
0
        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();
        }
Beispiel #2
0
 /// <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;
     }
 }
Beispiel #3
0
        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;
        }
Beispiel #4
0
 // methods used to update the UI when retrieving products
 private void OnSucceededListenerGetProducts(object sender, ClientRequestEventArgs args)
 {
     _syncContext.Post(OnSucceedGetProducts, null);
 }
Beispiel #5
0
        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));
            }
        }
Beispiel #6
0
 protected virtual void OnCompletedRequest(ClientRequestEventArgs e)
 {
     CompletedRequest?.Invoke(this, e);
 }
Beispiel #7
0
 async private Task OnCompletedRequestAsync(ClientRequestEventArgs e)
 {
     CompletedRequestAsync?.InvokeAsync(this, e);
 }
Beispiel #8
0
 protected virtual void OnSuccessRequest(ClientRequestEventArgs e)
 {
     SuccessRequest?.Invoke(this, e);
 }
Beispiel #9
0
 async private Task OnSuccessRequestAsync(ClientRequestEventArgs e)
 {
     SuccessRequestAsync?.InvokeAsync(this, e);
 }
Beispiel #10
0
 protected virtual void OnBeforeRequest(ClientRequestEventArgs e)
 {
     BeforeRequest?.Invoke(this, e);
 }
Beispiel #11
0
 private async Task OnBeforeRequestAsync(ClientRequestEventArgs e) => BeforeRequestAsync?.InvokeAsync(this, e);