Skip to content

Commit

Permalink
Exploring storage and persistence options
Browse files Browse the repository at this point in the history
* starting with BlazorDB
  • Loading branch information
ebekker committed Jul 12, 2018
1 parent 85f53f8 commit 8d54421
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/examples/ACMEBlazor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2026
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ACMEBlazor", "ACMEBlazor\ACMEBlazor.csproj", "{B94A1327-02ED-4214-8B57-7F5A5AE022D2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ACMEBlazor", "ACMEBlazor\ACMEBlazor.csproj", "{B94A1327-02ED-4214-8B57-7F5A5AE022D2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
9 changes: 8 additions & 1 deletion src/examples/ACMEBlazor/ACMEBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
Expand All @@ -12,6 +12,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BlazorDB" Version="0.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Browser" Version="0.4.0" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="0.4.0" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
Expand All @@ -27,4 +28,10 @@
<ProjectReference Include="..\..\PKISharp.SimplePKI\PKISharp.SimplePKI.csproj" />
</ItemGroup>

<ItemGroup>
<Content Update="Pages\TryBlazorDB.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions src/examples/ACMEBlazor/Pages/Account.cshtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
@page "/account"

@using Newtonsoft.Json;
@using PKISharp.SimplePKI;
@using ACMEBlazor.Services;

@inject HttpClient http
@inject IRepository repo

<h1>ACME Account</h1>

Expand Down
62 changes: 62 additions & 0 deletions src/examples/ACMEBlazor/Pages/TryBlazorDB.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
@page "/tryblazordb"

@inject Context Context

<h1>Try BlazorDB</h1>

<p><textarea rows="5" cols="80" readonly="readonly" bind="@_accountList"></textarea></p>

@*<p>Current count: @currentCount</p>*@

<button class="btn btn-primary" onclick="@ListAccounts">List Accounts</button>
<button class="btn btn-primary" onclick="@CreateAccount">Create Account</button>
<button class="btn btn-primary" onclick="@CreateAccount">Create Account</button>

@functions
{
//int currentCount = 0;
string _accountList;

void ListAccounts()
{
var l = "";
foreach (var acct in Context.Accounts)
{
l += $"{acct.Id}:{acct.Details.Kid}:{string.Join(",", acct.Details.Payload.Contact)}\r\n";
}
_accountList = l;
}

void CreateAccount()
{
var acct = new BlazorAccount
{
Details = new AccountDetails
{
Kid = Guid.NewGuid().ToString(), //"https://acme-staging-v02.api.letsencrypt.org/acme/acct/6440557",
TosLink = "https://www.google.com/",
Payload = new ACMESharp.Protocol.Resources.Account
{
Id = "6440557",
Contact = new[]
{
"mailto:[email protected]",
"mailto:[email protected]",
},
Status = "StillGoing!",
Key = new
{
kty = "EC",
crv = "P-256",
x = "4yLZoZQdYHrypdiZudPDL649wBDmR4YjG2DHxX7MZEU",
y = "rUvtY-AnB4eihRyFaqwwbDGM6ZNtVjFuepPweFuDp3c",
},
},
},
};

Context.Accounts.Add(acct);
Context.SaveChanges();
}
}
8 changes: 8 additions & 0 deletions src/examples/ACMEBlazor/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using ACMEBlazor.Services;
using ACMESharp.Protocol;
using BlazorDB;
using Microsoft.AspNetCore.Blazor.Browser.Rendering;
using Microsoft.AspNetCore.Blazor.Browser.Services;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -17,6 +19,12 @@ static void Main(string[] args)
var serviceProvider = new BrowserServiceProvider(services =>
{
//services.AddSingleton(new AcmeProtocolClient(new Uri(LetsEncryptV2StagingEndpoint)));
services.AddSingleton<IRepository>(new Repository());
services.AddBlazorDB(options =>
{
options.LogDebug = true;
options.Assembly = typeof(Program).Assembly;
});
});

new BrowserRenderer(serviceProvider).AddComponent<App>("app");
Expand Down
21 changes: 21 additions & 0 deletions src/examples/ACMEBlazor/Services/Repository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ACMESharp.Protocol;

namespace ACMEBlazor.Services
{
public interface IRepository
{
Task<AccountDetails> GetAccount();
}

public class Repository : IRepository
{
public async Task<AccountDetails> GetAccount()
{
return null;
}
}
}
25 changes: 21 additions & 4 deletions src/examples/ACMEBlazor/Shared/NavMenu.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,43 @@

<div class=@(collapseNavMenu ? "collapse" : null) 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> Home
<span class="oi oi-home" aria-hidden="true"></span>
Home
</NavLink>
</li>

<li class="nav-item px-3">
<NavLink class="nav-link" href="account">
<span class="oi oi-plus" aria-hidden="true"></span> ACME Account
<span class="oi oi-plus" aria-hidden="true"></span>
ACME Account
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="tryblazordb">
<span class="oi oi-plus" aria-hidden="true"></span>
Try BlazorDB
</NavLink>
</li>




<li class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="oi oi-plus" aria-hidden="true"></span> Counter
<span class="oi oi-plus" aria-hidden="true"></span>
Counter
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="fetchdata">
<span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data
<span class="oi oi-list-rich" aria-hidden="true"></span>
Fetch data
</NavLink>
</li>

</ul>
</div>

Expand Down
17 changes: 17 additions & 0 deletions src/examples/ACMEBlazor/Storage/BlazorAccount.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using ACMESharp.Protocol;

namespace ACMEBlazor.Storage
{
public class BlazorAccount
{
public int Id { get; set; }

[Required]
public AccountDetails Details { get; set; }
}
}
20 changes: 20 additions & 0 deletions src/examples/ACMEBlazor/Storage/BlazorOrder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using ACMESharp.Protocol;

namespace ACMEBlazor.Storage
{
public class BlazorOrder
{
public int Id { get; set; }

[Required]
public BlazorAccount Account { get; set; }

[Required]
public OrderDetails Details { get; set; }
}
}
15 changes: 15 additions & 0 deletions src/examples/ACMEBlazor/Storage/Context.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ACMESharp.Protocol;
using BlazorDB;

namespace ACMEBlazor.Storage
{
public class Context : StorageContext
{
public StorageSet<BlazorAccount> Accounts { get; set; }
public StorageSet<BlazorOrder> Orders { get; set; }
}
}
3 changes: 2 additions & 1 deletion src/examples/ACMEBlazor/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@using System.Net.Http
@using System.Net.Http
@using Microsoft.AspNetCore.Blazor.Layouts
@using Microsoft.AspNetCore.Blazor.Routing
@using ACMEBlazor
@using ACMEBlazor.Shared
@using ACMEBlazor.Storage

0 comments on commit 8d54421

Please sign in to comment.