Skip to content

Express 6.1.0 | EventLog | Demo GUI#10

Merged
gkjpettet merged 26 commits into
sworteu:mainfrom
jo-tools:feature/demo-gui
Mar 4, 2024
Merged

Express 6.1.0 | EventLog | Demo GUI#10
gkjpettet merged 26 commits into
sworteu:mainfrom
jo-tools:feature/demo-gui

Conversation

@jo-tools
Copy link
Copy Markdown
Collaborator

@jo-tools jo-tools commented Mar 3, 2024

Express 6.1.0

Introduces: Express.EventLogHandlerDelegate

Express is designed to be a standalone component that can be dropped into any Xojo project.

Each Xojo project might want to handle Logs differently.

Express provides a default logging facility in: Express.EventLog

  • TargetConsole: write to StdOut
  • TargetDesktop: write to System.DebugLog (see Xojo's Documentation)

If an application wants Express to redirect Logs to it's own Logging facility, then Express needed to be modified accordingly.

Express 6.1.0 decouples this hardcoded requirement by introducing the Express.EventLogHandlerDelegate.

A Xojo project using it can now specify which Method (that implements the delegate) an Express instance
should use as it's Event Log handler.

Usage:

// Configure App to handle Express EventLog with LogLevel Warning
Express.EventLogLevel = Express.LogLevel.Warning

// Assign the Express.EventLogHandlerDelegate to tell Express which method is processing the EventLogs
// Comment out or Assign Nil if you want to use Express's default EventLog-Handling
Express.EventLogHandler = WeakAddressOf ExpressEventLog

Introduces: Express Demo GUI

This repository is now a MonoRepo containing two example projects:

  • Express-Demo-Console.xojo_project
  • Express-Demo-GUI.xojo_project

The new "Express Demo GUI" shows how to:

  • use Express in a Desktop application
  • switch between the provided Demos on the fly
  • adjust Log Level on the fly
  • use the recently added Delegates:
    • Express.RequestHandlerDelegate
    • Express.EventLogHandlerDelegate

ScreenShot:
Express Demo GUI

Fixes: Multipart Forms Demo

The issue had been in the Express.Request.

  • DataAvailable: uses Lookahead.Bytes to determine if the Content has been fully received
  • Fix in Method BodyGet, so that Multipart Form Content is no longer stripped
  • DataGet and BodyGet in now called in Method "Process"

Demos: SpecialFolder.Resources

A Copy File Post Build Step now copies the demo's ressources to the Resources Folder.
All Demos have been updated to look for the resources in SpecialFolder.Resources.

Note: The Multipart Forms Upload will go into the following folder

  • SpecialFolder.(Desktop | UserHome).Child("express-demo-uploads")

Demos have been updated with Nil checks for Request.Server (which is a WeakRef).
Server might be Nil if stopped while Request is still alive.

Breaking Changes | Update from 6.0 to 6.1

None.

If you don't assign an own Event Log Handler (see above), then Express will continue to use it's default logging mechanism.

Comment thread Modules/Express/Request.xojo_code Outdated

// Get the length of the content that has been received.
Var contentReceivedLength As Integer = Body.Bytes
Var DataReceivedLength As Integer = Lookahead.Bytes
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite happy with that change.

Data needs to be appended (in case this Event fires multiple times).
However, Body ist just part of Data, and Content-Length has to be the Body-Length (not Data Length).

I'll push a change shortly to do this correctly.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done... see commit below.

  • Data is now always being appended while .ReadAll.
  • Comparison against Content-Length now always compares to Body.Bytes
  • Data is cleared when no longer needed in Method Process
  • Process checks Body.Bytes <> ContentLength and returns Error 400 (Bad Request) if needed

So back to previous Body/Content-Length comparison, while still having the fix regarding parsing the Body in case of Multipart Form Data.

@gkjpettet gkjpettet merged commit 78ba492 into sworteu:main Mar 4, 2024
@jo-tools jo-tools deleted the feature/demo-gui branch March 5, 2024 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants