Skip to content

Commit

Permalink
Added Serverside Blazor Sample using RX.Net and DynamicData.
Browse files Browse the repository at this point in the history
  • Loading branch information
jspuij committed Feb 24, 2020
1 parent aaf3577 commit 9a8eea8
Show file tree
Hide file tree
Showing 55 changed files with 3,036 additions and 554 deletions.
24 changes: 22 additions & 2 deletions Cortex.Net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlightFinder.Server", "samp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlightFinder.Client", "samples\FlightFinder.Client\FlightFinder.Client.csproj", "{69505BBC-EC8F-40AF-A2BD-326C6BF5C1C4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Server Side Blazor", "Server Side Blazor", "{B46378E7-E888-4475-B74C-86A1F333EE29}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cortex.Net.DynamicData", "src\Cortex.Net.DynamicData\Cortex.Net.DynamicData.csproj", "{D8EBE787-671B-46B1-ACF1-03378488AE71}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Client Side Blazor", "Client Side Blazor", "{B66DF57B-ED6E-45C9-A21A-1AE8EFDC008E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cortex.Net.BitcoinTicker", "samples\Cortex.Net.BitcoinTicker\Cortex.Net.BitcoinTicker.csproj", "{1320CF2A-19E0-4444-BEAA-7E99E9088763}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -91,6 +99,14 @@ Global
{69505BBC-EC8F-40AF-A2BD-326C6BF5C1C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{69505BBC-EC8F-40AF-A2BD-326C6BF5C1C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{69505BBC-EC8F-40AF-A2BD-326C6BF5C1C4}.Release|Any CPU.Build.0 = Release|Any CPU
{D8EBE787-671B-46B1-ACF1-03378488AE71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D8EBE787-671B-46B1-ACF1-03378488AE71}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8EBE787-671B-46B1-ACF1-03378488AE71}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8EBE787-671B-46B1-ACF1-03378488AE71}.Release|Any CPU.Build.0 = Release|Any CPU
{1320CF2A-19E0-4444-BEAA-7E99E9088763}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1320CF2A-19E0-4444-BEAA-7E99E9088763}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1320CF2A-19E0-4444-BEAA-7E99E9088763}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1320CF2A-19E0-4444-BEAA-7E99E9088763}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -103,11 +119,15 @@ Global
{6A213F26-6769-432E-A157-DCEBA92F9E3D} = {3FEECB8E-0064-4CA1-B796-B62EDB6387D5}
{2F1F7856-1D48-4087-B368-31A2CE1206EA} = {222F158B-3299-40FA-B8FA-ADF8E611EE54}
{A9CA7C47-8A56-4BBC-B943-6BE37D1BAE3F} = {59F94FD7-B4D5-4CBE-9F55-27FA6537B9E6}
{CBB14AD6-8431-47E4-B014-F047B07583B7} = {79D4183C-B3B6-4ACE-82EF-3D103EB90049}
{59F94FD7-B4D5-4CBE-9F55-27FA6537B9E6} = {79D4183C-B3B6-4ACE-82EF-3D103EB90049}
{CBB14AD6-8431-47E4-B014-F047B07583B7} = {B66DF57B-ED6E-45C9-A21A-1AE8EFDC008E}
{59F94FD7-B4D5-4CBE-9F55-27FA6537B9E6} = {B66DF57B-ED6E-45C9-A21A-1AE8EFDC008E}
{BBF20B8B-4208-40CB-BCBB-AF33B5A251CA} = {CBB14AD6-8431-47E4-B014-F047B07583B7}
{FDB5D494-7FE7-400E-82C9-B48F210054A8} = {CBB14AD6-8431-47E4-B014-F047B07583B7}
{69505BBC-EC8F-40AF-A2BD-326C6BF5C1C4} = {CBB14AD6-8431-47E4-B014-F047B07583B7}
{B46378E7-E888-4475-B74C-86A1F333EE29} = {79D4183C-B3B6-4ACE-82EF-3D103EB90049}
{D8EBE787-671B-46B1-ACF1-03378488AE71} = {222F158B-3299-40FA-B8FA-ADF8E611EE54}
{B66DF57B-ED6E-45C9-A21A-1AE8EFDC008E} = {79D4183C-B3B6-4ACE-82EF-3D103EB90049}
{1320CF2A-19E0-4444-BEAA-7E99E9088763} = {B46378E7-E888-4475-B74C-86A1F333EE29}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {101D3B0F-E9EE-48BA-BEA0-18A9904B157A}
Expand Down
10 changes: 10 additions & 0 deletions samples/Cortex.Net.BitcoinTicker/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<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>
13 changes: 13 additions & 0 deletions samples/Cortex.Net.BitcoinTicker/Components/ExchangeRateRow.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@using Cortex.Net.BitcoinTicker.Models

<tr>
<td>@ExchangeRate.Name (@ExchangeRate.Symbol)</td>
<td>@($"{ExchangeRate.Value:N}")</td>
<td>@($"{ExchangeRate.Min:N}")</td>
<td>@($"{ExchangeRate.Max:N}")</td>
</tr>

@code {
[Parameter]
public ExchangeRate ExchangeRate { get; set; }
}
36 changes: 36 additions & 0 deletions samples/Cortex.Net.BitcoinTicker/Cortex.Net.BitcoinTicker.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>bin\Debug</OutputPath>
<DocumentationFile>bin\Debug\netcoreapp3.1\BitcoinTicker.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<Content Remove="stylecop.json" />
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="stylecop.json" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.2.0-preview1.20073.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Reactive" Version="4.3.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Cortex.Net.Blazor\Cortex.Net.Blazor.csproj" />
<ProjectReference Include="..\..\src\Cortex.Net.DynamicData\Cortex.Net.DynamicData.csproj" />
<ProjectReference Include="..\..\src\Cortex.Net\Cortex.Net.csproj" />
</ItemGroup>
<ItemGroup>
<WeaverFiles Include="$(SolutionDir)src\Cortex.Net.Fody\bin\$(Configuration)\netstandard2.0\Cortex.Net.Fody.dll" WeaverClassNames="ModuleWeaver" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions samples/Cortex.Net.BitcoinTicker/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ModuleWeaver />
</Weavers>
26 changes: 26 additions & 0 deletions samples/Cortex.Net.BitcoinTicker/FodyWeavers.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="ModuleWeaver" minOccurs="0" maxOccurs="1" type="xs:anyType" />
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
52 changes: 52 additions & 0 deletions samples/Cortex.Net.BitcoinTicker/Models/ExchangeRate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// <copyright file="ExchangeRate.cs" company="Jan-Willem Spuij">
// Copyright 2019 Jan-Willem Spuij
//
// 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.
// </copyright>

namespace Cortex.Net.BitcoinTicker.Models
{
using Cortex.Net.Api;

/// <summary>
/// Observable Ticker item.
/// </summary>
[Observable]
public class ExchangeRate
{
/// <summary>
/// Gets or sets the name of the exchange rate.
/// </summary>
public string Name { get; set; }

/// <summary>
/// Gets or sets the symbol of the exchange rate.
/// </summary>
public string Symbol { get; set; }

/// <summary>
/// Gets or sets the value of the echange rate.
/// </summary>
public decimal Value { get; set; }

/// <summary>
/// Gets or sets the min value of the exchange rate.
/// </summary>
public decimal Min { get; set; }

/// <summary>
/// Gets or sets the max value of the exchange rate.
/// </summary>
public decimal Max { get; set; }
}
}
46 changes: 46 additions & 0 deletions samples/Cortex.Net.BitcoinTicker/Models/Transaction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// <copyright file="Transaction.cs" company="Jan-Willem Spuij">
// Copyright 2019 Jan-Willem Spuij
//
// 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.
// </copyright>

namespace Cortex.Net.BitcoinTicker.Models
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Cortex.Net.Api;

/// <summary>
/// A bitcoin transaction.
/// </summary>
[Observable]
public class Transaction
{
/// <summary>
/// Gets or sets the Hash.
/// </summary>
public string Hash { get; set; }

/// <summary>
/// Gets or sets the time of the transaction.
/// </summary>
public DateTime Time { get; set; }

/// <summary>
/// Gets or sets the amount in BTC.
/// </summary>
public decimal Amount { get; set; }
}
}
57 changes: 57 additions & 0 deletions samples/Cortex.Net.BitcoinTicker/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@page "/"
@using BitcoinTicker.Store
@using Cortex.Net.Api
@using Cortex.Net.Blazor

@attribute [Observer]
@inject TickerStore TickerStore

<h1>Bitcoin.info exchange rates.</h1>

@if (this.FilteredRates.Any())
{
<table class="table table-striped">
<thead>
<tr>
<td>Currency</td>
<td>Last</td>
<td>Min</td>
<td>Max</td>
</tr>
<tr>
<td><input @bind-value="FilterText" @bind-value:event="oninput" /></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</thead>
<tbody>
@foreach (var keyValuePair in this.FilteredRates)
{
<ExchangeRateRow @key="keyValuePair.Key" ExchangeRate="keyValuePair.Value" />
}
</tbody>
<tfoot>
<tr>
<td colspan="4">Number of exchange rates: @this.FilteredRates.Count()</td>
</tr>
</tfoot>
</table>
}
else
{
<p>There are no exchange rates.</p>
<p>@TickerStore.ErrorMessage</p>
}


@code
{
[Computed]
public IEnumerable<KeyValuePair<string, Models.ExchangeRate>> FilteredRates => this.TickerStore.ExchangeRates.Where(x => FilterText == null || x.Key.StartsWith(FilterText));

[Observable]
public string FilterText { get; set; }
}


75 changes: 75 additions & 0 deletions samples/Cortex.Net.BitcoinTicker/Pages/Transactions.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
@page "/transactions"
@page "/transactions/{PageIndex:int}"
@using BitcoinTicker.Store
@using BitcoinTicker.Models
@using Cortex.Net.Api
@using Cortex.Net.Blazor

@attribute [Observer]
@inject TransactionStore TransactionStore

<h1>Bitcoin.info unconfirmed transactions.</h1>


@if (this.TransactionStore.Transactions.Any())
{
<table class="table table-striped">
<thead>
<tr>
<td>Hash</td>
<td>Time</td>
<td>Amount (BTC)</td>
</tr>
</thead>
<tbody>
@foreach (var transaction in this.PagedTransactions)
{
<tr>
<td @key="transaction.Hash">@transaction.Hash</td>
<td>@($"{transaction.Time:t}")</td>
<td>@($"{transaction.Amount:N8}")</td>
</tr>
}
</tbody>
<tfoot>
<tr>
<td>
@foreach (int pagenr in Pages)
{
<NavLink href="@($"/transactions/{pagenr}")">@pagenr</NavLink>
}
</td>
<td>Number of transactions: @this.TransactionStore.Transactions.Count()</td>
<td>PageSize: <input type="number" @bind-value="PageSize" /></td>
</tr>
</tfoot>
</table>
}
else
{
<p>There are no transactions.</p>
<p>@TransactionStore.ErrorMessage</p>
}

@code
{
[Computed]
public IEnumerable<Transaction> PagedTransactions => this.TransactionStore.Transactions.Skip((PageIndex - 1) * PageSize).Take(PageSize);

[Observable]
[Parameter]
public int PageIndex { get; set; }

[Observable]
public int PageSize { get; set; }

[Computed]
public IEnumerable<int> Pages => Enumerable.Range(1, this.TransactionStore.Transactions.Count > 0 ? this.TransactionStore.Transactions.Count / PageSize : 1);

protected override void OnInitialized()
{
base.OnInitialized();
PageSize = 20;
PageIndex = 1;
}
}
Loading

0 comments on commit 9a8eea8

Please sign in to comment.