Merge branch 'develop' into feature/desktop-view
# Conflicts: # products/ASC.Files/Client/src/components/pages/Home/Section/Body/FilesRowContent.js # web/ASC.Web.Common/src/components/NavMenu/index.js # web/ASC.Web.Common/src/pages/login/index.js # web/ASC.Web.Common/src/store/auth/actions.js
This commit is contained in:
commit
813c9c4b1d
@ -17,6 +17,7 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Api.Core.Auth
|
||||
{
|
||||
[Scope(Additional = typeof(ConfirmAuthHandlerExtension))]
|
||||
public class ConfirmAuthHandler : AuthenticationHandler<AuthenticationSchemeOptions>
|
||||
{
|
||||
public ConfirmAuthHandler(IOptionsMonitor<AuthenticationSchemeOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock)
|
||||
@ -96,12 +97,11 @@ namespace ASC.Api.Core.Auth
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConfirmAuthHandlerExtension
|
||||
public class ConfirmAuthHandlerExtension
|
||||
{
|
||||
public static DIHelper AddConfirmAuthHandler(this DIHelper services)
|
||||
public static void Register(DIHelper services)
|
||||
{
|
||||
return services
|
||||
.AddSecurityContextService();
|
||||
services.TryAdd<EmailValidationKeyModelHelper>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ using System.Security.Authentication;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Core;
|
||||
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
@ -38,12 +37,4 @@ namespace ASC.Api.Core.Auth
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static class CookieAuthHandlerExtension
|
||||
{
|
||||
public static DIHelper AddCookieAuthHandler(this DIHelper services)
|
||||
{
|
||||
return services.AddSecurityContextService();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace ASC.Api.Core
|
||||
{
|
||||
[Scope]
|
||||
public class ApiContext : ICloneable
|
||||
{
|
||||
public IHttpContextAccessor HttpContextAccessor { get; set; }
|
||||
@ -268,19 +269,4 @@ namespace ASC.Api.Core
|
||||
return context?.Fields == null || (context.Fields != null && context.Fields.Contains(field, StringComparer.InvariantCultureIgnoreCase));
|
||||
}
|
||||
}
|
||||
|
||||
public static class ApiContextConfigExtension
|
||||
{
|
||||
public static DIHelper AddApiContextService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<ApiContext>())
|
||||
{
|
||||
services
|
||||
.AddTenantManagerService()
|
||||
.AddSecurityContextService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -348,6 +348,7 @@ namespace ASC.Api.Core
|
||||
}
|
||||
}
|
||||
|
||||
[Scope]
|
||||
public class ApiDateTimeHelper
|
||||
{
|
||||
private TenantManager TenantManager { get; }
|
||||
@ -364,18 +365,4 @@ namespace ASC.Api.Core
|
||||
return ApiDateTime.FromDate(TenantManager, TimeZoneConverter, from);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ApiDateTimeHelperExtension
|
||||
{
|
||||
public static DIHelper AddApiDateTimeHelper(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<ApiDateTimeHelper>())
|
||||
{
|
||||
return services
|
||||
.AddTenantManagerService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ using ASC.Api.Core.Auth;
|
||||
using ASC.Api.Core.Core;
|
||||
using ASC.Api.Core.Middleware;
|
||||
using ASC.Common;
|
||||
using ASC.Common.Caching;
|
||||
using ASC.Common.Logging;
|
||||
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
@ -63,12 +64,15 @@ namespace ASC.Api.Core
|
||||
});
|
||||
}
|
||||
|
||||
DIHelper
|
||||
.AddCultureMiddleware()
|
||||
.AddIpSecurityFilter()
|
||||
.AddPaymentFilter()
|
||||
.AddProductSecurityFilter()
|
||||
.AddTenantStatusFilter();
|
||||
DIHelper.TryAdd<DisposeMiddleware>();
|
||||
DIHelper.TryAdd<CultureMiddleware>();
|
||||
DIHelper.TryAdd<IpSecurityFilter>();
|
||||
DIHelper.TryAdd<PaymentFilter>();
|
||||
DIHelper.TryAdd<ProductSecurityFilter>();
|
||||
DIHelper.TryAdd<TenantStatusFilter>();
|
||||
DIHelper.TryAdd<ConfirmAuthHandler>();
|
||||
|
||||
DIHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>));
|
||||
|
||||
var builder = services.AddMvcCore(config =>
|
||||
{
|
||||
@ -86,7 +90,7 @@ namespace ASC.Api.Core
|
||||
config.OutputFormatters.Add(new XmlOutputFormatter());
|
||||
});
|
||||
|
||||
DIHelper.AddCookieAuthHandler();
|
||||
|
||||
var authBuilder = services.AddAuthentication("cookie")
|
||||
.AddScheme<AuthenticationSchemeOptions, CookieAuthHandler>("cookie", a => { });
|
||||
|
||||
@ -97,7 +101,7 @@ namespace ASC.Api.Core
|
||||
|
||||
if (LogParams != null)
|
||||
{
|
||||
DIHelper.AddNLogManager(LogParams);
|
||||
LogNLogExtension.ConfigureLog(DIHelper, LogParams);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Core;
|
||||
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
@ -51,13 +50,5 @@ namespace ASC.Api.Core.Middleware
|
||||
{
|
||||
return builder.UseMiddleware<CultureMiddleware>();
|
||||
}
|
||||
|
||||
public static DIHelper AddCultureMiddleware(this DIHelper services)
|
||||
{
|
||||
return services
|
||||
.AddUserManagerService()
|
||||
.AddTenantManagerService()
|
||||
.AddAuthContextService();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
using ASC.Common;
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Core;
|
||||
using ASC.Core.Common.Settings;
|
||||
using ASC.IPSecurity;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@ -12,6 +11,7 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Api.Core.Middleware
|
||||
{
|
||||
[Scope]
|
||||
public class IpSecurityFilter : IResourceFilter
|
||||
{
|
||||
private readonly ILog log;
|
||||
@ -44,15 +44,4 @@ namespace ASC.Api.Core.Middleware
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class IpSecurityFilterExtension
|
||||
{
|
||||
public static DIHelper AddIpSecurityFilter(this DIHelper services)
|
||||
{
|
||||
return services
|
||||
.AddSettingsManagerService()
|
||||
.AddAuthContextService()
|
||||
.AddIPSecurityService();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Api.Core.Middleware
|
||||
{
|
||||
[Scope]
|
||||
public class PaymentFilter : IResourceFilter
|
||||
{
|
||||
private readonly ILog log;
|
||||
@ -49,13 +50,4 @@ namespace ASC.Api.Core.Middleware
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class PaymentFilterExtension
|
||||
{
|
||||
public static DIHelper AddPaymentFilter(this DIHelper services)
|
||||
{
|
||||
return services
|
||||
.AddTenantExtraService();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Api.Core.Middleware
|
||||
{
|
||||
[Scope]
|
||||
public class ProductSecurityFilter : IResourceFilter
|
||||
{
|
||||
private static readonly IDictionary<string, Guid> products;
|
||||
@ -116,14 +117,4 @@ namespace ASC.Api.Core.Middleware
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ProductSecurityFilterExtension
|
||||
{
|
||||
public static DIHelper AddProductSecurityFilter(this DIHelper services)
|
||||
{
|
||||
return services
|
||||
.AddWebItemSecurity()
|
||||
.AddAuthContextService();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Api.Core.Middleware
|
||||
{
|
||||
[Scope]
|
||||
public class TenantStatusFilter : IResourceFilter
|
||||
{
|
||||
private readonly ILog log;
|
||||
@ -45,13 +46,4 @@ namespace ASC.Api.Core.Middleware
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class TenantStatusFilterExtension
|
||||
{
|
||||
public static DIHelper AddTenantStatusFilter(this DIHelper services)
|
||||
{
|
||||
return services
|
||||
.AddTenantManagerService();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ namespace ASC.Web.Api.Models
|
||||
}
|
||||
}
|
||||
|
||||
[Scope]
|
||||
public class EmployeeWraperHelper
|
||||
{
|
||||
private ApiContext HttpContext { get; }
|
||||
@ -124,21 +125,4 @@ namespace ASC.Web.Api.Models
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EmployeeWraperExtension
|
||||
{
|
||||
public static DIHelper AddEmployeeWraper(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<EmployeeWraperHelper>())
|
||||
{
|
||||
return services
|
||||
.AddApiContextService()
|
||||
.AddDisplayUserSettingsService()
|
||||
.AddUserPhotoManagerService()
|
||||
.AddCommonLinkUtilityService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -131,6 +131,7 @@ namespace ASC.Web.Api.Models
|
||||
}
|
||||
}
|
||||
|
||||
[Scope]
|
||||
public class EmployeeWraperFullHelper : EmployeeWraperHelper
|
||||
{
|
||||
private ApiContext Context { get; }
|
||||
@ -288,22 +289,4 @@ namespace ASC.Web.Api.Models
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class EmployeeWraperFullExtension
|
||||
{
|
||||
public static DIHelper AddEmployeeWraperFull(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<EmployeeWraperFullHelper>())
|
||||
{
|
||||
return services
|
||||
.AddTenantManagerService()
|
||||
.AddWebItemSecurity()
|
||||
.AddUserManagerService()
|
||||
.AddEmployeeWraper()
|
||||
.AddApiDateTimeHelper();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -45,10 +45,12 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="3.1.9" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.9" />
|
||||
<PackageReference Include="Microsoft.Windows.Compatibility" Version="3.1.1" />
|
||||
<!-- <PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="2.9.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
@ -59,7 +61,6 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference> -->
|
||||
<PackageReference Include="MySql.Data" Version="8.0.21" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="NLog" Version="4.7.5" />
|
||||
<PackageReference Include="NLog.Web.AspNetCore" Version="4.9.3" />
|
||||
<PackageReference Include="NUnit" Version="3.12.0" />
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
using System.Runtime.Caching;
|
||||
using System.Text.RegularExpressions;
|
||||
@ -34,6 +34,7 @@ using Google.Protobuf;
|
||||
|
||||
namespace ASC.Common.Caching
|
||||
{
|
||||
[Singletone]
|
||||
public class AscCacheNotify
|
||||
{
|
||||
private ICacheNotify<AscCacheItem> CacheNotify { get; }
|
||||
@ -113,17 +114,17 @@ namespace ASC.Common.Caching
|
||||
}
|
||||
|
||||
|
||||
public IDictionary<string, T> HashGetAll<T>(string key)
|
||||
public ConcurrentDictionary<string, T> HashGetAll<T>(string key)
|
||||
{
|
||||
var cache = GetCache();
|
||||
var dic = (IDictionary<string, T>)cache.Get(key);
|
||||
return dic != null ? new Dictionary<string, T>(dic) : new Dictionary<string, T>();
|
||||
var dic = (ConcurrentDictionary<string, T>)cache.Get(key);
|
||||
return dic != null ? dic : new ConcurrentDictionary<string, T>();
|
||||
}
|
||||
|
||||
public T HashGet<T>(string key, string field)
|
||||
{
|
||||
var cache = GetCache();
|
||||
var dic = (IDictionary<string, T>)cache.Get(key);
|
||||
var dic = (ConcurrentDictionary<string, T>)cache.Get(key);
|
||||
if (dic != null && dic.TryGetValue(field, out var value))
|
||||
{
|
||||
return value;
|
||||
@ -134,19 +135,15 @@ namespace ASC.Common.Caching
|
||||
public void HashSet<T>(string key, string field, T value)
|
||||
{
|
||||
var cache = GetCache();
|
||||
var dic = (IDictionary<string, T>)cache.Get(key);
|
||||
var dic = HashGetAll<T>(key);
|
||||
if (value != null)
|
||||
{
|
||||
if (dic == null)
|
||||
{
|
||||
dic = new Dictionary<string, T>();
|
||||
}
|
||||
dic[field] = value;
|
||||
{
|
||||
dic.AddOrUpdate(field, value, (k, v) => value);
|
||||
cache.Set(key, dic, null);
|
||||
}
|
||||
else if (dic != null)
|
||||
{
|
||||
dic.Remove(field);
|
||||
dic.TryRemove(field, out _);
|
||||
if (dic.Count == 0)
|
||||
{
|
||||
cache.Remove(key);
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace ASC.Common.Caching
|
||||
@ -43,7 +43,7 @@ namespace ASC.Common.Caching
|
||||
void Remove(Regex pattern);
|
||||
|
||||
|
||||
IDictionary<string, T> HashGetAll<T>(string key);
|
||||
ConcurrentDictionary<string, T> HashGetAll<T>(string key);
|
||||
|
||||
T HashGet<T>(string key, string field);
|
||||
|
||||
|
@ -30,6 +30,7 @@ using Google.Protobuf;
|
||||
|
||||
namespace ASC.Common.Caching
|
||||
{
|
||||
[Singletone]
|
||||
public interface ICacheNotify<T> where T : IMessage<T>, new()
|
||||
{
|
||||
void Publish(T obj, CacheNotifyAction action);
|
||||
|
@ -11,11 +11,11 @@ using Confluent.Kafka;
|
||||
|
||||
using Google.Protobuf;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Common.Caching
|
||||
{
|
||||
[Singletone]
|
||||
public class KafkaCache<T> : IDisposable, ICacheNotify<T> where T : IMessage<T>, new()
|
||||
{
|
||||
private ClientConfig ClientConfig { get; set; }
|
||||
@ -31,7 +31,7 @@ namespace ASC.Common.Caching
|
||||
private IProducer<AscCacheItem, T> Producer { get; set; }
|
||||
private Guid Key { get; set; }
|
||||
|
||||
public KafkaCache(IConfiguration configuration, IOptionsMonitor<ILog> options)
|
||||
public KafkaCache(ConfigurationExtension configuration, IOptionsMonitor<ILog> options)
|
||||
{
|
||||
Log = options.CurrentValue;
|
||||
Cts = new ConcurrentDictionary<string, CancellationTokenSource>();
|
||||
@ -238,14 +238,4 @@ namespace ASC.Common.Caching
|
||||
return $"{typeof(T).Name}{cacheNotifyAction}";
|
||||
}
|
||||
}
|
||||
|
||||
public static class KafkaExtention
|
||||
{
|
||||
public static DIHelper AddKafkaService(this DIHelper services)
|
||||
{
|
||||
services.TryAddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>));
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,27 +1,134 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
using ASC.Common.Threading.Progress;
|
||||
using ASC.Common.Threading.Workers;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Common
|
||||
{
|
||||
public enum DIAttributeEnum
|
||||
{
|
||||
Singletone,
|
||||
Scope,
|
||||
Transient
|
||||
}
|
||||
|
||||
public class TransientAttribute : DIAttribute
|
||||
{
|
||||
public override DIAttributeEnum DIAttributeEnum { get => DIAttributeEnum.Transient; }
|
||||
|
||||
public TransientAttribute() { }
|
||||
|
||||
public TransientAttribute(Type service) : base(service) { }
|
||||
|
||||
public TransientAttribute(Type service, Type implementation) : base(service, implementation) { }
|
||||
|
||||
public override void TryAdd(IServiceCollection services, Type service, Type implementation = null)
|
||||
{
|
||||
if (implementation != null)
|
||||
{
|
||||
services.AddTransient(service, implementation);
|
||||
}
|
||||
else
|
||||
{
|
||||
services.AddTransient(service);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ScopeAttribute : DIAttribute
|
||||
{
|
||||
public override DIAttributeEnum DIAttributeEnum { get => DIAttributeEnum.Scope; }
|
||||
|
||||
public ScopeAttribute() { }
|
||||
|
||||
public ScopeAttribute(Type service) : base(service) { }
|
||||
|
||||
public ScopeAttribute(Type service, Type implementation) : base(service, implementation) { }
|
||||
|
||||
public override void TryAdd(IServiceCollection services, Type service, Type implementation = null)
|
||||
{
|
||||
if (implementation != null)
|
||||
{
|
||||
services.AddScoped(service, implementation);
|
||||
}
|
||||
else
|
||||
{
|
||||
services.AddScoped(service);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SingletoneAttribute : DIAttribute
|
||||
{
|
||||
public override DIAttributeEnum DIAttributeEnum { get => DIAttributeEnum.Singletone; }
|
||||
|
||||
public SingletoneAttribute() { }
|
||||
|
||||
public SingletoneAttribute(Type service) : base(service) { }
|
||||
|
||||
public SingletoneAttribute(Type service, Type implementation) : base(service, implementation) { }
|
||||
|
||||
public override void TryAdd(IServiceCollection services, Type service, Type implementation = null)
|
||||
{
|
||||
if (implementation != null)
|
||||
{
|
||||
services.AddSingleton(service, implementation);
|
||||
}
|
||||
else
|
||||
{
|
||||
services.AddSingleton(service);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class DIAttribute : Attribute
|
||||
{
|
||||
public abstract DIAttributeEnum DIAttributeEnum { get; }
|
||||
public Type Implementation { get; }
|
||||
public Type Service { get; }
|
||||
public Type Additional { get; set; }
|
||||
|
||||
public DIAttribute() { }
|
||||
|
||||
public DIAttribute(Type service)
|
||||
{
|
||||
Service = service;
|
||||
}
|
||||
|
||||
public DIAttribute(Type service, Type implementation)
|
||||
{
|
||||
Implementation = implementation;
|
||||
Service = service;
|
||||
}
|
||||
|
||||
public abstract void TryAdd(IServiceCollection services, Type service, Type implementation = null);
|
||||
}
|
||||
|
||||
public class DIHelper
|
||||
{
|
||||
public List<string> Singleton { get; set; }
|
||||
public List<string> Scoped { get; set; }
|
||||
public List<string> Transient { get; set; }
|
||||
public Dictionary<DIAttributeEnum, List<string>> Services { get; set; }
|
||||
public List<string> Added { get; set; }
|
||||
public List<string> Configured { get; set; }
|
||||
public IServiceCollection ServiceCollection { get; private set; }
|
||||
|
||||
public DIHelper()
|
||||
{
|
||||
Singleton = new List<string>();
|
||||
Scoped = new List<string>();
|
||||
Transient = new List<string>();
|
||||
Services = new Dictionary<DIAttributeEnum, List<string>>()
|
||||
{
|
||||
{ DIAttributeEnum.Singletone, new List<string>() },
|
||||
{ DIAttributeEnum.Scope, new List<string>() },
|
||||
{ DIAttributeEnum.Transient, new List<string>() }
|
||||
};
|
||||
Added = new List<string>();
|
||||
Configured = new List<string>();
|
||||
}
|
||||
|
||||
@ -35,129 +142,242 @@ namespace ASC.Common
|
||||
ServiceCollection = serviceCollection;
|
||||
}
|
||||
|
||||
public bool TryAddScoped<TService>() where TService : class
|
||||
public bool TryAdd<TService>() where TService : class
|
||||
{
|
||||
var serviceName = $"{typeof(TService)}";
|
||||
if (!Scoped.Contains(serviceName))
|
||||
{
|
||||
Scoped.Add(serviceName);
|
||||
ServiceCollection.TryAddScoped<TService>();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return TryAdd(typeof(TService));
|
||||
}
|
||||
|
||||
public bool TryAddScoped<TService, TImplementation>() where TService : class where TImplementation : class, TService
|
||||
public bool TryAdd<TService, TImplementation>() where TService : class
|
||||
{
|
||||
var serviceName = $"{typeof(TService)}{typeof(TImplementation)}";
|
||||
if (!Scoped.Contains(serviceName))
|
||||
return TryAdd(typeof(TService), typeof(TImplementation));
|
||||
}
|
||||
|
||||
public bool TryAdd(Type service, Type implementation = null)
|
||||
{
|
||||
if (service.IsInterface && service.IsGenericType && implementation == null &&
|
||||
(service.GetGenericTypeDefinition() == typeof(IOptionsSnapshot<>) ||
|
||||
service.GetGenericTypeDefinition() == typeof(IOptions<>) ||
|
||||
service.GetGenericTypeDefinition() == typeof(IOptionsMonitor<>)
|
||||
))
|
||||
{
|
||||
Scoped.Add(serviceName);
|
||||
ServiceCollection.TryAddScoped<TService, TImplementation>();
|
||||
service = service.GetGenericArguments().FirstOrDefault();
|
||||
if (service == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var serviceName = $"{service}{implementation}";
|
||||
if (Added.Contains(serviceName)) return false;
|
||||
Added.Add(serviceName);
|
||||
|
||||
var di = service.IsGenericType && (
|
||||
service.GetGenericTypeDefinition() == typeof(IConfigureOptions<>) ||
|
||||
service.GetGenericTypeDefinition() == typeof(IPostConfigureOptions<>) ||
|
||||
service.GetGenericTypeDefinition() == typeof(IOptionsMonitor<>)
|
||||
) && implementation != null ? implementation.GetCustomAttribute<DIAttribute>() : service.GetCustomAttribute<DIAttribute>();
|
||||
var isnew = false;
|
||||
|
||||
if (di != null)
|
||||
{
|
||||
if (di.Additional != null)
|
||||
{
|
||||
var m = di.Additional.GetMethod("Register", BindingFlags.Public | BindingFlags.Static);
|
||||
m.Invoke(null, new[] { this });
|
||||
}
|
||||
|
||||
if (!service.IsInterface || implementation != null)
|
||||
{
|
||||
isnew = implementation != null ? Register(service, implementation) : Register(service);
|
||||
if (!isnew) return false;
|
||||
}
|
||||
|
||||
if (service.IsInterface && implementation == null || !service.IsInterface)
|
||||
{
|
||||
if (di.Service != null)
|
||||
{
|
||||
var a = di.Service.GetInterfaces().FirstOrDefault(x => x.IsGenericType && (
|
||||
x.GetGenericTypeDefinition() == typeof(IConfigureOptions<>) ||
|
||||
x.GetGenericTypeDefinition() == typeof(IPostConfigureOptions<>) ||
|
||||
x.GetGenericTypeDefinition() == typeof(IOptionsMonitor<>)
|
||||
));
|
||||
if (a != null)
|
||||
{
|
||||
if (!a.ContainsGenericParameters)
|
||||
{
|
||||
var b = a.GetGenericArguments();
|
||||
|
||||
foreach (var g in b)
|
||||
{
|
||||
if (g != service)
|
||||
{
|
||||
TryAdd(g);
|
||||
if (service.IsInterface && di.Implementation == null)
|
||||
{
|
||||
TryAdd(service, g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TryAdd(a, di.Service);
|
||||
}
|
||||
else
|
||||
{
|
||||
Type c = null;
|
||||
var a1 = a.GetGenericTypeDefinition();
|
||||
var b = a.GetGenericArguments().FirstOrDefault();
|
||||
|
||||
if (b != null && b.IsGenericType)
|
||||
{
|
||||
var b1 = b.GetGenericTypeDefinition().MakeGenericType(service.GetGenericArguments());
|
||||
|
||||
TryAdd(b1);
|
||||
c = a1.MakeGenericType(b1);
|
||||
}
|
||||
else
|
||||
{
|
||||
c = a1.MakeGenericType(service.GetGenericArguments());
|
||||
}
|
||||
|
||||
TryAdd(c, di.Service.MakeGenericType(service.GetGenericArguments()));
|
||||
//a, di.Service
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (di.Implementation == null)
|
||||
{
|
||||
isnew = Register(service, di.Service);
|
||||
TryAdd(di.Service);
|
||||
}
|
||||
else
|
||||
{
|
||||
Register(di.Service);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (di.Implementation != null)
|
||||
{
|
||||
var a = di.Implementation.GetInterfaces().FirstOrDefault(x => x.IsGenericType &&
|
||||
(x.GetGenericTypeDefinition() == typeof(IConfigureOptions<>) ||
|
||||
x.GetGenericTypeDefinition() == typeof(IPostConfigureOptions<>) ||
|
||||
x.GetGenericTypeDefinition() == typeof(IOptionsMonitor<>))
|
||||
);
|
||||
if (a != null)
|
||||
{
|
||||
if (!a.ContainsGenericParameters)
|
||||
{
|
||||
var b = a.GetGenericArguments();
|
||||
|
||||
foreach (var g in b)
|
||||
{
|
||||
if (g != service)
|
||||
{
|
||||
//TryAdd(g);
|
||||
if (service.IsInterface && implementation == null)
|
||||
{
|
||||
TryAdd(service, g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TryAdd(a, di.Implementation);
|
||||
}
|
||||
else
|
||||
{
|
||||
Type c = null;
|
||||
var a1 = a.GetGenericTypeDefinition();
|
||||
var b = a.GetGenericArguments().FirstOrDefault();
|
||||
|
||||
if (b != null && b.IsGenericType)
|
||||
{
|
||||
var b1 = b.GetGenericTypeDefinition().MakeGenericType(service.GetGenericArguments());
|
||||
|
||||
TryAdd(b1);
|
||||
c = a1.MakeGenericType(b1);
|
||||
}
|
||||
else
|
||||
{
|
||||
c = a1.MakeGenericType(service.GetGenericArguments());
|
||||
}
|
||||
|
||||
TryAdd(c, di.Implementation.MakeGenericType(service.GetGenericArguments()));
|
||||
//a, di.Service
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
isnew = TryAdd(service, di.Implementation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isnew)
|
||||
{
|
||||
ConstructorInfo[] props = null;
|
||||
|
||||
if (!service.IsInterface)
|
||||
{
|
||||
props = service.GetConstructors();
|
||||
}
|
||||
else if (implementation != null)
|
||||
{
|
||||
props = implementation.GetConstructors();
|
||||
}
|
||||
else if (di.Service != null)
|
||||
{
|
||||
props = di.Service.GetConstructors();
|
||||
}
|
||||
|
||||
if (props != null)
|
||||
{
|
||||
var par = props.SelectMany(r => r.GetParameters()).Distinct();
|
||||
foreach (var p1 in par)
|
||||
{
|
||||
TryAdd(p1.ParameterType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return isnew;
|
||||
}
|
||||
|
||||
private bool Register(Type service, Type implementation = null)
|
||||
{
|
||||
if (service.IsSubclassOf(typeof(ControllerBase))|| service.GetInterfaces().Contains(typeof(IResourceFilter)) || service.GetInterfaces().Contains(typeof(IDictionary<string, string>))) return true;
|
||||
var c = service.IsGenericType && (
|
||||
service.GetGenericTypeDefinition() == typeof(IConfigureOptions<>) ||
|
||||
service.GetGenericTypeDefinition() == typeof(IPostConfigureOptions<>) ||
|
||||
service.GetGenericTypeDefinition() == typeof(IOptionsMonitor<>)
|
||||
) && implementation != null ? implementation.GetCustomAttribute<DIAttribute>() : service.GetCustomAttribute<DIAttribute>();
|
||||
var serviceName = $"{service}{implementation}";
|
||||
|
||||
if (!Services[c.DIAttributeEnum].Contains(serviceName))
|
||||
{
|
||||
c.TryAdd(ServiceCollection, service, implementation);
|
||||
Services[c.DIAttributeEnum].Add(serviceName);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryAddScoped<TService, TImplementation>(TService tservice, TImplementation tImplementation) where TService : Type where TImplementation : Type
|
||||
{
|
||||
var serviceName = $"{tservice}{tImplementation}";
|
||||
if (!Scoped.Contains(serviceName))
|
||||
{
|
||||
Scoped.Add(serviceName);
|
||||
ServiceCollection.TryAddScoped(tservice, tImplementation);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public DIHelper TryAddSingleton<TService>() where TService : class
|
||||
{
|
||||
var serviceName = $"{typeof(TService)}";
|
||||
if (!Singleton.Contains(serviceName))
|
||||
{
|
||||
Singleton.Add(serviceName);
|
||||
ServiceCollection.TryAddSingleton<TService>();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public DIHelper TryAddSingleton<TService>(Func<IServiceProvider, TService> implementationFactory) where TService : class
|
||||
{
|
||||
var serviceName = $"{typeof(TService)}";
|
||||
if (!Singleton.Contains(serviceName))
|
||||
if (!Services[DIAttributeEnum.Singletone].Contains(serviceName))
|
||||
{
|
||||
Singleton.Add(serviceName);
|
||||
Services[DIAttributeEnum.Singletone].Add(serviceName);
|
||||
ServiceCollection.TryAddSingleton(implementationFactory);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public DIHelper TryAddSingleton<TService>(TService t) where TService : class
|
||||
{
|
||||
var serviceName = $"{typeof(TService)}";
|
||||
if (!Singleton.Contains(serviceName))
|
||||
{
|
||||
Singleton.Add(serviceName);
|
||||
ServiceCollection.TryAddSingleton(t);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public DIHelper TryAddSingleton<TService, TImplementation>() where TService : class where TImplementation : class, TService
|
||||
{
|
||||
var serviceName = $"{typeof(TService)}{typeof(TImplementation)}";
|
||||
if (!Singleton.Contains(serviceName))
|
||||
{
|
||||
Singleton.Add(serviceName);
|
||||
ServiceCollection.TryAddSingleton<TService, TImplementation>();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public DIHelper AddSingleton<TService, TImplementation>() where TService : class where TImplementation : class, TService
|
||||
{
|
||||
var serviceName = $"{typeof(TService)}{typeof(TImplementation)}";
|
||||
if (!Singleton.Contains(serviceName))
|
||||
{
|
||||
Singleton.Add(serviceName);
|
||||
ServiceCollection.AddSingleton<TService, TImplementation>();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public DIHelper TryAddSingleton<TService, TImplementation>(TService tservice, TImplementation tImplementation) where TService : Type where TImplementation : Type
|
||||
{
|
||||
var serviceName = $"{tservice}{tImplementation}";
|
||||
if (!Singleton.Contains(serviceName))
|
||||
{
|
||||
Singleton.Add(serviceName);
|
||||
ServiceCollection.TryAddSingleton(tservice, tImplementation);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public DIHelper TryAddTransient<TService>() where TService : class
|
||||
{
|
||||
var serviceName = $"{typeof(TService)}";
|
||||
if (!Transient.Contains(serviceName))
|
||||
{
|
||||
Transient.Add(serviceName);
|
||||
ServiceCollection.TryAddTransient<TService>();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public DIHelper Configure<TOptions>(Action<TOptions> configureOptions) where TOptions : class
|
||||
{
|
||||
var serviceName = $"{typeof(TOptions)}";
|
||||
@ -191,6 +411,7 @@ namespace ASC.Common
|
||||
AddToConfigured($"{typeof(WorkerQueue<T1>)}", (Action<WorkerQueue<T1>>)action);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DIHelper AddProgressQueue<T1>(int workerCount, int waitInterval, bool removeAfterCompleted, bool stopAfterFinsih, int errorCount) where T1 : class, IProgressItem
|
||||
{
|
||||
void action(ProgressQueue<T1> a)
|
||||
@ -204,6 +425,7 @@ namespace ASC.Common
|
||||
AddToConfigured($"{typeof(ProgressQueue<T1>)}", (Action<ProgressQueue<T1>>)action);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DIHelper Configure<TOptions>(string name, Action<TOptions> configureOptions) where TOptions : class
|
||||
{
|
||||
var serviceName = $"{typeof(TOptions)}{name}";
|
||||
|
@ -6,6 +6,7 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Common.Logging
|
||||
{
|
||||
[Scope]
|
||||
public class EFLoggerFactory : ILoggerFactory
|
||||
{
|
||||
Dictionary<string, ILogger> Loggers { get; set; }
|
||||
@ -34,6 +35,7 @@ namespace ASC.Common.Logging
|
||||
}
|
||||
}
|
||||
|
||||
[Scope]
|
||||
public class EFLoggerProvider : ILoggerProvider
|
||||
{
|
||||
private IOptionsMonitor<ILog> Option { get; }
|
||||
@ -122,17 +124,4 @@ namespace ASC.Common.Logging
|
||||
string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static class LoggerExtension
|
||||
{
|
||||
public static DIHelper AddLoggerService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<EFLoggerFactory>())
|
||||
{
|
||||
services.TryAddScoped<EFLoggerProvider>();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,8 @@ using Microsoft.Extensions.Options;
|
||||
using NLog;
|
||||
|
||||
namespace ASC.Common.Logging
|
||||
{
|
||||
{
|
||||
[Singletone(typeof(ConfigureLogNLog), Additional = typeof(LogNLogExtension))]
|
||||
public interface ILog
|
||||
{
|
||||
bool IsDebugEnabled { get; }
|
||||
@ -371,22 +372,25 @@ namespace ASC.Common.Logging
|
||||
public string Name { get; set; }
|
||||
public string Dir { get; set; }
|
||||
}
|
||||
|
||||
|
||||
[Singletone]
|
||||
public class ConfigureLogNLog : IConfigureNamedOptions<LogNLog>
|
||||
{
|
||||
public ConfigureLogNLog(IConfiguration configuration)
|
||||
{
|
||||
private IConfiguration Configuration { get; }
|
||||
private ConfigurationExtension ConfigurationExtension { get; }
|
||||
|
||||
public ConfigureLogNLog(IConfiguration configuration, ConfigurationExtension configurationExtension)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
private IConfiguration Configuration { get; }
|
||||
|
||||
Configuration = configuration;
|
||||
ConfigurationExtension = configurationExtension;
|
||||
}
|
||||
|
||||
public void Configure(LogNLog options)
|
||||
{
|
||||
LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(Path.Combine(Configuration["pathToConf"], "nlog.config"));
|
||||
LogManager.ThrowConfigExceptions = false;
|
||||
|
||||
var settings = Configuration.GetSetting<NLogSettings>("log");
|
||||
var settings = ConfigurationExtension.GetSetting<NLogSettings>("log");
|
||||
if (!string.IsNullOrEmpty(settings.Name))
|
||||
{
|
||||
LogManager.Configuration.Variables["name"] = settings.Name;
|
||||
@ -851,7 +855,8 @@ namespace ASC.Common.Logging
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Singletone]
|
||||
public class LogManager<T> : OptionsMonitor<T> where T : class, ILog, new()
|
||||
{
|
||||
public LogManager(IOptionsFactory<T> factory, IEnumerable<IOptionsChangeTokenSource<T>> sources, IOptionsMonitorCache<T> cache) : base(factory, sources, cache)
|
||||
@ -871,30 +876,32 @@ namespace ASC.Common.Logging
|
||||
}
|
||||
}
|
||||
|
||||
public static class StudioNotifyHelperExtension
|
||||
public class LoggerExtension<T> where T : class, ILog, new()
|
||||
{
|
||||
public static DIHelper AddLogManager<T>(this DIHelper services, params string[] additionalLoggers) where T : class, ILog, new()
|
||||
public static void RegisterLog(DIHelper services)
|
||||
{
|
||||
const string baseName = "ASC";
|
||||
var baseSqlName = $"{baseName}.SQL";
|
||||
services.Configure<T>(r => r.Name = baseName);
|
||||
services.Configure<T>(baseName, r => r.Name = baseName);
|
||||
services.Configure<T>(baseSqlName, r => r.Name = baseSqlName);
|
||||
|
||||
services.Configure<T>(baseSqlName, r => r.Name = baseSqlName);
|
||||
services.TryAdd(typeof(IOptionsMonitor<ILog>), typeof(LogManager<T>));
|
||||
}
|
||||
|
||||
public static void ConfigureLog(DIHelper services, params string[] additionalLoggers)
|
||||
{
|
||||
foreach (var l in additionalLoggers)
|
||||
{
|
||||
services.Configure<T>(l, r => r.Name = l);
|
||||
}
|
||||
|
||||
services.TryAddSingleton(typeof(IOptionsMonitor<ILog>), typeof(LogManager<T>));
|
||||
return services;
|
||||
}
|
||||
|
||||
public static DIHelper AddNLogManager(this DIHelper services, params string[] additionalLoggers)
|
||||
{
|
||||
services.TryAddSingleton<IConfigureNamedOptions<LogNLog>, ConfigureLogNLog>();
|
||||
services.TryAddSingleton<IConfigureOptions<LogNLog>, ConfigureLogNLog>();
|
||||
return services.AddLogManager<LogNLog>(additionalLoggers);
|
||||
}
|
||||
}
|
||||
|
||||
public class LogNLogExtension : LoggerExtension<LogNLog>
|
||||
{
|
||||
public static void Register(DIHelper services)
|
||||
{
|
||||
RegisterLog(services);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ using ASC.Common;
|
||||
|
||||
namespace ASC.Security.Cryptography
|
||||
{
|
||||
[Singletone]
|
||||
public class InstanceCrypto
|
||||
{
|
||||
private MachinePseudoKeys MachinePseudoKeys { get; }
|
||||
@ -86,14 +87,4 @@ namespace ASC.Security.Cryptography
|
||||
return MachinePseudoKeys.GetMachineConstant(32);
|
||||
}
|
||||
}
|
||||
public static class InstanceCryptoExtension
|
||||
{
|
||||
public static DIHelper AddInstanceCryptoService(this DIHelper services)
|
||||
{
|
||||
services.TryAddSingleton<InstanceCrypto>();
|
||||
|
||||
return services
|
||||
.AddMachinePseudoKeysService();
|
||||
}
|
||||
}
|
||||
}
|
@ -36,6 +36,7 @@ using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace ASC.Security.Cryptography
|
||||
{
|
||||
[Singletone]
|
||||
public class MachinePseudoKeys
|
||||
{
|
||||
private readonly byte[] confkey = null;
|
||||
@ -76,13 +77,4 @@ namespace ASC.Security.Cryptography
|
||||
return buff;
|
||||
}
|
||||
}
|
||||
public static class MachinePseudoKeysExtension
|
||||
{
|
||||
public static DIHelper AddMachinePseudoKeysService(this DIHelper services)
|
||||
{
|
||||
services.TryAddSingleton<MachinePseudoKeys>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -34,6 +34,7 @@ using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace ASC.Security.Cryptography
|
||||
{
|
||||
[Singletone]
|
||||
public class PasswordHasher
|
||||
{
|
||||
public PasswordHasher(IConfiguration configuration, MachinePseudoKeys machinePseudoKeys)
|
||||
@ -95,14 +96,5 @@ namespace ASC.Security.Cryptography
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
public static class PasswordHasherExtension
|
||||
{
|
||||
public static DIHelper AddPasswordHasherService(this DIHelper services)
|
||||
{
|
||||
services.TryAddSingleton<PasswordHasher>();
|
||||
|
||||
return services.AddMachinePseudoKeysService();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -25,10 +25,9 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ASC.Common.Threading
|
||||
{
|
||||
public class DistributedTask
|
||||
@ -37,7 +36,7 @@ namespace ASC.Common.Threading
|
||||
|
||||
public DistributedTaskCache DistributedTaskCache { get; internal set; }
|
||||
|
||||
public string InstanceId
|
||||
public int InstanceId
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -45,7 +44,7 @@ namespace ASC.Common.Threading
|
||||
}
|
||||
set
|
||||
{
|
||||
DistributedTaskCache.InstanceId = value?.ToString() ?? "";
|
||||
DistributedTaskCache.InstanceId = value;
|
||||
}
|
||||
}
|
||||
public string Id
|
||||
@ -98,10 +97,14 @@ namespace ASC.Common.Threading
|
||||
|
||||
|
||||
public T GetProperty<T>(string name)
|
||||
{
|
||||
return DistributedTaskCache.Props.Any(r => r.Key == name) ?
|
||||
JsonConvert.DeserializeObject<T>(DistributedTaskCache.Props.Single(r => r.Key == name).Value) :
|
||||
default;
|
||||
{
|
||||
if (!DistributedTaskCache.Props.Any(r => r.Key == name)) return default;
|
||||
|
||||
var val = DistributedTaskCache.Props.SingleOrDefault(r => r.Key == name);
|
||||
|
||||
if (val == null) return default;
|
||||
|
||||
return JsonSerializer.Deserialize<T>(val.Value);
|
||||
}
|
||||
|
||||
public void SetProperty(string name, object value)
|
||||
@ -109,7 +112,7 @@ namespace ASC.Common.Threading
|
||||
var prop = new DistributedTaskCache.Types.DistributedTaskCacheProp()
|
||||
{
|
||||
Key = name,
|
||||
Value = JsonConvert.SerializeObject(value)
|
||||
Value = JsonSerializer.Serialize(value)
|
||||
};
|
||||
|
||||
var current = DistributedTaskCache.Props.SingleOrDefault(r => r.Key == name);
|
||||
|
@ -36,6 +36,7 @@ using ASC.Common.Caching;
|
||||
|
||||
namespace ASC.Common.Threading
|
||||
{
|
||||
[Singletone]
|
||||
public class DistributedTaskCacheNotify
|
||||
{
|
||||
public ConcurrentDictionary<string, CancellationTokenSource> Cancelations { get; }
|
||||
@ -90,7 +91,7 @@ namespace ASC.Common.Threading
|
||||
|
||||
public class DistributedTaskQueue
|
||||
{
|
||||
public static readonly string InstanceId;
|
||||
public static readonly int InstanceId;
|
||||
|
||||
private readonly string key;
|
||||
private readonly ICache cache;
|
||||
@ -101,7 +102,7 @@ namespace ASC.Common.Threading
|
||||
|
||||
static DistributedTaskQueue()
|
||||
{
|
||||
InstanceId = Process.GetCurrentProcess().Id.ToString();
|
||||
InstanceId = Process.GetCurrentProcess().Id;
|
||||
}
|
||||
|
||||
|
||||
|
@ -33,14 +33,16 @@ using ASC.Common.Threading.Workers;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Common.Threading.Progress
|
||||
{
|
||||
{
|
||||
[Singletone(typeof(ConfigureProgressQueue<>))]
|
||||
public class ProgressQueueOptionsManager<T> : OptionsManager<ProgressQueue<T>> where T : class, IProgressItem
|
||||
{
|
||||
public ProgressQueueOptionsManager(IOptionsFactory<ProgressQueue<T>> factory) : base(factory)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Singletone]
|
||||
public class ConfigureProgressQueue<T> : IPostConfigureOptions<ProgressQueue<T>> where T : class, IProgressItem
|
||||
{
|
||||
public ConfigureProgressQueue(IOptionsMonitor<ILog> log)
|
||||
@ -56,7 +58,8 @@ namespace ASC.Common.Threading.Progress
|
||||
queue.Start(x => x.RunJob());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Singletone]
|
||||
public class ProgressQueue<T> : WorkerQueue<T> where T : class, IProgressItem
|
||||
{
|
||||
public bool removeAfterCompleted;
|
||||
|
@ -34,14 +34,16 @@ using ASC.Common.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Common.Threading.Workers
|
||||
{
|
||||
{
|
||||
[Singletone(typeof(ConfigureWorkerQueue<>))]
|
||||
public class WorkerQueueOptionsManager<T> : OptionsManager<WorkerQueue<T>>
|
||||
{
|
||||
public WorkerQueueOptionsManager(IOptionsFactory<WorkerQueue<T>> factory) : base(factory)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Singletone]
|
||||
public class ConfigureWorkerQueue<T> : IConfigureOptions<WorkerQueue<T>>
|
||||
{
|
||||
public ConfigureWorkerQueue(IOptionsMonitor<ILog> log)
|
||||
@ -56,7 +58,8 @@ namespace ASC.Common.Threading.Workers
|
||||
queue.log = Log.Get("ASC.WorkerQueue");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Singletone]
|
||||
public class WorkerQueue<T>
|
||||
{
|
||||
internal ILog log;
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
@ -32,13 +33,23 @@ namespace ASC.Common.Utils
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConfigurationExtension
|
||||
[Singletone]
|
||||
public class ConfigurationExtension
|
||||
{
|
||||
public static IEnumerable<T> GetSettings<T>(this IConfiguration configuration, string section) where T : new()
|
||||
private IConfiguration Configuration { get; }
|
||||
private Lazy<ConnectionStringCollection> ConnectionStringSettings { get; }
|
||||
|
||||
public ConfigurationExtension(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
ConnectionStringSettings = new Lazy<ConnectionStringCollection>(new ConnectionStringCollection(GetSettings<ConnectionStringSettings>("ConnectionStrings")));
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetSettings<T>(string section) where T : new()
|
||||
{
|
||||
var result = new List<T>();
|
||||
|
||||
var sectionSettings = configuration.GetSection(section);
|
||||
var sectionSettings = Configuration.GetSection(section);
|
||||
|
||||
foreach (var ch in sectionSettings.GetChildren())
|
||||
{
|
||||
@ -49,9 +60,10 @@ namespace ASC.Common.Utils
|
||||
|
||||
return result;
|
||||
}
|
||||
public static T GetSetting<T>(this IConfiguration configuration, string section) where T : new()
|
||||
|
||||
public T GetSetting<T>(string section) where T : new()
|
||||
{
|
||||
var sectionSettings = configuration.GetSection(section);
|
||||
var sectionSettings = Configuration.GetSection(section);
|
||||
|
||||
var cs = new T();
|
||||
sectionSettings.Bind(cs);
|
||||
@ -59,13 +71,14 @@ namespace ASC.Common.Utils
|
||||
return cs;
|
||||
}
|
||||
|
||||
public static ConnectionStringCollection GetConnectionStrings(this IConfiguration configuration)
|
||||
public ConnectionStringCollection GetConnectionStrings()
|
||||
{
|
||||
return new ConnectionStringCollection(configuration.GetSettings<ConnectionStringSettings>("ConnectionStrings"));
|
||||
return ConnectionStringSettings.Value;
|
||||
}
|
||||
public static ConnectionStringSettings GetConnectionStrings(this IConfiguration configuration, string key)
|
||||
|
||||
public ConnectionStringSettings GetConnectionStrings(string key)
|
||||
{
|
||||
return configuration.GetConnectionStrings()[key];
|
||||
return GetConnectionStrings()[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ using Newtonsoft.Json;
|
||||
|
||||
namespace ASC.Common.Utils
|
||||
{
|
||||
[Singletone]
|
||||
public class Signature
|
||||
{
|
||||
public Signature(MachinePseudoKeys machinePseudoKeys)
|
||||
@ -91,13 +92,4 @@ namespace ASC.Common.Utils
|
||||
return Convert.ToBase64String(md5.ComputeHash(Encoding.UTF8.GetBytes(str)));
|
||||
}
|
||||
}
|
||||
|
||||
public static class SignatureExtension
|
||||
{
|
||||
public static DIHelper AddSignatureService(this DIHelper services)
|
||||
{
|
||||
services.TryAddSingleton<Signature>();
|
||||
return services.AddMachinePseudoKeysService();
|
||||
}
|
||||
}
|
||||
}
|
@ -40,7 +40,8 @@ using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Common.Utils
|
||||
{
|
||||
{
|
||||
[Singletone]
|
||||
public class TimeZoneConverter
|
||||
{
|
||||
private TimeZoneInfo defaultTimeZone;
|
||||
|
@ -4,7 +4,7 @@ package ASC.Common.Threading;
|
||||
|
||||
message DistributedTaskCache {
|
||||
string Id = 1;
|
||||
string InstanceId = 2;
|
||||
int32 InstanceId = 2;
|
||||
string Status = 3;
|
||||
string Exception = 4;
|
||||
repeated DistributedTaskCacheProp Props = 5;
|
||||
|
@ -38,12 +38,14 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Common
|
||||
{
|
||||
[Singletone]
|
||||
public class CommonLinkUtilitySettings
|
||||
{
|
||||
public string ServerUri { get; set; }
|
||||
}
|
||||
|
||||
|
||||
[Scope]
|
||||
public class BaseCommonLinkUtility
|
||||
{
|
||||
private const string LOCALHOST = "localhost";
|
||||
@ -243,21 +245,4 @@ namespace ASC.Core.Common
|
||||
_vpath = "/" + uri.AbsolutePath.Trim('/');
|
||||
}
|
||||
}
|
||||
|
||||
public static class BaseCommonLinkUtilityExtension
|
||||
{
|
||||
public static DIHelper AddBaseCommonLinkUtilityService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<BaseCommonLinkUtility>())
|
||||
{
|
||||
services.TryAddScoped<CommonLinkUtilitySettings>();
|
||||
return services
|
||||
.AddCoreBaseSettingsService()
|
||||
.AddCoreSettingsService()
|
||||
.AddTenantManagerService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Logging;
|
||||
|
||||
using Microsoft.Extensions.Options;
|
||||
@ -42,7 +43,8 @@ using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ASC.Core.Common.Billing
|
||||
{
|
||||
{
|
||||
[Singletone]
|
||||
public class CouponManager
|
||||
{
|
||||
private IEnumerable<AvangateProduct> Products { get; set; }
|
||||
|
@ -25,10 +25,13 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
using ASC.Common;
|
||||
|
||||
namespace ASC.Core.Billing
|
||||
{
|
||||
{
|
||||
[Scope(typeof(ConfigureTariffService))]
|
||||
public interface ITariffService
|
||||
{
|
||||
Tariff GetTariff(int tenantId, bool withRequestToPaymentSystem = true);
|
||||
|
@ -37,7 +37,8 @@ using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Billing
|
||||
{
|
||||
{
|
||||
[Scope]
|
||||
public class LicenseReader
|
||||
{
|
||||
private readonly ILog Log;
|
||||
@ -340,21 +341,4 @@ namespace ASC.Core.Billing
|
||||
private CoreSettings CoreSettings { get; }
|
||||
private IConfiguration Configuration { get; }
|
||||
}
|
||||
|
||||
public static class LicenseReaderExtension
|
||||
{
|
||||
public static DIHelper AddLicenseReaderService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<LicenseReader>())
|
||||
{
|
||||
return services
|
||||
.AddUserManagerService()
|
||||
.AddPaymentManagerService()
|
||||
.AddTenantManagerService()
|
||||
.AddCoreSettingsService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -42,7 +42,8 @@ using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Billing
|
||||
{
|
||||
{
|
||||
[Singletone]
|
||||
public class TariffServiceStorage
|
||||
{
|
||||
public ICache Cache { get; }
|
||||
@ -75,7 +76,8 @@ namespace ASC.Core.Billing
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope]
|
||||
class ConfigureTariffService : IConfigureNamedOptions<TariffService>
|
||||
{
|
||||
public ConfigureTariffService(
|
||||
@ -686,19 +688,4 @@ namespace ASC.Core.Billing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class TariffConfigExtension
|
||||
{
|
||||
public static DIHelper AddTariffService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<ITariffService, TariffService>())
|
||||
{
|
||||
services.AddCoreDbContextService();
|
||||
services.TryAddSingleton<TariffServiceStorage>();
|
||||
services.TryAddScoped<IConfigureOptions<TariffService>, ConfigureTariffService>();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -35,7 +35,6 @@ using ASC.Common.Utils;
|
||||
using ASC.Core.Data;
|
||||
using ASC.Core.Tenants;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
@ -51,7 +50,7 @@ namespace ASC.Core.Billing
|
||||
|
||||
public TariffSyncService(
|
||||
IServiceProvider serviceProvider,
|
||||
IConfiguration configuration,
|
||||
ConfigurationExtension configuration,
|
||||
DbQuotaService dbQuotaService,
|
||||
IOptionsMonitor<ILog> options)
|
||||
{
|
||||
@ -86,7 +85,7 @@ namespace ASC.Core.Billing
|
||||
}
|
||||
|
||||
private IServiceProvider ServiceProvider { get; }
|
||||
private IConfiguration Configuration { get; }
|
||||
private ConfigurationExtension Configuration { get; }
|
||||
private DbQuotaService DbQuotaService { get; }
|
||||
|
||||
public void Start()
|
||||
|
@ -29,11 +29,11 @@ using System.Collections.Generic;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Caching;
|
||||
using ASC.Core.Common.EF;
|
||||
using ASC.Core.Data;
|
||||
|
||||
namespace ASC.Core.Caching
|
||||
{
|
||||
{
|
||||
[Singletone]
|
||||
class AzServiceCache
|
||||
{
|
||||
internal ICache Cache { get; }
|
||||
@ -72,7 +72,8 @@ namespace ASC.Core.Caching
|
||||
return "acl" + tenant.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope]
|
||||
class CachedAzService : IAzService
|
||||
{
|
||||
private readonly IAzService service;
|
||||
@ -118,20 +119,4 @@ namespace ASC.Core.Caching
|
||||
cacheNotify.Publish(r, CacheNotifyAction.Remove);
|
||||
}
|
||||
}
|
||||
|
||||
public static class AzConfigExtension
|
||||
{
|
||||
public static DIHelper AddAzService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<DbAzService>())
|
||||
{
|
||||
services.TryAddScoped<IAzService, CachedAzService>();
|
||||
services.TryAddSingleton<AzServiceCache>();
|
||||
services.TryAddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>));
|
||||
services.AddCoreDbContextService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -30,7 +30,6 @@ using System.Linq;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Caching;
|
||||
using ASC.Core.Common.EF;
|
||||
using ASC.Core.Data;
|
||||
using ASC.Core.Tenants;
|
||||
|
||||
@ -38,7 +37,8 @@ using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Caching
|
||||
{
|
||||
{
|
||||
[Singletone]
|
||||
class QuotaServiceCache
|
||||
{
|
||||
internal const string KEY_QUOTA = "quota";
|
||||
@ -78,7 +78,8 @@ namespace ASC.Core.Caching
|
||||
}, CacheNotifyAction.Any);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope]
|
||||
class ConfigureCachedQuotaService : IConfigureNamedOptions<CachedQuotaService>
|
||||
{
|
||||
private IOptionsSnapshot<DbQuotaService> Service { get; }
|
||||
@ -106,7 +107,8 @@ namespace ASC.Core.Caching
|
||||
options.CacheNotify = QuotaServiceCache.CacheNotify;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope]
|
||||
class CachedQuotaService : IQuotaService
|
||||
{
|
||||
internal IQuotaService Service { get; set; }
|
||||
@ -237,25 +239,4 @@ namespace ASC.Core.Caching
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class QuotaConfigExtension
|
||||
{
|
||||
public static DIHelper AddQuotaService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<DbQuotaService>())
|
||||
{
|
||||
services.TryAddScoped<IQuotaService, CachedQuotaService>();
|
||||
|
||||
services.TryAddScoped<IConfigureOptions<DbQuotaService>, ConfigureDbQuotaService>();
|
||||
services.TryAddScoped<IConfigureOptions<CachedQuotaService>, ConfigureCachedQuotaService>();
|
||||
|
||||
services.AddCoreDbContextService();
|
||||
|
||||
services.TryAddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>));
|
||||
services.TryAddSingleton<QuotaServiceCache>();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,11 +30,11 @@ using System.Linq;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Caching;
|
||||
using ASC.Core.Common.EF;
|
||||
using ASC.Core.Data;
|
||||
|
||||
namespace ASC.Core.Caching
|
||||
{
|
||||
[Singletone]
|
||||
class SubscriptionServiceCache
|
||||
{
|
||||
internal ICache Cache { get; }
|
||||
@ -102,6 +102,7 @@ namespace ASC.Core.Caching
|
||||
}
|
||||
}
|
||||
|
||||
[Scope]
|
||||
class CachedSubscriptionService : ISubscriptionService
|
||||
{
|
||||
private readonly ISubscriptionService service;
|
||||
@ -285,20 +286,4 @@ namespace ASC.Core.Caching
|
||||
methodsByRec = methods.GroupBy(r => r.RecipientId).ToDictionary(g => g.Key, g => g.ToList());
|
||||
}
|
||||
}
|
||||
|
||||
public static class SubscriptionConfigExtension
|
||||
{
|
||||
public static DIHelper AddSubscriptionService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<DbSubscriptionService>())
|
||||
{
|
||||
services.TryAddScoped<ISubscriptionService, CachedSubscriptionService>();
|
||||
services.TryAddSingleton<SubscriptionServiceCache>();
|
||||
services.TryAddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>));
|
||||
services.AddUserDbContextService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,15 +29,14 @@ using System.Collections.Generic;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Caching;
|
||||
using ASC.Common.Utils;
|
||||
using ASC.Core.Common.EF.Context;
|
||||
using ASC.Core.Data;
|
||||
using ASC.Core.Tenants;
|
||||
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Caching
|
||||
{
|
||||
{
|
||||
[Singletone]
|
||||
class TenantServiceCache
|
||||
{
|
||||
private const string KEY = "tenants";
|
||||
@ -151,7 +150,8 @@ namespace ASC.Core.Caching
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope]
|
||||
class ConfigureCachedTenantService : IConfigureNamedOptions<CachedTenantService>
|
||||
{
|
||||
private IOptionsSnapshot<DbTenantService> Service { get; }
|
||||
@ -179,7 +179,8 @@ namespace ASC.Core.Caching
|
||||
options.CacheNotifySettings = TenantServiceCache.CacheNotifySettings;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope]
|
||||
class CachedTenantService : ITenantService
|
||||
{
|
||||
internal ITenantService Service { get; set; }
|
||||
@ -302,29 +303,4 @@ namespace ASC.Core.Caching
|
||||
CacheNotifySettings.Publish(new TenantSetting { Key = cacheKey }, CacheNotifyAction.Remove);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TenantConfigExtension
|
||||
{
|
||||
public static DIHelper AddTenantService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<DbTenantService>())
|
||||
{
|
||||
services.TryAddScoped<ITenantService, CachedTenantService>();
|
||||
|
||||
services.TryAddScoped<IConfigureOptions<DbTenantService>, ConfigureDbTenantService>();
|
||||
services.TryAddScoped<IConfigureOptions<CachedTenantService>, ConfigureCachedTenantService>();
|
||||
|
||||
services.TryAddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>));
|
||||
services.TryAddSingleton<TenantDomainValidator>();
|
||||
services.TryAddSingleton<TimeZoneConverter>();
|
||||
services.TryAddSingleton<TenantServiceCache>();
|
||||
|
||||
return services
|
||||
.AddCoreBaseSettingsService()
|
||||
.AddTenantDbContextService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,17 +32,16 @@ using System.Threading;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Caching;
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Core.Common.EF;
|
||||
using ASC.Core.Data;
|
||||
using ASC.Core.Tenants;
|
||||
using ASC.Core.Users;
|
||||
using ASC.Security.Cryptography;
|
||||
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Caching
|
||||
{
|
||||
{
|
||||
[Singletone]
|
||||
public class UserServiceCache
|
||||
{
|
||||
public const string USERS = "users";
|
||||
@ -138,6 +137,7 @@ namespace ASC.Core.Caching
|
||||
}
|
||||
}
|
||||
|
||||
[Scope]
|
||||
class ConfigureCachedUserService : IConfigureNamedOptions<CachedUserService>
|
||||
{
|
||||
internal IOptionsSnapshot<EFUserService> Service { get; }
|
||||
@ -173,7 +173,8 @@ namespace ASC.Core.Caching
|
||||
options.TrustInterval = UserServiceCache.TrustInterval;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope]
|
||||
public class CachedUserService : IUserService, ICachedService
|
||||
{
|
||||
internal IUserService Service { get; set; }
|
||||
@ -520,28 +521,4 @@ namespace ASC.Core.Caching
|
||||
public string Key { get; set; }
|
||||
}
|
||||
}
|
||||
public static class UserConfigExtension
|
||||
{
|
||||
public static DIHelper AddUserService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<EFUserService>())
|
||||
{
|
||||
services.TryAddScoped<IUserService, CachedUserService>();
|
||||
|
||||
services.TryAddScoped<IConfigureOptions<EFUserService>, ConfigureEFUserService>();
|
||||
services.TryAddScoped<IConfigureOptions<CachedUserService>, ConfigureCachedUserService>();
|
||||
|
||||
services.TryAddSingleton<UserServiceCache>();
|
||||
services.TryAddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>));
|
||||
|
||||
services
|
||||
.AddCoreSettingsService()
|
||||
.AddLoggerService()
|
||||
.AddUserDbContextService()
|
||||
.AddPasswordHasherService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -377,7 +377,8 @@ namespace ASC.Core.Common.Configuration
|
||||
return new DataStoreConsumer(TenantManager, CoreBaseSettings, CoreSettings, Configuration, Cache, ConsumerFactory, Name, Order, Props.ToDictionary(r => r.Key, r => r.Value), Additional.ToDictionary(r => r.Key, r => r.Value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope]
|
||||
public class ConsumerFactory : IDisposable
|
||||
{
|
||||
public ILifetimeScope Builder { get; set; }
|
||||
@ -432,13 +433,4 @@ namespace ASC.Core.Common.Configuration
|
||||
Builder.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConsumerFactoryExtension
|
||||
{
|
||||
public static DIHelper AddConsumerFactoryService(this DIHelper services)
|
||||
{
|
||||
services.TryAddScoped<ConsumerFactory>();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,13 +29,13 @@ using System.Linq;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Security.Authentication;
|
||||
using ASC.Core.Caching;
|
||||
using ASC.Core.Security.Authentication;
|
||||
using ASC.Core.Tenants;
|
||||
using ASC.Core.Users;
|
||||
|
||||
namespace ASC.Core
|
||||
{
|
||||
{
|
||||
[Scope]
|
||||
public class AuthManager
|
||||
{
|
||||
private readonly IUserService userService;
|
||||
@ -83,19 +83,4 @@ namespace ASC.Core
|
||||
return new UserAccount(u, tenantId, UserFormatter);
|
||||
}
|
||||
}
|
||||
public static class AuthManagerExtension
|
||||
{
|
||||
public static DIHelper AddAuthManager(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<AuthManager>())
|
||||
{
|
||||
return services
|
||||
.AddUserService()
|
||||
.AddUserFormatter()
|
||||
.AddUserManagerService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -34,7 +34,8 @@ using ASC.Common.Security.Authorizing;
|
||||
using ASC.Core.Caching;
|
||||
|
||||
namespace ASC.Core
|
||||
{
|
||||
{
|
||||
[Scope]
|
||||
public class AuthorizationManager
|
||||
{
|
||||
private readonly IAzService service;
|
||||
@ -128,19 +129,4 @@ namespace ASC.Core
|
||||
aces.Where(a => (a.SubjectId == subjectId || subjectId == Guid.Empty) && (a.ActionId == actionId || actionId == Guid.Empty) && a.ObjectId == objId);
|
||||
}
|
||||
}
|
||||
|
||||
public static class AuthorizationManagerConfigExtension
|
||||
{
|
||||
public static DIHelper AddAuthorizationManagerService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<AuthorizationManager>())
|
||||
{
|
||||
return services
|
||||
.AddAzService()
|
||||
.AddTenantManagerService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -39,7 +39,8 @@ using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ASC.Core
|
||||
{
|
||||
{
|
||||
[Singletone]
|
||||
public class CoreBaseSettings
|
||||
{
|
||||
private bool? standalone;
|
||||
@ -103,7 +104,8 @@ namespace ASC.Core
|
||||
options.TenantService = TenantService.Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope(typeof(ConfigureCoreSettings))]
|
||||
public class CoreSettings
|
||||
{
|
||||
private string basedomain;
|
||||
@ -242,7 +244,8 @@ namespace ASC.Core
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope]
|
||||
public class CoreConfiguration
|
||||
{
|
||||
private long? personalMaxSpace;
|
||||
@ -373,35 +376,4 @@ namespace ASC.Core
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public static class CoreSettingsConfigExtension
|
||||
{
|
||||
public static DIHelper AddCoreBaseSettingsService(this DIHelper services)
|
||||
{
|
||||
services.TryAddSingleton<CoreBaseSettings>();
|
||||
return services;
|
||||
}
|
||||
|
||||
public static DIHelper AddCoreSettingsService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<CoreSettings>())
|
||||
{
|
||||
services.TryAddScoped<CoreConfiguration>();
|
||||
services.TryAddScoped<IConfigureOptions<CoreSettings>, ConfigureCoreSettings>();
|
||||
|
||||
return services
|
||||
.AddCoreBaseSettingsService()
|
||||
.AddTenantService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
public static DIHelper AddCoreConfigurationService(this DIHelper services)
|
||||
{
|
||||
services.TryAddScoped<CoreConfiguration>();
|
||||
return services
|
||||
.AddTenantManagerService()
|
||||
.AddCoreSettingsService();
|
||||
}
|
||||
}
|
||||
}
|
@ -36,7 +36,6 @@ using System.Web;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Core.Billing;
|
||||
using ASC.Core.Caching;
|
||||
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@ -45,7 +44,8 @@ using Newtonsoft.Json;
|
||||
|
||||
|
||||
namespace ASC.Core
|
||||
{
|
||||
{
|
||||
[Scope]
|
||||
public class PaymentManager
|
||||
{
|
||||
private readonly ITariffService tariffService;
|
||||
@ -182,20 +182,4 @@ namespace ASC.Core
|
||||
public string stackTrace = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PaymentManagerExtension
|
||||
{
|
||||
public static DIHelper AddPaymentManagerService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<PaymentManager>())
|
||||
{
|
||||
return services
|
||||
.AddTenantManagerService()
|
||||
.AddQuotaService()
|
||||
.AddTariffService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,10 +28,10 @@ using System;
|
||||
using System.Linq;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Core.Caching;
|
||||
|
||||
namespace ASC.Core
|
||||
{
|
||||
{
|
||||
[Scope]
|
||||
public class SubscriptionManager
|
||||
{
|
||||
private readonly ISubscriptionService service;
|
||||
@ -148,19 +148,4 @@ namespace ASC.Core
|
||||
return TenantManager.GetCurrentTenant().TenantId;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SubscriptionConfigExtension
|
||||
{
|
||||
public static DIHelper AddSubscriptionManagerService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<SubscriptionManager>())
|
||||
{
|
||||
return services
|
||||
.AddSubscriptionService()
|
||||
.AddTenantManagerService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,8 @@ using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core
|
||||
{
|
||||
{
|
||||
[Scope]
|
||||
class ConfigureTenantManager : IConfigureNamedOptions<TenantManager>
|
||||
{
|
||||
private IOptionsSnapshot<CachedTenantService> TenantService { get; }
|
||||
@ -88,7 +89,8 @@ namespace ASC.Core
|
||||
options.TariffService = TariffService.Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope(typeof(ConfigureTenantManager))]
|
||||
public class TenantManager
|
||||
{
|
||||
private Tenant CurrentTenant { get; set; }
|
||||
@ -352,24 +354,4 @@ namespace ASC.Core
|
||||
return QuotaService.FindTenantQuotaRows(query).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public static class TenantManagerConfigExtension
|
||||
{
|
||||
public static DIHelper AddTenantManagerService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<TenantManager>())
|
||||
{
|
||||
services.TryAddScoped<IConfigureOptions<TenantManager>, ConfigureTenantManager>();
|
||||
|
||||
return services
|
||||
.AddTenantService()
|
||||
.AddQuotaService()
|
||||
.AddTariffService()
|
||||
.AddCoreBaseSettingsService()
|
||||
.AddCoreSettingsService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,8 @@ using ASC.Core.Users;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace ASC.Core
|
||||
{
|
||||
{
|
||||
[Singletone]
|
||||
public class UserManagerConstants
|
||||
{
|
||||
public IDictionary<Guid, UserInfo> SystemUsers { get; }
|
||||
@ -54,7 +55,8 @@ namespace ASC.Core
|
||||
Constants = constants;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope]
|
||||
public class UserManager
|
||||
{
|
||||
private IDictionary<Guid, UserInfo> SystemUsers { get => UserManagerConstants.SystemUsers; }
|
||||
@ -652,23 +654,4 @@ namespace ASC.Core
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class UserManagerConfigExtension
|
||||
{
|
||||
public static DIHelper AddUserManagerService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<UserManager>())
|
||||
{
|
||||
services.TryAddSingleton<UserManagerConstants>();
|
||||
|
||||
return services
|
||||
.AddUserService()
|
||||
.AddTenantManagerService()
|
||||
.AddConstantsService()
|
||||
.AddPermissionContextService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -41,7 +41,6 @@ using ASC.Common.Security.Authorizing;
|
||||
using ASC.Core.Billing;
|
||||
using ASC.Core.Common.Security;
|
||||
using ASC.Core.Security.Authentication;
|
||||
using ASC.Core.Security.Authorizing;
|
||||
using ASC.Core.Tenants;
|
||||
using ASC.Core.Users;
|
||||
|
||||
@ -50,6 +49,7 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core
|
||||
{
|
||||
[Scope]
|
||||
public class SecurityContext
|
||||
{
|
||||
private readonly ILog log;
|
||||
@ -290,6 +290,7 @@ namespace ASC.Core
|
||||
}
|
||||
}
|
||||
|
||||
[Scope]
|
||||
public class PermissionContext
|
||||
{
|
||||
public IPermissionResolver PermissionResolver { get; set; }
|
||||
@ -332,6 +333,7 @@ namespace ASC.Core
|
||||
}
|
||||
}
|
||||
|
||||
[Scope]
|
||||
public class AuthContext
|
||||
{
|
||||
private IHttpContextAccessor HttpContextAccessor { get; }
|
||||
@ -371,41 +373,4 @@ namespace ASC.Core
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class AuthContextConfigExtension
|
||||
{
|
||||
public static DIHelper AddSecurityContextService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<SecurityContext>())
|
||||
{
|
||||
return services
|
||||
.AddCookieStorageService()
|
||||
.AddTenantCookieSettingsService()
|
||||
.AddAuthManager()
|
||||
.AddUserFormatter()
|
||||
.AddAuthContextService()
|
||||
.AddUserManagerService()
|
||||
.AddTenantManagerService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
public static DIHelper AddAuthContextService(this DIHelper services)
|
||||
{
|
||||
services.TryAddScoped<AuthContext>();
|
||||
return services;
|
||||
}
|
||||
|
||||
public static DIHelper AddPermissionContextService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<PermissionContext>())
|
||||
{
|
||||
return services
|
||||
.AddAuthContextService()
|
||||
.AddPermissionResolverService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -27,7 +27,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Caching;
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Core.Common.Notify;
|
||||
@ -103,14 +104,13 @@ namespace ASC.Core
|
||||
var configuration = serviceProvider.GetService<IConfiguration>();
|
||||
var cacheNotify = serviceProvider.GetService<ICacheNotify<NotifyMessage>>();
|
||||
var cacheInvoke = serviceProvider.GetService<ICacheNotify<NotifyInvoke>>();
|
||||
var options = serviceProvider.GetService<IOptionsMonitor<ILog>>();
|
||||
var telegramHelper = serviceProvider.GetService<TelegramHelper>();
|
||||
var options = serviceProvider.GetService<IOptionsMonitor<ILog>>();
|
||||
|
||||
NotifyContext = new NotifyContext(serviceProvider);
|
||||
|
||||
INotifySender jabberSender = new NotifyServiceSender(cacheNotify, cacheInvoke);
|
||||
INotifySender emailSender = new NotifyServiceSender(cacheNotify, cacheInvoke);
|
||||
INotifySender telegramSender = new TelegramSender(options, telegramHelper);
|
||||
INotifySender telegramSender = new TelegramSender(options, serviceProvider);
|
||||
|
||||
var postman = configuration["core:notify:postman"];
|
||||
|
||||
@ -169,5 +169,15 @@ namespace ASC.Core
|
||||
tenantManager.SetCurrentTenant(tenant);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class WorkContextExtension
|
||||
{
|
||||
public static void Register(DIHelper dIHelper)
|
||||
{
|
||||
dIHelper.TryAdd<TelegramHelper>();
|
||||
dIHelper.TryAdd<EmailSenderSinkScope>();
|
||||
dIHelper.TryAdd<JabberSenderSinkScope>();
|
||||
}
|
||||
}
|
||||
}
|
@ -277,7 +277,8 @@ namespace TMResourceData
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Singletone]
|
||||
public class WhiteLabelHelper
|
||||
{
|
||||
private readonly ILog log;
|
||||
@ -366,13 +367,4 @@ namespace TMResourceData
|
||||
return resourceValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static class WhiteLabelHelperExtension
|
||||
{
|
||||
public static DIHelper AddWhiteLabelHelperService(this DIHelper services)
|
||||
{
|
||||
services.TryAddSingleton<WhiteLabelHelper>();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,10 +25,15 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Core.Caching;
|
||||
using ASC.Core.Data;
|
||||
|
||||
namespace ASC.Core
|
||||
{
|
||||
{
|
||||
[Scope(typeof(DbAzService), typeof(CachedAzService))]
|
||||
public interface IAzService
|
||||
{
|
||||
IEnumerable<AzRecord> GetAces(int tenant, DateTime from);
|
||||
|
@ -26,10 +26,14 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Core.Caching;
|
||||
using ASC.Core.Data;
|
||||
using ASC.Core.Tenants;
|
||||
|
||||
namespace ASC.Core
|
||||
{
|
||||
{
|
||||
[Scope(typeof(ConfigureDbQuotaService), typeof(ConfigureCachedQuotaService))]
|
||||
public interface IQuotaService
|
||||
{
|
||||
IEnumerable<TenantQuota> GetTenantQuotas();
|
||||
|
@ -24,10 +24,15 @@
|
||||
*/
|
||||
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Core.Caching;
|
||||
using ASC.Core.Data;
|
||||
|
||||
namespace ASC.Core
|
||||
{
|
||||
{
|
||||
[Scope(typeof(DbSubscriptionService), typeof(CachedSubscriptionService))]
|
||||
public interface ISubscriptionService
|
||||
{
|
||||
IEnumerable<SubscriptionRecord> GetSubscriptions(int tenant, string sourceId, string actionId);
|
||||
|
@ -27,10 +27,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Core.Caching;
|
||||
using ASC.Core.Data;
|
||||
using ASC.Core.Tenants;
|
||||
|
||||
namespace ASC.Core
|
||||
{
|
||||
{
|
||||
[Scope(typeof(ConfigureDbTenantService), typeof(ConfigureCachedTenantService))]
|
||||
public interface ITenantService
|
||||
{
|
||||
void ValidateDomain(string domain);
|
||||
|
@ -29,11 +29,15 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Core.Caching;
|
||||
using ASC.Core.Common.EF;
|
||||
using ASC.Core.Data;
|
||||
using ASC.Core.Users;
|
||||
|
||||
namespace ASC.Core
|
||||
{
|
||||
{
|
||||
[Scope(typeof(ConfigureEFUserService), typeof(ConfigureCachedUserService))]
|
||||
public interface IUserService
|
||||
{
|
||||
IDictionary<Guid, UserInfo> GetUsers(int tenant, DateTime from);
|
||||
|
@ -29,11 +29,13 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Core.Common.EF;
|
||||
using ASC.Core.Tenants;
|
||||
|
||||
namespace ASC.Core.Data
|
||||
{
|
||||
{
|
||||
[Scope]
|
||||
class DbAzService : IAzService
|
||||
{
|
||||
public Expression<Func<Acl, AzRecord>> FromAclToAzRecord { get; set; }
|
||||
|
@ -29,13 +29,15 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Core.Common.EF;
|
||||
using ASC.Core.Tenants;
|
||||
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Data
|
||||
{
|
||||
{
|
||||
[Scope]
|
||||
class ConfigureDbQuotaService : IConfigureNamedOptions<DbQuotaService>
|
||||
{
|
||||
private DbContextManager<CoreDbContext> DbContextManager { get; }
|
||||
@ -56,7 +58,8 @@ namespace ASC.Core.Data
|
||||
options.LazyCoreDbContext = new Lazy<CoreDbContext>(() => DbContextManager.Value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope]
|
||||
class DbQuotaService : IQuotaService
|
||||
{
|
||||
private Expression<Func<DbQuota, TenantQuota>> FromDbQuotaToTenantQuota { get; set; }
|
||||
|
@ -41,7 +41,8 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Data
|
||||
{
|
||||
{
|
||||
[Singletone]
|
||||
public class DbSettingsManagerCache
|
||||
{
|
||||
public ICache Cache { get; }
|
||||
@ -59,7 +60,8 @@ namespace ASC.Core.Data
|
||||
Notify.Publish(new SettingsCacheItem { Key = key }, CacheNotifyAction.Remove);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope]
|
||||
class ConfigureDbSettingsManager : IConfigureNamedOptions<DbSettingsManager>
|
||||
{
|
||||
private IServiceProvider ServiceProvider { get; }
|
||||
@ -105,7 +107,8 @@ namespace ASC.Core.Data
|
||||
options.LazyWebstudioDbContext = new Lazy<WebstudioDbContext>(() => DbContextManager.Value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope(typeof(ConfigureDbSettingsManager))]
|
||||
public class DbSettingsManager
|
||||
{
|
||||
private readonly TimeSpan expirationTimeout = TimeSpan.FromMinutes(5);
|
||||
@ -330,20 +333,4 @@ namespace ASC.Core.Data
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class DbSettingsManagerExtension
|
||||
{
|
||||
public static DIHelper AddDbSettingsManagerService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<DbSettingsManager>())
|
||||
{
|
||||
services.TryAddScoped<IConfigureOptions<DbSettingsManager>, ConfigureDbSettingsManager>();
|
||||
services.TryAddSingleton<DbSettingsManagerCache>();
|
||||
|
||||
return services.AddWebstudioDbContextService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -29,11 +29,13 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Core.Common.EF;
|
||||
using ASC.Core.Tenants;
|
||||
|
||||
namespace ASC.Core.Data
|
||||
{
|
||||
{
|
||||
[Scope]
|
||||
class DbSubscriptionService : ISubscriptionService
|
||||
{
|
||||
private Expression<Func<Subscription, SubscriptionRecord>> FromSubscriptionToSubscriptionRecord { get; set; }
|
||||
|
@ -30,6 +30,7 @@ using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Core.Common.EF;
|
||||
using ASC.Core.Common.EF.Context;
|
||||
using ASC.Core.Common.EF.Model;
|
||||
@ -41,7 +42,8 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Data
|
||||
{
|
||||
{
|
||||
[Scope]
|
||||
public class ConfigureDbTenantService : IConfigureNamedOptions<DbTenantService>
|
||||
{
|
||||
private TenantDomainValidator TenantDomainValidator { get; }
|
||||
@ -68,19 +70,20 @@ namespace ASC.Core.Data
|
||||
}
|
||||
}
|
||||
|
||||
[Scope]
|
||||
public class DbTenantService : ITenantService
|
||||
{
|
||||
private List<string> forbiddenDomains;
|
||||
|
||||
internal TenantDomainValidator TenantDomainValidator { get; set; }
|
||||
public MachinePseudoKeys MachinePseudoKeys { get; }
|
||||
private MachinePseudoKeys MachinePseudoKeys { get; }
|
||||
internal TenantDbContext TenantDbContext { get => LazyTenantDbContext.Value; }
|
||||
internal Lazy<TenantDbContext> LazyTenantDbContext { get; set; }
|
||||
|
||||
public Expression<Func<DbTenant, Tenant>> FromDbTenantToTenant { get; set; }
|
||||
public Expression<Func<TenantUserSecurity, Tenant>> FromTenantUserToTenant { get; set; }
|
||||
private static Expression<Func<DbTenant, Tenant>> FromDbTenantToTenant { get; set; }
|
||||
private static Expression<Func<TenantUserSecurity, Tenant>> FromTenantUserToTenant { get; set; }
|
||||
|
||||
public DbTenantService()
|
||||
static DbTenantService()
|
||||
{
|
||||
FromDbTenantToTenant = r => new Tenant
|
||||
{
|
||||
@ -102,21 +105,25 @@ namespace ASC.Core.Data
|
||||
VersionChanged = r.VersionChanged,
|
||||
TrustedDomainsRaw = r.TrustedDomains,
|
||||
TrustedDomainsType = r.TrustedDomainsEnabled,
|
||||
AffiliateId = r.Partner != null ? r.Partner.AffiliateId : null,
|
||||
PartnerId = r.Partner != null ? r.Partner.PartnerId : null,
|
||||
//AffiliateId = r.Partner != null ? r.Partner.AffiliateId : null,
|
||||
//PartnerId = r.Partner != null ? r.Partner.PartnerId : null,
|
||||
TimeZone = r.TimeZone,
|
||||
Campaign = r.Partner != null ? r.Partner.Campaign : null
|
||||
//Campaign = r.Partner != null ? r.Partner.Campaign : null
|
||||
};
|
||||
|
||||
var fromDbTenantToTenant = FromDbTenantToTenant.Compile();
|
||||
FromTenantUserToTenant = r => fromDbTenantToTenant(r.DbTenant);
|
||||
}
|
||||
|
||||
public DbTenantService()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DbTenantService(
|
||||
DbContextManager<TenantDbContext> dbContextManager,
|
||||
TenantDomainValidator tenantDomainValidator,
|
||||
MachinePseudoKeys machinePseudoKeys)
|
||||
: this()
|
||||
{
|
||||
LazyTenantDbContext = new Lazy<TenantDbContext>(() => dbContextManager.Value);
|
||||
TenantDomainValidator = tenantDomainValidator;
|
||||
@ -451,8 +458,7 @@ namespace ASC.Core.Data
|
||||
|
||||
private IQueryable<DbTenant> TenantsQuery()
|
||||
{
|
||||
return TenantDbContext.Tenants
|
||||
.Include(r => r.Partner);
|
||||
return TenantDbContext.Tenants;
|
||||
}
|
||||
|
||||
private void ValidateDomain(string domain, int tenantId, bool validateCharacters)
|
||||
|
@ -30,6 +30,7 @@ using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Core.Common.EF;
|
||||
using ASC.Core.Tenants;
|
||||
using ASC.Core.Users;
|
||||
@ -38,7 +39,8 @@ using ASC.Security.Cryptography;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Data
|
||||
{
|
||||
{
|
||||
[Scope]
|
||||
public class ConfigureEFUserService : IConfigureNamedOptions<EFUserService>
|
||||
{
|
||||
private DbContextManager<UserDbContext> DbContextManager { get; }
|
||||
@ -63,15 +65,15 @@ namespace ASC.Core.Data
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope]
|
||||
public class EFUserService : IUserService
|
||||
{
|
||||
public Expression<Func<User, UserInfo>> FromUserToUserInfo { get; set; }
|
||||
public Func<UserInfo, User> FromUserInfoToUser { get; set; }
|
||||
public Expression<Func<DbGroup, Group>> FromDbGroupToGroup { get; set; }
|
||||
public Func<Group, DbGroup> FromGroupToDbGroup { get; set; }
|
||||
public Expression<Func<UserGroup, UserGroupRef>> FromUserGroupToUserGroupRef { get; set; }
|
||||
public Func<UserGroupRef, UserGroup> FromUserGroupRefToUserGroup { get; set; }
|
||||
private static Expression<Func<User, UserInfo>> FromUserToUserInfo { get; set; }
|
||||
private static Func<UserInfo, User> FromUserInfoToUser { get; set; }
|
||||
private static Expression<Func<DbGroup, Group>> FromDbGroupToGroup { get; set; }
|
||||
private static Func<Group, DbGroup> FromGroupToDbGroup { get; set; }
|
||||
private static Expression<Func<UserGroup, UserGroupRef>> FromUserGroupToUserGroupRef { get; set; }
|
||||
private static Func<UserGroupRef, UserGroup> FromUserGroupRefToUserGroup { get; set; }
|
||||
|
||||
internal UserDbContext UserDbContext { get => LazyUserDbContext.Value; }
|
||||
internal Lazy<UserDbContext> LazyUserDbContext { get; set; }
|
||||
@ -80,7 +82,7 @@ namespace ASC.Core.Data
|
||||
public MachinePseudoKeys MachinePseudoKeys { get; }
|
||||
internal string DbId { get; set; }
|
||||
|
||||
public EFUserService()
|
||||
static EFUserService()
|
||||
{
|
||||
FromUserToUserInfo = user => new UserInfo
|
||||
{
|
||||
@ -185,7 +187,12 @@ namespace ASC.Core.Data
|
||||
};
|
||||
}
|
||||
|
||||
public EFUserService(DbContextManager<UserDbContext> userDbContextManager, PasswordHasher passwordHasher, MachinePseudoKeys machinePseudoKeys) : this()
|
||||
public EFUserService()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public EFUserService(DbContextManager<UserDbContext> userDbContextManager, PasswordHasher passwordHasher, MachinePseudoKeys machinePseudoKeys)
|
||||
{
|
||||
UserDbContextManager = userDbContextManager;
|
||||
PasswordHasher = passwordHasher;
|
||||
|
@ -1,33 +1,34 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Common.Utils;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Common.EF
|
||||
{
|
||||
public class ConfigureDbContext : IConfigureNamedOptions<BaseDbContext>
|
||||
[Scope]
|
||||
public class ConfigureDbContext<T> : IConfigureNamedOptions<T> where T : BaseDbContext, new()
|
||||
{
|
||||
public const string baseName = "default";
|
||||
private EFLoggerFactory LoggerFactory { get; }
|
||||
private IConfiguration Configuration { get; }
|
||||
private ConfigurationExtension Configuration { get; }
|
||||
|
||||
public ConfigureDbContext(EFLoggerFactory loggerFactory, IConfiguration configuration)
|
||||
public ConfigureDbContext(EFLoggerFactory loggerFactory, ConfigurationExtension configuration)
|
||||
{
|
||||
LoggerFactory = loggerFactory;
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public void Configure(string name, BaseDbContext context)
|
||||
public void Configure(string name, T context)
|
||||
{
|
||||
context.LoggerFactory = LoggerFactory;
|
||||
context.ConnectionStringSettings = Configuration.GetConnectionStrings(name) ?? Configuration.GetConnectionStrings(baseName);
|
||||
}
|
||||
|
||||
public void Configure(BaseDbContext context)
|
||||
public void Configure(T context)
|
||||
{
|
||||
Configure(baseName, context);
|
||||
}
|
||||
@ -36,10 +37,10 @@ namespace ASC.Core.Common.EF
|
||||
public class ConfigureMultiRegionalDbContext<T> : IConfigureNamedOptions<MultiRegionalDbContext<T>> where T : BaseDbContext, new()
|
||||
{
|
||||
public string baseName = "default";
|
||||
private IConfiguration Configuration { get; }
|
||||
private ConfigurationExtension Configuration { get; }
|
||||
private DbContextManager<T> DbContext { get; }
|
||||
|
||||
public ConfigureMultiRegionalDbContext(IConfiguration configuration, DbContextManager<T> dbContext)
|
||||
public ConfigureMultiRegionalDbContext(ConfigurationExtension configuration, DbContextManager<T> dbContext)
|
||||
{
|
||||
Configuration = configuration;
|
||||
DbContext = dbContext;
|
||||
|
@ -1,12 +1,11 @@
|
||||
|
||||
using ASC.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using ASC.Core.Common.EF.Model;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ASC.Core.Common.EF
|
||||
{
|
||||
public class MySqlCoreDbContext : CoreDbContext { }
|
||||
@ -40,13 +39,4 @@ namespace ASC.Core.Common.EF
|
||||
.AddDbTariff();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class CoreDbExtension
|
||||
{
|
||||
public static DIHelper AddCoreDbContextService(this DIHelper services)
|
||||
{
|
||||
return services.AddDbContextManagerService<CoreDbContext>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Logging;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
@ -66,6 +65,7 @@ namespace ASC.Core.Common.EF
|
||||
}
|
||||
}
|
||||
|
||||
[Scope(typeof(ConfigureDbContext<>))]
|
||||
public class DbContextManager<T> : BaseDbContextManager<T> where T : BaseDbContext, new()
|
||||
{
|
||||
public DbContextManager(IOptionsFactory<T> factory, IConfiguration configuration) : base(factory, configuration)
|
||||
@ -84,13 +84,9 @@ namespace ASC.Core.Common.EF
|
||||
{
|
||||
public static DIHelper AddDbContextManagerService<T>(this DIHelper services) where T : BaseDbContext, new()
|
||||
{
|
||||
if (services.TryAddScoped<DbContextManager<T>>())
|
||||
{
|
||||
services.TryAddScoped<MultiRegionalDbContextManager<T>>();
|
||||
services.TryAddScoped<IConfigureOptions<T>, ConfigureDbContext>();
|
||||
services.TryAddScoped<IConfigureOptions<MultiRegionalDbContext<T>>, ConfigureMultiRegionalDbContext<T>>();
|
||||
return services.AddLoggerService();
|
||||
}
|
||||
//TODO
|
||||
//services.TryAddScoped<MultiRegionalDbContextManager<T>>();
|
||||
//services.TryAddScoped<IConfigureOptions<MultiRegionalDbContext<T>>, ConfigureMultiRegionalDbContext<T>>();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ namespace ASC.Core.Common.EF.Model
|
||||
public bool Spam { get; set; }
|
||||
public bool Calls { get; set; }
|
||||
|
||||
public DbTenantPartner Partner { get; set; }
|
||||
// public DbTenantPartner Partner { get; set; }
|
||||
}
|
||||
|
||||
public static class DbTenantExtension
|
||||
@ -74,10 +74,10 @@ namespace ASC.Core.Common.EF.Model
|
||||
|
||||
public static void MySqlAddDbTenant(this ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<DbTenant>()
|
||||
.HasOne(r => r.Partner)
|
||||
.WithOne(r => r.Tenant)
|
||||
.HasPrincipalKey<DbTenant>(r => new { r.Id });
|
||||
//modelBuilder.Entity<DbTenant>()
|
||||
// .HasOne(r => r.Partner)
|
||||
// .WithOne(r => r.Tenant)
|
||||
// .HasPrincipalKey<DbTenant>(r => new { r.Id });
|
||||
|
||||
modelBuilder.Entity<DbTenant>(entity =>
|
||||
{
|
||||
|
@ -103,7 +103,8 @@ namespace ASC.Core
|
||||
hostedSolution.CoreSettings = CoreSettings.Get(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope(typeof(ConfigureHostedSolution))]
|
||||
public class HostedSolution
|
||||
{
|
||||
internal ITenantService TenantService { get; set; }
|
||||
@ -283,27 +284,5 @@ namespace ASC.Core
|
||||
}
|
||||
return tenant;
|
||||
}
|
||||
}
|
||||
|
||||
public static class HostedSolutionExtension
|
||||
{
|
||||
public static DIHelper AddHostedSolutionService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<IConfigureOptions<HostedSolution>, ConfigureHostedSolution>())
|
||||
{
|
||||
return services
|
||||
.AddUserFormatter()
|
||||
.AddTenantService()
|
||||
.AddUserService()
|
||||
.AddQuotaService()
|
||||
.AddTariffService()
|
||||
.AddTenantManagerService()
|
||||
.AddTenantUtilService()
|
||||
.AddDbSettingsManagerService()
|
||||
.AddCoreSettingsService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -50,21 +50,24 @@ namespace ASC.Core
|
||||
private readonly Dictionary<string, HostedSolution> regions = new Dictionary<string, HostedSolution>();
|
||||
private readonly string dbid;
|
||||
|
||||
private IConfiguration Configuraion { get; }
|
||||
private IConfiguration Configuraion { get; }
|
||||
public ConfigurationExtension ConfigurationExtension { get; }
|
||||
private CookieStorage CookieStorage { get; }
|
||||
private EFLoggerFactory LoggerFactory { get; }
|
||||
private PasswordHasher PasswordHasher { get; }
|
||||
private IOptionsSnapshot<HostedSolution> HostedSolutionOptions { get; }
|
||||
|
||||
public MultiRegionHostedSolution(string dbid,
|
||||
IConfiguration configuraion,
|
||||
IConfiguration configuraion,
|
||||
ConfigurationExtension configurationExtension,
|
||||
CookieStorage cookieStorage,
|
||||
EFLoggerFactory loggerFactory,
|
||||
PasswordHasher passwordHasher,
|
||||
IOptionsSnapshot<HostedSolution> hostedSolutionOptions)
|
||||
{
|
||||
this.dbid = dbid;
|
||||
Configuraion = configuraion;
|
||||
Configuraion = configuraion;
|
||||
ConfigurationExtension = configurationExtension;
|
||||
CookieStorage = cookieStorage;
|
||||
LoggerFactory = loggerFactory;
|
||||
PasswordHasher = passwordHasher;
|
||||
@ -200,12 +203,12 @@ namespace ASC.Core
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
var connectionStrings = Configuraion.GetConnectionStrings();
|
||||
var dbConnectionStrings = Configuraion.GetConnectionStrings(dbid);
|
||||
var connectionStrings = ConfigurationExtension.GetConnectionStrings();
|
||||
var dbConnectionStrings = ConfigurationExtension.GetConnectionStrings(dbid);
|
||||
|
||||
if (Convert.ToBoolean(Configuraion["core.multi-hosted.config-only"] ?? "false"))
|
||||
{
|
||||
foreach (var cs in Configuraion.GetConnectionStrings())
|
||||
foreach (var cs in ConfigurationExtension.GetConnectionStrings())
|
||||
{
|
||||
if (cs.Name.StartsWith(dbid + "."))
|
||||
{
|
||||
|
@ -41,7 +41,7 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Notify
|
||||
{
|
||||
class EmailSenderSink : Sink
|
||||
public class EmailSenderSink : Sink
|
||||
{
|
||||
private static readonly string senderName = ASC.Core.Configuration.Constants.NotifyEMailSenderSysName;
|
||||
private readonly INotifySender sender;
|
||||
@ -166,7 +166,8 @@ namespace ASC.Core.Notify
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope]
|
||||
public class EmailSenderSinkScope
|
||||
{
|
||||
private TenantManager TenantManager { get; }
|
||||
@ -185,13 +186,4 @@ namespace ASC.Core.Notify
|
||||
(tenantManager, coreConfiguration, optionsMonitor) = (TenantManager, CoreConfiguration, Options);
|
||||
}
|
||||
}
|
||||
|
||||
public static class EmailSenderSinkExtension
|
||||
{
|
||||
public static DIHelper AddEmailSenderSinkService(this DIHelper services)
|
||||
{
|
||||
services.TryAddScoped<EmailSenderSinkScope>();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -23,8 +23,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Core.Notify;
|
||||
|
||||
namespace ASC.Notify.Recipients
|
||||
{
|
||||
{
|
||||
[Scope(typeof(RecipientProviderImpl))]
|
||||
public interface IRecipientProvider
|
||||
{
|
||||
IRecipient GetRecipient(string id);
|
||||
|
@ -32,7 +32,8 @@ using ASC.Common;
|
||||
using ASC.Core.Common.Notify.Jabber;
|
||||
|
||||
namespace ASC.Core.Notify.Jabber
|
||||
{
|
||||
{
|
||||
[Scope]
|
||||
public class JabberServiceClient
|
||||
{
|
||||
private static readonly TimeSpan Timeout = TimeSpan.FromMinutes(2);
|
||||
@ -239,20 +240,4 @@ namespace ASC.Core.Notify.Jabber
|
||||
return new JabberServiceClientWcf();
|
||||
}
|
||||
}
|
||||
|
||||
public static class JabberServiceClientExtension
|
||||
{
|
||||
public static DIHelper AddJabberServiceClient(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<JabberServiceClient>())
|
||||
{
|
||||
return services
|
||||
.AddUserManagerService()
|
||||
.AddAuthContextService()
|
||||
.AddTenantManagerService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,8 @@ namespace ASC.Core.Notify
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope]
|
||||
public class JabberSenderSinkScope
|
||||
{
|
||||
private UserManager UserManager { get; }
|
||||
@ -104,14 +105,5 @@ namespace ASC.Core.Notify
|
||||
{
|
||||
(userManager, tenantManager) = (UserManager, TenantManager);
|
||||
}
|
||||
}
|
||||
|
||||
public static class JabberSenderSinkExtension
|
||||
{
|
||||
public static DIHelper AddJabberSenderSinkService(this DIHelper services)
|
||||
{
|
||||
services.TryAddScoped<JabberSenderSinkScope>();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,12 +24,14 @@
|
||||
*/
|
||||
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Caching;
|
||||
using ASC.Notify;
|
||||
using ASC.Notify.Messages;
|
||||
|
||||
namespace ASC.Core.Notify
|
||||
{
|
||||
{
|
||||
[Scope]
|
||||
public class NotifyServiceClient : INotifyService
|
||||
{
|
||||
private readonly ICacheNotify<NotifyMessage> СacheNotify;
|
||||
|
@ -26,9 +26,8 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Core.Users;
|
||||
using ASC.Notify.Recipients;
|
||||
|
||||
@ -158,15 +157,4 @@ namespace ASC.Core.Notify
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static class RecipientProviderImplExtension
|
||||
{
|
||||
public static DIHelper AddRecipientProviderImplService(this DIHelper services)
|
||||
{
|
||||
services.TryAddScoped(typeof(IRecipientProvider), typeof(RecipientProviderImpl));
|
||||
|
||||
return services
|
||||
.AddUserManagerService();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,8 +45,9 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Notify.Senders
|
||||
{
|
||||
class AWSSender : SmtpSender
|
||||
{
|
||||
[Singletone(Additional = typeof(AWSSenderExtension))]
|
||||
public class AWSSender : SmtpSender
|
||||
{
|
||||
private readonly object locker = new object();
|
||||
private AmazonSimpleEmailServiceClient ses;
|
||||
@ -229,7 +230,8 @@ namespace ASC.Core.Notify.Senders
|
||||
return quota == null || (DateTime.UtcNow - lastRefresh) > refreshTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope]
|
||||
public class AWSSenderScope
|
||||
{
|
||||
private TenantManager TenantManager { get; }
|
||||
@ -247,15 +249,11 @@ namespace ASC.Core.Notify.Senders
|
||||
}
|
||||
}
|
||||
|
||||
public static class AWSSenderExtension
|
||||
public class AWSSenderExtension
|
||||
{
|
||||
public static DIHelper AddAWSSenderService(this DIHelper services)
|
||||
public static void Register(DIHelper services)
|
||||
{
|
||||
services.TryAddSingleton<AWSSender>();
|
||||
services.TryAddScoped<AWSSenderScope>();
|
||||
return services
|
||||
.AddTenantManagerService()
|
||||
.AddCoreSettingsService();
|
||||
services.TryAdd<AWSSenderScope>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,8 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Notify.Senders
|
||||
{
|
||||
{
|
||||
[Singletone(Additional = typeof(JabberSenderExtension))]
|
||||
public class JabberSender : INotifySender
|
||||
{
|
||||
private readonly ILog log;
|
||||
@ -75,14 +76,13 @@ namespace ASC.Core.Notify.Senders
|
||||
}
|
||||
return NoticeSendResult.OK;
|
||||
}
|
||||
}
|
||||
|
||||
public static class JabberSenderExtension
|
||||
}
|
||||
|
||||
public class JabberSenderExtension
|
||||
{
|
||||
public static DIHelper AddJabberSenderService(this DIHelper services)
|
||||
public static void Register(DIHelper services)
|
||||
{
|
||||
services.TryAddSingleton<JabberSender>();
|
||||
return services.AddJabberServiceClient();
|
||||
services.TryAdd<JabberServiceClient>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,8 +45,9 @@ using Microsoft.Extensions.Options;
|
||||
using MimeKit;
|
||||
|
||||
namespace ASC.Core.Notify.Senders
|
||||
{
|
||||
internal class SmtpSender : INotifySender
|
||||
{
|
||||
[Singletone(Additional = typeof(SmtpSenderExtension))]
|
||||
public class SmtpSender : INotifySender
|
||||
{
|
||||
private const string HTML_FORMAT =
|
||||
@"<!DOCTYPE html PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN"">
|
||||
@ -321,7 +322,8 @@ namespace ASC.Core.Notify.Senders
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope]
|
||||
public class SmtpSenderScope
|
||||
{
|
||||
private TenantManager TenantManager { get; }
|
||||
@ -339,15 +341,11 @@ namespace ASC.Core.Notify.Senders
|
||||
}
|
||||
}
|
||||
|
||||
public static class SmtpSenderExtension
|
||||
public class SmtpSenderExtension
|
||||
{
|
||||
public static DIHelper AddSmtpSenderService(this DIHelper services)
|
||||
public static void Register(DIHelper services)
|
||||
{
|
||||
services.TryAddSingleton<SmtpSender>();
|
||||
services.TryAddScoped<SmtpSenderScope>();
|
||||
return services
|
||||
.AddTenantManagerService()
|
||||
.AddCoreSettingsService();
|
||||
services.TryAdd<SmtpSenderScope>();
|
||||
}
|
||||
}
|
||||
}
|
@ -31,6 +31,7 @@ using ASC.Common.Logging;
|
||||
using ASC.Core.Common.Notify;
|
||||
using ASC.Notify.Messages;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Notify.Senders
|
||||
@ -38,14 +39,14 @@ namespace ASC.Core.Notify.Senders
|
||||
public class TelegramSender : INotifySender
|
||||
{
|
||||
private readonly ILog log;
|
||||
private TelegramHelper TelegramHelper { get; }
|
||||
|
||||
public TelegramSender(IOptionsMonitor<ILog> options, TelegramHelper telegramHelper)
|
||||
public TelegramSender(IOptionsMonitor<ILog> options, IServiceProvider serviceProvider)
|
||||
{
|
||||
log = options.Get("ASC");
|
||||
TelegramHelper = telegramHelper;
|
||||
ServiceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public IServiceProvider ServiceProvider { get; }
|
||||
|
||||
public void Init(IDictionary<string, string> properties)
|
||||
{
|
||||
@ -59,7 +60,9 @@ namespace ASC.Core.Notify.Senders
|
||||
m.Content = Regex.Replace(m.Content, "\n{3,}", "\n\n");
|
||||
}
|
||||
try
|
||||
{
|
||||
{
|
||||
using var scope = ServiceProvider.CreateScope();
|
||||
var TelegramHelper = scope.ServiceProvider.GetService<TelegramHelper>();
|
||||
TelegramHelper.SendMessage(m);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -43,7 +43,8 @@ using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ASC.Core.Notify.Signalr
|
||||
{
|
||||
{
|
||||
[Scope]
|
||||
public class ConfigureSignalrServiceClient : IConfigureNamedOptions<SignalrServiceClient>
|
||||
{
|
||||
internal TenantManager TenantManager { get; }
|
||||
@ -100,7 +101,8 @@ namespace ASC.Core.Notify.Signalr
|
||||
Configure("default", options);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope(typeof(ConfigureSignalrServiceClient))]
|
||||
public class SignalrServiceClient
|
||||
{
|
||||
private static readonly TimeSpan Timeout;
|
||||
@ -394,22 +396,4 @@ namespace ASC.Core.Notify.Signalr
|
||||
return string.Format("ASC {0}:{1}:{2}", pkey, now, hash);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SignalrServiceClientExtension
|
||||
{
|
||||
public static DIHelper AddSignalrServiceClient(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<SignalrServiceClient>())
|
||||
{
|
||||
services.TryAddScoped<IConfigureNamedOptions<SignalrServiceClient>, ConfigureSignalrServiceClient>();
|
||||
|
||||
return services
|
||||
.AddTenantManagerService()
|
||||
.AddCoreSettingsService()
|
||||
.AddMachinePseudoKeysService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -30,7 +30,6 @@ using System.Linq;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Caching;
|
||||
using ASC.Core.Common.EF.Context;
|
||||
using ASC.Core.Common.EF.Model;
|
||||
|
||||
using Microsoft.Extensions.Options;
|
||||
@ -62,7 +61,8 @@ namespace ASC.Core.Common.Notify.Telegram
|
||||
options.SingleKeyFormat = "tgUser:{0}";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope(typeof(ConfigureCachedTelegramDao))]
|
||||
public class CachedTelegramDao
|
||||
{
|
||||
public TelegramDao TgDao { get; set; }
|
||||
@ -116,24 +116,5 @@ namespace ASC.Core.Common.Notify.Telegram
|
||||
var key = string.Format(PairKeyFormat, userId, tenantId);
|
||||
Cache.Insert(key, new TelegramUser { PortalUserId = userId, TenantId = tenantId, TelegramUserId = telegramId }, Expiration);
|
||||
}
|
||||
}
|
||||
|
||||
public static class CachedTelegramDaoExtension
|
||||
{
|
||||
public static DIHelper AddCachedTelegramDaoService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<TelegramDao>())
|
||||
{
|
||||
|
||||
services.TryAddScoped<IConfigureOptions<TelegramDao>, ConfigureTelegramDaoService>();
|
||||
services.TryAddScoped<IConfigureOptions<CachedTelegramDao>, ConfigureCachedTelegramDao>();
|
||||
|
||||
services.TryAddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>));
|
||||
|
||||
return services.AddTelegramDbContextService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Core.Common.EF;
|
||||
using ASC.Core.Common.EF.Context;
|
||||
using ASC.Core.Common.EF.Model;
|
||||
@ -58,6 +59,7 @@ namespace ASC.Core.Common.Notify.Telegram
|
||||
}
|
||||
}
|
||||
|
||||
[Scope(typeof(ConfigureTelegramDaoService))]
|
||||
public class TelegramDao
|
||||
{
|
||||
public TelegramDbContext TelegramDbContext { get; set; }
|
||||
|
@ -40,7 +40,8 @@ using Microsoft.Extensions.Options;
|
||||
using Telegram.Bot;
|
||||
|
||||
namespace ASC.Core.Common.Notify
|
||||
{
|
||||
{
|
||||
[Scope]
|
||||
public class TelegramHelper
|
||||
{
|
||||
public enum RegStatus
|
||||
@ -169,18 +170,5 @@ namespace ASC.Core.Common.Notify
|
||||
{
|
||||
return string.IsNullOrEmpty(proxy) ? new TelegramBotClient(token) : new TelegramBotClient(token, new WebProxy(proxy));
|
||||
}
|
||||
}
|
||||
|
||||
public static class TelegramHelperExtension
|
||||
{
|
||||
public static DIHelper AddTelegramHelperSerivce(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<TelegramHelper>())
|
||||
{
|
||||
return services.AddTelegramServiceClient()
|
||||
.AddCachedTelegramDaoService();
|
||||
}
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,8 @@ using ASC.Common.Caching;
|
||||
using ASC.Notify.Messages;
|
||||
|
||||
namespace ASC.Core.Common.Notify
|
||||
{
|
||||
{
|
||||
[Singletone]
|
||||
public class TelegramServiceClient : ITelegramService
|
||||
{
|
||||
private ICacheNotify<NotifyMessage> CacheMessage { get; }
|
||||
@ -95,13 +96,4 @@ namespace ASC.Core.Common.Notify
|
||||
return "Token" + userId + tenantId;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TelegramServiceClientExtension
|
||||
{
|
||||
public static DIHelper AddTelegramServiceClient(this DIHelper services)
|
||||
{
|
||||
services.TryAddSingleton<TelegramServiceClient>();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Security.Authentication
|
||||
{
|
||||
[Scope]
|
||||
public class CookieStorage
|
||||
{
|
||||
private const string DateTimeFormat = "yyyy-MM-dd HH:mm:ss,fff";
|
||||
@ -141,19 +142,4 @@ namespace ASC.Core.Security.Authentication
|
||||
return Hasher.Base64Hash(data ?? string.Empty, HashAlg.SHA256);
|
||||
}
|
||||
}
|
||||
|
||||
public static class CookieStorageExtension
|
||||
{
|
||||
public static DIHelper AddCookieStorageService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<CookieStorage>())
|
||||
{
|
||||
return services
|
||||
.AddTenantCookieSettingsService()
|
||||
.AddInstanceCryptoService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -26,11 +26,10 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using ASC.Core.Security.Authorizing;
|
||||
|
||||
namespace ASC.Common.Security.Authorizing
|
||||
{
|
||||
{
|
||||
[Scope]
|
||||
public class AzManager
|
||||
{
|
||||
private readonly IPermissionProvider permissionProvider;
|
||||
@ -146,19 +145,4 @@ namespace ASC.Common.Security.Authorizing
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public static class AzManagerConfigExtension
|
||||
{
|
||||
public static DIHelper AddAzManagerService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<AzManager>())
|
||||
{
|
||||
return services
|
||||
.AddPermissionProviderService()
|
||||
.AddRoleProviderService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -27,9 +27,11 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using ASC.Common.Security.Authorizing;
|
||||
|
||||
using ASC.Core.Security.Authorizing;
|
||||
|
||||
namespace ASC.Common.Security
|
||||
{
|
||||
{
|
||||
[Scope(typeof(PermissionProvider))]
|
||||
public interface IPermissionProvider
|
||||
{
|
||||
IEnumerable<Ace> GetAcl(ISubject subject, IAction action, ISecurityObjectId objectId, ISecurityObjectProvider secObjProvider);
|
@ -25,9 +25,11 @@
|
||||
|
||||
|
||||
using ASC.Common.Security.Authorizing;
|
||||
using ASC.Core.Security.Authorizing;
|
||||
|
||||
namespace ASC.Common.Security
|
||||
{
|
||||
{
|
||||
[Scope(typeof(PermissionResolver))]
|
||||
public interface IPermissionResolver
|
||||
{
|
||||
bool Check(ISubject subject, params IAction[] actions);
|
||||
|
@ -26,9 +26,8 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Security;
|
||||
using ASC.Common.Security.Authorizing;
|
||||
|
||||
@ -53,13 +52,4 @@ namespace ASC.Core.Security.Authorizing
|
||||
.Select(r => new Ace(r.ActionId, r.Reaction));
|
||||
}
|
||||
}
|
||||
|
||||
public static class PermissionProviderConfigExtension
|
||||
{
|
||||
public static DIHelper AddPermissionProviderService(this DIHelper services)
|
||||
{
|
||||
services.TryAddScoped(typeof(IPermissionProvider), typeof(PermissionProvider));
|
||||
return services.AddAuthorizationManagerService();
|
||||
}
|
||||
}
|
||||
}
|
@ -36,7 +36,8 @@ using ASC.Common.Security.Authorizing;
|
||||
using Constants = ASC.Core.Configuration.Constants;
|
||||
|
||||
namespace ASC.Core.Security.Authorizing
|
||||
{
|
||||
{
|
||||
[Scope]
|
||||
class PermissionResolver : IPermissionResolver
|
||||
{
|
||||
private readonly AzManager azManager;
|
||||
@ -123,13 +124,4 @@ namespace ASC.Core.Security.Authorizing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class PermissionResolverConfigExtention
|
||||
{
|
||||
public static DIHelper AddPermissionResolverService(this DIHelper services)
|
||||
{
|
||||
services.TryAddScoped(typeof(IPermissionResolver), typeof(PermissionResolver));
|
||||
return services.AddAzManagerService();
|
||||
}
|
||||
}
|
||||
}
|
@ -37,7 +37,8 @@ using ASC.Core.Users;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace ASC.Core.Security.Authorizing
|
||||
{
|
||||
{
|
||||
[Scope]
|
||||
class RoleProvider : IRoleProvider
|
||||
{
|
||||
//circ dep
|
||||
@ -85,13 +86,4 @@ namespace ASC.Core.Security.Authorizing
|
||||
return roles;
|
||||
}
|
||||
}
|
||||
|
||||
public static class RoleProviderConfigExtention
|
||||
{
|
||||
public static DIHelper AddRoleProviderService(this DIHelper services)
|
||||
{
|
||||
services.TryAddScoped(typeof(IRoleProvider), typeof(RoleProvider));
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -41,7 +41,8 @@ using Microsoft.Extensions.Options;
|
||||
using static ASC.Security.Cryptography.EmailValidationKeyProvider;
|
||||
|
||||
namespace ASC.Security.Cryptography
|
||||
{
|
||||
{
|
||||
[Scope]
|
||||
public class EmailValidationKeyProvider
|
||||
{
|
||||
public enum ValidationResult
|
||||
@ -164,6 +165,7 @@ namespace ASC.Security.Cryptography
|
||||
}
|
||||
}
|
||||
|
||||
[Transient]
|
||||
public class EmailValidationKeyModelHelper
|
||||
{
|
||||
private IHttpContextAccessor HttpContextAccessor { get; }
|
||||
@ -272,21 +274,4 @@ namespace ASC.Security.Cryptography
|
||||
return checkKeyResult;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EmailValidationKeyProviderExtension
|
||||
{
|
||||
public static DIHelper AddEmailValidationKeyProviderService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<EmailValidationKeyProvider>())
|
||||
{
|
||||
services.TryAddTransient<EmailValidationKeyModelHelper>();
|
||||
|
||||
return services
|
||||
.AddTenantManagerService()
|
||||
.AddMachinePseudoKeysService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -27,9 +27,11 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using ASC.Common.Security.Authorizing;
|
||||
using ASC.Core.Security.Authorizing;
|
||||
|
||||
namespace ASC.Common.Security
|
||||
{
|
||||
{
|
||||
[Scope(typeof(RoleProvider))]
|
||||
public interface IRoleProvider
|
||||
{
|
||||
List<IRole> GetRoles(ISubject account);
|
||||
|
@ -35,7 +35,8 @@ using ASC.Core.Data;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Common.Settings
|
||||
{
|
||||
{
|
||||
[Scope]
|
||||
public class SettingsManager : DbSettingsManager
|
||||
{
|
||||
public SettingsManager(
|
||||
@ -50,19 +51,4 @@ namespace ASC.Core.Common.Settings
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static class SettingsManagerExtention
|
||||
{
|
||||
public static DIHelper AddSettingsManagerService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<SettingsManager>())
|
||||
{
|
||||
return services
|
||||
.AddAuthContextService()
|
||||
.AddDbSettingsManagerService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -65,6 +65,7 @@ namespace ASC.Core.Tenants
|
||||
}
|
||||
}
|
||||
|
||||
[Scope]
|
||||
public class TenantCookieSettingsHelper
|
||||
{
|
||||
public bool IsVisibleSettings { get; internal set; }
|
||||
@ -119,18 +120,5 @@ namespace ASC.Core.Tenants
|
||||
var expires = settingsTenant.IsDefault() ? DateTime.UtcNow.AddYears(1) : DateTime.UtcNow.AddMinutes(settingsTenant.LifeTime);
|
||||
return expires;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TenantCookieSettingsExtention
|
||||
{
|
||||
public static DIHelper AddTenantCookieSettingsService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<TenantCookieSettingsHelper>())
|
||||
{
|
||||
return services.AddSettingsManagerService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -27,10 +27,13 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using ASC.Common;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace ASC.Core.Tenants
|
||||
{
|
||||
{
|
||||
[Singletone]
|
||||
public class TenantDomainValidator
|
||||
{
|
||||
private static readonly Regex ValidDomain = new Regex("^[a-z0-9]([a-z0-9-]){1,98}[a-z0-9]$",
|
||||
|
@ -32,7 +32,8 @@ using ASC.Common.Utils;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Tenants
|
||||
{
|
||||
{
|
||||
[Scope]
|
||||
class ConfigureTenantUtil : IConfigureNamedOptions<TenantUtil>
|
||||
{
|
||||
private IOptionsSnapshot<TenantManager> TenantManager { get; }
|
||||
@ -59,7 +60,8 @@ namespace ASC.Core.Tenants
|
||||
options.TenantManager = TenantManager.Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Scope(typeof(ConfigureTenantUtil))]
|
||||
public class TenantUtil
|
||||
{
|
||||
internal TenantManager TenantManager { get; set; }
|
||||
@ -146,18 +148,4 @@ namespace ASC.Core.Tenants
|
||||
return DateTimeNow(TimeZoneConverter.GetTimeZone(timeZone));
|
||||
}
|
||||
}
|
||||
|
||||
public static class TenantUtilExtention
|
||||
{
|
||||
public static DIHelper AddTenantUtilService(this DIHelper services)
|
||||
{
|
||||
if (services.TryAddScoped<TenantUtil>())
|
||||
{
|
||||
services.TryAddScoped<IConfigureOptions<TenantUtil>, ConfigureTenantUtil>();
|
||||
return services.AddTenantManagerService();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -31,8 +31,6 @@ namespace ASC.Core.Common.Tests
|
||||
|
||||
using ASC.Common.Utils;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
public class DbBaseTest<TDbService>
|
||||
{
|
||||
protected TDbService Service
|
||||
@ -47,7 +45,7 @@ namespace ASC.Core.Common.Tests
|
||||
private set;
|
||||
}
|
||||
|
||||
internal IConfiguration Configuration { get; set; }
|
||||
internal ConfigurationExtension Configuration { get; set; }
|
||||
|
||||
protected DbBaseTest()
|
||||
{
|
||||
|
@ -34,7 +34,8 @@ using Action = ASC.Common.Security.Authorizing.Action;
|
||||
using AuthConst = ASC.Common.Security.Authorizing.Constants;
|
||||
|
||||
namespace ASC.Core.Users
|
||||
{
|
||||
{
|
||||
[Singletone]
|
||||
public sealed class Constants
|
||||
{
|
||||
public Constants(IConfiguration configuration)
|
||||
@ -144,13 +145,4 @@ namespace ASC.Core.Users
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public static class ConstantsConfigFactory
|
||||
{
|
||||
public static DIHelper AddConstantsService(this DIHelper services)
|
||||
{
|
||||
services.TryAddSingleton<Constants>();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user