Skip to content

Commit

Permalink
Merge pull request #53 from seesharprun/dotnet-9-update
Browse files Browse the repository at this point in the history
Update to .NET 9
  • Loading branch information
seesharprun authored Oct 22, 2024
2 parents 5261069 + 93063ba commit 968a7b2
Show file tree
Hide file tree
Showing 22 changed files with 231 additions and 196 deletions.
6 changes: 3 additions & 3 deletions azure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ services:
language: csharp
host: containerapp
docker:
path: ./Dockerfile
path: ../Dockerfile
context: ../
pipeline:
provider: github
hooks:
postprovision:
windows:
run: |
dotnet user-secrets set "AZURE_COSMOS_DB_NOSQL_ENDPOINT" "$env:AZURE_COSMOS_DB_NOSQL_ENDPOINT" --project ./src/web/Cosmos.Samples.NoSQL.Quickstart.Web.csproj
dotnet user-secrets set "AZURE_COSMOS_DB_NOSQL_ENDPOINT" "$env:AZURE_COSMOS_DB_NOSQL_ENDPOINT" --project ./src/web/Microsoft.Samples.Cosmos.NoSQL.Quickstart.Web.csproj
shell: pwsh
continueOnError: false
interactive: true
posix:
run: |
dotnet user-secrets set "AZURE_COSMOS_DB_NOSQL_ENDPOINT" "$AZURE_COSMOS_DB_NOSQL_ENDPOINT" --project ./src/web/Cosmos.Samples.NoSQL.Quickstart.Web.csproj
dotnet user-secrets set "AZURE_COSMOS_DB_NOSQL_ENDPOINT" "$AZURE_COSMOS_DB_NOSQL_ENDPOINT" --project ./src/web/Microsoft.Samples.Cosmos.NoSQL.Quickstart.Web.csproj
shell: sh
continueOnError: false
interactive: true
22 changes: 0 additions & 22 deletions src/Cosmos.Samples.NoSQL.Quickstart.sln

This file was deleted.

24 changes: 24 additions & 0 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
USER app
WORKDIR /app
EXPOSE 8080
EXPOSE 8081
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["web/Microsoft.Samples.Cosmos.NoSQL.Quickstart.Web.csproj", "web/"]
COPY ["models/Microsoft.Samples.Cosmos.NoSQL.Quickstart.Models.csproj", "models/"]
COPY ["services/Microsoft.Samples.Cosmos.NoSQL.Quickstart.Services.csproj", "services/"]
COPY ["Microsoft.Samples.Cosmos.NoSQL.Quickstart.sln", "."]
RUN dotnet restore "Microsoft.Samples.Cosmos.NoSQL.Quickstart.sln"
COPY . .
RUN dotnet build "Microsoft.Samples.Cosmos.NoSQL.Quickstart.sln" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "web/Microsoft.Samples.Cosmos.NoSQL.Quickstart.Web.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Microsoft.Samples.Cosmos.NoSQL.Quickstart.Web.dll"]
34 changes: 34 additions & 0 deletions src/Microsoft.Samples.Cosmos.NoSQL.Quickstart.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Samples.Cosmos.NoSQL.Quickstart.Web", "web\Microsoft.Samples.Cosmos.NoSQL.Quickstart.Web.csproj", "{DB1EBDE0-AA02-4D28-8574-EF28DAC09147}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Samples.Cosmos.NoSQL.Quickstart.Models", "models\Microsoft.Samples.Cosmos.NoSQL.Quickstart.Models.csproj", "{5FC7FBD8-3D5B-4E86-AFA5-DC26BA5CB4D3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Samples.Cosmos.NoSQL.Quickstart.Services", "services\Microsoft.Samples.Cosmos.NoSQL.Quickstart.Services.csproj", "{BE19E8F8-0FE7-437B-AFD3-F31F854BCE87}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DB1EBDE0-AA02-4D28-8574-EF28DAC09147}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DB1EBDE0-AA02-4D28-8574-EF28DAC09147}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DB1EBDE0-AA02-4D28-8574-EF28DAC09147}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DB1EBDE0-AA02-4D28-8574-EF28DAC09147}.Release|Any CPU.Build.0 = Release|Any CPU
{5FC7FBD8-3D5B-4E86-AFA5-DC26BA5CB4D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5FC7FBD8-3D5B-4E86-AFA5-DC26BA5CB4D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5FC7FBD8-3D5B-4E86-AFA5-DC26BA5CB4D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5FC7FBD8-3D5B-4E86-AFA5-DC26BA5CB4D3}.Release|Any CPU.Build.0 = Release|Any CPU
{BE19E8F8-0FE7-437B-AFD3-F31F854BCE87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BE19E8F8-0FE7-437B-AFD3-F31F854BCE87}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE19E8F8-0FE7-437B-AFD3-F31F854BCE87}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BE19E8F8-0FE7-437B-AFD3-F31F854BCE87}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/web/Models/Product.cs → src/models/Product.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Cosmos.Samples.NoSQL.Quickstart.Web.Models;
namespace Microsoft.Samples.Cosmos.NoSQL.Quickstart.Models;

public record Product(
string id,
Expand Down
12 changes: 4 additions & 8 deletions src/web/Services/DemoService.cs → src/services/DemoService.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using Cosmos.Samples.NoSQL.Quickstart.Web.Models;
using Microsoft.Azure.Cosmos;
using Microsoft.Samples.Cosmos.NoSQL.Quickstart.Models;
using Microsoft.Samples.Cosmos.NoSQL.Quickstart.Services.Interfaces;

internal interface IDemoService
{
Task RunAsync(Func<string, Task> writeOutputAync);

string GetEndpoint();
}
namespace Microsoft.Samples.Cosmos.NoSQL.Quickstart.Services;

internal sealed class DemoService(CosmosClient client) : IDemoService
public sealed class DemoService(CosmosClient client) : IDemoService
{
public string GetEndpoint() => $"{client.Endpoint}";

Expand Down
8 changes: 8 additions & 0 deletions src/services/Interfaces/IDemoService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Microsoft.Samples.Cosmos.NoSQL.Quickstart.Services.Interfaces;

public interface IDemoService
{
Task RunAsync(Func<string, Task> writeOutputAync);

string GetEndpoint();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.*" />
<PackageReference Include="Newtonsoft.Json" Version="13.*" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\models\Microsoft.Samples.Cosmos.NoSQL.Quickstart.Models.csproj" />
</ItemGroup>
</Project>
24 changes: 24 additions & 0 deletions src/web/Components/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1/font/bootstrap-icons.min.css">
<ImportMap />
<link rel="icon" type="image/png" href="favicon.png" />
<HeadOutlet />
<PageTitle>
Azure Cosmos DB for NoSQL
</PageTitle>
</head>

<body data-bs-theme="dark">
<Routes />
<script src="_framework/blazor.web.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5/dist/css/bootstrap.min.css">
</body>

</html>
13 changes: 13 additions & 0 deletions src/web/Components/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@inherits LayoutComponentBase

<main class="container">
<h1 class="my-5 text-center">
Azure Cosmos DB for NoSQL | .NET Quickstart
</h1>
@Body
<div id="blazor-error-ui" class="collapse fixed-top rounded-0 mb-0 alert alert-danger" role="alert">
An unhandled error has occurred.
<a href="." class="reload">Reload</a>
<span class="dismiss">🗙</span>
</div>
</main>
66 changes: 41 additions & 25 deletions src/web/Pages/Index.razor → src/web/Components/Pages/Home.razor
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
@page "/"
@inject IDemoService demoService
@using System.Text
@inject IDemoService demoService
@rendermode InteractiveServer

<PageTitle>
Azure Cosmos DB for NoSQL | .NET Quickstart
</PageTitle>

<pre class="bg-light text-dark fw-light font-monospace mt-5 p-2">
@_console.ToString()
@ConsoleText
</pre>

<section class="d-flex justify-content-center">
<div class="list-group py-2">
<button type="button" class="list-group-item list-group-item-action @(_runAgainEnabled ? "" : "disabled") active" aria-current="true" @onclick="RunAgain">
<button type="button" class="list-group-item list-group-item-action @(RunAgainEnabled ? "" : "disabled") active" aria-current="true" @onclick="RunAgainAsync">
<i class="bi bi-arrow-clockwise me-2"></i>
Restart
</button>
Expand Down Expand Up @@ -41,13 +46,24 @@
@code {
private StringBuilder _console = new();

private bool _runAgainEnabled = false;
private string ConsoleText
{
get => _console.ToString();
}

private bool RunAgainEnabled { get; set; }

protected override void OnInitialized() => GenerateQueryDataAsync();
protected override async Task OnInitializedAsync()
{
await GenerateQueryDataAsync();
}

private void RunAgain() => GenerateQueryDataAsync();
private async Task RunAgainAsync()
{
await GenerateQueryDataAsync();
}

private async void GenerateQueryDataAsync()
private async Task GenerateQueryDataAsync()
{
await SetRunAgain(false);
await ClearConsoleAsync();
Expand All @@ -58,24 +74,24 @@

await WriteToConsoleAync("Current Status:\tStopping...");
await SetRunAgain(true);
}

async Task WriteToConsoleAync(string message)
{
_console.AppendLine(message);
await InvokeAsync(StateHasChanged);
await Task.Delay(TimeSpan.FromSeconds(0.75));
}

async Task ClearConsoleAsync()
{
_console.Clear();
await InvokeAsync(StateHasChanged);
}

async Task SetRunAgain(bool state)
{
_runAgainEnabled = state;
await InvokeAsync(StateHasChanged);
}
private async Task WriteToConsoleAync(string message)
{
_console.AppendLine(message);
await InvokeAsync(StateHasChanged);
}

private async Task ClearConsoleAsync()
{
_console.Clear();
await InvokeAsync(StateHasChanged);
}

private async Task SetRunAgain(bool state)
{
RunAgainEnabled = state;
await InvokeAsync(StateHasChanged);
}
}

6 changes: 3 additions & 3 deletions src/web/App.razor → src/web/Components/Routes.razor
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Router AppAssembly="@typeof(App).Assembly">
<Router AppAssembly="typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<LayoutView Layout="@typeof(Layout.MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
Expand Down
12 changes: 12 additions & 0 deletions src/web/Components/_Imports.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using Microsoft.Samples.Cosmos.NoSQL.Quickstart.Models
@using Microsoft.Samples.Cosmos.NoSQL.Quickstart.Services.Interfaces
@using Microsoft.Samples.Cosmos.NoSQL.Quickstart.Web
@using Microsoft.Samples.Cosmos.NoSQL.Quickstart.Web.Components
14 changes: 0 additions & 14 deletions src/web/Cosmos.Samples.NoSQL.Quickstart.Web.csproj

This file was deleted.

25 changes: 0 additions & 25 deletions src/web/Dockerfile

This file was deleted.

8 changes: 0 additions & 8 deletions src/web/MainLayout.razor

This file was deleted.

Loading

0 comments on commit 968a7b2

Please sign in to comment.