Skip to content

Commit 5e6c58c

Browse files
committed
Add project files.
1 parent 2475991 commit 5e6c58c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+4107
-0
lines changed

IndexDb.Example/App.razor

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Router AppAssembly="@typeof(App).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
5+
</Found>
6+
<NotFound>
7+
<PageTitle>Not found</PageTitle>
8+
<LayoutView Layout="@typeof(MainLayout)">
9+
<p role="alert">Sorry, there's nothing at this address.</p>
10+
</LayoutView>
11+
</NotFound>
12+
</Router>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.4" />
12+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.4" PrivateAssets="all" />
13+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\Magic.IndexedDb\Magic.IndexedDb.csproj" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
22+
</ItemGroup>
23+
24+
</Project>

IndexDb.Example/Models/DbNames.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace IndexDb.Example
2+
{
3+
public static class DbNames
4+
{
5+
public const string Client = "client";
6+
}
7+
}

IndexDb.Example/Models/Person.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Magic.IndexedDb;
2+
using Magic.IndexedDb.SchemaAnnotations;
3+
4+
namespace IndexDb.Example
5+
{
6+
[MagicTable("Person", DbNames.Client)]
7+
public class Person
8+
{
9+
[MagicPrimaryKey("id")]
10+
public int _Id { get; set; }
11+
12+
[MagicIndex]
13+
public string Name { get; set; }
14+
15+
[MagicIndex("Age")]
16+
public int _Age { get; set; }
17+
18+
[MagicIndex]
19+
public int TestInt { get; set; }
20+
21+
[MagicUniqueIndex("guid")]
22+
public Guid GUIY { get; set; } = Guid.NewGuid();
23+
24+
[MagicEncrypt]
25+
public string Secret { get; set; }
26+
27+
[MagicNotMapped]
28+
public string DoNotMapTest { get; set; }
29+
30+
[MagicNotMapped]
31+
public string SecretDecrypted { get; set; }
32+
33+
private bool testPrivate { get; set; } = false;
34+
35+
public bool GetTest()
36+
{
37+
return true;
38+
}
39+
40+
}
41+
42+
43+
}

IndexDb.Example/Pages/Index.razor

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
@page "/"
2+
@inject IMagicDbFactory _MagicDb
3+
4+
<PageTitle>Example</PageTitle>
5+
6+
<h3>People In IndexedDb!</h3>
7+
<table class="table">
8+
<thead>
9+
<tr>
10+
<th>ID</th>
11+
<th>Name</th>
12+
<th>Age</th>
13+
<th>DecryptedSecret</th>
14+
<th>Encrypted Secret</th>
15+
</tr>
16+
</thead>
17+
<tbody>
18+
@foreach (Person person in allPeople)
19+
{
20+
<tr>
21+
<td>@person._Id</td>
22+
<td>@person.Name</td>
23+
<td>@person._Age</td>
24+
<td>
25+
<div style="max-width: 400px; overflow-x: auto;">
26+
@person.SecretDecrypted
27+
</div>
28+
</td>
29+
<td>
30+
<div style="max-width: 200px; overflow-x: auto;">
31+
@person.Secret
32+
</div>
33+
</td>
34+
35+
</tr>
36+
}
37+
</tbody>
38+
</table>
39+
40+
<br />
41+
<br />
42+
<h3>Complex query capabilities!</h3>
43+
<pre>
44+
<code>
45+
<span style="color: #2A56C6;">await</span> manager.<span style="color: #2A56C6;">Where</span><span style="color: #A31515;">&lt;Person&gt;</span>(x =&gt; x.Name.<span style="color: #2A56C6;">StartsWith</span>(<span style="color: #A31515;">"c"</span>, <span style="color: #2A56C6;">StringComparison</span>.<span style="color: #2A56C6;">OrdinalIgnoreCase</span>)
46+
<span style="color: #2A56C6;">||</span> x.Name.<span style="color: #2A56C6;">StartsWith</span>(<span style="color: #A31515;">"l"</span>, <span style="color: #2A56C6;">StringComparison</span>.<span style="color: #2A56C6;">OrdinalIgnoreCase</span>)
47+
<span style="color: #2A56C6;">||</span> x.Name.<span style="color: #2A56C6;">StartsWith</span>(<span style="color: #A31515;">"j"</span>, <span style="color: #2A56C6;">StringComparison</span>.<span style="color: #2A56C6;">OrdinalIgnoreCase</span>) <span style="color: #2A56C6;">&amp;&amp;</span> x._Age <span style="color: #2A56C6;">&gt;</span> <span style="color: #2A56C6;">35</span>
48+
).<span style="color: #2A56C6;">OrderBy</span>(x =&gt; x._Id).<span style="color: #2A56C6;">Skip</span>(<span style="color: #2A56C6;">1</span>).<span style="color: #2A56C6;">Execute</span>();
49+
</code>
50+
</pre>
51+
52+
@foreach (Person person in WhereExample)
53+
{
54+
<p><b>Name:</b> @person.Name - <b>Age:</b> @person._Age</p>
55+
}

IndexDb.Example/Pages/Index.razor.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using Magic.IndexedDb.Models;
2+
using System;
3+
4+
namespace IndexDb.Example.Pages
5+
{
6+
public partial class Index
7+
{
8+
private List<Person> allPeople { get; set; } = new List<Person>();
9+
10+
private IEnumerable<Person> WhereExample { get; set; } = Enumerable.Empty<Person>();
11+
12+
13+
protected override async Task OnAfterRenderAsync(bool firstRender)
14+
{
15+
if (firstRender)
16+
{
17+
18+
try
19+
{
20+
var manager = await _MagicDb.GetDbManager(DbNames.Client);
21+
22+
//await manager.ClearTable<Person>();
23+
24+
var AllThePeeps = await manager.GetAll<Person>();
25+
if (AllThePeeps.Count() < 1)
26+
{
27+
Person[] persons = new Person[] {
28+
new Person { Name = "Zack", TestInt = 9, _Age = 45, GUIY = Guid.NewGuid(), Secret = "I buried treasure behind my house"},
29+
new Person { Name = "Luna", TestInt = 9, _Age = 35, GUIY = Guid.NewGuid(), Secret = "Jerry is my husband and I had an affair with Bob."},
30+
new Person { Name = "Jerry", TestInt = 9, _Age = 35, GUIY = Guid.NewGuid(), Secret = "My wife is amazing"},
31+
new Person { Name = "Jon", TestInt = 9, _Age = 37, GUIY = Guid.NewGuid(), Secret = "I black mail Luna for money because I know her secret"},
32+
new Person { Name = "Jack", TestInt = 9, _Age = 37, GUIY = Guid.NewGuid(), Secret = "I have a drug problem"},
33+
new Person { Name = "Cathy", TestInt = 9, _Age = 22, GUIY = Guid.NewGuid(), Secret = "I got away with reading Bobs diary."},
34+
new Person { Name = "Bob", TestInt = 3 , _Age = 69, GUIY = Guid.NewGuid(), Secret = "I caught Cathy reading my diary, but I'm too shy to confront her." },
35+
new Person { Name = "Alex", TestInt = 3 , _Age = 80, GUIY = Guid.NewGuid(), Secret = "I'm naked! But nobody can know!" }
36+
};
37+
38+
await manager.AddRange(persons);
39+
}
40+
41+
var allPeopleDecrypted = await manager.GetAll<Person>();
42+
43+
foreach (Person person in allPeopleDecrypted)
44+
{
45+
person.SecretDecrypted = await manager.Decrypt(person.Secret);
46+
allPeople.Add(person);
47+
}
48+
49+
WhereExample = await manager.Where<Person>(x => x.Name.StartsWith("c", StringComparison.OrdinalIgnoreCase)
50+
|| x.Name.StartsWith("l", StringComparison.OrdinalIgnoreCase)
51+
|| x.Name.StartsWith("j", StringComparison.OrdinalIgnoreCase) && x._Age > 35
52+
).OrderBy(x => x._Id).Skip(1).Execute();
53+
54+
StateHasChanged();
55+
}
56+
catch (Exception ex)
57+
{
58+
59+
}
60+
61+
}
62+
}
63+
}
64+
}

IndexDb.Example/Program.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using IndexDb.Example;
2+
using Magic.IndexedDb;
3+
using Magic.IndexedDb.Extensions;
4+
using Magic.IndexedDb.Helpers;
5+
using Microsoft.AspNetCore.Components.Web;
6+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
7+
8+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
9+
builder.RootComponents.Add<App>("#app");
10+
builder.RootComponents.Add<HeadOutlet>("head::after");
11+
12+
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
13+
14+
15+
/*
16+
* This is an example encryption key. You must make your own 128 bit or 256 bit
17+
* key! Do not use this example encryption key that I've provided here as that's
18+
* incredibly unsafe!
19+
*/
20+
string EncryptionKey = "zQfTuWnZi8u7x!A%C*F-JaBdRlUkXp2l";
21+
22+
builder.Services.AddBlazorDB(options =>
23+
{
24+
options.Name = DbNames.Client;
25+
options.Version = "1";
26+
options.EncryptionKey = EncryptionKey;
27+
options.StoreSchemas = SchemaHelper.GetAllSchemas(DbNames.Client);
28+
options.DbMigrations = new List<DbMigration>
29+
{
30+
/*
31+
* The DbMigration is not currently working or setup!
32+
* This is an example and idea I'm thinking about, but
33+
* this will very likely be depreciated so do not use or rely
34+
* on any of this syntax right now. If you want to have
35+
* your own migration knowledge. Write JavaScript on the front end
36+
* that will check the indedDb version and then apply migration code
37+
* on the front end if needed. But this is only needed for complex
38+
* migration projects.
39+
*/
40+
new DbMigration
41+
{
42+
FromVersion = "1.1",
43+
ToVersion = "2.2",
44+
Instructions = new List<DbMigrationInstruction>
45+
{
46+
new DbMigrationInstruction
47+
{
48+
Action = "renameStore",
49+
StoreName = "oldStore",
50+
Details = "newStore"
51+
}
52+
}
53+
}
54+
};
55+
});
56+
57+
await builder.Build().RunAsync();
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:4007",
7+
"sslPort": 44370
8+
}
9+
},
10+
"profiles": {
11+
"http": {
12+
"commandName": "Project",
13+
"dotnetRunMessages": true,
14+
"launchBrowser": true,
15+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
16+
"applicationUrl": "http://localhost:5148",
17+
"environmentVariables": {
18+
"ASPNETCORE_ENVIRONMENT": "Development"
19+
}
20+
},
21+
"https": {
22+
"commandName": "Project",
23+
"dotnetRunMessages": true,
24+
"launchBrowser": true,
25+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
26+
"applicationUrl": "https://localhost:7034;http://localhost:5148",
27+
"environmentVariables": {
28+
"ASPNETCORE_ENVIRONMENT": "Development"
29+
}
30+
},
31+
"IIS Express": {
32+
"commandName": "IISExpress",
33+
"launchBrowser": true,
34+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
35+
"environmentVariables": {
36+
"ASPNETCORE_ENVIRONMENT": "Development"
37+
}
38+
}
39+
}
40+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@inherits LayoutComponentBase
2+
3+
<div class="page">
4+
<div class="sidebar">
5+
<NavMenu />
6+
</div>
7+
8+
<main>
9+
<div class="top-row px-4">
10+
<a href="https://github.com/magiccodingman" target="_blank">About</a>
11+
</div>
12+
13+
<article class="content px-4">
14+
@Body
15+
</article>
16+
</main>
17+
</div>

0 commit comments

Comments
 (0)