-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Keep track of reservation time client-side and add debug settings to aid
development
- Loading branch information
1 parent
4c18eb8
commit e96111d
Showing
20 changed files
with
346 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,6 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=10ba09a3_002D1640_002D4bef_002Db3c4_002D8eaf8e690b9b/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="Test_When_ForThisStationCalled_Then_MatchingStationNumberAndHostnameReturnTrue" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
 | ||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=3c5c5451_002Dbe2a_002D4e87_002Da7ba_002D85cf30564cd6/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="UtilsTests" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
 | ||
<TestAncestor>
 | ||
<TestId>xUnit::8B549C98-F78C-422A-8C26-E1D7A0881CAD::net8.0-windows::Lanpartyseating.Desktop.Tests.UtilsTests.Test_When_ForThisStationCalled_Then_MatchingStationNumberAndHostnameReturnTrue</TestId>
 | ||
</TestAncestor>
 | ||
</SessionState></s:String> | ||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=27b22507_002D9043_002D43f5_002D9688_002Df4a293a50701/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" Name="Test_When_ForThisStationCalled_Then_MatchingStationNumberAndHostnameReturnTrue #2" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
 | ||
<TestAncestor>
 | ||
<TestId>xUnit::8B549C98-F78C-422A-8C26-E1D7A0881CAD::net8.0-windows::Lanpartyseating.Desktop.Tests.UtilsTests.Test_When_ForThisStationCalled_Then_MatchingStationNumberAndHostnameReturnTrue</TestId>
 | ||
<TestId>xUnit::8B549C98-F78C-422A-8C26-E1D7A0881CAD::net8.0-windows::Lanpartyseating.Desktop.Tests.UtilsTests</TestId>
 | ||
</TestAncestor>
 | ||
</SessionState></s:String></wpf:ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Lanpartyseating.Desktop.Business; | ||
|
||
public class DummySessionManager : ISessionManager | ||
{ | ||
private readonly ILogger _logger; | ||
|
||
public DummySessionManager(ILogger<DummySessionManager> logger) | ||
{ | ||
_logger = logger; | ||
_logger.LogInformation("The dummy session manager is in use"); | ||
} | ||
|
||
public void SignInGamerAccount() | ||
{ | ||
_logger.LogInformation("The client would have logged in an interactive session for the gamer account now"); | ||
} | ||
|
||
public void SignInTournamentAccount() | ||
{ | ||
_logger.LogInformation("The client would have logged in an interactive session for the tournament account now"); | ||
} | ||
|
||
public void SignOut() | ||
{ | ||
_logger.LogInformation("The client would have logged out an the current interactive session now"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Lanpartyseating.Desktop.Business; | ||
|
||
public interface ISessionManager | ||
{ | ||
public void SignInGamerAccount(); | ||
public void SignInTournamentAccount(); | ||
public void SignOut(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Lanpartyseating.Desktop.Business; | ||
|
||
using System; | ||
using System.Threading; | ||
|
||
public class Timekeeper : IDisposable | ||
{ | ||
private readonly ILogger _logger; | ||
private readonly ISessionManager _sessionManager; | ||
private Timer _timer; | ||
private DateTimeOffset _sessionEndTime; | ||
private readonly object _lock = new(); | ||
|
||
public Timekeeper(ILogger<Timekeeper> logger, ISessionManager sessionManager) | ||
{ | ||
_logger = logger; | ||
_sessionManager = sessionManager; | ||
_timer = new Timer(SessionEnded, null, Timeout.Infinite, Timeout.Infinite); | ||
Check warning on line 20 in Lanpartyseating.Desktop/Business/Timekeeper.cs GitHub Actions / build (x64)
Check warning on line 20 in Lanpartyseating.Desktop/Business/Timekeeper.cs GitHub Actions / build (x64)
Check warning on line 20 in Lanpartyseating.Desktop/Business/Timekeeper.cs GitHub Actions / build (arm64)
Check warning on line 20 in Lanpartyseating.Desktop/Business/Timekeeper.cs GitHub Actions / build (arm64)
|
||
} | ||
|
||
public void StartSession(DateTimeOffset startTime, DateTimeOffset endTime) | ||
{ | ||
lock (_lock) | ||
{ | ||
if (endTime <= startTime) | ||
{ | ||
throw new ArgumentException("End time must be later than start time."); | ||
} | ||
|
||
if (endTime <= DateTimeOffset.UtcNow) | ||
{ | ||
throw new ArgumentException("End time must be in the future."); | ||
} | ||
|
||
_sessionEndTime = endTime; | ||
var duration = endTime - DateTimeOffset.UtcNow; | ||
|
||
// If the start time is in the future, delay the timer start | ||
if (startTime > DateTimeOffset.UtcNow) | ||
{ | ||
_timer.Change(startTime - DateTimeOffset.UtcNow, Timeout.InfiniteTimeSpan); | ||
} | ||
else | ||
{ | ||
_timer.Change(duration, Timeout.InfiniteTimeSpan); | ||
} | ||
|
||
_logger.LogInformation($"Session started. Will end at {endTime}."); | ||
_sessionManager.SignInGamerAccount(); | ||
} | ||
} | ||
|
||
public void ExtendSession(DateTimeOffset newEndTime) | ||
{ | ||
lock (_lock) | ||
{ | ||
if (newEndTime <= DateTimeOffset.UtcNow) | ||
{ | ||
throw new ArgumentException("New end time must be in the future."); | ||
} | ||
|
||
if (newEndTime > _sessionEndTime) | ||
{ | ||
_sessionEndTime = newEndTime; | ||
var duration = newEndTime - DateTimeOffset.UtcNow; | ||
_timer.Change(duration, Timeout.InfiniteTimeSpan); | ||
_logger.LogInformation($"Session extended. New end time: {newEndTime}."); | ||
} | ||
else | ||
{ | ||
_logger.LogInformation("New end time must be later than the current end time."); | ||
} | ||
} | ||
} | ||
|
||
public void EndSession() | ||
{ | ||
lock (_lock) | ||
{ | ||
_timer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan); | ||
_sessionEndTime = DateTimeOffset.MinValue; | ||
_logger.LogInformation("Session forcibly ended."); | ||
_sessionManager.SignOut(); | ||
} | ||
} | ||
|
||
private void SessionEnded(object state) | ||
{ | ||
_logger.LogInformation("Session ended."); | ||
_sessionManager.SignOut(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_timer?.Dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.