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

Commit fd1de94

Browse files
committed
version 1.0.0-preview4
1 parent 6593714 commit fd1de94

File tree

82 files changed

+344
-1866
lines changed

Some content is hidden

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

82 files changed

+344
-1866
lines changed

BlazorDB.sln

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27701.1
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.28809.33
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorDB", "src\BlazorDB\BlazorDB.csproj", "{3ED7CA17-E65D-48B9-A218-3EBFF0F9FD03}"
77
EndProject
8-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample", "src\Sample\Sample.csproj", "{DAABB1BD-F735-4AB8-8ECF-70E00048175B}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample", "src\Sample\Sample.csproj", "{0C2A5B10-1805-41AB-B8CF-EFADD93BE494}"
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -17,10 +17,10 @@ Global
1717
{3ED7CA17-E65D-48B9-A218-3EBFF0F9FD03}.Debug|Any CPU.Build.0 = Debug|Any CPU
1818
{3ED7CA17-E65D-48B9-A218-3EBFF0F9FD03}.Release|Any CPU.ActiveCfg = Release|Any CPU
1919
{3ED7CA17-E65D-48B9-A218-3EBFF0F9FD03}.Release|Any CPU.Build.0 = Release|Any CPU
20-
{DAABB1BD-F735-4AB8-8ECF-70E00048175B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21-
{DAABB1BD-F735-4AB8-8ECF-70E00048175B}.Debug|Any CPU.Build.0 = Debug|Any CPU
22-
{DAABB1BD-F735-4AB8-8ECF-70E00048175B}.Release|Any CPU.ActiveCfg = Release|Any CPU
23-
{DAABB1BD-F735-4AB8-8ECF-70E00048175B}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{0C2A5B10-1805-41AB-B8CF-EFADD93BE494}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{0C2A5B10-1805-41AB-B8CF-EFADD93BE494}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{0C2A5B10-1805-41AB-B8CF-EFADD93BE494}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{0C2A5B10-1805-41AB-B8CF-EFADD93BE494}.Release|Any CPU.Build.0 = Release|Any CPU
2424
EndGlobalSection
2525
GlobalSection(SolutionProperties) = preSolution
2626
HideSolutionNode = FALSE

src/BlazorDB/BlazorDB.csproj

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5+
<RestoreAdditionalProjectSources>
6+
https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json;
7+
https://dotnet.myget.org/F/blazor-dev/api/v3/index.json;
8+
</RestoreAdditionalProjectSources>
59
<OutputType>Library</OutputType>
610
<IsPackable>true</IsPackable>
711
<BlazorLinkOnBuild>false</BlazorLinkOnBuild>
812
<LangVersion>7.3</LangVersion>
13+
<RazorLangVersion>3.0</RazorLangVersion>
914
<PackageId>BlazorDB</PackageId>
10-
<Version>0.8.0-pre</Version>
15+
<Version>1.0.0-preview4</Version>
1116
<Authors>Chanan Braunstein</Authors>
1217
<Title>Blazor localStorage Database</Title>
1318
<Description>In memory, persisted to localstorage, database for .net Blazor browser framework</Description>
@@ -23,9 +28,9 @@
2328
</ItemGroup>
2429

2530
<ItemGroup>
26-
<PackageReference Include="BlazorLogger" Version="0.8.0-pre" />
27-
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="0.8.0-preview-19104-04" />
28-
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="0.8.0-preview-19104-04" PrivateAssets="all" />
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" />
2934
</ItemGroup>
3035

3136
</Project>

src/BlazorDB/ServiceCollectionExtensions.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
using System.Collections.Generic;
55
using System.Linq;
66
using System.Reflection;
7-
using System.Threading.Tasks;
87
using Microsoft.JSInterop;
8+
using BlazorLogger;
99

1010
namespace BlazorDB
1111
{
1212
public static class ServiceCollectionExtensions
1313
{
14-
private static readonly IStorageManager StorageManager = new StorageManager();
1514
private static readonly Type StorageContext = typeof(StorageContext);
1615

1716
public static IServiceCollection AddBlazorDB(this IServiceCollection serviceCollection,
@@ -20,15 +19,21 @@ public static IServiceCollection AddBlazorDB(this IServiceCollection serviceColl
2019
if (configure == null) throw new ArgumentNullException(nameof(configure));
2120
var options = new Options();
2221
configure(options);
23-
if (options.LogDebug) Logger.LogDebug = true;
22+
if (options.LogDebug) BlazorDBLogger.LogDebug = true;
2423
Scan(serviceCollection, options.Assembly);
2524
return serviceCollection;
2625
}
2726

2827
private static void Scan(IServiceCollection serviceCollection, Assembly assembly)
2928
{
3029
var types = ScanForContexts(serviceCollection, assembly);
31-
serviceCollection.AddSingleton(StorageManager);
30+
serviceCollection.AddJavascriptLogger();
31+
serviceCollection.AddSingleton<IBlazorDBInterop, BlazorDBInterop>();
32+
serviceCollection.AddSingleton<IBlazorDBLogger, BlazorDBLogger>();
33+
serviceCollection.AddSingleton<IStorageManagerUtil, StorageManagerUtil>();
34+
serviceCollection.AddSingleton<IStorageManager, StorageManager>();
35+
serviceCollection.AddSingleton<IStorageManagerSave, StorageManagerSave>();
36+
serviceCollection.AddSingleton<IStorageManagerLoad, StorageManagerLoad>();
3237

3338
foreach (var type in types)
3439
{
@@ -37,7 +42,16 @@ private static void Scan(IServiceCollection serviceCollection, Assembly assembly
3742
var jsRuntime = s.GetRequiredService<IJSRuntime>();
3843
var instance = Activator.CreateInstance(type);
3944
var smProp = type.GetProperty("StorageManager", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
40-
smProp.SetValue(instance, StorageManager);
45+
var storageManager = s.GetRequiredService<IStorageManager>();
46+
smProp.SetValue(instance, storageManager);
47+
48+
var lProp = type.GetProperty("Logger", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
49+
var logger = s.GetRequiredService<IBlazorDBLogger>();
50+
lProp.SetValue(instance, logger);
51+
52+
var smuProp = type.GetProperty("StorageManagerUtil", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
53+
var storageManagerUtil = s.GetRequiredService<IStorageManagerUtil>();
54+
smuProp.SetValue(instance, storageManagerUtil);
4155
return instance;
4256
});
4357
}
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,86 @@
1-
using System;
1+
using BlazorLogger;
2+
using System;
23
using System.Threading.Tasks;
34

45
namespace BlazorDB.Storage
56
{
6-
internal static class Logger
7+
internal class BlazorDBLogger : IBlazorDBLogger
78
{
89
private const string Blue = "color: blue; font-style: bold;";
910
private const string Green = "color: green; font-style: bold;";
1011
private const string Red = "color: red; font-style: bold;";
1112
private const string Normal = "color: black; font-style: normal;";
1213
internal static bool LogDebug { get; set; } = true;
1314

14-
internal async static Task LogStorageSetToConsole(Type type, object list)
15+
private ILogger _logger;
16+
public BlazorDBLogger(ILogger logger)
17+
{
18+
_logger = logger;
19+
}
20+
21+
public async Task LogStorageSetToConsole(Type type, object list)
1522
{
1623
if (!LogDebug) return;
17-
await BlazorLogger.Logger.Log($"StorageSet<{type.GetGenericArguments()[0].Name}>: %o", list);
24+
await _logger.Log($"StorageSet<{type.GetGenericArguments()[0].Name}>: %o", list);
1825
}
1926

20-
internal async static Task StartContextType(Type contextType, bool loading = true)
27+
public async Task StartContextType(Type contextType, bool loading = true)
2128
{
2229
if (!LogDebug) return;
2330
var message = loading ? "loading" : "log";
24-
await BlazorLogger.Logger.GroupCollapsed($"Context {message}: %c{contextType.Namespace}.{contextType.Name}", Blue);
31+
await _logger.GroupCollapsed($"Context {message}: %c{contextType.Namespace}.{contextType.Name}", Blue);
2532
}
2633

27-
internal async static Task ContextSaved(Type contextType)
34+
public async Task ContextSaved(Type contextType)
2835
{
2936
if (!LogDebug) return;
30-
await BlazorLogger.Logger.GroupCollapsed($"Context %csaved: %c{contextType.Namespace}.{contextType.Name}", Green,
37+
await _logger.GroupCollapsed($"Context %csaved: %c{contextType.Namespace}.{contextType.Name}", Green,
3138
Blue);
3239
}
3340

34-
internal static void StorageSetSaved(Type modelType, int count)
41+
public void StorageSetSaved(Type modelType, int count)
3542
{
3643
if (!LogDebug) return;
37-
BlazorLogger.Logger.Log(
44+
_logger.Log(
3845
$"StorageSet %csaved: %c{modelType.Namespace}.{modelType.Name}%c with {count} items", Green, Blue,
3946
Normal);
4047
}
4148

42-
internal static void EndGroup()
49+
public void EndGroup()
4350
{
4451
if (!LogDebug) return;
45-
BlazorLogger.Logger.GroupEnd();
52+
_logger.GroupEnd();
4653
}
4754

48-
internal static void ItemAddedToContext(string contextTypeName, Type modelType, object item)
55+
public void ItemAddedToContext(string contextTypeName, Type modelType, object item)
4956
{
5057
if (!LogDebug) return;
51-
BlazorLogger.Logger.GroupCollapsed(
58+
_logger.GroupCollapsed(
5259
$"Item %c{modelType.Namespace}.{modelType.Name}%c %cadded%c to context: %c{contextTypeName}", Blue,
5360
Normal, Green, Normal, Blue);
54-
BlazorLogger.Logger.Log("Item: %o", item);
55-
BlazorLogger.Logger.GroupEnd();
61+
_logger.Log("Item: %o", item);
62+
_logger.GroupEnd();
5663
}
5764

58-
internal static void LoadModelInContext(Type modelType, int count)
65+
public void LoadModelInContext(Type modelType, int count)
5966
{
6067
if (!LogDebug) return;
61-
BlazorLogger.Logger.Log(
68+
_logger.Log(
6269
$"StorageSet loaded: %c{modelType.Namespace}.{modelType.Name}%c with {count} items", Blue, Normal);
6370
}
6471

65-
internal static void ItemRemovedFromContext(string contextTypeName, Type modelType)
72+
public void ItemRemovedFromContext(string contextTypeName, Type modelType)
6673
{
6774
if (!LogDebug) return;
68-
BlazorLogger.Logger.Log(
75+
_logger.Log(
6976
$"Item %c{modelType.Namespace}.{modelType.Name}%c %cremoved%c from context: %c{contextTypeName}", Blue,
7077
Normal, Red, Normal, Blue);
7178
}
79+
80+
public void Error(string error)
81+
{
82+
//Always log errors
83+
_logger.Error(error);
84+
}
7285
}
7386
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Threading.Tasks;
2+
3+
namespace BlazorDB.Storage
4+
{
5+
internal interface IBlazorDBInterop
6+
{
7+
Task<bool> Clear(bool session);
8+
Task<string> GetItem(string key, bool session);
9+
Task<bool> Log(params object[] list);
10+
Task<bool> RemoveItem(string key, bool session);
11+
Task<bool> SetItem(string key, string value, bool session);
12+
}
13+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
4+
namespace BlazorDB.Storage
5+
{
6+
public interface IBlazorDBLogger
7+
{
8+
Task ContextSaved(Type contextType);
9+
void EndGroup();
10+
void ItemAddedToContext(string contextTypeName, Type modelType, object item);
11+
void ItemRemovedFromContext(string contextTypeName, Type modelType);
12+
void LoadModelInContext(Type modelType, int count);
13+
Task LogStorageSetToConsole(Type type, object list);
14+
Task StartContextType(Type contextType, bool loading = true);
15+
void StorageSetSaved(Type modelType, int count);
16+
void Error(string error);
17+
}
18+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Threading.Tasks;
2+
3+
namespace BlazorDB.Storage
4+
{
5+
internal interface IStorageManagerLoad
6+
{
7+
Task LoadContextFromLocalStorage(StorageContext context);
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Threading.Tasks;
2+
3+
namespace BlazorDB.Storage
4+
{
5+
internal interface IStorageManagerSave
6+
{
7+
Task<int> SaveContextToLocalStorage(StorageContext context);
8+
}
9+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Reflection;
4+
using System.Threading.Tasks;
5+
6+
namespace BlazorDB.Storage
7+
{
8+
public interface IStorageManagerUtil
9+
{
10+
List<PropertyInfo> GetStorageSets(Type contextType);
11+
bool IsInContext(List<PropertyInfo> storageSets, PropertyInfo prop);
12+
bool IsListInContext(List<PropertyInfo> storageSets, PropertyInfo prop);
13+
Task<Metadata> LoadMetadata(string storageTableName);
14+
string ReplaceString(string source, int start, int end, string stringToInsert);
15+
}
16+
}

src/BlazorDB/Storage/Metadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace BlazorDB.Storage
55
{
6-
internal class Metadata
6+
public class Metadata
77
{
88
public List<Guid> Guids { get; set; }
99
public string ModelName { get; set; }

0 commit comments

Comments
 (0)