diff --git a/zero.Core/Api/ApplicationContext.cs b/zero.Core/Api/ApplicationContext.cs index 2c07929a..099cf6ac 100644 --- a/zero.Core/Api/ApplicationContext.cs +++ b/zero.Core/Api/ApplicationContext.cs @@ -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 /// 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 logger, IHandlerHolder handler = null) + public ApplicationContext(IZeroStore store, IZeroOptions options, ILogger 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(appId); } @@ -179,10 +180,10 @@ namespace zero.Core.Api /// public async Task ForId(string appId) { - using IAsyncDocumentSession session = Raven.OpenAsyncSession(); + using IAsyncDocumentSession session = Store.OpenAsyncSession(); IApplication app = await session.LoadAsync(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().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(userId); } diff --git a/zero.Core/Database/ZeroStore.cs b/zero.Core/Database/ZeroStore.cs index e42c87ec..33a02e52 100644 --- a/zero.Core/Database/ZeroStore.cs +++ b/zero.Core/Database/ZeroStore.cs @@ -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() { diff --git a/zero.Core/Entities/Applications/Application.cs b/zero.Core/Entities/Applications/Application.cs index b41b35e1..bd420a77 100644 --- a/zero.Core/Entities/Applications/Application.cs +++ b/zero.Core/Entities/Applications/Application.cs @@ -48,7 +48,7 @@ namespace zero.Core.Entities string ImageId { get; set; } /// - /// Simple image of the application (used as favicon) + /// Simple image of the application (can be used as favicon) /// string IconId { get; set; } diff --git a/zero.Core/Options/RoleOptions.cs b/zero.Core/Options/RoleOptions.cs new file mode 100644 index 00000000..6094d0bf --- /dev/null +++ b/zero.Core/Options/RoleOptions.cs @@ -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, IZeroCollectionOptions + { + public RoleOptions() + { + + } + + + public void Add() where T : Space, new() + { + Items.Add(new T()); + } + + + public void AddList(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(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(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 + }); + } + } +} diff --git a/zero.Web/Controllers/ApplicationsController.cs b/zero.Web/Controllers/ApplicationsController.cs index 0a1d2c66..308dd006 100644 --- a/zero.Web/Controllers/ApplicationsController.cs +++ b/zero.Web/Controllers/ApplicationsController.cs @@ -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;