Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Add remote service interactions #6

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
248f8a5
WIP - hack authentication for my tenant into the client to verifythat…
artl93 Dec 29, 2024
227a7df
WIP started playingwith request APIs
artl93 Dec 29, 2024
9f7f0eb
Fix await
artl93 Dec 30, 2024
5a39818
Merge branch 'main' into remote-approvals
artl93 Dec 30, 2024
cb4e2c2
Update .gitignore
artl93 Dec 30, 2024
b3c14a9
Merge branch 'main' into remote-approvals
artl93 Dec 31, 2024
8457c99
General cleanup
artl93 Dec 31, 2024
3e6ca52
Rename UserConfigurationProvider to LocalConfigurationProvider
artl93 Dec 31, 2024
6318016
- Fixup namespaces.
artl93 Dec 31, 2024
ba86cf4
WIP - refactor remote services from HiddenForm into their own classes
artl93 Dec 31, 2024
1d83e57
WIP - Add remote / local switcher
artl93 Dec 31, 2024
5ab47d7
Refactor user configuration and service registrations
artl93 Dec 31, 2024
bf59620
Add heartbeat functionality and simplify service setup
artl93 Jan 1, 2025
d8d9b6f
Refactor common record types into a common assembly
artl93 Jan 1, 2025
b43ea29
Add ScreenTIme.Common project reference
artl93 Jan 1, 2025
d05746d
Rename fields
artl93 Jan 1, 2025
0fb20e1
Move Heartbeat to ScreenTime.Common
artl93 Jan 1, 2025
f5f97ae
Heartbeat is now working end-to-end
artl93 Jan 1, 2025
93eb5bc
Rename RemoteUserConfigurationProvicer to ScreenTimeServiceClient
artl93 Jan 2, 2025
96516cd
Update src/ScreenTimeClient/Configuration/RemoteUserConfigurationProv…
artl93 Jan 2, 2025
d4a1b1d
Update src/ScreenTimeClient/Configuration/RemoteUserConfigurationProv…
artl93 Jan 2, 2025
50d72c8
Github copilot led me wrong - I didn't check - these weren't async me…
artl93 Jan 2, 2025
ef90cad
Add verification builds
artl93 Jan 2, 2025
cee21e8
WIP - screentimeservice is all up to date with the EF models from the…
artl93 Jan 2, 2025
f99a058
Remove unused "name" field from user configuration
artl93 Jan 2, 2025
1d04eba
Separate client configuration from user's daily limits / configuation
artl93 Jan 3, 2025
43c868a
Back to working
artl93 Jan 3, 2025
ffc25f2
Remove old database concepts.
artl93 Jan 3, 2025
9b4caa2
Remove old types
artl93 Jan 3, 2025
ed86562
Updated models to represent new reality. And it works.
artl93 Jan 4, 2025
7baa8e5
Updated models and ensured heartbeat works.
artl93 Jan 4, 2025
b520146
- Add Request Extensions
artl93 Jan 4, 2025
a557a36
Service can now to approvals and denials.
artl93 Jan 4, 2025
2baa97d
Sending a message using SignalR actually kind of works now (using Sca…
artl93 Jan 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/dotnet-desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# For a complete CI/CD sample to get started with GitHub Action workflows for Desktop Applications,
# refer to https://github.com/microsoft/github-actions-for-desktop-apps

name: .NET Core Desktop Build and Verify
name: Desktop Build and Verify
permissions:
contents: read
pull-requests: write
Expand All @@ -53,7 +53,7 @@ jobs:

strategy:
matrix:
configuration: [Debug, Release]
configuration: [Release]

runs-on: windows-latest # For a list of available runner types, refer to
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
Expand Down
88 changes: 88 additions & 0 deletions .github/workflows/dotnet-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# This workflow will build, test, sign and package a WPF or Windows Forms desktop application
# built on .NET Core.
# To learn how to migrate your existing application to .NET Core,
# refer to https://docs.microsoft.com/en-us/dotnet/desktop-wpf/migration/convert-project-from-net-framework
#
# To configure this workflow:
#
# 1. Configure environment variables
# GitHub sets default environment variables for every workflow run.
# Replace the variables relative to your project in the "env" section below.
#
# 2. Signing
# Generate a signing certificate in the Windows Application
# Packaging Project or add an existing signing certificate to the project.
# Next, use PowerShell to encode the .pfx file using Base64 encoding
# by running the following Powershell script to generate the output string:
#
# $pfx_cert = Get-Content '.\SigningCertificate.pfx' -Encoding Byte
# [System.Convert]::ToBase64String($pfx_cert) | Out-File 'SigningCertificate_Encoded.txt'
#
# Open the output file, SigningCertificate_Encoded.txt, and copy the
# string inside. Then, add the string to the repo as a GitHub secret
# and name it "Base64_Encoded_Pfx."
# For more information on how to configure your signing certificate for
# this workflow, refer to https://github.com/microsoft/github-actions-for-desktop-apps#signing
#
# Finally, add the signing certificate password to the repo as a secret and name it "Pfx_Key".
# See "Build the Windows Application Packaging project" below to see how the secret is used.
#
# For more information on GitHub Actions, refer to https://github.com/features/actions
# For a complete CI/CD sample to get started with GitHub Action workflows for Desktop Applications,
# refer to https://github.com/microsoft/github-actions-for-desktop-apps

name: Service Build and Verify
permissions:
contents: read
pull-requests: write

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:

build:

strategy:
matrix:
configuration: [Release]

runs-on: windows-latest # For a list of available runner types, refer to
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on

env:
Solution_Name: services.sln # Replace with your solution name, i.e. MyWpfApp.sln.
Test_Project_Path: src\ScreenTimeTest\ScreenTimeTest.csproj # Replace with the path to your test project, i.e. MyWpfApp.Tests\MyWpfApp.Tests.csproj.
# Wap_Project_Directory: your-wap-project-directory-name # Replace with the Wap project directory relative to the solution, i.e. MyWpfApp.Package.
# Wap_Project_Path: your-wap-project-path # Replace with the path to your Wap project, i.e. MyWpf.App.Package\MyWpfApp.Package.wapproj.

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

# Install the .NET Core workload
- name: Install .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x

# Build the application to populate the obj folder with RuntimeIdentifiers
- name: Build the application
run: dotnet build $env:Solution_Name
Copy link
Preview

Copilot AI Jan 4, 2025

Choose a reason for hiding this comment

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

The build command does not correctly use the Configuration environment variable. It should be passed as an argument to the dotnet build command.

Suggested change
run: dotnet build $env:Solution_Name
run: dotnet build $env:Solution_Name --configuration ${{ matrix.configuration }}

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
env:
Configuration: ${{ matrix.configuration }}

# Execute all unit tests in the solution
- name: Execute unit tests
run: dotnet test $env:Test_Project_Path

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,4 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml
.VSCodeCounter/*
9 changes: 9 additions & 0 deletions client.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScreenTimeClient", "src\ScreenTimeClient\ScreenTimeClient.csproj", "{C8F5B159-EE59-4DF2-AE4F-F29720D2C411}"
ProjectSection(ProjectDependencies) = postProject
{6F2B1F0F-759D-4F8A-85D3-EAB7900F4106} = {6F2B1F0F-759D-4F8A-85D3-EAB7900F4106}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScreenTimeTest", "src\ScreenTimeTest\ScreenTimeTest.csproj", "{723DBE42-FDB4-09D1-B381-2B18C4E0C02D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScreenTIme.Common", "src\ScreenTIme.Common\ScreenTIme.Common.csproj", "{6F2B1F0F-759D-4F8A-85D3-EAB7900F4106}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +26,10 @@ Global
{723DBE42-FDB4-09D1-B381-2B18C4E0C02D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{723DBE42-FDB4-09D1-B381-2B18C4E0C02D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{723DBE42-FDB4-09D1-B381-2B18C4E0C02D}.Release|Any CPU.Build.0 = Release|Any CPU
{6F2B1F0F-759D-4F8A-85D3-EAB7900F4106}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6F2B1F0F-759D-4F8A-85D3-EAB7900F4106}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F2B1F0F-759D-4F8A-85D3-EAB7900F4106}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F2B1F0F-759D-4F8A-85D3-EAB7900F4106}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 6 additions & 0 deletions screentime.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScreenTimeService", "src\Sc
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScreenTimeWebApp", "src\ScreenTimeWebApp\ScreenTimeWebApp.csproj", "{74824E5D-D706-4B15-8FAC-519481DFD92F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScreenTime.Common", "src\ScreenTIme.Common\ScreenTime.Common.csproj", "{7123C63B-9341-FCC6-F236-F06D8B356B34}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -39,6 +41,10 @@ Global
{74824E5D-D706-4B15-8FAC-519481DFD92F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74824E5D-D706-4B15-8FAC-519481DFD92F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74824E5D-D706-4B15-8FAC-519481DFD92F}.Release|Any CPU.Build.0 = Release|Any CPU
{7123C63B-9341-FCC6-F236-F06D8B356B34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7123C63B-9341-FCC6-F236-F06D8B356B34}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7123C63B-9341-FCC6-F236-F06D8B356B34}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7123C63B-9341-FCC6-F236-F06D8B356B34}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
8 changes: 7 additions & 1 deletion services.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.13.35617.110 d17.13
VisualStudioVersion = 17.13.35617.110
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScreenTimeService", "src\ScreenTimeService\ScreenTimeService.csproj", "{E14F7292-B70E-774F-19D4-C483AEF4B32D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScreenTimeWebApp", "src\ScreenTimeWebApp\ScreenTimeWebApp.csproj", "{E56516C9-FC8D-185C-B490-01A74AB009A4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScreenTIme.Common", "src\ScreenTIme.Common\ScreenTIme.Common.csproj", "{7123C63B-9341-FCC6-F236-F06D8B356B34}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{E56516C9-FC8D-185C-B490-01A74AB009A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E56516C9-FC8D-185C-B490-01A74AB009A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E56516C9-FC8D-185C-B490-01A74AB009A4}.Release|Any CPU.Build.0 = Release|Any CPU
{7123C63B-9341-FCC6-F236-F06D8B356B34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7123C63B-9341-FCC6-F236-F06D8B356B34}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7123C63B-9341-FCC6-F236-F06D8B356B34}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7123C63B-9341-FCC6-F236-F06D8B356B34}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
using System.Diagnostics.CodeAnalysis;

namespace ScreenTimeClient
namespace ScreenTime.Common
{
public record class UserConfiguration(
string Name,
public record DailyConfiguration(
int DailyLimitMinutes = 60,
int WarningTimeMinutes = 10,
int WarningIntervalSeconds = 60,
int GraceMinutes = 5,
string ResetTime = "06:00",
bool DisableLock = false,
int DelayLockSeconds = 10,
bool EnableOnline = false,
List<(DateTimeOffset, int)>? Extensions = null) : IEquatable<UserConfiguration>, IComparable<UserConfiguration>
List<(DateTimeOffset, int)>? Extensions = null) : IEquatable<DailyConfiguration>, IComparable<DailyConfiguration>
{
public TimeSpan TotalTimeAllowed
{
Expand Down Expand Up @@ -46,22 +43,17 @@
}
}

public int CompareTo(UserConfiguration? other)
public int CompareTo(DailyConfiguration? other)
{
throw new Exception();
}

virtual public bool Equals(UserConfiguration? other)
virtual public bool Equals(DailyConfiguration? other)
{
// throw new Exception();
if (other == null)
{
return false;
}
if (Name != other.Name)
{
return false;
}
if (DailyLimitMinutes != other.DailyLimitMinutes)
{
return false;
Expand All @@ -70,10 +62,6 @@
{
return false;
}
if (WarningIntervalSeconds != other.WarningIntervalSeconds)
{
return false;
}
if (GraceMinutes != other.GraceMinutes)
{
return false;
Expand All @@ -90,10 +78,6 @@
{
return false;
}
if (EnableOnline != other.EnableOnline)
{
return false;
}
if (Extensions == null && other.Extensions == null)
{
return true;
Expand Down Expand Up @@ -126,6 +110,6 @@
{
// test
throw new Exception();
return base.GetHashCode();

Check warning on line 113 in src/ScreenTIme.Common/DailyConfiguration.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Unreachable code detected

Check warning on line 113 in src/ScreenTIme.Common/DailyConfiguration.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Unreachable code detected

Check warning on line 113 in src/ScreenTIme.Common/DailyConfiguration.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Unreachable code detected

Check warning on line 113 in src/ScreenTIme.Common/DailyConfiguration.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Unreachable code detected

Check warning on line 113 in src/ScreenTIme.Common/DailyConfiguration.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Unreachable code detected

Check warning on line 113 in src/ScreenTIme.Common/DailyConfiguration.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Unreachable code detected
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/ScreenTIme.Common/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ScreenTime.Common
{
public record AdminExtensionGrant(Guid UserId, TimeSpan Duration, Guid[] RequestIds);
public record ExtensionGrant(DateTimeOffset GrantDate, TimeSpan Duration);
public record ExtensionRequest(TimeSpan Duration);
public record AdminExtensionRequest(Guid requestId, User User, DateTimeOffset SubmissionDate, TimeSpan Duration);
}
6 changes: 6 additions & 0 deletions src/ScreenTIme.Common/Heartbeat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ScreenTime.Common
{
public record Heartbeat(DateTimeOffset Timestamp, TimeSpan Duration, UserState UserState);

public record User (Guid Id, string Name, string Email);
}
9 changes: 9 additions & 0 deletions src/ScreenTIme.Common/ScreenTIme.Common.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

namespace ScreenTimeClient
namespace ScreenTime.Common
{

public enum UserActivityState
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace ScreenTimeClient
namespace ScreenTime.Common
{
// make it so that the properties can be lowercase when deserialized by json
public record UserMessage(string Title, string Message, string Icon, string Action);
Expand Down
8 changes: 8 additions & 0 deletions src/ScreenTIme.Common/UserState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Text.Json.Serialization;

namespace ScreenTime.Common
{
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum UserState { Invalid, Okay, Warn, Error, Lock, Paused }

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ScreenTimeClient
namespace ScreenTime.Common
{
public record UserStatus(TimeSpan LoggedInTime, string Icon, string Action, UserState State, TimeSpan DailyTimeLimit, TimeSpan ExtensionTime);

Expand Down
4 changes: 3 additions & 1 deletion src/ScreenTimeClient/ComputerStateEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace ScreenTimeClient
using ScreenTime.Common;

namespace ScreenTimeClient
{
public class ComputerStateEventArgs(UserState state) : EventArgs
{
Expand Down
13 changes: 13 additions & 0 deletions src/ScreenTimeClient/Configuration/ClientConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using ScreenTime.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace ScreenTimeClient.Configuration
{

public record ClientConfiguration(int WarningInterval, bool EnableOnline);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Microsoft.Win32;

namespace ScreenTimeClient.Configuration
{
public class ClientConfigurationRegistryReader : IClientConfigurationReader
{
const string _baseKey = @"HKEY_CURRENT_USER\Software\ScreenTime";

public ClientConfiguration GetConfiguration()
{
var warningInterval = GetRegistryIntValue(_baseKey, "WarningInterval", 60);
var enableOnline = GetRegistryIntValue(_baseKey, "EnableOnline", 0) == 1; // convert to boolean

return new ClientConfiguration(warningInterval, enableOnline);

}

private static int GetRegistryIntValue(string key, string valueName, int defaultValue)
{
var objectValue = Registry.GetValue(key, valueName, defaultValue);
if (objectValue == null)
{
return defaultValue;
}
else if (objectValue is int intValue)
{
return intValue;
}
else if (objectValue is string stringValue)
{
if (int.TryParse(stringValue, out int result))
{
return result;
}
}
return defaultValue;
}

}
}
11 changes: 11 additions & 0 deletions src/ScreenTimeClient/Configuration/DailyConfigurationEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using ScreenTime.Common;


namespace ScreenTimeClient.Configuration
{
public class DailyConfigurationEventArgs(object Sender, DailyConfiguration Configuration) : EventArgs
{
public DailyConfiguration Configuration { get; } = Configuration;
public object Sender { get; } = Sender;
}
}
Loading
Loading