mirror of https://github.com/Squidex/squidex.git
committed by
GitHub
508 changed files with 7606 additions and 5890 deletions
@ -1,6 +1,7 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<configuration> |
|||
<packageSources> |
|||
<add key="localfeed" value="libs" /> |
|||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> |
|||
</packageSources> |
|||
</configuration> |
|||
Binary file not shown.
@ -0,0 +1 @@ |
|||
5W20j9jiNog4dHUEt+cCnePb8z6jFEMnkwO4XilajM7FCnen3KTnN/G8PAUGuQieSlTI9MRe0sRYcafLJl900w== |
|||
@ -0,0 +1,23 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd"> |
|||
<metadata> |
|||
<id>Microsoft.Orleans.OrleansCodeGenerator.Build</id> |
|||
<version>2.0.0-beta1-fix</version> |
|||
<title>Microsoft Orleans Build-time Code Generator</title> |
|||
<authors>Microsoft</authors> |
|||
<owners>Microsoft</owners> |
|||
<requireLicenseAcceptance>false</requireLicenseAcceptance> |
|||
<developmentDependency>true</developmentDependency> |
|||
<licenseUrl>https://github.com/dotnet/Orleans#license</licenseUrl> |
|||
<projectUrl>https://github.com/dotnet/Orleans</projectUrl> |
|||
<iconUrl>https://raw.githubusercontent.com/dotnet/orleans/gh-pages/assets/logo_128.png</iconUrl> |
|||
<description>Microsoft Orleans build-time code generator to install in all grain interface & implementation projects.</description> |
|||
<copyright>© Microsoft Corporation. All rights reserved.</copyright> |
|||
<tags>Orleans Cloud-Computing Actor-Model Actors Distributed-Systems C# .NET</tags> |
|||
<repository type="git" url="https://github.com/dotnet/Orleans" /> |
|||
<dependencies> |
|||
<group targetFramework=".NETFramework4.6.1" /> |
|||
<group targetFramework=".NETCoreApp2.0" /> |
|||
</dependencies> |
|||
</metadata> |
|||
</package> |
|||
Binary file not shown.
@ -0,0 +1 @@ |
|||
mBHlGWl+bNTPP463JBEB/dftmdZKQRD8X72F7lsTFqYWddW5Ytp1gbzChCxW0d/Pt71KLF6XrVmyecbFlNdFBA== |
|||
@ -0,0 +1,25 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"> |
|||
<metadata> |
|||
<id>OrleansDashboard</id> |
|||
<version>2.0.0-beta3</version> |
|||
<authors>OrleansContrib</authors> |
|||
<owners>OrleansContrib</owners> |
|||
<requireLicenseAcceptance>false</requireLicenseAcceptance> |
|||
<licenseUrl>https://opensource.org/licenses/MIT</licenseUrl> |
|||
<projectUrl>https://github.com/OrleansContrib/OrleansDashboard</projectUrl> |
|||
<iconUrl>http://dotnet.github.io/orleans/assets/logo.png</iconUrl> |
|||
<description>An admin dashboard for Microsoft Orleans</description> |
|||
<copyright>Copyright © 2017</copyright> |
|||
<tags>orleans dashboard metrics monitor</tags> |
|||
<repository url="https://github.com/OrleansContrib/OrleansDashboard" /> |
|||
<dependencies> |
|||
<group targetFramework=".NETStandard2.0"> |
|||
<dependency id="Microsoft.AspNetCore" version="2.0.1" exclude="Build,Analyzers" /> |
|||
<dependency id="Microsoft.Orleans.Core" version="2.0.0-beta1" exclude="Build,Analyzers" /> |
|||
<dependency id="Microsoft.Orleans.OrleansCodeGenerator.Build" version="2.0.0-beta1" exclude="Build,Analyzers" /> |
|||
<dependency id="Microsoft.Orleans.OrleansRuntime" version="2.0.0-beta1" exclude="Build,Analyzers" /> |
|||
</group> |
|||
</dependencies> |
|||
</metadata> |
|||
</package> |
|||
Binary file not shown.
@ -1,59 +0,0 @@ |
|||
// ==========================================================================
|
|||
// MongoAppEntity.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using MongoDB.Bson.Serialization.Attributes; |
|||
using Squidex.Domain.Apps.Core; |
|||
using Squidex.Domain.Apps.Core.Apps; |
|||
using Squidex.Domain.Apps.Read.Apps; |
|||
using Squidex.Infrastructure.MongoDb; |
|||
|
|||
namespace Squidex.Domain.Apps.Read.MongoDb.Apps |
|||
{ |
|||
public sealed class MongoAppEntity : MongoEntity, IAppEntity |
|||
{ |
|||
[BsonRequired] |
|||
[BsonElement] |
|||
public string Name { get; set; } |
|||
|
|||
[BsonRequired] |
|||
[BsonElement] |
|||
public long Version { get; set; } |
|||
|
|||
[BsonIgnoreIfDefault] |
|||
[BsonElement] |
|||
public string PlanId { get; set; } |
|||
|
|||
[BsonIgnoreIfDefault] |
|||
[BsonElement] |
|||
public string PlanOwner { get; set; } |
|||
|
|||
[BsonIgnoreIfDefault] |
|||
[BsonElement] |
|||
public string[] ContributorIds { get; set; } |
|||
|
|||
[BsonRequired] |
|||
[BsonElement] |
|||
[BsonJson] |
|||
public AppClients Clients { get; set; } |
|||
|
|||
[BsonRequired] |
|||
[BsonElement] |
|||
[BsonJson] |
|||
public AppContributors Contributors { get; set; } |
|||
|
|||
[BsonRequired] |
|||
[BsonElement] |
|||
[BsonJson] |
|||
public LanguagesConfig LanguagesConfig { get; set; } |
|||
|
|||
public PartitionResolver PartitionResolver |
|||
{ |
|||
get { return LanguagesConfig.ToResolver(); } |
|||
} |
|||
} |
|||
} |
|||
@ -1,70 +0,0 @@ |
|||
// ==========================================================================
|
|||
// MongoAppRepository.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using MongoDB.Driver; |
|||
using Squidex.Domain.Apps.Read.Apps; |
|||
using Squidex.Domain.Apps.Read.Apps.Repositories; |
|||
using Squidex.Infrastructure.MongoDb; |
|||
|
|||
namespace Squidex.Domain.Apps.Read.MongoDb.Apps |
|||
{ |
|||
public partial class MongoAppRepository : MongoRepositoryBase<MongoAppEntity>, IAppRepository, IAppEventConsumer |
|||
{ |
|||
public MongoAppRepository(IMongoDatabase database) |
|||
: base(database) |
|||
{ |
|||
} |
|||
|
|||
protected override string CollectionName() |
|||
{ |
|||
return "Projections_Apps"; |
|||
} |
|||
|
|||
protected override async Task SetupCollectionAsync(IMongoCollection<MongoAppEntity> collection) |
|||
{ |
|||
await collection.Indexes.CreateOneAsync(Index.Ascending(x => x.Name)); |
|||
await collection.Indexes.CreateOneAsync(Index.Ascending(x => x.ContributorIds)); |
|||
} |
|||
|
|||
protected override MongoCollectionSettings CollectionSettings() |
|||
{ |
|||
return new MongoCollectionSettings { WriteConcern = WriteConcern.WMajority }; |
|||
} |
|||
|
|||
public async Task<IReadOnlyList<IAppEntity>> QueryAllAsync(string subjectId) |
|||
{ |
|||
var appEntities = |
|||
await Collection.Find(s => s.ContributorIds.Contains(subjectId)) |
|||
.ToListAsync(); |
|||
|
|||
return appEntities; |
|||
} |
|||
|
|||
public async Task<IAppEntity> FindAppAsync(Guid id) |
|||
{ |
|||
var appEntity = |
|||
await Collection.Find(s => s.Id == id) |
|||
.FirstOrDefaultAsync(); |
|||
|
|||
return appEntity; |
|||
} |
|||
|
|||
public async Task<IAppEntity> FindAppAsync(string name) |
|||
{ |
|||
var appEntity = |
|||
await Collection.Find(s => s.Name == name) |
|||
.FirstOrDefaultAsync(); |
|||
|
|||
return appEntity; |
|||
} |
|||
} |
|||
} |
|||
@ -1,143 +0,0 @@ |
|||
// ==========================================================================
|
|||
// MongoAppRepository_EventHandling.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Squidex.Domain.Apps.Core.Apps; |
|||
using Squidex.Domain.Apps.Events; |
|||
using Squidex.Domain.Apps.Events.Apps; |
|||
using Squidex.Domain.Apps.Events.Apps.Utils; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.CQRS.Events; |
|||
using Squidex.Infrastructure.Dispatching; |
|||
using Squidex.Infrastructure.Reflection; |
|||
|
|||
namespace Squidex.Domain.Apps.Read.MongoDb.Apps |
|||
{ |
|||
public partial class MongoAppRepository |
|||
{ |
|||
public string Name |
|||
{ |
|||
get { return GetType().Name; } |
|||
} |
|||
|
|||
public string EventsFilter |
|||
{ |
|||
get { return "^app-"; } |
|||
} |
|||
|
|||
public Task On(Envelope<IEvent> @event) |
|||
{ |
|||
return this.DispatchActionAsync(@event.Payload, @event.Headers); |
|||
} |
|||
|
|||
protected Task On(AppCreated @event, EnvelopeHeaders headers) |
|||
{ |
|||
return Collection.CreateAsync(@event, headers, a => |
|||
{ |
|||
SimpleMapper.Map(@event, a); |
|||
|
|||
a.Clients = new AppClients(); |
|||
a.Contributors = new AppContributors(); |
|||
|
|||
a.LanguagesConfig = LanguagesConfig.Build(Language.EN); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(AppPlanChanged @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateAppAsync(@event, headers, a => |
|||
{ |
|||
SimpleMapper.Map(@event, a); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(AppClientAttached @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateAppAsync(@event, headers, a => |
|||
{ |
|||
a.Clients.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(AppClientRevoked @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateAppAsync(@event, headers, a => |
|||
{ |
|||
a.Clients.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(AppClientRenamed @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateAppAsync(@event, headers, a => |
|||
{ |
|||
a.Clients.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(AppClientUpdated @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateAppAsync(@event, headers, a => |
|||
{ |
|||
a.Clients.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(AppContributorRemoved @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateAppAsync(@event, headers, a => |
|||
{ |
|||
a.Contributors.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(AppContributorAssigned @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateAppAsync(@event, headers, a => |
|||
{ |
|||
a.Contributors.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(AppLanguageAdded @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateAppAsync(@event, headers, a => |
|||
{ |
|||
a.LanguagesConfig.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(AppLanguageRemoved @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateAppAsync(@event, headers, a => |
|||
{ |
|||
a.LanguagesConfig.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(AppLanguageUpdated @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateAppAsync(@event, headers, a => |
|||
{ |
|||
a.LanguagesConfig.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
private async Task UpdateAppAsync(AppEvent @event, EnvelopeHeaders headers, Action<MongoAppEntity> updater) |
|||
{ |
|||
await Collection.UpdateAsync(@event, headers, a => |
|||
{ |
|||
updater(a); |
|||
|
|||
a.ContributorIds = a.Contributors.Keys.ToArray(); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -1,90 +0,0 @@ |
|||
// ==========================================================================
|
|||
// MongoRuleRepository.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using MongoDB.Bson; |
|||
using MongoDB.Driver; |
|||
using Squidex.Domain.Apps.Read.Rules; |
|||
using Squidex.Domain.Apps.Read.Rules.Repositories; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.CQRS.Events; |
|||
using Squidex.Infrastructure.MongoDb; |
|||
|
|||
namespace Squidex.Domain.Apps.Read.MongoDb.Rules |
|||
{ |
|||
public partial class MongoRuleRepository : MongoRepositoryBase<MongoRuleEntity>, IRuleRepository, IEventConsumer |
|||
{ |
|||
private static readonly List<IRuleEntity> EmptyRules = new List<IRuleEntity>(); |
|||
private readonly SemaphoreSlim lockObject = new SemaphoreSlim(1); |
|||
private Dictionary<Guid, List<IRuleEntity>> inMemoryRules; |
|||
|
|||
public MongoRuleRepository(IMongoDatabase database) |
|||
: base(database) |
|||
{ |
|||
} |
|||
|
|||
protected override string CollectionName() |
|||
{ |
|||
return "Projections_Rules"; |
|||
} |
|||
|
|||
protected override Task SetupCollectionAsync(IMongoCollection<MongoRuleEntity> collection) |
|||
{ |
|||
return Task.WhenAll(collection.Indexes.CreateOneAsync(Index.Ascending(x => x.AppId))); |
|||
} |
|||
|
|||
public async Task<IReadOnlyList<IRuleEntity>> QueryByAppAsync(Guid appId) |
|||
{ |
|||
var entities = |
|||
await Collection.Find(x => x.AppId == appId) |
|||
.ToListAsync(); |
|||
|
|||
return entities.OfType<IRuleEntity>().ToList(); |
|||
} |
|||
|
|||
public async Task<IReadOnlyList<IRuleEntity>> QueryCachedByAppAsync(Guid appId) |
|||
{ |
|||
await EnsureRulesLoadedAsync(); |
|||
|
|||
return inMemoryRules.GetOrDefault(appId)?.ToList() ?? EmptyRules; |
|||
} |
|||
|
|||
private async Task EnsureRulesLoadedAsync() |
|||
{ |
|||
if (inMemoryRules == null) |
|||
{ |
|||
try |
|||
{ |
|||
await lockObject.WaitAsync(); |
|||
|
|||
if (inMemoryRules == null) |
|||
{ |
|||
inMemoryRules = new Dictionary<Guid, List<IRuleEntity>>(); |
|||
|
|||
var webhooks = |
|||
await Collection.Find(new BsonDocument()) |
|||
.ToListAsync(); |
|||
|
|||
foreach (var webhook in webhooks) |
|||
{ |
|||
inMemoryRules.GetOrAddNew(webhook.AppId).Add(webhook); |
|||
} |
|||
} |
|||
} |
|||
finally |
|||
{ |
|||
lockObject.Release(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,97 +0,0 @@ |
|||
// ==========================================================================
|
|||
// MongoRuleRepository_EventHandling.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Threading.Tasks; |
|||
using MongoDB.Driver; |
|||
using Squidex.Domain.Apps.Events.Rules; |
|||
using Squidex.Domain.Apps.Events.Rules.Utils; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.CQRS.Events; |
|||
using Squidex.Infrastructure.Dispatching; |
|||
|
|||
namespace Squidex.Domain.Apps.Read.MongoDb.Rules |
|||
{ |
|||
public partial class MongoRuleRepository |
|||
{ |
|||
public string Name |
|||
{ |
|||
get { return GetType().Name; } |
|||
} |
|||
|
|||
public string EventsFilter |
|||
{ |
|||
get { return "^rule-"; } |
|||
} |
|||
|
|||
public Task On(Envelope<IEvent> @event) |
|||
{ |
|||
return this.DispatchActionAsync(@event.Payload, @event.Headers); |
|||
} |
|||
|
|||
protected async Task On(RuleCreated @event, EnvelopeHeaders headers) |
|||
{ |
|||
await EnsureRulesLoadedAsync(); |
|||
|
|||
await Collection.CreateAsync(@event, headers, w => |
|||
{ |
|||
w.Rule = RuleEventDispatcher.Create(@event); |
|||
|
|||
inMemoryRules.GetOrAddNew(w.AppId).RemoveAll(x => x.Id == w.Id); |
|||
inMemoryRules.GetOrAddNew(w.AppId).Add(w); |
|||
}); |
|||
} |
|||
|
|||
protected async Task On(RuleUpdated @event, EnvelopeHeaders headers) |
|||
{ |
|||
await EnsureRulesLoadedAsync(); |
|||
|
|||
await Collection.UpdateAsync(@event, headers, w => |
|||
{ |
|||
w.Rule.Apply(@event); |
|||
|
|||
inMemoryRules.GetOrAddNew(w.AppId).RemoveAll(x => x.Id == w.Id); |
|||
inMemoryRules.GetOrAddNew(w.AppId).Add(w); |
|||
}); |
|||
} |
|||
|
|||
protected async Task On(RuleEnabled @event, EnvelopeHeaders headers) |
|||
{ |
|||
await EnsureRulesLoadedAsync(); |
|||
|
|||
await Collection.UpdateAsync(@event, headers, w => |
|||
{ |
|||
w.Rule.Apply(@event); |
|||
|
|||
inMemoryRules.GetOrAddNew(w.AppId).RemoveAll(x => x.Id == w.Id); |
|||
inMemoryRules.GetOrAddNew(w.AppId).Add(w); |
|||
}); |
|||
} |
|||
|
|||
protected async Task On(RuleDisabled @event, EnvelopeHeaders headers) |
|||
{ |
|||
await EnsureRulesLoadedAsync(); |
|||
|
|||
await Collection.UpdateAsync(@event, headers, w => |
|||
{ |
|||
w.Rule.Apply(@event); |
|||
|
|||
inMemoryRules.GetOrAddNew(w.AppId).RemoveAll(x => x.Id == w.Id); |
|||
inMemoryRules.GetOrAddNew(w.AppId).Add(w); |
|||
}); |
|||
} |
|||
|
|||
protected async Task On(RuleDeleted @event, EnvelopeHeaders headers) |
|||
{ |
|||
await EnsureRulesLoadedAsync(); |
|||
|
|||
inMemoryRules.GetOrAddNew(@event.AppId.Id).RemoveAll(x => x.Id == @event.RuleId); |
|||
|
|||
await Collection.DeleteManyAsync(x => x.Id == @event.RuleId); |
|||
} |
|||
} |
|||
} |
|||
@ -1,73 +0,0 @@ |
|||
// ==========================================================================
|
|||
// MongoSchemaRepository.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using MongoDB.Driver; |
|||
using Squidex.Domain.Apps.Core.Schemas; |
|||
using Squidex.Domain.Apps.Read.Schemas; |
|||
using Squidex.Domain.Apps.Read.Schemas.Repositories; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.MongoDb; |
|||
|
|||
namespace Squidex.Domain.Apps.Read.MongoDb.Schemas |
|||
{ |
|||
public partial class MongoSchemaRepository : MongoRepositoryBase<MongoSchemaEntity>, ISchemaRepository, ISchemaEventConsumer |
|||
{ |
|||
private readonly FieldRegistry registry; |
|||
|
|||
public MongoSchemaRepository(IMongoDatabase database, FieldRegistry registry) |
|||
: base(database) |
|||
{ |
|||
Guard.NotNull(registry, nameof(registry)); |
|||
|
|||
this.registry = registry; |
|||
} |
|||
|
|||
protected override string CollectionName() |
|||
{ |
|||
return "Projections_Schemas"; |
|||
} |
|||
|
|||
protected override Task SetupCollectionAsync(IMongoCollection<MongoSchemaEntity> collection) |
|||
{ |
|||
return Task.WhenAll( |
|||
collection.Indexes.CreateOneAsync(Index.Ascending(x => x.Name)), |
|||
collection.Indexes.CreateOneAsync(Index.Ascending(x => x.AppId).Ascending(x => x.IsDeleted).Ascending(x => x.Name))); |
|||
} |
|||
|
|||
public async Task<IReadOnlyList<ISchemaEntity>> QueryAllAsync(Guid appId) |
|||
{ |
|||
var schemaEntities = |
|||
await Collection.Find(s => s.AppId == appId && !s.IsDeleted) |
|||
.ToListAsync(); |
|||
|
|||
return schemaEntities.OfType<ISchemaEntity>().ToList(); |
|||
} |
|||
|
|||
public async Task<ISchemaEntity> FindSchemaAsync(Guid appId, string name) |
|||
{ |
|||
var schemaEntity = |
|||
await Collection.Find(s => s.AppId == appId && !s.IsDeleted && s.Name == name) |
|||
.FirstOrDefaultAsync(); |
|||
|
|||
return schemaEntity; |
|||
} |
|||
|
|||
public async Task<ISchemaEntity> FindSchemaAsync(Guid schemaId) |
|||
{ |
|||
var schemaEntity = |
|||
await Collection.Find(s => s.Id == schemaId) |
|||
.FirstOrDefaultAsync(); |
|||
|
|||
return schemaEntity; |
|||
} |
|||
} |
|||
} |
|||
@ -1,188 +0,0 @@ |
|||
// ==========================================================================
|
|||
// MongoSchemaRepository_EventHandling.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Squidex.Domain.Apps.Events; |
|||
using Squidex.Domain.Apps.Events.Schemas; |
|||
using Squidex.Domain.Apps.Events.Schemas.Old; |
|||
using Squidex.Domain.Apps.Events.Schemas.Utils; |
|||
using Squidex.Infrastructure.CQRS.Events; |
|||
using Squidex.Infrastructure.Dispatching; |
|||
using Squidex.Infrastructure.Reflection; |
|||
|
|||
#pragma warning disable CS0612 // Type or member is obsolete
|
|||
|
|||
namespace Squidex.Domain.Apps.Read.MongoDb.Schemas |
|||
{ |
|||
public partial class MongoSchemaRepository |
|||
{ |
|||
public string Name |
|||
{ |
|||
get { return GetType().Name; } |
|||
} |
|||
|
|||
public string EventsFilter |
|||
{ |
|||
get { return "^schema-"; } |
|||
} |
|||
|
|||
public Task On(Envelope<IEvent> @event) |
|||
{ |
|||
return this.DispatchActionAsync(@event.Payload, @event.Headers); |
|||
} |
|||
|
|||
protected Task On(SchemaCreated @event, EnvelopeHeaders headers) |
|||
{ |
|||
return Collection.CreateAsync(@event, headers, s => |
|||
{ |
|||
s.SchemaDef = SchemaEventDispatcher.Create(@event, registry); |
|||
|
|||
SimpleMapper.Map(@event, s); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(FieldDeleted @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateSchemaAsync(@event, headers, s => |
|||
{ |
|||
s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(FieldLocked @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateSchemaAsync(@event, headers, s => |
|||
{ |
|||
s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(FieldHidden @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateSchemaAsync(@event, headers, s => |
|||
{ |
|||
s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(FieldShown @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateSchemaAsync(@event, headers, s => |
|||
{ |
|||
s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(FieldDisabled @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateSchemaAsync(@event, headers, s => |
|||
{ |
|||
s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(FieldEnabled @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateSchemaAsync(@event, headers, s => |
|||
{ |
|||
s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(FieldUpdated @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateSchemaAsync(@event, headers, s => |
|||
{ |
|||
s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(SchemaFieldsReordered @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateSchemaAsync(@event, headers, s => |
|||
{ |
|||
s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(SchemaUpdated @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateSchemaAsync(@event, headers, s => |
|||
{ |
|||
s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(SchemaPublished @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateSchemaAsync(@event, headers, s => |
|||
{ |
|||
s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(SchemaUnpublished @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateSchemaAsync(@event, headers, s => |
|||
{ |
|||
s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(FieldAdded @event, EnvelopeHeaders headers) |
|||
{ |
|||
return UpdateSchemaAsync(@event, headers, s => |
|||
{ |
|||
s.SchemaDef.Apply(@event, registry); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(ScriptsConfigured @event, EnvelopeHeaders headers) |
|||
{ |
|||
return Collection.UpdateAsync(@event, headers, s => |
|||
{ |
|||
SimpleMapper.Map(@event, s); |
|||
}); |
|||
} |
|||
|
|||
protected Task On(SchemaDeleted @event, EnvelopeHeaders headers) |
|||
{ |
|||
return Collection.UpdateAsync(@event, headers, s => |
|||
{ |
|||
s.IsDeleted = true; |
|||
}); |
|||
} |
|||
|
|||
protected Task On(WebhookAdded @event, EnvelopeHeaders headers) |
|||
{ |
|||
return Collection.UpdateAsync(@event, headers, s => |
|||
{ |
|||
/* NOOP */ |
|||
}); |
|||
} |
|||
|
|||
protected Task On(WebhookDeleted @event, EnvelopeHeaders headers) |
|||
{ |
|||
return Collection.UpdateAsync(@event, headers, s => |
|||
{ |
|||
/* NOOP */ |
|||
}); |
|||
} |
|||
|
|||
private Task UpdateSchemaAsync(SquidexEvent @event, EnvelopeHeaders headers, Action<MongoSchemaEntity> updater) |
|||
{ |
|||
return Collection.UpdateAsync(@event, headers, s => |
|||
{ |
|||
updater(s); |
|||
|
|||
s.IsPublished = s.SchemaDef.IsPublished; |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -1,22 +1,20 @@ |
|||
// ==========================================================================
|
|||
// AuthenticationExtensions.cs
|
|||
// AppEntityExtensions.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using Microsoft.AspNetCore.Builder; |
|||
using Squidex.Domain.Apps.Core; |
|||
|
|||
namespace Squidex.Config.Identity |
|||
namespace Squidex.Domain.Apps.Read.Apps |
|||
{ |
|||
public static class AuthenticationExtensions |
|||
public static class AppEntityExtensions |
|||
{ |
|||
public static IApplicationBuilder UseMyAuthentication(this IApplicationBuilder app) |
|||
public static PartitionResolver PartitionResolver(this IAppEntity entity) |
|||
{ |
|||
app.UseAuthentication(); |
|||
|
|||
return app; |
|||
return entity.LanguagesConfig.ToResolver(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
// ==========================================================================
|
|||
// IAppRepository.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Squidex.Domain.Apps.Read.Apps.Repositories |
|||
{ |
|||
public interface IAppRepository |
|||
{ |
|||
Task<IReadOnlyList<IAppEntity>> QueryAllAsync(string subjectId); |
|||
|
|||
Task<IAppEntity> FindAppAsync(Guid appId); |
|||
|
|||
Task<IAppEntity> FindAppAsync(string name); |
|||
} |
|||
} |
|||
@ -1,121 +0,0 @@ |
|||
// ==========================================================================
|
|||
// CachingAppProvider.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.Caching.Memory; |
|||
using Squidex.Domain.Apps.Events; |
|||
using Squidex.Domain.Apps.Read.Apps.Repositories; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.Caching; |
|||
using Squidex.Infrastructure.CQRS.Events; |
|||
using Squidex.Infrastructure.Tasks; |
|||
|
|||
namespace Squidex.Domain.Apps.Read.Apps.Services.Implementations |
|||
{ |
|||
public class CachingAppProvider : CachingProviderBase, IAppProvider, IEventConsumer |
|||
{ |
|||
private static readonly TimeSpan CacheDuration = TimeSpan.FromMinutes(30); |
|||
private readonly IAppRepository repository; |
|||
|
|||
public string Name |
|||
{ |
|||
get { return GetType().Name; } |
|||
} |
|||
|
|||
public string EventsFilter |
|||
{ |
|||
get { return string.Empty; } |
|||
} |
|||
|
|||
public CachingAppProvider(IMemoryCache cache, IAppRepository repository) |
|||
: base(cache) |
|||
{ |
|||
Guard.NotNull(cache, nameof(cache)); |
|||
|
|||
this.repository = repository; |
|||
} |
|||
|
|||
public async Task<IAppEntity> FindAppByIdAsync(Guid appId) |
|||
{ |
|||
var cacheKey = BuildIdCacheKey(appId); |
|||
|
|||
if (!Cache.TryGetValue(cacheKey, out IAppEntity result)) |
|||
{ |
|||
result = await repository.FindAppAsync(appId); |
|||
|
|||
Cache.Set(cacheKey, result, CacheDuration); |
|||
|
|||
if (result != null) |
|||
{ |
|||
Cache.Set(BuildNameCacheKey(result.Name), result, CacheDuration); |
|||
} |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
|
|||
public async Task<IAppEntity> FindAppByNameAsync(string name) |
|||
{ |
|||
Guard.NotNullOrEmpty(name, nameof(name)); |
|||
|
|||
var cacheKey = BuildNameCacheKey(name); |
|||
|
|||
if (!Cache.TryGetValue(cacheKey, out IAppEntity result)) |
|||
{ |
|||
result = await repository.FindAppAsync(name); |
|||
|
|||
Cache.Set(cacheKey, result, CacheDuration); |
|||
|
|||
if (result != null) |
|||
{ |
|||
Cache.Set(BuildIdCacheKey(result.Id), result, CacheDuration); |
|||
} |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
|
|||
public Task On(Envelope<IEvent> @event) |
|||
{ |
|||
void Remove(NamedId<Guid> id) |
|||
{ |
|||
var cacheKeyById = BuildIdCacheKey(id.Id); |
|||
var cacheKeyByName = BuildNameCacheKey(id.Name); |
|||
|
|||
Cache.Remove(cacheKeyById); |
|||
Cache.Remove(cacheKeyByName); |
|||
|
|||
Cache.Invalidate(cacheKeyById); |
|||
Cache.Invalidate(cacheKeyByName); |
|||
} |
|||
|
|||
if (@event.Payload is AppEvent appEvent) |
|||
{ |
|||
Remove(appEvent.AppId); |
|||
} |
|||
|
|||
return TaskHelper.Done; |
|||
} |
|||
|
|||
private static string BuildNameCacheKey(string name) |
|||
{ |
|||
return $"App_Ids_{name}"; |
|||
} |
|||
|
|||
private static string BuildIdCacheKey(Guid schemaId) |
|||
{ |
|||
return $"App_Names_{schemaId}"; |
|||
} |
|||
|
|||
public Task ClearAsync() |
|||
{ |
|||
return TaskHelper.Done; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
// ==========================================================================
|
|||
// IApps.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Squidex.Domain.Apps.Read.Apps; |
|||
using Squidex.Domain.Apps.Read.Rules; |
|||
using Squidex.Domain.Apps.Read.Schemas; |
|||
|
|||
namespace Squidex.Domain.Apps.Read |
|||
{ |
|||
public interface IAppProvider |
|||
{ |
|||
Task<(IAppEntity, ISchemaEntity)> GetAppWithSchemaAsync(string appName, Guid id); |
|||
|
|||
Task<IAppEntity> GetAppAsync(string appName); |
|||
|
|||
Task<ISchemaEntity> GetSchemaAsync(string appName, Guid id, bool provideDeleted = false); |
|||
|
|||
Task<ISchemaEntity> GetSchemaAsync(string appName, string name, bool provideDeleted = false); |
|||
|
|||
Task<List<ISchemaEntity>> GetSchemasAsync(string appName); |
|||
|
|||
Task<List<IRuleEntity>> GetRulesAsync(string appName); |
|||
|
|||
Task<List<IAppEntity>> GetUserApps(string userId); |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
// ==========================================================================
|
|||
// IEntityWithAppRef.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
|
|||
namespace Squidex.Domain.Apps.Read |
|||
{ |
|||
public interface IEntityWithAppRef : IEntity |
|||
{ |
|||
Guid AppId { get; } |
|||
} |
|||
} |
|||
@ -1,16 +1,17 @@ |
|||
// ==========================================================================
|
|||
// ISchemaEventConsumer.cs
|
|||
// IUpdateableEntityWithCreatedBy.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using Squidex.Infrastructure.CQRS.Events; |
|||
using Squidex.Infrastructure; |
|||
|
|||
namespace Squidex.Domain.Apps.Read.Schemas |
|||
namespace Squidex.Domain.Apps.Read |
|||
{ |
|||
public interface ISchemaEventConsumer : IEventConsumer |
|||
public interface IUpdateableEntityWithCreatedBy |
|||
{ |
|||
RefToken CreatedBy { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
// ==========================================================================
|
|||
// IUpdateableEntityWithLastModifiedBy.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using Squidex.Infrastructure; |
|||
|
|||
namespace Squidex.Domain.Apps.Read |
|||
{ |
|||
public interface IUpdateableEntityWithLastModifiedBy |
|||
{ |
|||
RefToken LastModifiedBy { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
// ==========================================================================
|
|||
// IUpdateableEntityWithVersion.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
namespace Squidex.Domain.Apps.Read |
|||
{ |
|||
public interface IUpdateableEntityWithVersion |
|||
{ |
|||
long Version { get; set; } |
|||
} |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
// ==========================================================================
|
|||
// ISchemaRepository.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Squidex.Domain.Apps.Read.Schemas.Repositories |
|||
{ |
|||
public interface ISchemaRepository |
|||
{ |
|||
Task<IReadOnlyList<ISchemaEntity>> QueryAllAsync(Guid appId); |
|||
|
|||
Task<ISchemaEntity> FindSchemaAsync(Guid appId, string name); |
|||
|
|||
Task<ISchemaEntity> FindSchemaAsync(Guid schemaId); |
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue