Skip to content

Commit

Permalink
Merge pull request #12 from jo-tools/feature/demos-environment-variables
Browse files Browse the repository at this point in the history
Express 6.2.1 | Demos: Launch Arguments and Environment Variables
  • Loading branch information
sworteu authored Mar 16, 2024
2 parents 7520975 + d656563 commit afc9fc8
Show file tree
Hide file tree
Showing 17 changed files with 287 additions and 224 deletions.
4 changes: 2 additions & 2 deletions Demos/DemoCaching/DrummersList.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Protected Class DrummersList

#tag Method, Flags = &h0, Description = 4F70656E73206120636F6E6E656374696F6E20746F207468652053514C6974652064617461626173652E
Sub DatabaseConnect()
/// Opens a connection to the SQLite database.
// Opens a connection to the SQLite database.

// Create a folderitem that points to the database file.
DatabaseFile = SpecialFolder.Resources.Child("data").Child("drummers.sqlite")
Expand Down Expand Up @@ -107,7 +107,7 @@ Protected Class DrummersList

#tag Method, Flags = &h0, Description = 4765747320616C6C207265636F7264732066726F6D20746865204472756D6D657273207461626C652E
Sub RecordsGet()
/// Gets all records from the Drummers table.
// Gets all records from the Drummers table.

// Simulate a slow query.
Thread.SleepCurrent(3000)
Expand Down
4 changes: 2 additions & 2 deletions Express-Demo-Console.xojo_project
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ Class=XSContext;Modules/Express/XSContext.xojo_code;&h000000006B7387FF;&h0000000
Class=App;Express-Demo-Console/App.xojo_code;&h00000000771BB7FF;&h00000000692A97FF;false
MajorVersion=6
MinorVersion=2
SubVersion=0
SubVersion=1
NonRelease=0
Release=3
InfoVersion=Express, A Webserver Based on AloeExpress
LongVersion=N/A Use at your own risk.
ShortVersion=6.2.0
ShortVersion=6.2.1
WinCompanyName=example.com
WinInternalName=Express-Demo-Console
WinProductName=Express Demo
Expand Down
79 changes: 54 additions & 25 deletions Express-Demo-Console/App.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,41 @@ Inherits ConsoleApplication
Function Run(args() as String) As Integer
// Use Port 8080 for this demo if not specified otherwise
Var arguments As Dictionary = Express.ArgsToDictionary(args)
If (Not arguments.HasKey("--Port")) Then
Var argValue As String
If (Not Express.LaunchArgumentGetValue(arguments, "--Port", "EXPRESS_PORT", argValue)) Then
args.Add("--Port=8080")
End If

// Use Loopback Network Interface for Debug Builds
#If DebugBuild Then
If (Not Express.LaunchArgumentIsSet(arguments, "--Loopback", "EXPRESS_LOOPBACK")) Then
args.Add("--Loopback")
End If
#EndIf

// Express Demo
Print "----------------"
Print "- Express-Demo -"
Print "----------------"
Print Express.CHAR_LOG_BULLET + " Express Version: " + Express.VERSION_STRING
Print ""
Print ""
Print "-----------------"
Print "- Choose a demo -"
Print "-----------------"
Print " 1: Hello World"
Print " 2: Hello World (simple plain text response)"
Print " 3: Caching (Drummers)"
Print " 4: Multipart Forms"
Print " 5: Sessions"
Print " 6: Templates Client Side"
Print " 7: Templates Server Side"
Print " 8: WebSockets (simple chat app)"
Print " 9: XojoScript"
Print "10: ServerThread"
Print ""
Print ""
Print "Enter number and <enter> to start a demo:"

Var inputString As String = Input
Var inputNumber As Integer = Val(inputString)
// Choose a Demo
Var demoNumber As Integer = 0

Select Case inputNumber
// Get from Launch Parameter or from Environment Variable
If Express.LaunchArgumentGetValue(arguments, "--Demo", "EXPRESS_DEMO", argValue) Then
demoNumber = Val(argValue)
End If

If (demoNumber < 1) Or (demoNumber > 10) Then
// Ask to choose a Demo
demoNumber = Me.Demo_Choose
End If

// Launch Demo
Select Case demoNumber
Case 1
Me.Demo_01_HelloWorld(args)
Case 2
Expand Down Expand Up @@ -293,14 +296,40 @@ Inherits ConsoleApplication
End Sub
#tag EndMethod

#tag Method, Flags = &h21
Private Function Demo_Choose() As Integer
// Choose Express Demo
Print "-----------------"
Print "- Choose a demo -"
Print "-----------------"
Print " 1: Hello World"
Print " 2: Hello World (simple plain text response)"
Print " 3: Caching (Drummers)"
Print " 4: Multipart Forms"
Print " 5: Sessions"
Print " 6: Templates Client Side"
Print " 7: Templates Server Side"
Print " 8: WebSockets (simple chat app)"
Print " 9: XojoScript"
Print "10: ServerThread"
Print ""
Print ""
Print "Enter number and <enter> to start a demo:"

Var inputString As String = Input
Return Val(inputString)

End Function
#tag EndMethod

#tag Method, Flags = &h21
Private Function ExpressEventLog(Message As String, Level As Express.LogLevel) As Boolean
//If you don't want to use Express's default EventLog-Handling (StdOut in Console Applications,
//System.DebugLog in GUI Applications), then you can add the Express.EventLogHandlerDelegate and
//handle the Logging there.
//Just make sure to 'Return True' to tell Express to NOT handle the EventLog as well
// If you don't want to use Express's default EventLog-Handling (StdOut in Console Applications,
// System.DebugLog in GUI Applications), then you can add the Express.EventLogHandlerDelegate and
// handle the Logging there.
// Just make sure to 'Return True' to tell Express to NOT handle the EventLog as well

//So this would be the place to forward the Logs to your App's own Log-Handling facility
// So this would be the place to forward the Logs to your App's own Log-Handling facility

Select Case CType(Level, Integer)

Expand Down
6 changes: 3 additions & 3 deletions Express-Demo-GUI.xojo_project
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ RBProjectVersion=2023.04
MinIDEVersion=20210300
OrigIDEVersion=20230400
Folder=Express-Demo-GUI;Express-Demo-GUI;&h0000000009B38FFF;&h0000000000000000;false
Folder=Demos;Demos;&h000000002B9BD7FF;&h0000000000000000;false
Folder=resources;Express-Demo-GUI/resources;&h000000003071DFFF;&h0000000009B38FFF;false
Picture=Express_512;Express-Demo-GUI/resources/Express_512.png;&h00000000042917FF;&h000000003071DFFF;false;0;&h0000000000000000
Class=App;Express-Demo-GUI/App.xojo_code;&h000000006FA95FFF;&h0000000009B38FFF;false
Expand All @@ -23,7 +24,6 @@ Class=RequestThread;Modules/Express/RequestThread.xojo_code;&h000000000B14C7FF;&
Class=XSContext;Modules/Express/XSContext.xojo_code;&h000000006B7387FF;&h000000001B3587FF;false
Module=Templates;Modules/Templates.xojo_code;&h0000000031C117FF;&h000000005B71A7FF;false
Class=MustacheLite;Modules/Templates/MustacheLite.xojo_code;&h0000000044A817FF;&h0000000031C117FF;false
Folder=Demos;Demos;&h000000002B9BD7FF;&h0000000000000000;false
Module=DemoCaching;Demos/DemoCaching.xojo_code;&h00000000243057FF;&h000000002B9BD7FF;false
Class=DrummersList;Demos/DemoCaching/DrummersList.xojo_code;&h000000001ED20FFF;&h00000000243057FF;false
Module=DemoHelloWorld;Demos/DemoHelloWorld.xojo_code;&h000000000F920FFF;&h000000002B9BD7FF;false
Expand All @@ -47,12 +47,12 @@ DefaultWindow=Window1
AppMenuBar=MainMenuBar
MajorVersion=6
MinorVersion=2
SubVersion=0
SubVersion=1
NonRelease=0
Release=3
InfoVersion=Express, A Webserver Based on AloeExpress
LongVersion=N/A Use at your own risk.
ShortVersion=6.2.0
ShortVersion=6.2.1
WinCompanyName=example.com
WinInternalName=Express-Demo-GUI
WinProductName=Express Demo
Expand Down
16 changes: 15 additions & 1 deletion Express-Demo-GUI/Window1.xojo_window
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,21 @@ End

// Create an instance of Express.Server, and configure it with optional command-line arguments.
// Note: The Express.RequestHandlerDelegate tells Express.Server which method is going to process the requests
Var args() As String = Array("--Port=8080")
Var args() As String
Var arguments As Dictionary = Express.ArgsToDictionary(args)
Var argValue As String

// Use Port 8080 for this demo if not specified otherwise
If (Not Express.LaunchArgumentGetValue(arguments, "--Port", "EXPRESS_PORT", argValue)) Then
args.Add("--Port=8080")
End If

// Use Loopback Network Interface for Debug Builds
#If DebugBuild Then
If (Not Express.LaunchArgumentIsSet(arguments, "--Loopback", "EXPRESS_LOOPBACK")) Then
args.Add("--Loopback")
End If
#EndIf

Select Case lstDemo.RowTagAt(lstDemo.SelectedRowIndex)

Expand Down
Loading

0 comments on commit afc9fc8

Please sign in to comment.