4.0 KiB
4.0 KiB
Role: Senior .NET Developer
Goal: Build a Transparent & Pilot-Ready ASP.NET Core latest Sync App
Context:
A prototype for Microsoft Graph Calendar Sync that makes the background process visible via a Web Dashboard.
Core Tech:
- .NET 10.0 MVC + EF Core SQLite.
- Microsoft.Identity.Web (Confidential Client flow).
Key Requirements:
-
Database Schema (SQLite):
- 'UserConfigs': Tracks 'UserId', 'Email', 'SubscriptionId', 'Expiration', 'LastDeltaToken'.
- 'WebhookLogs': Tracks 'Id', 'ReceivedAt', 'Payload' (raw JSON), 'Type' (Notification/Lifecycle).
-
Webhook Controller ('/api/notifications'):
- Implement '/listen' and '/lifecycle'.
- Crucial: Log every incoming request body into 'WebhookLogs' before processing.
- Return 'validationToken' as text/plain (not JSON).
-
Management Dashboard ('/Sync/Dashboard'):
- Create a Razor View that displays:
- A table of all rows in 'UserConfigs'.
- A table of the last 20 rows in 'WebhookLogs' (ordered by newest).
- A "Sync Now" button that triggers a manual Delta query for a specific user.
- Create a Razor View that displays:
-
Background Logic:
- 'SubscriptionManagerService': A background worker that checks for expiring subscriptions every 12 hours.
- When a webhook hits, trigger a 'SyncTask' that performs the Delta query and writes updates to the 'SyncResults.xlsx' file.
-
Transparency/Feedback:
- Use 'ILogger' to print the specific Subject and ChangeType of every event processed to the console.
- Ensure the 'validationToken' handshake is logged so I can see it succeed.
Instructions:
- Provide placeholders for ClientId, TenantId, ClientSecret, and BaseUrl.
- Ensure the app can run on macOS using 'dotnet run'.
Implementation Status (Updated: 2026-02-20)
Completed Tasks:
-
Project Initialization:
- Created ASP.NET Core MVC project targeting .NET 10.0.
- Added required NuGet packages:
Microsoft.EntityFrameworkCore.SqliteMicrosoft.EntityFrameworkCore.DesignMicrosoft.Identity.WebClosedXML(for Excel)Microsoft.Graph&Azure.Identity
-
Database Implementation:
- Created
UserConfigandWebhookLogmodels inModels/. - Configured
AppDbContextinData/. - Configured SQLite connection string in
appsettings.json. - Added logic in
Program.csto automatically ensure the database is created (EnsureCreated).
- Created
-
Webhook Handling:
- Implemented
WebhookController(/api/notifications). [HttpPost("listen")]and[HttpPost("lifecycle")]endpoints created.- Validation: Handles
validationTokenquery parameter and returns it astext/plain. - Logging: Logs all request payloads to
WebhookLogstable before processing.
- Implemented
-
Sync Logic & Excel Reporting:
- Implemented
SyncService(ISyncService) to encapsulate synchronization logic. - Configured
GraphServiceClientwithClientSecretCredential. - Added logic to perform (simulated) Delta queries.
- Implemented
ClosedXMLlogic to write/append sync results toSyncResults.xlsx.
- Implemented
-
Dashboard:
- Created
SyncControllerwithDashboardaction. - Implemented Razor View
Views/Sync/Dashboard.cshtmldisplaying:UserConfigstable.- Last 20
WebhookLogs. - "Sync Now" button triggering manual sync via
SyncService.
- Created
-
Background Services:
- Implemented
SubscriptionManagerServiceas anIHostedService. - Checks for expiring subscriptions every 12 hours (and on startup).
- Implemented
-
Configuration:
- Updated
appsettings.jsonwith placeholders for Azure AD credentials (ClientId,TenantId,ClientSecret,BaseUrl).
- Updated
How to Run:
- Navigate to the project directory:
cd GraphCalendarSync - Update
appsettings.jsonwith your actual Azure AD credentials. - Run the application:
dotnet run - Access the dashboard at
https://localhost:7197/Sync/Dashboard(port may vary, check console output).