mirror of https://github.com/dotnet/tye.git
Browse Source
* Add Dapr integration to Tye Adds a new `extensions` integration point. Currently all extensbility has to be inside the Tye codebase. There's no functionality for loading or distributing plugins. Enable dapr for an application like: ```yaml name: test_app extensions: - name: dapr ``` The dapr extension currently accepts and requires no additional options, and applies to all services defined in the application. What it does: - In local run: starts a dapr sidecar for each project that does http - In local run: sidecars start in the directory of tye.yaml, so dapr will look for component manifests in ./components (relative to tye.yaml - In deployment: adds required annotations to deployments Some new features that were added to tye to enable this: - Config: Ability to parse and conditionally run extensions - Run: Ability to token replace env-vars into command line args - Deploy: Ability to configure labels and annotations * format * Massage labesl: * PR feedback * Fix testspull/254/head
committed by
GitHub
99 changed files with 3030 additions and 134 deletions
@ -1,15 +1,25 @@ |
|||||
# 📖 Tye documentation |
# 📖 Tye documentation |
||||
|
|
||||
|
## Tutorials |
||||
|
|
||||
| Topic | Description | |
| Topic | Description | |
||||
|-------|-------------| |
|-------|-------------| |
||||
|**[Getting Started](getting_started.md)** | Set up your development environment. |
|**[Getting Started](getting_started.md)** | Set up your development environment. |
||||
|**[Frontend Backend Run Example](frontend_backend_run.md)** | Learn how to run an application locally with tye. |
|**[Frontend Backend Run Example](frontend_backend_run.md)** | Learn how to run an application locally with tye. |
||||
|**[Frontend Backend Deploy Example](frontend_backend_deploy.md)** | Learn how to deploy an application with tye. |
|**[Frontend Backend Deploy Example](frontend_backend_deploy.md)** | Learn how to deploy an application with tye. |
||||
|**[Tye Schema](schema.md)** | `tye.yaml` configuration. |
| **[Adding Redis](redis.md)** | Learn how to add redis for development and deployed to a development cluster. |
||||
|
|
||||
|
|
||||
|
## Recipes |
||||
|
|
||||
|
| Topic | Description| |
||||
|
|-------|------------| |
||||
|
|**[Using Dapr with Tye](recipes/dapr.md)** | Using Tye for local development and deployment with a [Dapr](https://dapr.io) application. |
||||
|
|
||||
|
|
||||
## Further documentation |
## Further documentation |
||||
|
|
||||
| Area | Description | |
| Area | Description | |
||||
|------|-------------| |
|------|-------------| |
||||
| **[Service Discovery](service_discovery.md)** | Learn more about service discovery in tye. |
| **[Service Discovery](service_discovery.md)** | Learn more about service discovery in tye. |
||||
| **[Redis](redis.md)** | Learn how to both run and deploy redis inside of a cluster. |
|**[Tye Schema](schema.md)** | `tye.yaml` configuration. |
||||
|
|||||
@ -0,0 +1,145 @@ |
|||||
|
# Using Tye with Dapr |
||||
|
|
||||
|
You can use Tye to accelerate local development and deployments of [Dapr](https://dapr.io) applications. |
||||
|
|
||||
|
Documentation for using Dapr with .NET applications can be found here: https://github.com/dapr/dotnet-sdk. |
||||
|
|
||||
|
This document will describe how to integrate a Dapr application with Tye. See Dapr's documentation on how to build applications that make use of what Dapr provides. |
||||
|
|
||||
|
## Getting Started with Dapr |
||||
|
|
||||
|
Getting started documentation for Dapr can be found [here](https://github.com/dapr/docs/tree/master/getting-started) |
||||
|
|
||||
|
## Sample Code |
||||
|
|
||||
|
The sample code for document can be found [here](https://github.com/dotnet/tye/tree/master/samples/dapr). |
||||
|
|
||||
|
This application has three services: |
||||
|
|
||||
|
- A frontend application (`store`) |
||||
|
- A products backend service (`products`) |
||||
|
- An order fulfillment service (`orders`) |
||||
|
|
||||
|
These services use a variety of Dapr's features: |
||||
|
|
||||
|
- State Storate (`store`) |
||||
|
- Invoke (`store`, `products`) |
||||
|
- Pub/Sub (`store`, `orders`) |
||||
|
|
||||
|
You can find the Dapr component files [here](https://github.com/dotnet/tye/tree/master/samples/dapr/components). |
||||
|
|
||||
|
## Running the sample locally |
||||
|
|
||||
|
To run this sample, simply go to the `samples/dapr` directory and run the following command: |
||||
|
|
||||
|
```sh |
||||
|
tye run |
||||
|
``` |
||||
|
|
||||
|
When the application runs, you should be able to see something like the following on the tye dashboard. |
||||
|
|
||||
|
<img width="1497" alt="image" src="https://user-images.githubusercontent.com/1430011/77840703-2d977380-713f-11ea-9e76-560ce2b47cd3.png"> |
||||
|
|
||||
|
- Each .NET project has launched |
||||
|
- One `daprd` sidecar has launched per-project |
||||
|
- Redis has been launched as Dapr component |
||||
|
|
||||
|
When using `tye run` in this way, Dapr discover components like redis for state storage and pubsub from the `components` directory next to the solution. |
||||
|
|
||||
|
> :warning: You may encounter a port conflict for redis if you have already used `dapr --init` locally to start redis. This will likely be visible as a high never of restarts for the redis service in the dashboard. You can either use `dapr` to manage redis or `tye`, but not both. To work around this remove the `redis` service from `tye.yaml`. |
||||
|
|
||||
|
--- |
||||
|
|
||||
|
Without Tye in the picture, running these three services would require running a command like the following for each service: |
||||
|
|
||||
|
```sh |
||||
|
dapr run --app-id store --app-port 5000 dotnet run --urls http://localhost:5000 |
||||
|
``` |
||||
|
|
||||
|
Each application would need to be given a unique port to listen on, and launched in its own terminal window. |
||||
|
|
||||
|
>:bulb: The current release of Dapr (0.5.1) [will not recognize](https://github.com/dapr/cli/issues/235) the `daprd` instances launched by Tye, and so commands like `dapr list` or `dapr publish` will not work when using Tye. This will be fixed in a future release. |
||||
|
|
||||
|
--- |
||||
|
|
||||
|
Tye has built-in support that can make this more productive by: |
||||
|
|
||||
|
- Launching everything at once |
||||
|
- Automatically manging ports |
||||
|
|
||||
|
Tye's Dapr integration is activated in `tye.yaml` (seen below for this sample): |
||||
|
|
||||
|
```yaml |
||||
|
name: dapr |
||||
|
extensions: |
||||
|
- name: dapr |
||||
|
services: |
||||
|
- name: orders |
||||
|
project: orders/orders.csproj |
||||
|
- name: products |
||||
|
project: products/products.csproj |
||||
|
- name: store |
||||
|
project: store/store.csproj |
||||
|
- name: redis |
||||
|
image: redis |
||||
|
bindings: |
||||
|
- port: 6973 |
||||
|
``` |
||||
|
|
||||
|
All that's needed to enable Dapr integration for an application is: |
||||
|
|
||||
|
```yaml |
||||
|
extensions: |
||||
|
- name: dapr |
||||
|
``` |
||||
|
|
||||
|
## Deploying the sample to Kubernetes |
||||
|
|
||||
|
**:warning: The current Dapr dotnet-sdk release has an issue where its default settings don't work when deployed with mTLS enabled. This will be resolved as part of the upcoming 0.6.0 release. For now you can work around this by disabling mTLS as part of Dapr installation.** |
||||
|
|
||||
|
First, you will need a Kubernetes instance to deploy to. The [Frontend-Backed Deployment tutorial](/docs/frontend_backend_deploy.md) covers some options. |
||||
|
|
||||
|
Secondly initialize Dapr for your cluster following the instructions [here](https://github.com/dapr/samples/tree/master/2.hello-kubernetes). Make sure to configure redis as both a state store and as pub-sub as described [here](https://github.com/dapr/docs/blob/master/howto/configure-redis/README.md#configuration). |
||||
|
|
||||
|
You can verify that these steps have been performed correctly by running the following command: |
||||
|
|
||||
|
```sh |
||||
|
dapr components--kubernetes |
||||
|
``` |
||||
|
|
||||
|
```txt |
||||
|
NAME TYPE AGE CREATED |
||||
|
messagebus pubsub.redis 13h 2020-03-28 22:26.45 |
||||
|
statestore state.redis 13h 2020-03-28 22:26.40 |
||||
|
``` |
||||
|
|
||||
|
--- |
||||
|
|
||||
|
Once these prerequisites have been taken care, you can deploy the application using Tye. |
||||
|
|
||||
|
```sh |
||||
|
tye deploy --interactive |
||||
|
``` |
||||
|
|
||||
|
Using `--interactive` will allow you to enter your dockerhub username or container registry hostname when prompted. |
||||
|
|
||||
|
You can verify that the application has been successfully deployed using `kubectl get pods`. |
||||
|
|
||||
|
```text |
||||
|
> kubectl get pods |
||||
|
|
||||
|
NAME READY STATUS RESTARTS AGE |
||||
|
orders-687db7fdbd-jhxfx 2/2 Running 0 23s |
||||
|
products-69f4c94684-lvt9x 2/2 Running 0 18s |
||||
|
store-7dc698f97d-v6hlb 2/2 Running 0 12s |
||||
|
``` |
||||
|
|
||||
|
You should see `2/2` ready for each pod. This means that the application and the Dapr sidecar have both started. |
||||
|
|
||||
|
To access the application, port-forward to the `store` service. This will make the URL `http://localhost:5000` resolve to the instance running in the cluster for as long as the command is running. |
||||
|
|
||||
|
```sh |
||||
|
kubectl port-forward svc/store 5000:80 |
||||
|
``` |
||||
|
|
||||
|
>:bulb: If you need to see logs using `kubectl logs ...` you need to specify the container name when using Dapr, because there are multiple containers in the pod. Use `-c daprd` for the Dapr sidecar and `-c <projectname>` for the application (ex: `-c store`). |
||||
@ -0,0 +1,14 @@ |
|||||
|
{ |
||||
|
// Use IntelliSense to learn about possible attributes. |
||||
|
// Hover to view descriptions of existing attributes. |
||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 |
||||
|
"version": "0.2.0", |
||||
|
"configurations": [ |
||||
|
{ |
||||
|
"name": ".NET Core Attach", |
||||
|
"type": "coreclr", |
||||
|
"request": "attach", |
||||
|
"processId": "${command:pickProcess}" |
||||
|
} |
||||
|
] |
||||
|
} |
||||
@ -0,0 +1,42 @@ |
|||||
|
{ |
||||
|
"version": "2.0.0", |
||||
|
"tasks": [ |
||||
|
{ |
||||
|
"label": "build", |
||||
|
"command": "dotnet", |
||||
|
"type": "process", |
||||
|
"args": [ |
||||
|
"build", |
||||
|
"${workspaceFolder}/orders/orders.csproj", |
||||
|
"/property:GenerateFullPaths=true", |
||||
|
"/consoleloggerparameters:NoSummary" |
||||
|
], |
||||
|
"problemMatcher": "$msCompile" |
||||
|
}, |
||||
|
{ |
||||
|
"label": "publish", |
||||
|
"command": "dotnet", |
||||
|
"type": "process", |
||||
|
"args": [ |
||||
|
"publish", |
||||
|
"${workspaceFolder}/orders/orders.csproj", |
||||
|
"/property:GenerateFullPaths=true", |
||||
|
"/consoleloggerparameters:NoSummary" |
||||
|
], |
||||
|
"problemMatcher": "$msCompile" |
||||
|
}, |
||||
|
{ |
||||
|
"label": "watch", |
||||
|
"command": "dotnet", |
||||
|
"type": "process", |
||||
|
"args": [ |
||||
|
"watch", |
||||
|
"run", |
||||
|
"${workspaceFolder}/orders/orders.csproj", |
||||
|
"/property:GenerateFullPaths=true", |
||||
|
"/consoleloggerparameters:NoSummary" |
||||
|
], |
||||
|
"problemMatcher": "$msCompile" |
||||
|
} |
||||
|
] |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
apiVersion: dapr.io/v1alpha1 |
||||
|
kind: Component |
||||
|
metadata: |
||||
|
name: messagebus |
||||
|
spec: |
||||
|
type: pubsub.redis |
||||
|
metadata: |
||||
|
- name: redisHost |
||||
|
value: localhost:6379 |
||||
|
- name: redisPassword |
||||
|
value: "" |
||||
@ -0,0 +1,13 @@ |
|||||
|
apiVersion: dapr.io/v1alpha1 |
||||
|
kind: Component |
||||
|
metadata: |
||||
|
name: default |
||||
|
spec: |
||||
|
type: state.redis |
||||
|
metadata: |
||||
|
- name: redisHost |
||||
|
value: localhost:6379 |
||||
|
- name: redisPassword |
||||
|
value: "" |
||||
|
- name: actorStateStore |
||||
|
value: "true" |
||||
@ -0,0 +1,62 @@ |
|||||
|
|
||||
|
Microsoft Visual Studio Solution File, Format Version 12.00 |
||||
|
# Visual Studio 15 |
||||
|
VisualStudioVersion = 15.0.26124.0 |
||||
|
MinimumVisualStudioVersion = 15.0.26124.0 |
||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "orders", "orders\orders.csproj", "{206BCB04-37DC-48EC-B3D5-566C53291AEF}" |
||||
|
EndProject |
||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "products", "products\products.csproj", "{B9DB838D-2DCA-468E-A707-075A9FAE960F}" |
||||
|
EndProject |
||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "store", "store\store.csproj", "{7D053D12-7A1E-44B2-87AB-44DC391D2C13}" |
||||
|
EndProject |
||||
|
Global |
||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
||||
|
Debug|Any CPU = Debug|Any CPU |
||||
|
Debug|x64 = Debug|x64 |
||||
|
Debug|x86 = Debug|x86 |
||||
|
Release|Any CPU = Release|Any CPU |
||||
|
Release|x64 = Release|x64 |
||||
|
Release|x86 = Release|x86 |
||||
|
EndGlobalSection |
||||
|
GlobalSection(SolutionProperties) = preSolution |
||||
|
HideSolutionNode = FALSE |
||||
|
EndGlobalSection |
||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
||||
|
{206BCB04-37DC-48EC-B3D5-566C53291AEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
|
{206BCB04-37DC-48EC-B3D5-566C53291AEF}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
|
{206BCB04-37DC-48EC-B3D5-566C53291AEF}.Debug|x64.ActiveCfg = Debug|Any CPU |
||||
|
{206BCB04-37DC-48EC-B3D5-566C53291AEF}.Debug|x64.Build.0 = Debug|Any CPU |
||||
|
{206BCB04-37DC-48EC-B3D5-566C53291AEF}.Debug|x86.ActiveCfg = Debug|Any CPU |
||||
|
{206BCB04-37DC-48EC-B3D5-566C53291AEF}.Debug|x86.Build.0 = Debug|Any CPU |
||||
|
{206BCB04-37DC-48EC-B3D5-566C53291AEF}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
|
{206BCB04-37DC-48EC-B3D5-566C53291AEF}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
|
{206BCB04-37DC-48EC-B3D5-566C53291AEF}.Release|x64.ActiveCfg = Release|Any CPU |
||||
|
{206BCB04-37DC-48EC-B3D5-566C53291AEF}.Release|x64.Build.0 = Release|Any CPU |
||||
|
{206BCB04-37DC-48EC-B3D5-566C53291AEF}.Release|x86.ActiveCfg = Release|Any CPU |
||||
|
{206BCB04-37DC-48EC-B3D5-566C53291AEF}.Release|x86.Build.0 = Release|Any CPU |
||||
|
{B9DB838D-2DCA-468E-A707-075A9FAE960F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
|
{B9DB838D-2DCA-468E-A707-075A9FAE960F}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
|
{B9DB838D-2DCA-468E-A707-075A9FAE960F}.Debug|x64.ActiveCfg = Debug|Any CPU |
||||
|
{B9DB838D-2DCA-468E-A707-075A9FAE960F}.Debug|x64.Build.0 = Debug|Any CPU |
||||
|
{B9DB838D-2DCA-468E-A707-075A9FAE960F}.Debug|x86.ActiveCfg = Debug|Any CPU |
||||
|
{B9DB838D-2DCA-468E-A707-075A9FAE960F}.Debug|x86.Build.0 = Debug|Any CPU |
||||
|
{B9DB838D-2DCA-468E-A707-075A9FAE960F}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
|
{B9DB838D-2DCA-468E-A707-075A9FAE960F}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
|
{B9DB838D-2DCA-468E-A707-075A9FAE960F}.Release|x64.ActiveCfg = Release|Any CPU |
||||
|
{B9DB838D-2DCA-468E-A707-075A9FAE960F}.Release|x64.Build.0 = Release|Any CPU |
||||
|
{B9DB838D-2DCA-468E-A707-075A9FAE960F}.Release|x86.ActiveCfg = Release|Any CPU |
||||
|
{B9DB838D-2DCA-468E-A707-075A9FAE960F}.Release|x86.Build.0 = Release|Any CPU |
||||
|
{7D053D12-7A1E-44B2-87AB-44DC391D2C13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
|
{7D053D12-7A1E-44B2-87AB-44DC391D2C13}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
|
{7D053D12-7A1E-44B2-87AB-44DC391D2C13}.Debug|x64.ActiveCfg = Debug|Any CPU |
||||
|
{7D053D12-7A1E-44B2-87AB-44DC391D2C13}.Debug|x64.Build.0 = Debug|Any CPU |
||||
|
{7D053D12-7A1E-44B2-87AB-44DC391D2C13}.Debug|x86.ActiveCfg = Debug|Any CPU |
||||
|
{7D053D12-7A1E-44B2-87AB-44DC391D2C13}.Debug|x86.Build.0 = Debug|Any CPU |
||||
|
{7D053D12-7A1E-44B2-87AB-44DC391D2C13}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
|
{7D053D12-7A1E-44B2-87AB-44DC391D2C13}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
|
{7D053D12-7A1E-44B2-87AB-44DC391D2C13}.Release|x64.ActiveCfg = Release|Any CPU |
||||
|
{7D053D12-7A1E-44B2-87AB-44DC391D2C13}.Release|x64.Build.0 = Release|Any CPU |
||||
|
{7D053D12-7A1E-44B2-87AB-44DC391D2C13}.Release|x86.ActiveCfg = Release|Any CPU |
||||
|
{7D053D12-7A1E-44B2-87AB-44DC391D2C13}.Release|x86.Build.0 = Release|Any CPU |
||||
|
EndGlobalSection |
||||
|
EndGlobal |
||||
@ -0,0 +1,82 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Dapr; |
||||
|
using Dapr.Client; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
|
||||
|
namespace orders.Controllers |
||||
|
{ |
||||
|
[ApiController] |
||||
|
public class OrdersController : ControllerBase |
||||
|
{ |
||||
|
[Topic("orderplaced")] |
||||
|
[HttpPost("orderplaced")] |
||||
|
public async Task PlaceOrder(Order order, [FromServices] DaprClient dapr, [FromServices] ILogger<OrdersController> logger) |
||||
|
{ |
||||
|
logger.LogInformation("Got order {OrderId} for product {ProductId}", order.OrderId, order.ProductId); |
||||
|
|
||||
|
var state = await dapr.GetStateEntryAsync<InventoryState>("default", order.ProductId.ToString()); |
||||
|
if (state.Value == null || state.Value.Remaining < -10) |
||||
|
{ |
||||
|
// For demo purposes, assume we have 5 of these in stock :)
|
||||
|
state.Value = new InventoryState() { Remaining = 5, }; |
||||
|
} |
||||
|
|
||||
|
state.Value.Remaining--; |
||||
|
await state.SaveAsync(); |
||||
|
|
||||
|
logger.LogInformation("Updated inventory for product {ProductId} to {Inventory}", order.ProductId, state.Value.Remaining); |
||||
|
|
||||
|
OrderConfirmation confirmation; |
||||
|
if (state.Value.Remaining >= 0) |
||||
|
{ |
||||
|
confirmation = new OrderConfirmation() |
||||
|
{ |
||||
|
OrderId = order.OrderId, |
||||
|
Confirmed = true, |
||||
|
DeliveryDate = DateTime.Now.AddYears(1), |
||||
|
RemainingCount = state.Value.Remaining, |
||||
|
}; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
confirmation = new OrderConfirmation() |
||||
|
{ |
||||
|
OrderId = order.OrderId, |
||||
|
Confirmed = false, |
||||
|
BackorderCount = -1 * state.Value.Remaining, |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
await dapr.PublishEventAsync("orderprocessed", confirmation); |
||||
|
|
||||
|
logger.LogInformation("Sent confirmation for order {OrderId}", order.OrderId); |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public class Order |
||||
|
{ |
||||
|
public string OrderId { get; set; } = default!; |
||||
|
public int ProductId { get; set ; } |
||||
|
} |
||||
|
|
||||
|
public class InventoryState |
||||
|
{ |
||||
|
public int Remaining { get; set; } |
||||
|
} |
||||
|
|
||||
|
public class OrderConfirmation |
||||
|
{ |
||||
|
public string OrderId { get; set; } = default!; |
||||
|
|
||||
|
public DateTime? DeliveryDate { get; set; } |
||||
|
|
||||
|
public bool Confirmed { get; set; } |
||||
|
|
||||
|
public int BackorderCount { get; set; } |
||||
|
|
||||
|
public int RemainingCount { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,23 @@ |
|||||
|
using System; |
||||
|
using Microsoft.AspNetCore.Hosting; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
|
||||
|
namespace orders |
||||
|
{ |
||||
|
public class Program |
||||
|
{ |
||||
|
public static void Main(string[] args) |
||||
|
{ |
||||
|
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); |
||||
|
CreateHostBuilder(args).Build().Run(); |
||||
|
} |
||||
|
|
||||
|
public static IHostBuilder CreateHostBuilder(string[] args) => |
||||
|
Host.CreateDefaultBuilder(args) |
||||
|
.ConfigureWebHostDefaults(webBuilder => |
||||
|
{ |
||||
|
webBuilder.UseStartup<Startup>(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
{ |
||||
|
"$schema": "http://json.schemastore.org/launchsettings.json", |
||||
|
"iisSettings": { |
||||
|
"windowsAuthentication": false, |
||||
|
"anonymousAuthentication": true, |
||||
|
"iisExpress": { |
||||
|
"applicationUrl": "http://localhost:61012", |
||||
|
"sslPort": 44397 |
||||
|
} |
||||
|
}, |
||||
|
"profiles": { |
||||
|
"IIS Express": { |
||||
|
"commandName": "IISExpress", |
||||
|
"launchBrowser": true, |
||||
|
"launchUrl": "weatherforecast", |
||||
|
"environmentVariables": { |
||||
|
"ASPNETCORE_ENVIRONMENT": "Development" |
||||
|
} |
||||
|
}, |
||||
|
"orders": { |
||||
|
"commandName": "Project", |
||||
|
"launchBrowser": true, |
||||
|
"launchUrl": "weatherforecast", |
||||
|
"applicationUrl": "https://localhost:5001;http://localhost:5000", |
||||
|
"environmentVariables": { |
||||
|
"ASPNETCORE_ENVIRONMENT": "Development" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,63 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text.Json; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
using Microsoft.AspNetCore.Hosting; |
||||
|
using Microsoft.AspNetCore.HttpsPolicy; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
|
||||
|
namespace orders |
||||
|
{ |
||||
|
public class Startup |
||||
|
{ |
||||
|
private readonly JsonSerializerOptions options = new JsonSerializerOptions() |
||||
|
{ |
||||
|
PropertyNameCaseInsensitive = true, |
||||
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase, |
||||
|
}; |
||||
|
|
||||
|
public Startup(IConfiguration configuration) |
||||
|
{ |
||||
|
Configuration = configuration; |
||||
|
} |
||||
|
|
||||
|
public IConfiguration Configuration { get; } |
||||
|
|
||||
|
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
|
public void ConfigureServices(IServiceCollection services) |
||||
|
{ |
||||
|
services.AddDaprClient(client => |
||||
|
{ |
||||
|
client.UseJsonSerializationOptions(options); |
||||
|
}); |
||||
|
services.AddControllers().AddDapr(); |
||||
|
} |
||||
|
|
||||
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) |
||||
|
{ |
||||
|
if (env.IsDevelopment()) |
||||
|
{ |
||||
|
app.UseDeveloperExceptionPage(); |
||||
|
} |
||||
|
|
||||
|
app.UseRouting(); |
||||
|
|
||||
|
app.UseAuthorization(); |
||||
|
|
||||
|
app.UseCloudEvents(); |
||||
|
|
||||
|
app.UseEndpoints(endpoints => |
||||
|
{ |
||||
|
endpoints.MapSubscribeHandler(); |
||||
|
endpoints.MapControllers(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
{ |
||||
|
"Logging": { |
||||
|
"LogLevel": { |
||||
|
"Default": "Debug", |
||||
|
"Microsoft": "Debug", |
||||
|
"Microsoft.Hosting.Lifetime": "Information" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
{ |
||||
|
"Logging": { |
||||
|
"LogLevel": { |
||||
|
"Default": "Information", |
||||
|
"Microsoft": "Warning", |
||||
|
"Microsoft.Hosting.Lifetime": "Information" |
||||
|
} |
||||
|
}, |
||||
|
"AllowedHosts": "*" |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk.Web"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netcoreapp3.1</TargetFramework> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Dapr.AspNetCore" Version="0.5.0-preview02 " /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,27 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Hosting; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
|
||||
|
namespace products |
||||
|
{ |
||||
|
public class Program |
||||
|
{ |
||||
|
public static void Main(string[] args) |
||||
|
{ |
||||
|
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); |
||||
|
CreateHostBuilder(args).Build().Run(); |
||||
|
} |
||||
|
|
||||
|
public static IHostBuilder CreateHostBuilder(string[] args) => |
||||
|
Host.CreateDefaultBuilder(args) |
||||
|
.ConfigureWebHostDefaults(webBuilder => |
||||
|
{ |
||||
|
webBuilder.UseStartup<Startup>(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
{ |
||||
|
"iisSettings": { |
||||
|
"windowsAuthentication": false, |
||||
|
"anonymousAuthentication": true, |
||||
|
"iisExpress": { |
||||
|
"applicationUrl": "http://localhost:63287", |
||||
|
"sslPort": 44393 |
||||
|
} |
||||
|
}, |
||||
|
"profiles": { |
||||
|
"IIS Express": { |
||||
|
"commandName": "IISExpress", |
||||
|
"launchBrowser": true, |
||||
|
"environmentVariables": { |
||||
|
"ASPNETCORE_ENVIRONMENT": "Development" |
||||
|
} |
||||
|
}, |
||||
|
"products": { |
||||
|
"commandName": "Project", |
||||
|
"launchBrowser": true, |
||||
|
"applicationUrl": "https://localhost:5001;http://localhost:5000", |
||||
|
"environmentVariables": { |
||||
|
"ASPNETCORE_ENVIRONMENT": "Development" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,97 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text.Json; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
using Microsoft.AspNetCore.Hosting; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
|
||||
|
namespace products |
||||
|
{ |
||||
|
public class Startup |
||||
|
{ |
||||
|
private readonly JsonSerializerOptions options = new JsonSerializerOptions() |
||||
|
{ |
||||
|
PropertyNameCaseInsensitive = true, |
||||
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase, |
||||
|
}; |
||||
|
|
||||
|
public void ConfigureServices(IServiceCollection services) |
||||
|
{ |
||||
|
services.AddDaprClient(client => |
||||
|
{ |
||||
|
client.UseJsonSerializationOptions(options); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) |
||||
|
{ |
||||
|
if (env.IsDevelopment()) |
||||
|
{ |
||||
|
app.UseDeveloperExceptionPage(); |
||||
|
} |
||||
|
|
||||
|
app.UseRouting(); |
||||
|
|
||||
|
app.UseEndpoints(endpoints => |
||||
|
{ |
||||
|
endpoints.MapGet("/", async context => |
||||
|
{ |
||||
|
await context.Response.WriteAsync("Hello World!"); |
||||
|
}); |
||||
|
|
||||
|
endpoints.MapPost("/list", async context => |
||||
|
{ |
||||
|
context.Response.ContentType = "application/json"; |
||||
|
await JsonSerializer.SerializeAsync(context.Response.Body, AllProducts, options: options); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private class Product |
||||
|
{ |
||||
|
public int Id { get; set; } |
||||
|
|
||||
|
public string Name { get; set; } = default!; |
||||
|
|
||||
|
public string Description { get; set; } = default!; |
||||
|
|
||||
|
public decimal Price { get; set; } |
||||
|
} |
||||
|
|
||||
|
private static readonly Product[] AllProducts = new Product[] |
||||
|
{ |
||||
|
new Product() |
||||
|
{ |
||||
|
Id = 1, |
||||
|
Name = "Do it yourself haircut kit", |
||||
|
Description = "Some of us needed a haircut before Coronavirus hit...", |
||||
|
Price = 199.95m, |
||||
|
}, |
||||
|
new Product() |
||||
|
{ |
||||
|
Id = 2, |
||||
|
Name = "That book you've been meaning to read", |
||||
|
Description = "You know you have some free time now that you're stuck at home.", |
||||
|
Price = 15.73m, |
||||
|
}, |
||||
|
new Product() |
||||
|
{ |
||||
|
Id = 3, |
||||
|
Name = "That new video game you really want to play (preorder)", |
||||
|
Description = "This is the perfect way to self-isolate. Let's hope it ships on time.", |
||||
|
Price = 59.99m, |
||||
|
}, |
||||
|
new Product() |
||||
|
{ |
||||
|
Id = 4, |
||||
|
Name = "The Juice Loosener", |
||||
|
Description = "It's whisper quiet. Invented by Dr. Nick Riviera!", |
||||
|
Price = 199.95m, |
||||
|
} |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
{ |
||||
|
"Logging": { |
||||
|
"LogLevel": { |
||||
|
"Default": "Debug", |
||||
|
"Microsoft": "Debug", |
||||
|
"Microsoft.Hosting.Lifetime": "Information" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
{ |
||||
|
"Logging": { |
||||
|
"LogLevel": { |
||||
|
"Default": "Information", |
||||
|
"Microsoft": "Warning", |
||||
|
"Microsoft.Hosting.Lifetime": "Information" |
||||
|
} |
||||
|
}, |
||||
|
"AllowedHosts": "*" |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk.Web"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netcoreapp3.1</TargetFramework> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Dapr.AspNetCore" Version="0.5.0-preview02 " /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,11 @@ |
|||||
|
|
||||
|
<Router AppAssembly="@typeof(Program).Assembly"> |
||||
|
<Found Context="routeData"> |
||||
|
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> |
||||
|
</Found> |
||||
|
<NotFound> |
||||
|
<LayoutView Layout="@typeof(MainLayout)"> |
||||
|
<p>Sorry, there's nothing at this address.</p> |
||||
|
</LayoutView> |
||||
|
</NotFound> |
||||
|
</Router> |
||||
@ -0,0 +1,23 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace store |
||||
|
{ |
||||
|
public class Order |
||||
|
{ |
||||
|
public string OrderId { get; set; } = default!; |
||||
|
public int ProductId { get; set ; } |
||||
|
} |
||||
|
|
||||
|
public class OrderConfirmation |
||||
|
{ |
||||
|
public string OrderId { get; set; } = default!; |
||||
|
|
||||
|
public DateTime? DeliveryDate { get; set; } |
||||
|
|
||||
|
public bool Confirmed { get; set; } |
||||
|
|
||||
|
public int BackorderCount { get; set; } |
||||
|
|
||||
|
public int RemainingCount { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,66 @@ |
|||||
|
using System.Collections.Concurrent; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
|
||||
|
namespace store |
||||
|
{ |
||||
|
public class OrdersEventBroker |
||||
|
{ |
||||
|
private ConcurrentDictionary<string, Entry> _entries; |
||||
|
private ILogger<OrdersEventBroker> _logger; |
||||
|
|
||||
|
public OrdersEventBroker(ILogger<OrdersEventBroker> logger) |
||||
|
{ |
||||
|
_entries = new ConcurrentDictionary<string, Entry>(); |
||||
|
_logger = logger; |
||||
|
} |
||||
|
|
||||
|
public async Task<OrderConfirmation> GetOrderConfirmationAsync(string orderId, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
_logger.LogInformation("Waiting for confirmation of order {OrderId}", orderId); |
||||
|
|
||||
|
var entry = new Entry(orderId); |
||||
|
using (cancellationToken.Register(Cancel)) |
||||
|
{ |
||||
|
_entries.TryAdd(orderId, entry); |
||||
|
|
||||
|
var state = await entry.Completion.Task; |
||||
|
_entries.TryRemove(orderId, out _); |
||||
|
|
||||
|
_logger.LogInformation("Order {OrderId} has been processed", orderId); |
||||
|
return state; |
||||
|
} |
||||
|
|
||||
|
void Cancel() |
||||
|
{ |
||||
|
_logger.LogInformation("Canceling subscription {OrderId}", orderId); |
||||
|
_entries.TryRemove(orderId, out _); |
||||
|
entry.Completion.TrySetCanceled(cancellationToken); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void Complete(OrderConfirmation result) |
||||
|
{ |
||||
|
if (_entries.TryGetValue(result.OrderId, out var entry)) |
||||
|
{ |
||||
|
_logger.LogInformation("Processing order {OrderId}", result.OrderId); |
||||
|
entry.Completion.TrySetResult(result); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private class Entry |
||||
|
{ |
||||
|
public Entry(string orderId) |
||||
|
{ |
||||
|
OrderId = orderId; |
||||
|
|
||||
|
Completion = new TaskCompletionSource<OrderConfirmation>(); |
||||
|
} |
||||
|
|
||||
|
public string OrderId { get; } |
||||
|
|
||||
|
public TaskCompletionSource<OrderConfirmation> Completion { get; } |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,26 @@ |
|||||
|
@page "/" |
||||
|
@inject DaprClient Dapr |
||||
|
|
||||
|
<h1>Welcome to our awesome store!</h1> |
||||
|
<p>Please browse the products at your leisure.</p> |
||||
|
|
||||
|
@if (products == null) |
||||
|
{ |
||||
|
<h3>Loading...</h3> |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
foreach (var product in products) |
||||
|
{ |
||||
|
<ProductDisplay Product="product" /> |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@code { |
||||
|
Product[]? products; |
||||
|
|
||||
|
protected async override Task OnInitializedAsync() |
||||
|
{ |
||||
|
products = await Dapr.InvokeMethodAsync<Product[]>("products", "list"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
@page "/" |
||||
|
@namespace store.Pages |
||||
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers |
||||
|
@{ |
||||
|
Layout = null; |
||||
|
} |
||||
|
|
||||
|
<!DOCTYPE html> |
||||
|
<html lang="en"> |
||||
|
<head> |
||||
|
<meta charset="utf-8" /> |
||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
||||
|
<title>store</title> |
||||
|
<base href="~/" /> |
||||
|
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" /> |
||||
|
<link href="css/site.css" rel="stylesheet" /> |
||||
|
</head> |
||||
|
<body> |
||||
|
<app> |
||||
|
<component type="typeof(App)" render-mode="ServerPrerendered" /> |
||||
|
</app> |
||||
|
|
||||
|
<div id="blazor-error-ui"> |
||||
|
<environment include="Staging,Production"> |
||||
|
An error has occurred. This application may no longer respond until reloaded. |
||||
|
</environment> |
||||
|
<environment include="Development"> |
||||
|
An unhandled exception has occurred. See browser dev tools for details. |
||||
|
</environment> |
||||
|
<a href="" class="reload">Reload</a> |
||||
|
<a class="dismiss">🗙</a> |
||||
|
</div> |
||||
|
|
||||
|
<script src="_framework/blazor.server.js"></script> |
||||
|
</body> |
||||
|
</html> |
||||
@ -0,0 +1,13 @@ |
|||||
|
namespace store |
||||
|
{ |
||||
|
public class Product |
||||
|
{ |
||||
|
public int Id { get; set; } |
||||
|
|
||||
|
public string Name { get; set; } = default!; |
||||
|
|
||||
|
public string Description { get; set; } = default!; |
||||
|
|
||||
|
public decimal Price { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.IO; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore; |
||||
|
using Microsoft.AspNetCore.Hosting; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
|
||||
|
namespace store |
||||
|
{ |
||||
|
public class Program |
||||
|
{ |
||||
|
public static void Main(string[] args) |
||||
|
{ |
||||
|
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); |
||||
|
CreateHostBuilder(args).Build().Run(); |
||||
|
} |
||||
|
|
||||
|
public static IHostBuilder CreateHostBuilder(string[] args) => |
||||
|
Host.CreateDefaultBuilder(args) |
||||
|
.ConfigureWebHostDefaults(webBuilder => |
||||
|
{ |
||||
|
webBuilder.UseStartup<Startup>(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
{ |
||||
|
"iisSettings": { |
||||
|
"windowsAuthentication": false, |
||||
|
"anonymousAuthentication": true, |
||||
|
"iisExpress": { |
||||
|
"applicationUrl": "http://localhost:52990", |
||||
|
"sslPort": 44313 |
||||
|
} |
||||
|
}, |
||||
|
"profiles": { |
||||
|
"IIS Express": { |
||||
|
"commandName": "IISExpress", |
||||
|
"launchBrowser": true, |
||||
|
"environmentVariables": { |
||||
|
"ASPNETCORE_ENVIRONMENT": "Development" |
||||
|
} |
||||
|
}, |
||||
|
"store": { |
||||
|
"commandName": "Project", |
||||
|
"launchBrowser": true, |
||||
|
"applicationUrl": "https://localhost:5003;http://localhost:5002", |
||||
|
"environmentVariables": { |
||||
|
"ASPNETCORE_ENVIRONMENT": "Development" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
@inherits LayoutComponentBase |
||||
|
|
||||
|
<div class="sidebar"> |
||||
|
<NavMenu /> |
||||
|
</div> |
||||
|
|
||||
|
<div class="main"> |
||||
|
<div class="top-row px-4"> |
||||
|
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a> |
||||
|
</div> |
||||
|
|
||||
|
<div class="content px-4"> |
||||
|
@Body |
||||
|
</div> |
||||
|
</div> |
||||
@ -0,0 +1,27 @@ |
|||||
|
<div class="top-row pl-4 navbar navbar-dark"> |
||||
|
<a class="navbar-brand" href="">store</a> |
||||
|
<button class="navbar-toggler" @onclick="ToggleNavMenu"> |
||||
|
<span class="navbar-toggler-icon"></span> |
||||
|
</button> |
||||
|
</div> |
||||
|
|
||||
|
<div class="@NavMenuCssClass" @onclick="ToggleNavMenu"> |
||||
|
<ul class="nav flex-column"> |
||||
|
<li class="nav-item px-3"> |
||||
|
<NavLink class="nav-link" href="" Match="NavLinkMatch.All"> |
||||
|
<span class="oi oi-home" aria-hidden="true"></span> Store |
||||
|
</NavLink> |
||||
|
</li> |
||||
|
</ul> |
||||
|
</div> |
||||
|
|
||||
|
@code { |
||||
|
private bool collapseNavMenu = true; |
||||
|
|
||||
|
private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null; |
||||
|
|
||||
|
private void ToggleNavMenu() |
||||
|
{ |
||||
|
collapseNavMenu = !collapseNavMenu; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,77 @@ |
|||||
|
@inject DaprClient Dapr |
||||
|
@inject OrdersEventBroker Broker |
||||
|
@implements IDisposable |
||||
|
|
||||
|
<div class="py-4"> |
||||
|
<hr /> |
||||
|
<h4>@Product.Name</h4> |
||||
|
<p>@Product.Description</p> |
||||
|
<p>$@(Product.Price.ToString("0.00"))</p> |
||||
|
|
||||
|
@if (status is object) |
||||
|
{ |
||||
|
<p>@status</p> |
||||
|
} |
||||
|
|
||||
|
@if (processing) |
||||
|
{ |
||||
|
<p>Please wait...</p> |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
<button @onclick="@PlaceOrder">BUY!!!</button> |
||||
|
} |
||||
|
</div> |
||||
|
|
||||
|
@code { |
||||
|
[Parameter] public Product Product { get; set; } = default!; |
||||
|
|
||||
|
bool processing; |
||||
|
string? status; |
||||
|
private CancellationTokenSource? cts; |
||||
|
|
||||
|
async Task PlaceOrder() |
||||
|
{ |
||||
|
if (processing) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
try |
||||
|
{ |
||||
|
processing = true; |
||||
|
|
||||
|
var orderId = Guid.NewGuid().ToString(); |
||||
|
cts = new CancellationTokenSource(); |
||||
|
|
||||
|
var task = Broker.GetOrderConfirmationAsync(orderId, cts.Token); |
||||
|
|
||||
|
await Dapr.PublishEventAsync("orderplaced", new Order() |
||||
|
{ |
||||
|
ProductId = Product.Id, |
||||
|
OrderId = orderId, |
||||
|
}); |
||||
|
|
||||
|
var confirmation = await task; |
||||
|
if (confirmation.Confirmed) |
||||
|
{ |
||||
|
status = $"Confirmed! Order will arrive by {confirmation.DeliveryDate!.Value.ToString("MM/dd/yyyy")}. {confirmation.RemainingCount} are left."; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
status = $"Sorry, we're sold out of that. There are {confirmation.BackorderCount} people ahead of you in line."; |
||||
|
} |
||||
|
} |
||||
|
finally |
||||
|
{ |
||||
|
processing = false; |
||||
|
cts?.Dispose(); |
||||
|
cts = null; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void IDisposable.Dispose() |
||||
|
{ |
||||
|
cts?.Dispose(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,72 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text.Json; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
using Microsoft.AspNetCore.Components; |
||||
|
using Microsoft.AspNetCore.Hosting; |
||||
|
using Microsoft.AspNetCore.HttpsPolicy; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
|
||||
|
namespace store |
||||
|
{ |
||||
|
public class Startup |
||||
|
{ |
||||
|
private readonly JsonSerializerOptions options = new JsonSerializerOptions() |
||||
|
{ |
||||
|
PropertyNameCaseInsensitive = true, |
||||
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase, |
||||
|
}; |
||||
|
|
||||
|
public Startup(IConfiguration configuration) |
||||
|
{ |
||||
|
Configuration = configuration; |
||||
|
} |
||||
|
|
||||
|
public IConfiguration Configuration { get; } |
||||
|
|
||||
|
public void ConfigureServices(IServiceCollection services) |
||||
|
{ |
||||
|
services.AddRazorPages(); |
||||
|
services.AddServerSideBlazor(); |
||||
|
services.AddDaprClient(client => |
||||
|
{ |
||||
|
client.UseJsonSerializationOptions(options); |
||||
|
}); |
||||
|
|
||||
|
services.AddSingleton<OrdersEventBroker>(); |
||||
|
} |
||||
|
|
||||
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) |
||||
|
{ |
||||
|
if (env.IsDevelopment()) |
||||
|
{ |
||||
|
app.UseDeveloperExceptionPage(); |
||||
|
} |
||||
|
|
||||
|
app.UseStaticFiles(); |
||||
|
|
||||
|
app.UseRouting(); |
||||
|
|
||||
|
app.UseCloudEvents(); |
||||
|
|
||||
|
app.UseEndpoints(endpoints => |
||||
|
{ |
||||
|
endpoints.MapBlazorHub(); |
||||
|
endpoints.MapFallbackToPage("/_Host"); |
||||
|
|
||||
|
endpoints.MapSubscribeHandler(); |
||||
|
|
||||
|
var broker = endpoints.ServiceProvider.GetRequiredService<OrdersEventBroker>(); |
||||
|
endpoints.MapPost("/orderprocessed", async context => |
||||
|
{ |
||||
|
var confirmation = await JsonSerializer.DeserializeAsync<OrderConfirmation>(context.Request.Body); |
||||
|
broker.Complete(confirmation); |
||||
|
}).WithTopic("orderprocessed"); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
@using System.Net.Http |
||||
|
@using Microsoft.AspNetCore.Authorization |
||||
|
@using Microsoft.AspNetCore.Components.Authorization |
||||
|
@using Microsoft.AspNetCore.Components.Forms |
||||
|
@using Microsoft.AspNetCore.Components.Routing |
||||
|
@using Microsoft.AspNetCore.Components.Web |
||||
|
@using Microsoft.JSInterop |
||||
|
@using store |
||||
|
@using store.Shared |
||||
|
@using Dapr.Client |
||||
|
@using System.Threading |
||||
@ -0,0 +1,10 @@ |
|||||
|
{ |
||||
|
"DetailedErrors": true, |
||||
|
"Logging": { |
||||
|
"LogLevel": { |
||||
|
"Default": "Information", |
||||
|
"Microsoft": "Warning", |
||||
|
"Microsoft.Hosting.Lifetime": "Information" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
{ |
||||
|
"Logging": { |
||||
|
"LogLevel": { |
||||
|
"Default": "Information", |
||||
|
"Microsoft": "Warning", |
||||
|
"Microsoft.Hosting.Lifetime": "Information" |
||||
|
} |
||||
|
}, |
||||
|
"AllowedHosts": "*" |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk.Web"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netcoreapp3.1</TargetFramework> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Dapr.AspNetCore" Version="0.5.0-preview02 " /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,86 @@ |
|||||
|
SIL OPEN FONT LICENSE Version 1.1 |
||||
|
|
||||
|
Copyright (c) 2014 Waybury |
||||
|
|
||||
|
PREAMBLE |
||||
|
The goals of the Open Font License (OFL) are to stimulate worldwide |
||||
|
development of collaborative font projects, to support the font creation |
||||
|
efforts of academic and linguistic communities, and to provide a free and |
||||
|
open framework in which fonts may be shared and improved in partnership |
||||
|
with others. |
||||
|
|
||||
|
The OFL allows the licensed fonts to be used, studied, modified and |
||||
|
redistributed freely as long as they are not sold by themselves. The |
||||
|
fonts, including any derivative works, can be bundled, embedded, |
||||
|
redistributed and/or sold with any software provided that any reserved |
||||
|
names are not used by derivative works. The fonts and derivatives, |
||||
|
however, cannot be released under any other type of license. The |
||||
|
requirement for fonts to remain under this license does not apply |
||||
|
to any document created using the fonts or their derivatives. |
||||
|
|
||||
|
DEFINITIONS |
||||
|
"Font Software" refers to the set of files released by the Copyright |
||||
|
Holder(s) under this license and clearly marked as such. This may |
||||
|
include source files, build scripts and documentation. |
||||
|
|
||||
|
"Reserved Font Name" refers to any names specified as such after the |
||||
|
copyright statement(s). |
||||
|
|
||||
|
"Original Version" refers to the collection of Font Software components as |
||||
|
distributed by the Copyright Holder(s). |
||||
|
|
||||
|
"Modified Version" refers to any derivative made by adding to, deleting, |
||||
|
or substituting -- in part or in whole -- any of the components of the |
||||
|
Original Version, by changing formats or by porting the Font Software to a |
||||
|
new environment. |
||||
|
|
||||
|
"Author" refers to any designer, engineer, programmer, technical |
||||
|
writer or other person who contributed to the Font Software. |
||||
|
|
||||
|
PERMISSION & CONDITIONS |
||||
|
Permission is hereby granted, free of charge, to any person obtaining |
||||
|
a copy of the Font Software, to use, study, copy, merge, embed, modify, |
||||
|
redistribute, and sell modified and unmodified copies of the Font |
||||
|
Software, subject to the following conditions: |
||||
|
|
||||
|
1) Neither the Font Software nor any of its individual components, |
||||
|
in Original or Modified Versions, may be sold by itself. |
||||
|
|
||||
|
2) Original or Modified Versions of the Font Software may be bundled, |
||||
|
redistributed and/or sold with any software, provided that each copy |
||||
|
contains the above copyright notice and this license. These can be |
||||
|
included either as stand-alone text files, human-readable headers or |
||||
|
in the appropriate machine-readable metadata fields within text or |
||||
|
binary files as long as those fields can be easily viewed by the user. |
||||
|
|
||||
|
3) No Modified Version of the Font Software may use the Reserved Font |
||||
|
Name(s) unless explicit written permission is granted by the corresponding |
||||
|
Copyright Holder. This restriction only applies to the primary font name as |
||||
|
presented to the users. |
||||
|
|
||||
|
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font |
||||
|
Software shall not be used to promote, endorse or advertise any |
||||
|
Modified Version, except to acknowledge the contribution(s) of the |
||||
|
Copyright Holder(s) and the Author(s) or with their explicit written |
||||
|
permission. |
||||
|
|
||||
|
5) The Font Software, modified or unmodified, in part or in whole, |
||||
|
must be distributed entirely under this license, and must not be |
||||
|
distributed under any other license. The requirement for fonts to |
||||
|
remain under this license does not apply to any document created |
||||
|
using the Font Software. |
||||
|
|
||||
|
TERMINATION |
||||
|
This license becomes null and void if any of the above conditions are |
||||
|
not met. |
||||
|
|
||||
|
DISCLAIMER |
||||
|
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF |
||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT |
||||
|
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE |
||||
|
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
||||
|
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL |
||||
|
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
|
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM |
||||
|
OTHER DEALINGS IN THE FONT SOFTWARE. |
||||
@ -0,0 +1,21 @@ |
|||||
|
The MIT License (MIT) |
||||
|
|
||||
|
Copyright (c) 2014 Waybury |
||||
|
|
||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
of this software and associated documentation files (the "Software"), to deal |
||||
|
in the Software without restriction, including without limitation the rights |
||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
copies of the Software, and to permit persons to whom the Software is |
||||
|
furnished to do so, subject to the following conditions: |
||||
|
|
||||
|
The above copyright notice and this permission notice shall be included in |
||||
|
all copies or substantial portions of the Software. |
||||
|
|
||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
|
THE SOFTWARE. |
||||
@ -0,0 +1,114 @@ |
|||||
|
[Open Iconic v1.1.1](http://useiconic.com/open) |
||||
|
=========== |
||||
|
|
||||
|
### Open Iconic is the open source sibling of [Iconic](http://useiconic.com). It is a hyper-legible collection of 223 icons with a tiny footprint—ready to use with Bootstrap and Foundation. [View the collection](http://useiconic.com/open#icons) |
||||
|
|
||||
|
|
||||
|
|
||||
|
## What's in Open Iconic? |
||||
|
|
||||
|
* 223 icons designed to be legible down to 8 pixels |
||||
|
* Super-light SVG files - 61.8 for the entire set |
||||
|
* SVG sprite—the modern replacement for icon fonts |
||||
|
* Webfont (EOT, OTF, SVG, TTF, WOFF), PNG and WebP formats |
||||
|
* Webfont stylesheets (including versions for Bootstrap and Foundation) in CSS, LESS, SCSS and Stylus formats |
||||
|
* PNG and WebP raster images in 8px, 16px, 24px, 32px, 48px and 64px. |
||||
|
|
||||
|
|
||||
|
## Getting Started |
||||
|
|
||||
|
#### For code samples and everything else you need to get started with Open Iconic, check out our [Icons](http://useiconic.com/open#icons) and [Reference](http://useiconic.com/open#reference) sections. |
||||
|
|
||||
|
### General Usage |
||||
|
|
||||
|
#### Using Open Iconic's SVGs |
||||
|
|
||||
|
We like SVGs and we think they're the way to display icons on the web. Since Open Iconic are just basic SVGs, we suggest you display them like you would any other image (don't forget the `alt` attribute). |
||||
|
|
||||
|
``` |
||||
|
<img src="/open-iconic/svg/icon-name.svg" alt="icon name"> |
||||
|
``` |
||||
|
|
||||
|
#### Using Open Iconic's SVG Sprite |
||||
|
|
||||
|
Open Iconic also comes in a SVG sprite which allows you to display all the icons in the set with a single request. It's like an icon font, without being a hack. |
||||
|
|
||||
|
Adding an icon from an SVG sprite is a little different than what you're used to, but it's still a piece of cake. *Tip: To make your icons easily style able, we suggest adding a general class to the* `<svg>` *tag and a unique class name for each different icon in the* `<use>` *tag.* |
||||
|
|
||||
|
``` |
||||
|
<svg class="icon"> |
||||
|
<use xlink:href="open-iconic.svg#account-login" class="icon-account-login"></use> |
||||
|
</svg> |
||||
|
``` |
||||
|
|
||||
|
Sizing icons only needs basic CSS. All the icons are in a square format, so just set the `<svg>` tag with equal width and height dimensions. |
||||
|
|
||||
|
``` |
||||
|
.icon { |
||||
|
width: 16px; |
||||
|
height: 16px; |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
Coloring icons is even easier. All you need to do is set the `fill` rule on the `<use>` tag. |
||||
|
|
||||
|
``` |
||||
|
.icon-account-login { |
||||
|
fill: #f00; |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
To learn more about SVG Sprites, read [Chris Coyier's guide](http://css-tricks.com/svg-sprites-use-better-icon-fonts/). |
||||
|
|
||||
|
#### Using Open Iconic's Icon Font... |
||||
|
|
||||
|
|
||||
|
##### …with Bootstrap |
||||
|
|
||||
|
You can find our Bootstrap stylesheets in `font/css/open-iconic-bootstrap.{css, less, scss, styl}` |
||||
|
|
||||
|
|
||||
|
``` |
||||
|
<link href="/open-iconic/font/css/open-iconic-bootstrap.css" rel="stylesheet"> |
||||
|
``` |
||||
|
|
||||
|
|
||||
|
``` |
||||
|
<span class="oi oi-icon-name" title="icon name" aria-hidden="true"></span> |
||||
|
``` |
||||
|
|
||||
|
##### …with Foundation |
||||
|
|
||||
|
You can find our Foundation stylesheets in `font/css/open-iconic-foundation.{css, less, scss, styl}` |
||||
|
|
||||
|
``` |
||||
|
<link href="/open-iconic/font/css/open-iconic-foundation.css" rel="stylesheet"> |
||||
|
``` |
||||
|
|
||||
|
|
||||
|
``` |
||||
|
<span class="fi-icon-name" title="icon name" aria-hidden="true"></span> |
||||
|
``` |
||||
|
|
||||
|
##### …on its own |
||||
|
|
||||
|
You can find our default stylesheets in `font/css/open-iconic.{css, less, scss, styl}` |
||||
|
|
||||
|
``` |
||||
|
<link href="/open-iconic/font/css/open-iconic.css" rel="stylesheet"> |
||||
|
``` |
||||
|
|
||||
|
``` |
||||
|
<span class="oi" data-glyph="icon-name" title="icon name" aria-hidden="true"></span> |
||||
|
``` |
||||
|
|
||||
|
|
||||
|
## License |
||||
|
|
||||
|
### Icons |
||||
|
|
||||
|
All code (including SVG markup) is under the [MIT License](http://opensource.org/licenses/MIT). |
||||
|
|
||||
|
### Fonts |
||||
|
|
||||
|
All fonts are under the [SIL Licensed](http://scripts.sil.org/cms/scripts/page.php?item_id=OFL_web). |
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 54 KiB |
Binary file not shown.
Binary file not shown.
@ -0,0 +1,183 @@ |
|||||
|
@import url('open-iconic/font/css/open-iconic-bootstrap.min.css'); |
||||
|
|
||||
|
html, body { |
||||
|
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; |
||||
|
} |
||||
|
|
||||
|
a, .btn-link { |
||||
|
color: #0366d6; |
||||
|
} |
||||
|
|
||||
|
.btn-primary { |
||||
|
color: #fff; |
||||
|
background-color: #1b6ec2; |
||||
|
border-color: #1861ac; |
||||
|
} |
||||
|
|
||||
|
app { |
||||
|
position: relative; |
||||
|
display: flex; |
||||
|
flex-direction: column; |
||||
|
} |
||||
|
|
||||
|
.top-row { |
||||
|
height: 3.5rem; |
||||
|
display: flex; |
||||
|
align-items: center; |
||||
|
} |
||||
|
|
||||
|
.main { |
||||
|
flex: 1; |
||||
|
} |
||||
|
|
||||
|
.main .top-row { |
||||
|
background-color: #f7f7f7; |
||||
|
border-bottom: 1px solid #d6d5d5; |
||||
|
justify-content: flex-end; |
||||
|
} |
||||
|
|
||||
|
.main .top-row > a, .main .top-row .btn-link { |
||||
|
white-space: nowrap; |
||||
|
margin-left: 1.5rem; |
||||
|
} |
||||
|
|
||||
|
.main .top-row a:first-child { |
||||
|
overflow: hidden; |
||||
|
text-overflow: ellipsis; |
||||
|
} |
||||
|
|
||||
|
.sidebar { |
||||
|
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%); |
||||
|
} |
||||
|
|
||||
|
.sidebar .top-row { |
||||
|
background-color: rgba(0,0,0,0.4); |
||||
|
} |
||||
|
|
||||
|
.sidebar .navbar-brand { |
||||
|
font-size: 1.1rem; |
||||
|
} |
||||
|
|
||||
|
.sidebar .oi { |
||||
|
width: 2rem; |
||||
|
font-size: 1.1rem; |
||||
|
vertical-align: text-top; |
||||
|
top: -2px; |
||||
|
} |
||||
|
|
||||
|
.sidebar .nav-item { |
||||
|
font-size: 0.9rem; |
||||
|
padding-bottom: 0.5rem; |
||||
|
} |
||||
|
|
||||
|
.sidebar .nav-item:first-of-type { |
||||
|
padding-top: 1rem; |
||||
|
} |
||||
|
|
||||
|
.sidebar .nav-item:last-of-type { |
||||
|
padding-bottom: 1rem; |
||||
|
} |
||||
|
|
||||
|
.sidebar .nav-item a { |
||||
|
color: #d7d7d7; |
||||
|
border-radius: 4px; |
||||
|
height: 3rem; |
||||
|
display: flex; |
||||
|
align-items: center; |
||||
|
line-height: 3rem; |
||||
|
} |
||||
|
|
||||
|
.sidebar .nav-item a.active { |
||||
|
background-color: rgba(255,255,255,0.25); |
||||
|
color: white; |
||||
|
} |
||||
|
|
||||
|
.sidebar .nav-item a:hover { |
||||
|
background-color: rgba(255,255,255,0.1); |
||||
|
color: white; |
||||
|
} |
||||
|
|
||||
|
.content { |
||||
|
padding-top: 1.1rem; |
||||
|
} |
||||
|
|
||||
|
.navbar-toggler { |
||||
|
background-color: rgba(255, 255, 255, 0.1); |
||||
|
} |
||||
|
|
||||
|
.valid.modified:not([type=checkbox]) { |
||||
|
outline: 1px solid #26b050; |
||||
|
} |
||||
|
|
||||
|
.invalid { |
||||
|
outline: 1px solid red; |
||||
|
} |
||||
|
|
||||
|
.validation-message { |
||||
|
color: red; |
||||
|
} |
||||
|
|
||||
|
#blazor-error-ui { |
||||
|
background: lightyellow; |
||||
|
bottom: 0; |
||||
|
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); |
||||
|
display: none; |
||||
|
left: 0; |
||||
|
padding: 0.6rem 1.25rem 0.7rem 1.25rem; |
||||
|
position: fixed; |
||||
|
width: 100%; |
||||
|
z-index: 1000; |
||||
|
} |
||||
|
|
||||
|
#blazor-error-ui .dismiss { |
||||
|
cursor: pointer; |
||||
|
position: absolute; |
||||
|
right: 0.75rem; |
||||
|
top: 0.5rem; |
||||
|
} |
||||
|
|
||||
|
@media (max-width: 767.98px) { |
||||
|
.main .top-row:not(.auth) { |
||||
|
display: none; |
||||
|
} |
||||
|
|
||||
|
.main .top-row.auth { |
||||
|
justify-content: space-between; |
||||
|
} |
||||
|
|
||||
|
.main .top-row a, .main .top-row .btn-link { |
||||
|
margin-left: 0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@media (min-width: 768px) { |
||||
|
app { |
||||
|
flex-direction: row; |
||||
|
} |
||||
|
|
||||
|
.sidebar { |
||||
|
width: 250px; |
||||
|
height: 100vh; |
||||
|
position: sticky; |
||||
|
top: 0; |
||||
|
} |
||||
|
|
||||
|
.main .top-row { |
||||
|
position: sticky; |
||||
|
top: 0; |
||||
|
} |
||||
|
|
||||
|
.main > div { |
||||
|
padding-left: 2rem !important; |
||||
|
padding-right: 1.5rem !important; |
||||
|
} |
||||
|
|
||||
|
.navbar-toggler { |
||||
|
display: none; |
||||
|
} |
||||
|
|
||||
|
.sidebar .collapse { |
||||
|
/* Never collapse the sidebar for wide screens */ |
||||
|
display: block; |
||||
|
} |
||||
|
} |
||||
|
After Width: | Height: | Size: 31 KiB |
@ -0,0 +1,18 @@ |
|||||
|
# tye application configuration file |
||||
|
# read all about it at https://github.com/dotnet/tye |
||||
|
# |
||||
|
# when you've given us a try, we'd love to know what you think: |
||||
|
# https://aka.ms/AA7q20u |
||||
|
# |
||||
|
name: dapr |
||||
|
extensions: |
||||
|
- name: dapr |
||||
|
services: |
||||
|
- name: orders |
||||
|
project: orders/orders.csproj |
||||
|
- name: products |
||||
|
project: products/products.csproj |
||||
|
- name: store |
||||
|
project: store/store.csproj |
||||
|
- name: redis |
||||
|
image: redis |
||||
@ -0,0 +1,15 @@ |
|||||
|
// Licensed to the .NET Foundation under one or more agreements.
|
||||
|
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
// See the LICENSE file in the project root for more information.
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Microsoft.Tye |
||||
|
{ |
||||
|
public sealed class DeploymentManifestInfo |
||||
|
{ |
||||
|
public Dictionary<string, string> Annotations { get; } = new Dictionary<string, string>(); |
||||
|
|
||||
|
public Dictionary<string, string> Labels { get; } = new Dictionary<string, string>(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
// Licensed to the .NET Foundation under one or more agreements.
|
||||
|
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
// See the LICENSE file in the project root for more information.
|
||||
|
|
||||
|
namespace Microsoft.Tye |
||||
|
{ |
||||
|
public sealed class EnvironmentVariableSourceBuilder |
||||
|
{ |
||||
|
public EnvironmentVariableSourceBuilder(string service, string? binding) |
||||
|
{ |
||||
|
Service = service; |
||||
|
Binding = binding; |
||||
|
} |
||||
|
|
||||
|
public string Service { get; } |
||||
|
public string? Binding { get; } |
||||
|
|
||||
|
public SourceKind Kind { get; set; } |
||||
|
|
||||
|
public enum SourceKind |
||||
|
{ |
||||
|
Url, |
||||
|
Port, |
||||
|
Host, |
||||
|
ConnectionString, |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
// Licensed to the .NET Foundation under one or more agreements.
|
||||
|
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
// See the LICENSE file in the project root for more information.
|
||||
|
|
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Microsoft.Tye |
||||
|
{ |
||||
|
public abstract class Extension |
||||
|
{ |
||||
|
public abstract string Name { get; } |
||||
|
|
||||
|
public abstract Task ProcessAsync(ExtensionContext context, ExtensionConfiguration config); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
// Licensed to the .NET Foundation under one or more agreements.
|
||||
|
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
// See the LICENSE file in the project root for more information.
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Microsoft.Tye |
||||
|
{ |
||||
|
public sealed class ExtensionConfiguration |
||||
|
{ |
||||
|
public ExtensionConfiguration(string name) |
||||
|
{ |
||||
|
Name = name; |
||||
|
} |
||||
|
|
||||
|
public string Name { get; } |
||||
|
|
||||
|
public Dictionary<string, object> Data { get; } = new Dictionary<string, object>(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
// Licensed to the .NET Foundation under one or more agreements.
|
||||
|
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
// See the LICENSE file in the project root for more information.
|
||||
|
|
||||
|
namespace Microsoft.Tye |
||||
|
{ |
||||
|
public sealed class ExtensionContext |
||||
|
{ |
||||
|
public ExtensionContext(ApplicationBuilder application, OperationKind operation) |
||||
|
{ |
||||
|
Application = application; |
||||
|
Operation = operation; |
||||
|
} |
||||
|
|
||||
|
public ApplicationBuilder Application { get; } |
||||
|
|
||||
|
public OperationKind Operation { get; } |
||||
|
|
||||
|
public enum OperationKind |
||||
|
{ |
||||
|
LocalRun, |
||||
|
Deploy, |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
// Licensed to the .NET Foundation under one or more agreements.
|
||||
|
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
// See the LICENSE file in the project root for more information.
|
||||
|
|
||||
|
namespace Microsoft.Tye |
||||
|
{ |
||||
|
public sealed class KubernetesManifestInfo |
||||
|
{ |
||||
|
public KubernetesManifestInfo() |
||||
|
{ |
||||
|
// Create deployment and service by default
|
||||
|
Deployment = new DeploymentManifestInfo(); |
||||
|
Service = new ServiceManifestInfo(); |
||||
|
} |
||||
|
|
||||
|
public DeploymentManifestInfo? Deployment { get; set; } |
||||
|
|
||||
|
public ServiceManifestInfo Service { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
// Licensed to the .NET Foundation under one or more agreements.
|
||||
|
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
// See the LICENSE file in the project root for more information.
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Microsoft.Tye |
||||
|
{ |
||||
|
public sealed class ServiceManifestInfo |
||||
|
{ |
||||
|
public Dictionary<string, string> Annotations { get; } = new Dictionary<string, string>(); |
||||
|
|
||||
|
public Dictionary<string, string> Labels { get; } = new Dictionary<string, string>(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,147 @@ |
|||||
|
// Licensed to the .NET Foundation under one or more agreements.
|
||||
|
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
// See the LICENSE file in the project root for more information.
|
||||
|
|
||||
|
using System; |
||||
|
using System.Globalization; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Microsoft.Tye.Extensions.Dapr |
||||
|
{ |
||||
|
internal sealed class DaprExtension : Extension |
||||
|
{ |
||||
|
public override string Name => "dapr"; |
||||
|
|
||||
|
public override Task ProcessAsync(ExtensionContext context, ExtensionConfiguration config) |
||||
|
{ |
||||
|
// If we're getting called then the user configured dapr in their tye.yaml.
|
||||
|
// We don't have any of our own config.
|
||||
|
|
||||
|
if (context.Operation == ExtensionContext.OperationKind.LocalRun) |
||||
|
{ |
||||
|
// For local run, enumerate all projects, and add services for each dapr proxy.
|
||||
|
var projects = context.Application.Services.OfType<ProjectServiceBuilder>().ToList(); |
||||
|
foreach (var project in projects) |
||||
|
{ |
||||
|
// Dapr requires http. If this project isn't listening to HTTP then it's not daprized.
|
||||
|
var httpBinding = project.Bindings.Where(b => b.Protocol == "http").FirstOrDefault(); |
||||
|
if (httpBinding == null) |
||||
|
{ |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
var proxy = new ExecutableServiceBuilder($"{project.Name}-dapr", "daprd") |
||||
|
{ |
||||
|
WorkingDirectory = context.Application.Source.DirectoryName, |
||||
|
|
||||
|
// These environment variables are replaced with environment variables
|
||||
|
// defined for this service.
|
||||
|
Args = $"-app-id {project.Name} -app-port %APP_PORT% -dapr-grpc-port %DAPR_GRPC_PORT% --dapr-http-port %DAPR_HTTP_PORT% --metrics-port %METRICS_PORT% --placement-address localhost:50005", |
||||
|
}; |
||||
|
context.Application.Services.Add(proxy); |
||||
|
|
||||
|
// Listen for grpc on an auto-assigned port
|
||||
|
var grpc = new BindingBuilder() |
||||
|
{ |
||||
|
AutoAssignPort = true, |
||||
|
Name = "grpc", |
||||
|
Protocol = "https", |
||||
|
}; |
||||
|
proxy.Bindings.Add(grpc); |
||||
|
|
||||
|
// Listen for http on an auto-assigned port
|
||||
|
var http = new BindingBuilder() |
||||
|
{ |
||||
|
AutoAssignPort = true, |
||||
|
Name = "http", |
||||
|
Protocol = "http", |
||||
|
}; |
||||
|
proxy.Bindings.Add(http); |
||||
|
|
||||
|
// Listen for metrics on an auto-assigned port
|
||||
|
var metrics = new BindingBuilder() |
||||
|
{ |
||||
|
AutoAssignPort = true, |
||||
|
Name = "metrics", |
||||
|
Protocol = "http", |
||||
|
}; |
||||
|
proxy.Bindings.Add(metrics); |
||||
|
|
||||
|
// Set APP_PORT based on the project's assigned port for http
|
||||
|
var appPort = new EnvironmentVariableBuilder("APP_PORT") |
||||
|
{ |
||||
|
Source = new EnvironmentVariableSourceBuilder(project.Name, binding: httpBinding.Name) |
||||
|
{ |
||||
|
Kind = EnvironmentVariableSourceBuilder.SourceKind.Port, |
||||
|
}, |
||||
|
}; |
||||
|
proxy.EnvironmentVariables.Add(appPort); |
||||
|
|
||||
|
// Set DAPR_GRPC_PORT based on this service's assigned port
|
||||
|
var daprGrpcPort = new EnvironmentVariableBuilder("DAPR_GRPC_PORT") |
||||
|
{ |
||||
|
Source = new EnvironmentVariableSourceBuilder(proxy.Name, binding: "grpc") |
||||
|
{ |
||||
|
Kind = EnvironmentVariableSourceBuilder.SourceKind.Port, |
||||
|
}, |
||||
|
}; |
||||
|
proxy.EnvironmentVariables.Add(daprGrpcPort); |
||||
|
|
||||
|
// Add another copy of this envvar to the project.
|
||||
|
daprGrpcPort = new EnvironmentVariableBuilder("DAPR_GRPC_PORT") |
||||
|
{ |
||||
|
Source = new EnvironmentVariableSourceBuilder(proxy.Name, binding: "grpc") |
||||
|
{ |
||||
|
Kind = EnvironmentVariableSourceBuilder.SourceKind.Port, |
||||
|
}, |
||||
|
}; |
||||
|
project.EnvironmentVariables.Add(daprGrpcPort); |
||||
|
|
||||
|
// Set DAPR_Http_PORT based on this service's assigned port
|
||||
|
var daprHttpPort = new EnvironmentVariableBuilder("DAPR_HTTP_PORT") |
||||
|
{ |
||||
|
Source = new EnvironmentVariableSourceBuilder(proxy.Name, binding: "http") |
||||
|
{ |
||||
|
Kind = EnvironmentVariableSourceBuilder.SourceKind.Port, |
||||
|
}, |
||||
|
}; |
||||
|
proxy.EnvironmentVariables.Add(daprHttpPort); |
||||
|
|
||||
|
// Set METRICS_PORT to a random port
|
||||
|
var metricsPort = new EnvironmentVariableBuilder("METRICS_PORT") |
||||
|
{ |
||||
|
Source = new EnvironmentVariableSourceBuilder(proxy.Name, binding: "metrics") |
||||
|
{ |
||||
|
Kind = EnvironmentVariableSourceBuilder.SourceKind.Port, |
||||
|
}, |
||||
|
}; |
||||
|
proxy.EnvironmentVariables.Add(metricsPort); |
||||
|
} |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
// In deployment, enumerate all projects and add anotations to each one.
|
||||
|
var projects = context.Application.Services.OfType<ProjectServiceBuilder>(); |
||||
|
foreach (var project in projects) |
||||
|
{ |
||||
|
// Dapr requires http. If this project isn't listening to HTTP then it's not daprized.
|
||||
|
var httpBinding = project.Bindings.Where(b => b.Protocol == "http").FirstOrDefault(); |
||||
|
if (httpBinding == null) |
||||
|
{ |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if (project.ManifestInfo?.Deployment is DeploymentManifestInfo deployment) |
||||
|
{ |
||||
|
deployment.Annotations.Add("dapr.io/enabled", "true"); |
||||
|
deployment.Annotations.Add("dapr.io/id", project.Name); |
||||
|
deployment.Annotations.Add("dapr.io/port", (httpBinding.Port ?? 80).ToString(CultureInfo.InvariantCulture)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netcoreapp3.1</TargetFramework> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\Microsoft.Tye.Core\Microsoft.Tye.Core.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,18 @@ |
|||||
|
// Licensed to the .NET Foundation under one or more agreements.
|
||||
|
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
// See the LICENSE file in the project root for more information.
|
||||
|
|
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using Microsoft.Tye.Extensions.Dapr; |
||||
|
|
||||
|
namespace Microsoft.Tye.Extensions |
||||
|
{ |
||||
|
public static class WellKnownExtensions |
||||
|
{ |
||||
|
public static IReadOnlyDictionary<string, Extension> Extensions = new Dictionary<string, Extension>(StringComparer.InvariantCultureIgnoreCase) |
||||
|
{ |
||||
|
{ "dapr", new DaprExtension() }, |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
@ -1,19 +0,0 @@ |
|||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
using System.Linq; |
|
||||
using System.Threading.Tasks; |
|
||||
|
|
||||
namespace Microsoft.Tye.Hosting.Model |
|
||||
{ |
|
||||
public class ConfigurationSource |
|
||||
{ |
|
||||
public ConfigurationSource(string name, string value) |
|
||||
{ |
|
||||
Name = name; |
|
||||
Value = value; |
|
||||
} |
|
||||
|
|
||||
public string Name { get; } |
|
||||
public string Value { get; } |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,19 @@ |
|||||
|
// Licensed to the .NET Foundation under one or more agreements.
|
||||
|
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
// See the LICENSE file in the project root for more information.
|
||||
|
|
||||
|
namespace Microsoft.Tye.Hosting.Model |
||||
|
{ |
||||
|
public class EnvironmentVariable |
||||
|
{ |
||||
|
public EnvironmentVariable(string name) |
||||
|
{ |
||||
|
Name = name; |
||||
|
} |
||||
|
|
||||
|
public string Name { get; } |
||||
|
public string? Value { get; set; } |
||||
|
|
||||
|
public EnvironmentVariableSource? Source { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
// Licensed to the .NET Foundation under one or more agreements.
|
||||
|
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
// See the LICENSE file in the project root for more information.
|
||||
|
|
||||
|
namespace Microsoft.Tye.Hosting.Model |
||||
|
{ |
||||
|
public class EnvironmentVariableSource |
||||
|
{ |
||||
|
public EnvironmentVariableSource(string service, string? binding) |
||||
|
{ |
||||
|
Service = service; |
||||
|
Binding = binding; |
||||
|
} |
||||
|
|
||||
|
public string Service { get; } |
||||
|
|
||||
|
public string? Binding { get; } |
||||
|
|
||||
|
public SourceKind Kind { get; set; } |
||||
|
|
||||
|
public enum SourceKind |
||||
|
{ |
||||
|
Url, |
||||
|
Port, |
||||
|
Host, |
||||
|
ConnectionString, |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,56 @@ |
|||||
|
kind: Deployment |
||||
|
apiVersion: apps/v1 |
||||
|
metadata: |
||||
|
name: dapr_test_project |
||||
|
annotations: |
||||
|
dapr.io/enabled: 'true' |
||||
|
dapr.io/id: 'dapr_test_project' |
||||
|
dapr.io/port: '80' |
||||
|
labels: |
||||
|
app.kubernetes.io/name: 'dapr_test_project' |
||||
|
app.kubernetes.io/part-of: 'dapr_test_application' |
||||
|
spec: |
||||
|
replicas: 1 |
||||
|
selector: |
||||
|
matchLabels: |
||||
|
app.kubernetes.io/name: dapr_test_project |
||||
|
template: |
||||
|
metadata: |
||||
|
annotations: |
||||
|
dapr.io/enabled: 'true' |
||||
|
dapr.io/id: 'dapr_test_project' |
||||
|
dapr.io/port: '80' |
||||
|
labels: |
||||
|
app.kubernetes.io/name: 'dapr_test_project' |
||||
|
app.kubernetes.io/part-of: 'dapr_test_application' |
||||
|
spec: |
||||
|
containers: |
||||
|
- name: dapr_test_project |
||||
|
image: dapr_test_project:1.0.0 |
||||
|
imagePullPolicy: Always |
||||
|
env: |
||||
|
- name: ASPNETCORE_URLS |
||||
|
value: 'http://*' |
||||
|
- name: PORT |
||||
|
value: '80' |
||||
|
ports: |
||||
|
- containerPort: 80 |
||||
|
... |
||||
|
--- |
||||
|
kind: Service |
||||
|
apiVersion: v1 |
||||
|
metadata: |
||||
|
name: dapr_test_project |
||||
|
labels: |
||||
|
app.kubernetes.io/name: 'dapr_test_project' |
||||
|
app.kubernetes.io/part-of: 'dapr_test_application' |
||||
|
spec: |
||||
|
selector: |
||||
|
app.kubernetes.io/name: dapr_test_project |
||||
|
type: ClusterIP |
||||
|
ports: |
||||
|
- name: http |
||||
|
protocol: TCP |
||||
|
port: 80 |
||||
|
targetPort: 80 |
||||
|
... |
||||
@ -0,0 +1,26 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Hosting; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
|
||||
|
namespace dapr |
||||
|
{ |
||||
|
public class Program |
||||
|
{ |
||||
|
public static void Main(string[] args) |
||||
|
{ |
||||
|
CreateHostBuilder(args).Build().Run(); |
||||
|
} |
||||
|
|
||||
|
public static IHostBuilder CreateHostBuilder(string[] args) => |
||||
|
Host.CreateDefaultBuilder(args) |
||||
|
.ConfigureWebHostDefaults(webBuilder => |
||||
|
{ |
||||
|
webBuilder.UseStartup<Startup>(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
{ |
||||
|
"iisSettings": { |
||||
|
"windowsAuthentication": false, |
||||
|
"anonymousAuthentication": true, |
||||
|
"iisExpress": { |
||||
|
"applicationUrl": "http://localhost:64181", |
||||
|
"sslPort": 44315 |
||||
|
} |
||||
|
}, |
||||
|
"profiles": { |
||||
|
"IIS Express": { |
||||
|
"commandName": "IISExpress", |
||||
|
"launchBrowser": true, |
||||
|
"environmentVariables": { |
||||
|
"ASPNETCORE_ENVIRONMENT": "Development" |
||||
|
} |
||||
|
}, |
||||
|
"dapr": { |
||||
|
"commandName": "Project", |
||||
|
"launchBrowser": true, |
||||
|
"applicationUrl": "https://localhost:5001;http://localhost:5000", |
||||
|
"environmentVariables": { |
||||
|
"ASPNETCORE_ENVIRONMENT": "Development" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,40 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
using Microsoft.AspNetCore.Hosting; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
|
||||
|
namespace dapr |
||||
|
{ |
||||
|
public class Startup |
||||
|
{ |
||||
|
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
|
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
|
||||
|
public void ConfigureServices(IServiceCollection services) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) |
||||
|
{ |
||||
|
if (env.IsDevelopment()) |
||||
|
{ |
||||
|
app.UseDeveloperExceptionPage(); |
||||
|
} |
||||
|
|
||||
|
app.UseRouting(); |
||||
|
|
||||
|
app.UseEndpoints(endpoints => |
||||
|
{ |
||||
|
endpoints.MapGet("/", async context => |
||||
|
{ |
||||
|
await context.Response.WriteAsync("Hello World!"); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
{ |
||||
|
"Logging": { |
||||
|
"LogLevel": { |
||||
|
"Default": "Information", |
||||
|
"Microsoft": "Warning", |
||||
|
"Microsoft.Hosting.Lifetime": "Information" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
{ |
||||
|
"Logging": { |
||||
|
"LogLevel": { |
||||
|
"Default": "Information", |
||||
|
"Microsoft": "Warning", |
||||
|
"Microsoft.Hosting.Lifetime": "Information" |
||||
|
} |
||||
|
}, |
||||
|
"AllowedHosts": "*" |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk.Web"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netcoreapp3.1</TargetFramework> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,6 @@ |
|||||
|
name: dapr_test_application |
||||
|
extensions: |
||||
|
- name: dapr |
||||
|
services: |
||||
|
- name: dapr_test_project |
||||
|
project: dapr.csproj |
||||
Loading…
Reference in new issue