This commit is contained in:
2020-11-15 16:29:22 +01:00
parent c12c8ae525
commit 3943f92f4c
5 changed files with 117 additions and 14 deletions
+10 -9
View File
@@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using zero.Core.Database;
using zero.Core.Entities;
using zero.Core.Extensions;
using zero.Core.Handlers;
@@ -24,7 +25,7 @@ namespace zero.Core.Api
/// <inheritdoc />
public string AppId { get; protected set; }
protected IDocumentStore Raven { get; private set; }
protected IZeroStore Store { get; private set; }
protected IZeroOptions Options { get; private set; }
@@ -36,9 +37,9 @@ namespace zero.Core.Api
public ApplicationContext(IDocumentStore raven, IZeroOptions options, ILogger<ApplicationContext> logger, IHandlerHolder handler = null)
public ApplicationContext(IZeroStore store, IZeroOptions options, ILogger<ApplicationContext> logger, IHandlerHolder handler = null)
{
Raven = raven;
Store = store;
Options = options;
Logger = logger;
Handler = handler;
@@ -99,7 +100,7 @@ namespace zero.Core.Api
//RandomNumberGenerator.Fill(bytes);
//user.SecurityStamp = Base32.ToBase32(bytes); // TODO update security stamp but Base32 is .net core internal
using IAsyncDocumentSession session = Raven.OpenAsyncSession();
using IAsyncDocumentSession session = Store.OpenAsyncSession();
await session.StoreAsync(user);
await session.SaveChangesAsync();
@@ -150,7 +151,7 @@ namespace zero.Core.Api
throw new Exception($"User entity ${user.Id} needs a valid AppId");
}
using IAsyncDocumentSession session = Raven.OpenAsyncSession();
using IAsyncDocumentSession session = Store.OpenAsyncSession();
return await session.LoadAsync<Application>(appId);
}
@@ -179,10 +180,10 @@ namespace zero.Core.Api
/// <inheritdoc />
public async Task<IApplicationContext> ForId(string appId)
{
using IAsyncDocumentSession session = Raven.OpenAsyncSession();
using IAsyncDocumentSession session = Store.OpenAsyncSession();
IApplication app = await session.LoadAsync<Application>(appId);
return new ApplicationContext(Raven, Options, Logger, Handler)
return new ApplicationContext(Store, Options, Logger, Handler)
{
App = app,
AppId = appId
@@ -253,7 +254,7 @@ namespace zero.Core.Api
{
return Apps;
}
using (IAsyncDocumentSession session = Raven.OpenAsyncSession())
using (IAsyncDocumentSession session = Store.OpenAsyncSession())
{
Apps = await session.Query<IApplication>().ToListAsync();
return Apps;
@@ -268,7 +269,7 @@ namespace zero.Core.Api
{
string userId = user.FindFirstValue(Constants.Auth.Claims.UserId);
using IAsyncDocumentSession session = Raven.OpenAsyncSession();
using IAsyncDocumentSession session = Store.OpenAsyncSession();
return await session.LoadAsync<IBackofficeUser>(userId);
}
+15 -1
View File
@@ -5,7 +5,21 @@ using System.Threading;
namespace zero.Core.Database
{
public class ZeroStore : DocumentStore
public interface IZeroStore
{
IDocumentStore Store { get; }
BulkInsertOperation BulkInsert(CancellationToken token = default);
BulkInsertOperation BulkInsert(string database, CancellationToken token = default);
IAsyncDocumentSession OpenAsyncSession();
IAsyncDocumentSession OpenAsyncSession(SessionOptions options);
IAsyncDocumentSession OpenAsyncSession(string database);
IDocumentSession OpenSession();
IDocumentSession OpenSession(SessionOptions options);
IDocumentSession OpenSession(string database);
}
public class ZeroStore : DocumentStore, IZeroStore
{
public ZeroStore() : base()
{
@@ -48,7 +48,7 @@ namespace zero.Core.Entities
string ImageId { get; set; }
/// <summary>
/// Simple image of the application (used as favicon)
/// Simple image of the application (can be used as favicon)
/// </summary>
string IconId { get; set; }
+90
View File
@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using zero.Core.Entities;
namespace zero.Core.Options
{
public class RoleOptions : ZeroBackofficeCollection<Space>, IZeroCollectionOptions
{
public RoleOptions()
{
}
public void Add<T>() where T : Space, new()
{
Items.Add(new T());
}
public void AddList<T>(string alias, string name, string description, string icon) where T : SpaceContent, new()
{
Items.Add(new Space()
{
Alias = alias,
View = SpaceView.List,
Name = name,
Description = description,
Icon = icon,
Type = typeof(T)
});
}
public void AddEditor<T>(string alias, string name, string description, string icon) where T : SpaceContent, new()
{
Items.Add(new Space()
{
Alias = alias,
View = SpaceView.Editor,
Name = name,
Description = description,
Icon = icon,
Type = typeof(T)
});
}
public void AddSeparator()
{
Space lastSpace = Items.LastOrDefault();
if (lastSpace != null)
{
lastSpace.LineBelow = true;
}
}
public void AddCustom<T>(string componentPath, string alias, string name, string description, string icon) where T : SpaceContent, new()
{
Items.Add(new Space()
{
Alias = alias,
View = SpaceView.Custom,
ComponentPath = componentPath,
Name = name,
Description = description,
Icon = icon,
Type = typeof(T)
});
}
public void AddCustom(string componentPath, string alias, string name, string description, string icon)
{
Items.Add(new Space()
{
Alias = alias,
View = SpaceView.Custom,
ComponentPath = componentPath,
Name = name,
Description = description,
Icon = icon
});
}
}
}
@@ -1,10 +1,8 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using zero.Core.Api;
using zero.Core.Entities;
using zero.Core.Extensions;
using zero.Core.Identity;
using zero.Web.Models;