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

docs: update example app to run on macos #96

Merged
merged 5 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# .github/dependabot.yml

version: 2
updates:
- package-ecosystem: "nuget"
Expand Down
1 change: 1 addition & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# .github/release-drafter.yml

name-template: 'v$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'
categories:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# .github/workflows/main.yml

name: CI

on:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# .github/workflows/pull-request.yml

name: Pull Request

on:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# .github/workflows/release.yml

name: Deploy NuGet Package before Release

on:
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
21 changes: 21 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/RxDBDotNet.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
2 changes: 1 addition & 1 deletion example/LiveDocs.AppHost/LiveDocs.AppHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
<ImplicitUsings>enable</ImplicitUsings>

<WarningLevel>9999</WarningLevel>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<NoWarn>$(NoWarn);CA1848;CA2007;MA0004</NoWarn>
Expand Down
12 changes: 10 additions & 2 deletions example/LiveDocs.AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
// example/LiveDocs.AppHost/Program.cs

using System;
using Aspire.Hosting;
using Projects;

var builder = DistributedApplication.CreateBuilder(args);

var redis = builder.AddRedis("redis", 6379)
.WithImage("redis")
.WithImageTag("latest")
.WithEndpoint(port: 6380, targetPort: 6379, name: "redis-endpoint");

// Add SQL Server
var password = builder.AddParameter("sqlpassword", secret: true);
var sqlDb = builder.AddSqlServer("sql", password: password, port: 1433)
.WithImage("mssql/server")
.WithImageTag("2022-latest")
.WithEnvironment("ACCEPT_EULA", "Y")
.WithEnvironment("MSSQL_SA_PASSWORD", "Admin123!")
// this is here to preserve the data across restarts
.WithVolume("livedocs-sql-data", "/var/opt/mssql")
.WithEndpoint(port: 1146, targetPort: 1433, name: "sql-endpoint")
.AddDatabase("sqldata", databaseName: "LiveDocsDb");
Expand All @@ -27,5 +36,4 @@
.WithExternalHttpEndpoints();
}

await builder.Build()
.RunAsync();
await builder.Build().RunAsync();
1 change: 1 addition & 0 deletions example/LiveDocs.GraphQLApi/Data/LiveDocsDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// example/LiveDocs.GraphQLApi/Data/LiveDocsDbContext.cs

using System;
using LiveDocs.GraphQLApi.Infrastructure;
using LiveDocs.GraphQLApi.Models.Entities;
using Microsoft.EntityFrameworkCore;
Expand Down
112 changes: 63 additions & 49 deletions example/LiveDocs.GraphQLApi/Infrastructure/LiveDocsDbInitializer.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
// example/LiveDocs.GraphQLApi/Infrastructure/LiveDocsDbInitializer.cs

using System;
using System.Threading.Tasks;
using LiveDocs.GraphQLApi.Data;
using LiveDocs.GraphQLApi.Models.Entities;
using LiveDocs.GraphQLApi.Models.Replication;
using LiveDocs.GraphQLApi.Security;
using Microsoft.EntityFrameworkCore;

namespace LiveDocs.GraphQLApi.Infrastructure
namespace LiveDocs.GraphQLApi.Infrastructure;

public static class LiveDocsDbInitializer
{
public static class LiveDocsDbInitializer
public static async Task InitializeAsync()
{
public static async Task InitializeAsync()
{
await using var dbContext = new LiveDocsDbContext();
await using var dbContext = new LiveDocsDbContext();

// See https://github.com/dotnet/aspire/issues/1023#issuecomment-2156120941
// for macOS related issues
var strategy = new SqlServerRetryingExecutionStrategy(
dbContext,
maxRetryCount: 10,
TimeSpan.FromSeconds(5),
RetryIntervals);

await strategy.ExecuteAsync(async () =>
{
try
{
await dbContext.Database.EnsureCreatedAsync();
Expand All @@ -27,57 +39,59 @@ public static async Task InitializeAsync()
{
await SeedDataAsync(dbContext);
}
}
});
}

private static readonly int[] RetryIntervals = { 0 };

private static async Task SeedDataAsync(LiveDocsDbContext dbContext)
private static async Task SeedDataAsync(LiveDocsDbContext dbContext)
{
var rootWorkspace = new Workspace
{
var rootWorkspace = new Workspace
{
Id = RT.Comb.Provider.Sql.Create(),
Name = "Default Workspace",
UpdatedAt = DateTimeOffset.UtcNow,
IsDeleted = false,
ReplicatedDocumentId = Guid.NewGuid(),
Topics = [],
};
Id = RT.Comb.Provider.Sql.Create(),
Name = "Default Workspace",
UpdatedAt = DateTimeOffset.UtcNow,
IsDeleted = false,
ReplicatedDocumentId = Guid.NewGuid(),
Topics = [],
};

await dbContext.Workspaces.AddAsync(rootWorkspace);
await dbContext.Workspaces.AddAsync(rootWorkspace);

var systemAdminReplicatedUser = new ReplicatedUser
{
Id = Guid.NewGuid(),
FirstName = "System",
LastName = "Admin",
Email = "systemadmin@livedocs.example.org",
Role = UserRole.SystemAdmin,
WorkspaceId = rootWorkspace.ReplicatedDocumentId,
UpdatedAt = DateTimeOffset.UtcNow,
IsDeleted = false,
};
var systemAdminReplicatedUser = new ReplicatedUser
{
Id = Guid.NewGuid(),
FirstName = "System",
LastName = "Admin",
Email = "systemadmin@livedocs.example.org",
Role = UserRole.SystemAdmin,
WorkspaceId = rootWorkspace.ReplicatedDocumentId,
UpdatedAt = DateTimeOffset.UtcNow,
IsDeleted = false,
};

// Generate a non-expiring JWT token for the system admin user
// We'll use this in the client app to bootstrap the "logged in" state
// since we are not supporting username and password login in this example application
var nonExpiringToken = JwtUtil.GenerateJwtToken(systemAdminReplicatedUser, expires: DateTime.MaxValue);
// Generate a non-expiring JWT token for the system admin user
// We'll use this in the client app to bootstrap the "logged in" state
// since we are not supporting username and password login in this example application
var nonExpiringToken = JwtUtil.GenerateJwtToken(systemAdminReplicatedUser, expires: DateTime.MaxValue);

var systemAdminUser = new User
{
Id = RT.Comb.Provider.Sql.Create(),
FirstName = systemAdminReplicatedUser.FirstName,
LastName = systemAdminReplicatedUser.LastName,
Email = systemAdminReplicatedUser.Email,
Role = systemAdminReplicatedUser.Role,
JwtAccessToken = nonExpiringToken,
WorkspaceId = rootWorkspace.Id,
UpdatedAt = systemAdminReplicatedUser.UpdatedAt,
IsDeleted = systemAdminReplicatedUser.IsDeleted,
ReplicatedDocumentId = systemAdminReplicatedUser.Id,
Topics = [],
};
var systemAdminUser = new User
{
Id = RT.Comb.Provider.Sql.Create(),
FirstName = systemAdminReplicatedUser.FirstName,
LastName = systemAdminReplicatedUser.LastName,
Email = systemAdminReplicatedUser.Email,
Role = systemAdminReplicatedUser.Role,
JwtAccessToken = nonExpiringToken,
WorkspaceId = rootWorkspace.Id,
UpdatedAt = systemAdminReplicatedUser.UpdatedAt,
IsDeleted = systemAdminReplicatedUser.IsDeleted,
ReplicatedDocumentId = systemAdminReplicatedUser.Id,
Topics = [],
};

await dbContext.Users.AddAsync(systemAdminUser);
await dbContext.Users.AddAsync(systemAdminUser);

await dbContext.SaveChangesAsync();
}
await dbContext.SaveChangesAsync();
}
}
2 changes: 1 addition & 1 deletion example/LiveDocs.GraphQLApi/LiveDocs.GraphQLApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
<ImplicitUsings>enable</ImplicitUsings>

<WarningLevel>9999</WarningLevel>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<NoWarn>$(NoWarn);CA1848;CA2007;CA1716;MA0004</NoWarn>
Expand Down
1 change: 1 addition & 0 deletions example/LiveDocs.GraphQLApi/Models/Entities/LiveDoc.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// example/LiveDocs.GraphQLApi/Models/Entities/LiveDoc.cs

using System;
using System.ComponentModel.DataAnnotations;

namespace LiveDocs.GraphQLApi.Models.Entities;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// example/LiveDocs.GraphQLApi/Models/Entities/ReplicatedEntity.cs

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace LiveDocs.GraphQLApi.Models.Entities;
Expand Down
1 change: 1 addition & 0 deletions example/LiveDocs.GraphQLApi/Models/Entities/User.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// example/LiveDocs.GraphQLApi/Models/Entities/User.cs

using System;
using System.ComponentModel.DataAnnotations;
using LiveDocs.GraphQLApi.Security;
using LiveDocs.GraphQLApi.Validations;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// example/LiveDocs.GraphQLApi/Models/Replication/ReplicatedDocument.cs

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using LiveDocs.GraphQLApi.Validations;
using RxDBDotNet.Documents;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// example/LiveDocs.GraphQLApi/Models/Replication/ReplicatedLiveDoc.cs

using System;
using System.ComponentModel.DataAnnotations;
using HotChocolate;
using LiveDocs.GraphQLApi.Validations;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// example/LiveDocs.GraphQLApi/Models/Replication/ReplicatedUser.cs

using System;
using System.ComponentModel.DataAnnotations;
using HotChocolate;
using HotChocolate.Types;
Expand Down
6 changes: 6 additions & 0 deletions example/LiveDocs.GraphQLApi/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// example/LiveDocs.GraphQLApi/Program.cs

using System;
using System.Net;
using System.Security.Claims;
using System.Threading.Tasks;
using HotChocolate.AspNetCore;
using LiveDocs.GraphQLApi.Data;
using LiveDocs.GraphQLApi.Infrastructure;
Expand All @@ -10,6 +12,10 @@
using LiveDocs.GraphQLApi.Services;
using LiveDocs.ServiceDefaults;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using RxDBDotNet.Extensions;
using RxDBDotNet.Security;
using RxDBDotNet.Services;
Expand Down
2 changes: 2 additions & 0 deletions example/LiveDocs.GraphQLApi/Security/JwtUtil.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// example/LiveDocs.GraphQLApi/Security/JwtUtil.cs

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
Expand Down
5 changes: 5 additions & 0 deletions example/LiveDocs.GraphQLApi/Services/DocumentService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// example/LiveDocs.GraphQLApi/Services/DocumentService.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using LiveDocs.GraphQLApi.Data;
using LiveDocs.GraphQLApi.Models.Entities;
using Microsoft.EntityFrameworkCore;
Expand Down
4 changes: 4 additions & 0 deletions example/LiveDocs.GraphQLApi/Services/LiveDocService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// example/LiveDocs.GraphQLApi/Services/LiveDocService.cs

using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using LiveDocs.GraphQLApi.Data;
using LiveDocs.GraphQLApi.Models.Entities;
using LiveDocs.GraphQLApi.Models.Replication;
Expand Down
4 changes: 4 additions & 0 deletions example/LiveDocs.GraphQLApi/Services/UserService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// example/LiveDocs.GraphQLApi/Services/UserService.cs

using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using LiveDocs.GraphQLApi.Data;
using LiveDocs.GraphQLApi.Models.Entities;
using LiveDocs.GraphQLApi.Models.Replication;
Expand Down
4 changes: 4 additions & 0 deletions example/LiveDocs.GraphQLApi/Services/WorkspaceService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// example/LiveDocs.GraphQLApi/Services/WorkspaceService.cs

using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using LiveDocs.GraphQLApi.Data;
using LiveDocs.GraphQLApi.Models.Entities;
using LiveDocs.GraphQLApi.Models.Replication;
Expand Down
Loading
Loading