Skip to content

Commit

Permalink
final before release
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonysharpy committed May 10, 2024
1 parent b924677 commit ab69445
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 16 deletions.
11 changes: 8 additions & 3 deletions sandbank/Code/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@

static class Config
{
/// <summary>
/// Whether to show the startup and shutdown messages in the console when the database
/// stops and starts.
/// </summary>
public const bool STARTUP_SHUTDOWN_MESSAGES = true;
/// <summary>
/// If this is true then all warnings are thrown as exceptions. I probably wouldn't
/// recommend this but you can enable it if you want. This is used in the unit tests
/// to make life easier.
/// </summary>
public static bool WARNINGS_AS_EXCEPTIONS = false;
public const bool WARNINGS_AS_EXCEPTIONS = false;
/// <summary>
/// Set this to true if you want clients to be able to use the database too. You
/// probably don't want this - none of the data will get synced between host and clients
/// (that's not what it's designed to do). But there might be some situations where you
/// want to store data on the client for some reason.
/// </summary>
public static bool CLIENTS_CAN_USE = false;
public const bool CLIENTS_CAN_USE = false;
/// <summary>
/// This controls whether the written JSON files are indented or not.
/// Indentation makes them more human-readable, but probably makes saving
/// to disk a little bit slower.
/// </summary>
public static bool INDENT_JSON = true;
public const bool INDENT_JSON = true;
/// <summary>
/// The database will try to make sure that all stale data is written to disk
/// at most every this many seconds. In the event of a crash, all stale data
Expand Down
25 changes: 18 additions & 7 deletions sandbank/Code/Initialisation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ public static void Initialise()
if ( CurrentDatabaseState != DatabaseState.Uninitialised )
return; // Probably another thread already did all this.

Log.Info( "==================================" );
Log.Info( "Initialising Sandbank..." );

if ( Config.STARTUP_SHUTDOWN_MESSAGES )
{
Log.Info( "==================================" );
Log.Info( "Initialising Sandbank..." );
}

try
{
Expand All @@ -32,15 +36,22 @@ public static void Initialise()

CurrentDatabaseState = DatabaseState.Initialised;

Log.Info( "Sandbank initialisation finished successfully" );
Log.Info( "==================================" );

if ( Config.STARTUP_SHUTDOWN_MESSAGES )
{
Log.Info( "Sandbank initialisation finished successfully" );
Log.Info( "==================================" );
}
}
catch ( Exception e )
{
Logging.Error( $"failed to initialise database - the database will now not start: {Logging.ExtractExceptionString( e )}" );
Logging.Error( $"failed to initialise database: {Logging.ExtractExceptionString( e )}" );

Log.Info( "Sandbank initialisation finished unsuccessfully" );
Log.Info( "==================================" );
if ( Config.STARTUP_SHUTDOWN_MESSAGES )
{
Log.Info( "Sandbank initialisation finished unsuccessfully" );
Log.Info( "==================================" );
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion sandbank/Code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Sandbank.CopySavedData<PlayerData>(ourPlayerData, player.Data);

### Slow Queries

A well-designed query should return instantly.
Usually your queries will return instantly.

However, if you're doing something really hardcore, you should consider wrapping the call in its own thread:

Expand Down
13 changes: 11 additions & 2 deletions sandbank/Code/Shutdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public static void ShutdownDatabase()
// if closed quickly enough.
lock ( Initialisation.InitialisationLock )
{
if ( Config.STARTUP_SHUTDOWN_MESSAGES )
{
Log.Info( "==================================" );
Log.Info( "Shutting down Sandbank..." );
}

try
{
if ( Initialisation.CurrentDatabaseState == DatabaseState.Initialised )
Expand All @@ -43,10 +49,13 @@ public static void ShutdownDatabase()
{
Initialisation.CurrentDatabaseState = DatabaseState.Uninitialised;
Logging.Error( $"failed to shutdown database properly - some data may have been lost: {Logging.ExtractExceptionString( e )}" );
return;
}

Logging.Info( "Sandbank shutdown successful" );
if ( Config.STARTUP_SHUTDOWN_MESSAGES )
{
Log.Info( "Shutdown completed" );
Log.Info( "==================================" );
}
}
}
}
1 change: 1 addition & 0 deletions sandbank/UnitTests/.runsettings
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<!-- MSTest specific run settings -->
<MSTest>
<!-- Disable parallel test execution -->
<Parallelize Workers="1" Scope="MethodLevel"/>
Expand Down
13 changes: 10 additions & 3 deletions sandbank/sandbank.sbproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{
"Title": "sandbank",
"Title": "Sandbank",
"Type": "library",
"Org": "local",
"Org": "anthonysharpy",
"Ident": "sandbank",
"Schema": 1
"Tags": "database",
"Schema": 1,
"Resources": null,
"PackageReferences": [],
"EditorReferences": null,
"Metadata": {
"CsProjName": ""
}
}

0 comments on commit ab69445

Please sign in to comment.