// Override the Invoke() method public override void Invoke(INetworkOperationContext context) { // Start the stopwatch StartTimer(context.Request.RequestUri); // Invoke the next message handler in the chain Next(context); }
// Override the Invoke() method public override void Invoke(INetworkOperationContext context) { Debug.WriteLine("Start processing request: " + context.Request.RequestUri); // Invoke the next message handler in the chain Next(context); Debug.WriteLine("Finish processing request: " + context.Request.RequestUri); }
// Override the Invoke() method public override void Invoke(INetworkOperationContext context) { // Stop the stopwatch var duration = StopTimer(context.Request.RequestUri); // Print the result Debug.WriteLine($"Elapsed: {duration:g}, resource: {context.Request.RequestUri.Pathname}"); // Invoke the next message handler in the chain Next(context); }
public override void Invoke(INetworkOperationContext context) { // Check whether response is OK if (context.Response.StatusCode != HttpStatusCode.OK) { // Set error information errors.Add(string.Format("File '{0}' Not Found", context.Request.RequestUri)); } // Invoke the next message handler in the chain Next(context); }
// Override the Invoke() method public override void Invoke(INetworkOperationContext context) { // Start the stopwatch var stopwatch = Stopwatch.StartNew(); // Invoke the next message handler in the chain Next(context); // Stop the stopwatch stopwatch.Stop(); // Print the result Debug.WriteLine("Request: " + context.Request.RequestUri); Debug.WriteLine("Time: " + stopwatch.ElapsedMilliseconds + "ms"); }
// Override the Invoke() method public override void Invoke(INetworkOperationContext context) { var pathInsideArchive = context.Request.RequestUri.Pathname.TrimStart('/').Replace("\\", "/"); var stream = GetFile(pathInsideArchive); if (stream != null) { // If a resource is found in the archive, then return it as a Response var response = new ResponseMessage(HttpStatusCode.OK); response.Content = new StreamContent(stream); response.Headers.ContentType.MediaType = MimeType.FromFileExtension(context.Request.RequestUri.Pathname); context.Response = response; } else { context.Response = new ResponseMessage(HttpStatusCode.NotFound); } // Invoke the next message handler in the chain Next(context); }
// Override the Invoke() method public override void Invoke(INetworkOperationContext context) { // Call the GetFile() method that defines the logic in the Invoke() method var buff = GetFile(context.Request.RequestUri.Pathname.TrimStart('/')); if (buff != null) { // Checking: if a resource is found in the archive, then return it as a Response context.Response = new ResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(buff) }; context.Response.Headers.ContentType.MediaType = MimeType.FromFileExtension(context.Request.RequestUri.Pathname); } else { context.Response = new ResponseMessage(HttpStatusCode.NotFound); } // Call the next message handler Next(context); }
// Override the Match() method public override bool Match(INetworkOperationContext context) { return(string.Equals(schema, context.Request.RequestUri.Protocol.TrimEnd(':'))); }