Skip to content
This repository was archived by the owner on May 10, 2020. It is now read-only.

Commit b9de2e9

Browse files
committed
preview7
1 parent fd1de94 commit b9de2e9

Some content is hidden

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

42 files changed

+521
-1136
lines changed

src/BlazorDB/BlazorDB.csproj

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<LangVersion>7.3</LangVersion>
1313
<RazorLangVersion>3.0</RazorLangVersion>
1414
<PackageId>BlazorDB</PackageId>
15-
<Version>1.0.0-preview4</Version>
15+
<Version>1.0.0-preview7</Version>
1616
<Authors>Chanan Braunstein</Authors>
1717
<Title>Blazor localStorage Database</Title>
1818
<Description>In memory, persisted to localstorage, database for .net Blazor browser framework</Description>
@@ -22,15 +22,19 @@
2222

2323
<ItemGroup>
2424
<!-- .js/.css files will be referenced via <script>/<link> tags; other content files will just be included in the app's 'dist' directory without any tags referencing them -->
25-
<EmbeddedResource Include="content\**\*.js" LogicalName="blazor:js:%(RecursiveDir)%(Filename)%(Extension)" />
26-
<EmbeddedResource Include="content\**\*.css" LogicalName="blazor:css:%(RecursiveDir)%(Filename)%(Extension)" />
27-
<EmbeddedResource Include="content\**" Exclude="**\*.js;**\*.css" LogicalName="blazor:file:%(RecursiveDir)%(Filename)%(Extension)" />
25+
<EmbeddedResource Include="wwwroot\**\*.js" LogicalName="blazor:js:%(RecursiveDir)%(Filename)%(Extension)" />
26+
<EmbeddedResource Include="wwwroot\**\*.css" LogicalName="blazor:css:%(RecursiveDir)%(Filename)%(Extension)" />
27+
<EmbeddedResource Include="wwwroot\**" Exclude="**\*.js;**\*.css" LogicalName="blazor:file:%(RecursiveDir)%(Filename)%(Extension)" />
2828
</ItemGroup>
2929

3030
<ItemGroup>
31-
<PackageReference Include="BlazorLogger" Version="1.0.0-preview4" />
32-
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview4-19216-03" />
33-
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview4-19216-03" PrivateAssets="all" />
31+
<None Include="wwwroot\blazorDBInterop.js" />
32+
</ItemGroup>
33+
34+
<ItemGroup>
35+
<PackageReference Include="BlazorLogger" Version="1.0.0-preview7" />
36+
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview7.19365.7" />
37+
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview7.19365.7" PrivateAssets="all" />
3438
</ItemGroup>
3539

3640
</Project>

src/BlazorDB/BlazorDBUpdateException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ public class BlazorDBUpdateException : Exception
66
{
77
public BlazorDBUpdateException(string error) : base(error)
88
{
9-
}
9+
}
1010
}
1111
}

src/BlazorDB/ServiceCollectionExtensions.cs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using BlazorDB.Storage;
2+
using BlazorLogger;
23
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.JSInterop;
35
using System;
46
using System.Collections.Generic;
57
using System.Linq;
68
using System.Reflection;
7-
using Microsoft.JSInterop;
8-
using BlazorLogger;
99

1010
namespace BlazorDB
1111
{
@@ -16,17 +16,25 @@ public static class ServiceCollectionExtensions
1616
public static IServiceCollection AddBlazorDB(this IServiceCollection serviceCollection,
1717
Action<Options> configure)
1818
{
19-
if (configure == null) throw new ArgumentNullException(nameof(configure));
20-
var options = new Options();
19+
if (configure == null)
20+
{
21+
throw new ArgumentNullException(nameof(configure));
22+
}
23+
24+
Options options = new Options();
2125
configure(options);
22-
if (options.LogDebug) BlazorDBLogger.LogDebug = true;
26+
if (options.LogDebug)
27+
{
28+
BlazorDBLogger.LogDebug = true;
29+
}
30+
2331
Scan(serviceCollection, options.Assembly);
2432
return serviceCollection;
2533
}
2634

2735
private static void Scan(IServiceCollection serviceCollection, Assembly assembly)
2836
{
29-
var types = ScanForContexts(serviceCollection, assembly);
37+
IEnumerable<Type> types = ScanForContexts(serviceCollection, assembly);
3038
serviceCollection.AddJavascriptLogger();
3139
serviceCollection.AddSingleton<IBlazorDBInterop, BlazorDBInterop>();
3240
serviceCollection.AddSingleton<IBlazorDBLogger, BlazorDBLogger>();
@@ -35,22 +43,22 @@ private static void Scan(IServiceCollection serviceCollection, Assembly assembly
3543
serviceCollection.AddSingleton<IStorageManagerSave, StorageManagerSave>();
3644
serviceCollection.AddSingleton<IStorageManagerLoad, StorageManagerLoad>();
3745

38-
foreach (var type in types)
46+
foreach (Type type in types)
3947
{
4048
serviceCollection.AddSingleton(type, s =>
4149
{
42-
var jsRuntime = s.GetRequiredService<IJSRuntime>();
43-
var instance = Activator.CreateInstance(type);
44-
var smProp = type.GetProperty("StorageManager", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
45-
var storageManager = s.GetRequiredService<IStorageManager>();
50+
IJSRuntime jsRuntime = s.GetRequiredService<IJSRuntime>();
51+
object instance = Activator.CreateInstance(type);
52+
PropertyInfo smProp = type.GetProperty("StorageManager", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
53+
IStorageManager storageManager = s.GetRequiredService<IStorageManager>();
4654
smProp.SetValue(instance, storageManager);
4755

48-
var lProp = type.GetProperty("Logger", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
49-
var logger = s.GetRequiredService<IBlazorDBLogger>();
56+
PropertyInfo lProp = type.GetProperty("Logger", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
57+
IBlazorDBLogger logger = s.GetRequiredService<IBlazorDBLogger>();
5058
lProp.SetValue(instance, logger);
5159

52-
var smuProp = type.GetProperty("StorageManagerUtil", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
53-
var storageManagerUtil = s.GetRequiredService<IStorageManagerUtil>();
60+
PropertyInfo smuProp = type.GetProperty("StorageManagerUtil", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
61+
IStorageManagerUtil storageManagerUtil = s.GetRequiredService<IStorageManagerUtil>();
5462
smuProp.SetValue(instance, storageManagerUtil);
5563
return instance;
5664
});

src/BlazorDB/Storage/BlazorDBLogger.cs

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,73 @@ internal class BlazorDBLogger : IBlazorDBLogger
1212
private const string Normal = "color: black; font-style: normal;";
1313
internal static bool LogDebug { get; set; } = true;
1414

15-
private ILogger _logger;
15+
private readonly ILogger _logger;
1616
public BlazorDBLogger(ILogger logger)
1717
{
1818
_logger = logger;
1919
}
2020

2121
public async Task LogStorageSetToConsole(Type type, object list)
2222
{
23-
if (!LogDebug) return;
23+
if (!LogDebug)
24+
{
25+
return;
26+
}
27+
2428
await _logger.Log($"StorageSet<{type.GetGenericArguments()[0].Name}>: %o", list);
2529
}
2630

2731
public async Task StartContextType(Type contextType, bool loading = true)
2832
{
29-
if (!LogDebug) return;
30-
var message = loading ? "loading" : "log";
33+
if (!LogDebug)
34+
{
35+
return;
36+
}
37+
38+
string message = loading ? "loading" : "log";
3139
await _logger.GroupCollapsed($"Context {message}: %c{contextType.Namespace}.{contextType.Name}", Blue);
3240
}
3341

3442
public async Task ContextSaved(Type contextType)
3543
{
36-
if (!LogDebug) return;
44+
if (!LogDebug)
45+
{
46+
return;
47+
}
48+
3749
await _logger.GroupCollapsed($"Context %csaved: %c{contextType.Namespace}.{contextType.Name}", Green,
3850
Blue);
3951
}
4052

4153
public void StorageSetSaved(Type modelType, int count)
4254
{
43-
if (!LogDebug) return;
55+
if (!LogDebug)
56+
{
57+
return;
58+
}
59+
4460
_logger.Log(
4561
$"StorageSet %csaved: %c{modelType.Namespace}.{modelType.Name}%c with {count} items", Green, Blue,
4662
Normal);
4763
}
4864

4965
public void EndGroup()
5066
{
51-
if (!LogDebug) return;
67+
if (!LogDebug)
68+
{
69+
return;
70+
}
71+
5272
_logger.GroupEnd();
5373
}
5474

5575
public void ItemAddedToContext(string contextTypeName, Type modelType, object item)
5676
{
57-
if (!LogDebug) return;
77+
if (!LogDebug)
78+
{
79+
return;
80+
}
81+
5882
_logger.GroupCollapsed(
5983
$"Item %c{modelType.Namespace}.{modelType.Name}%c %cadded%c to context: %c{contextTypeName}", Blue,
6084
Normal, Green, Normal, Blue);
@@ -64,14 +88,22 @@ public void ItemAddedToContext(string contextTypeName, Type modelType, object it
6488

6589
public void LoadModelInContext(Type modelType, int count)
6690
{
67-
if (!LogDebug) return;
91+
if (!LogDebug)
92+
{
93+
return;
94+
}
95+
6896
_logger.Log(
6997
$"StorageSet loaded: %c{modelType.Namespace}.{modelType.Name}%c with {count} items", Blue, Normal);
7098
}
7199

72100
public void ItemRemovedFromContext(string contextTypeName, Type modelType)
73101
{
74-
if (!LogDebug) return;
102+
if (!LogDebug)
103+
{
104+
return;
105+
}
106+
75107
_logger.Log(
76108
$"Item %c{modelType.Namespace}.{modelType.Name}%c %cremoved%c from context: %c{contextTypeName}", Blue,
77109
Normal, Red, Normal, Blue);

src/BlazorDB/Storage/IStorageManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
32

43
namespace BlazorDB.Storage
54
{

src/BlazorDB/Storage/StorageManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
32

43
namespace BlazorDB.Storage
54
{

0 commit comments

Comments
 (0)