mirror of https://github.com/abpframework/abp.git
16 changed files with 213 additions and 0 deletions
@ -0,0 +1,16 @@ |
|||||
|
using JetBrains.Annotations; |
||||
|
using Volo.Abp.GlobalFeatures; |
||||
|
|
||||
|
namespace Volo.CmsKit.GlobalFeatures; |
||||
|
|
||||
|
[GlobalFeatureName(Name)] |
||||
|
public class GlobalResourcesFeature : GlobalFeature |
||||
|
{ |
||||
|
public const string Name = "CmsKit.GlobalResources"; |
||||
|
|
||||
|
internal GlobalResourcesFeature( |
||||
|
[NotNull] GlobalCmsKitFeatures cmsKit |
||||
|
) : base(cmsKit) |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
namespace Volo.CmsKit.GlobalResources; |
||||
|
|
||||
|
public class GlobalResourceConsts |
||||
|
{ |
||||
|
public const string GlobalStyleName = "GlobalStyle"; |
||||
|
|
||||
|
public const string GlobalScriptName = "GlobalScripit"; |
||||
|
|
||||
|
public static int MaxNameLength { get; set; } = 128; |
||||
|
|
||||
|
public static int MaxValueLength { get; set; } = int.MaxValue; |
||||
|
} |
||||
@ -0,0 +1,40 @@ |
|||||
|
using System; |
||||
|
using JetBrains.Annotations; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Domain.Entities.Auditing; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
|
||||
|
namespace Volo.CmsKit.GlobalResources; |
||||
|
|
||||
|
public class GlobalResource : AuditedAggregateRoot<Guid>, IMultiTenant |
||||
|
{ |
||||
|
public virtual string Name { get; } |
||||
|
|
||||
|
public virtual string Value { get; private set; } |
||||
|
|
||||
|
public virtual Guid? TenantId { get; protected set; } |
||||
|
|
||||
|
|
||||
|
protected GlobalResource() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
internal GlobalResource( |
||||
|
Guid id, |
||||
|
[NotNull] string name, |
||||
|
[CanBeNull] string value, |
||||
|
Guid? tenantId = null) : base(id) |
||||
|
{ |
||||
|
Name = Check.NotNullOrEmpty(name, nameof(name), GlobalResourceConsts.MaxNameLength); |
||||
|
Value = Check.Length(value, nameof(value), GlobalResourceConsts.MaxValueLength); |
||||
|
|
||||
|
TenantId = tenantId; |
||||
|
} |
||||
|
|
||||
|
public virtual void SetValue(string value) |
||||
|
{ |
||||
|
Check.Length(value, nameof(value), GlobalResourceConsts.MaxValueLength); |
||||
|
|
||||
|
Value = value; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,41 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Domain.Services; |
||||
|
|
||||
|
namespace Volo.CmsKit.GlobalResources; |
||||
|
|
||||
|
public class GlobalResourceManager : DomainService |
||||
|
{ |
||||
|
private readonly IGlobalResourceRepository _globalResourceRepository; |
||||
|
|
||||
|
public GlobalResourceManager(IGlobalResourceRepository globalResourceRepository) |
||||
|
{ |
||||
|
_globalResourceRepository = globalResourceRepository; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<GlobalResource> SetGlobalStyleAsync(string value) |
||||
|
{ |
||||
|
return await SetGlobalResourceAsync(GlobalResourceConsts.GlobalStyleName, value); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<GlobalResource> SetGlobalScriptAsync(string value) |
||||
|
{ |
||||
|
return await SetGlobalResourceAsync(GlobalResourceConsts.GlobalScriptName, value); |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task<GlobalResource> SetGlobalResourceAsync(string name, string value) |
||||
|
{ |
||||
|
var resource = await _globalResourceRepository.FindByName(name); |
||||
|
|
||||
|
if (resource == null) |
||||
|
{ |
||||
|
return await _globalResourceRepository.InsertAsync( |
||||
|
new GlobalResource(GuidGenerator.Create(), name, value, CurrentTenant.Id) |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
resource.SetValue(value); |
||||
|
|
||||
|
return await _globalResourceRepository.UpdateAsync(resource); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
using System; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using JetBrains.Annotations; |
||||
|
using Volo.Abp.Domain.Repositories; |
||||
|
|
||||
|
namespace Volo.CmsKit.GlobalResources; |
||||
|
|
||||
|
public interface IGlobalResourceRepository: IBasicRepository<GlobalResource, Guid> |
||||
|
{ |
||||
|
Task<GlobalResource> FindByName([NotNull] string name, CancellationToken cancellationToken = default); |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
using System; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
using Volo.CmsKit.EntityFrameworkCore; |
||||
|
|
||||
|
namespace Volo.CmsKit.GlobalResources; |
||||
|
|
||||
|
public class EfCoreGlobalResourceRepository: EfCoreRepository<ICmsKitDbContext, GlobalResource, Guid>, IGlobalResourceRepository |
||||
|
{ |
||||
|
public EfCoreGlobalResourceRepository(IDbContextProvider<ICmsKitDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public Task<GlobalResource> FindByName(string name, |
||||
|
CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
Check.NotNullOrEmpty(name, nameof(name)); |
||||
|
return FindAsync(x => x.Name == name, cancellationToken: GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
using System; |
||||
|
using System.Linq; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using MongoDB.Driver; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Domain.Repositories.MongoDB; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.CmsKit.GlobalResources; |
||||
|
|
||||
|
namespace Volo.CmsKit.MongoDB.GlobalResources; |
||||
|
|
||||
|
public class MongoGlobalResourceRepository: MongoDbRepository<ICmsKitMongoDbContext, GlobalResource, Guid>, IGlobalResourceRepository |
||||
|
{ |
||||
|
public MongoGlobalResourceRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public Task<GlobalResource> FindByName(string name, |
||||
|
CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
Check.NotNullOrEmpty(name, nameof(name)); |
||||
|
return FindAsync(x => x.Name == name, cancellationToken: GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue