diff --git a/build/build.backend.bat b/build/build.backend.bat index a0b36d35893..ff31327afd7 100644 --- a/build/build.backend.bat +++ b/build/build.backend.bat @@ -1,23 +1,33 @@ @echo off -PUSHD %~dp0.. -dotnet build ASC.Web.slnf /fl1 /flp1:LogFile=build/ASC.Web.log;Verbosity=Normal -echo. -echo Install nodejs projects dependencies... +echo Start build backend... echo. +cd /D "%~dp0" +call runasadmin.bat "%~dpnx0" + if %errorlevel% == 0 ( - for /R "build\scripts\" %%f in (*.bat) do ( - echo Run script %%~nxf... - echo. - call build\scripts\%%~nxf - ) -) +call start\stop.bat nopause +dotnet build ..\asc.web.slnf /fl1 /flp1:logfile=asc.web.log;verbosity=normal +echo. + +call start\start.bat nopause +echo install nodejs projects dependencies... echo. -POPD -if "%1"=="nopause" goto start +for /R "scripts\" %%f in (*.bat) do ( + echo Run script %%~nxf... + echo. + call scripts\%%~nxf +) + +echo. + +if "%1"=="nopause" goto end pause -:start \ No newline at end of file + +) + +:end \ No newline at end of file diff --git a/build/build.static.bat b/build/build.static.bat index 6d6b2c4df88..da765bc336b 100644 --- a/build/build.static.bat +++ b/build/build.static.bat @@ -1,6 +1,6 @@ @echo off -PUSHD %~dp0 +cd /D "%~dp0" call runasadmin.bat "%~dpnx0" if %errorlevel% == 0 ( diff --git a/build/buildAndDeploy.bat b/build/buildAndDeploy.bat index d47fe076f86..643da68383e 100644 --- a/build/buildAndDeploy.bat +++ b/build/buildAndDeploy.bat @@ -6,14 +6,11 @@ echo "##########################################################" echo. -PUSHD %~dp0 -setlocal EnableDelayedExpansion - +cd /D "%~dp0" call runasadmin.bat "%~dpnx0" if %errorlevel% == 0 ( -call start\stop.bat nopause echo "FRONT-END static" call build.static.bat nopause @@ -21,9 +18,8 @@ call build.static.bat nopause echo "BACK-END" call build.backend.bat nopause -call start\start.bat nopause - echo. pause -) \ No newline at end of file + +) diff --git a/build/scripts/urlshortener.bat b/build/scripts/urlshortener.bat index 6215530f9f8..de73870bc34 100644 --- a/build/scripts/urlshortener.bat +++ b/build/scripts/urlshortener.bat @@ -1 +1 @@ -yarn install --cwd common/ASC.UrlShortener/ --frozen-lockfile \ No newline at end of file +yarn install --cwd %~dp0../../common/ASC.UrlShortener/ --frozen-lockfile \ No newline at end of file diff --git a/common/ASC.Api.Core/Core/BaseStartup.cs b/common/ASC.Api.Core/Core/BaseStartup.cs index 27f17952cf7..056bd551463 100644 --- a/common/ASC.Api.Core/Core/BaseStartup.cs +++ b/common/ASC.Api.Core/Core/BaseStartup.cs @@ -23,6 +23,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Authorization; @@ -34,6 +35,8 @@ using NLog; using NLog.Extensions.Logging; +using StackExchange.Redis.Extensions.Core.Configuration; + namespace ASC.Api.Core { public abstract class BaseStartup @@ -56,7 +59,7 @@ public BaseStartup(IConfiguration configuration, IHostEnvironment hostEnvironmen if (bool.TryParse(Configuration["core:products"], out var loadProducts)) { LoadProducts = loadProducts; - } + } } public virtual void ConfigureServices(IServiceCollection services) @@ -82,8 +85,8 @@ public virtual void ConfigureServices(IServiceCollection services) { options.JsonSerializerOptions.Converters.Add(c); } - } - }; + } + }; services.AddControllers() .AddXmlSerializerFormatters() @@ -101,7 +104,18 @@ public virtual void ConfigureServices(IServiceCollection services) DIHelper.TryAdd(); DIHelper.TryAdd(); - DIHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>)); + var redisConfiguration = Configuration.GetSection("Redis").Get(); + + if (redisConfiguration != null) + { + DIHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>)); + } + else + { + DIHelper.TryAdd(typeof(ICacheNotify<>), typeof(MemoryCacheNotify<>)); + } + + DIHelper.TryAdd(typeof(IWebhookPublisher), typeof(WebhookPublisher)); if (LoadProducts) diff --git a/common/ASC.Common/ASC.Common.csproj b/common/ASC.Common/ASC.Common.csproj index e589ba86644..6038ef792cc 100644 --- a/common/ASC.Common/ASC.Common.csproj +++ b/common/ASC.Common/ASC.Common.csproj @@ -32,8 +32,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -55,12 +55,14 @@ --> + + - - - - + + + + diff --git a/common/ASC.Common/Caching/AscCache.cs b/common/ASC.Common/Caching/AscCache.cs index 8b593c00f5f..2a62898ad27 100644 --- a/common/ASC.Common/Caching/AscCache.cs +++ b/common/ASC.Common/Caching/AscCache.cs @@ -50,7 +50,7 @@ public AscCacheNotify(ICacheNotify cacheNotify) public void ClearCache() { - CacheNotify.Publish(new AscCacheItem { Id = ByteString.CopyFrom(Guid.NewGuid().ToByteArray()) }, CacheNotifyAction.Any); + CacheNotify.Publish(new AscCacheItem { Id = Guid.NewGuid().ToString() }, CacheNotifyAction.Any); } public static void OnClearCache() diff --git a/common/ASC.Common/Caching/KafkaCache.cs b/common/ASC.Common/Caching/KafkaCache.cs index 2931de38e15..a8bcbbc67b8 100644 --- a/common/ASC.Common/Caching/KafkaCache.cs +++ b/common/ASC.Common/Caching/KafkaCache.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Concurrent; -using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -24,8 +23,6 @@ namespace ASC.Common.Caching private ILog Log { get; set; } private ConcurrentDictionary Cts { get; set; } private ConcurrentDictionary> Actions { get; set; } - private MemoryCacheNotify MemoryCacheNotify { get; set; } - private string ChannelName { get; } = $"ascchannel{typeof(T).Name}"; private ProtobufSerializer ValueSerializer { get; } = new ProtobufSerializer(); private ProtobufDeserializer ValueDeserializer { get; } = new ProtobufDeserializer(); private ProtobufSerializer KeySerializer { get; } = new ProtobufSerializer(); @@ -41,26 +38,13 @@ public KafkaCache(ConfigurationExtension configuration, IOptionsMonitor op Key = Guid.NewGuid(); var settings = configuration.GetSetting("kafka"); - if (settings != null && !string.IsNullOrEmpty(settings.BootstrapServers)) - { - ClientConfig = new ClientConfig { BootstrapServers = settings.BootstrapServers }; - AdminClientConfig = new AdminClientConfig { BootstrapServers = settings.BootstrapServers }; - } - else - { - MemoryCacheNotify = new MemoryCacheNotify(); - } + ClientConfig = new ClientConfig { BootstrapServers = settings.BootstrapServers }; + AdminClientConfig = new AdminClientConfig { BootstrapServers = settings.BootstrapServers }; } public void Publish(T obj, CacheNotifyAction cacheNotifyAction) { - if (ClientConfig == null) - { - MemoryCacheNotify.Publish(obj, cacheNotifyAction); - return; - } - try { if (Producer == null) @@ -84,7 +68,7 @@ public void Publish(T obj, CacheNotifyAction cacheNotifyAction) Value = obj, Key = new AscCacheItem { - Id = ByteString.CopyFrom(Key.ToByteArray()) + Id = Key.ToString() } }; @@ -102,12 +86,8 @@ public void Publish(T obj, CacheNotifyAction cacheNotifyAction) public void Subscribe(Action onchange, CacheNotifyAction cacheNotifyAction) { - if (ClientConfig == null) - { - MemoryCacheNotify.Subscribe(onchange, cacheNotifyAction); - return; - } var channelName = GetChannelName(cacheNotifyAction); + Cts[channelName] = new CancellationTokenSource(); Actions[channelName] = onchange; @@ -137,7 +117,7 @@ void action() } }).Wait(); } - catch(AggregateException) + catch (AggregateException) { } @@ -159,7 +139,7 @@ void action() try { var cr = c.Consume(Cts[channelName].Token); - if (cr != null && cr.Message != null && cr.Message.Value != null && !(new Guid(cr.Message.Key.Id.ToByteArray())).Equals(Key) && Actions.TryGetValue(channelName, out var act)) + if (cr != null && cr.Message != null && cr.Message.Value != null && !(new Guid(cr.Message.Key.Id)).Equals(Key) && Actions.TryGetValue(channelName, out var act)) { try { @@ -189,7 +169,7 @@ void action() private string GetChannelName(CacheNotifyAction cacheNotifyAction) { - return $"{ChannelName}{cacheNotifyAction}"; + return $"asc:channel:{cacheNotifyAction}:{typeof(T).FullName}".ToLower(); } public void Unsubscribe(CacheNotifyAction action) @@ -231,40 +211,4 @@ public class KafkaSettings { public string BootstrapServers { get; set; } } - - public class MemoryCacheNotify : ICacheNotify where T : IMessage, new() - { - private readonly Dictionary>> actions = new Dictionary>>(); - - public void Publish(T obj, CacheNotifyAction action) - { - if (actions.TryGetValue(GetKey(action), out var onchange) && onchange != null) - { - foreach (var a in onchange) - { - a(obj); - } - } - } - - public void Subscribe(Action onchange, CacheNotifyAction notifyAction) - { - if (onchange != null) - { - var key = GetKey(notifyAction); - actions.TryAdd(key, new List>()); - actions[key].Add(onchange); - } - } - - public void Unsubscribe(CacheNotifyAction action) - { - actions.Remove(GetKey(action)); - } - - private string GetKey(CacheNotifyAction cacheNotifyAction) - { - return $"{typeof(T).Name}{cacheNotifyAction}"; - } - } } \ No newline at end of file diff --git a/common/ASC.Common/Caching/MemoryCacheNotify.cs b/common/ASC.Common/Caching/MemoryCacheNotify.cs new file mode 100644 index 00000000000..fa9e1eeb7ec --- /dev/null +++ b/common/ASC.Common/Caching/MemoryCacheNotify.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Threading.Tasks; + +using Google.Protobuf; + +namespace ASC.Common.Caching +{ + [Singletone] + public class MemoryCacheNotify : ICacheNotify where T : IMessage, new() + { + private readonly ConcurrentDictionary>> _actions; + + public MemoryCacheNotify() + { + _actions = new ConcurrentDictionary>>(); + } + + public void Publish(T obj, CacheNotifyAction action) + { + if (_actions.TryGetValue(GetKey(action), out var onchange) && onchange != null) + { + Parallel.ForEach(onchange, a => a(obj)); + } + } + + public void Subscribe(Action onchange, CacheNotifyAction notifyAction) + { + if (onchange != null) + { + var key = GetKey(notifyAction); + _actions.TryAdd(key, new List>()); + _actions[key].Add(onchange); + } + } + + public void Unsubscribe(CacheNotifyAction action) + { + _actions.TryRemove(GetKey(action), out _); + } + + private string GetKey(CacheNotifyAction cacheNotifyAction) + { + return $"asc:channel:{cacheNotifyAction}:{typeof(T).FullName}".ToLower(); + } + } +} \ No newline at end of file diff --git a/common/ASC.Common/Caching/RedisCache.cs b/common/ASC.Common/Caching/RedisCache.cs new file mode 100644 index 00000000000..611831a7bef --- /dev/null +++ b/common/ASC.Common/Caching/RedisCache.cs @@ -0,0 +1,78 @@ +/* + * + * (c) Copyright Ascensio System Limited 2010-2021 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + + +using System; +using System.Threading.Tasks; + +using Google.Protobuf; + +using StackExchange.Redis.Extensions.Core.Abstractions; + +namespace ASC.Common.Caching; + +[Singletone] +public class RedisCache : ICacheNotify where T : IMessage, new() +{ + private readonly IRedisDatabase _redis; + + public RedisCache(IRedisCacheClient redisCacheClient) + { + _redis = redisCacheClient.GetDbFromConfiguration(); + } + + public void Publish(T obj, CacheNotifyAction action) + { + Task.Run(() => _redis.PublishAsync(GetChannelName(action), new RedisCachePubSubItem() { Object = obj, Action = action })) + .GetAwaiter() + .GetResult(); + } + + public void Subscribe(Action onchange, CacheNotifyAction action) + { + Task.Run(() => _redis.SubscribeAsync>(GetChannelName(action), (i) => + { + onchange(i.Object); + + return Task.FromResult(true); + })).GetAwaiter() + .GetResult(); + } + + public void Unsubscribe(CacheNotifyAction action) + { + Task.Run(() => _redis.UnsubscribeAsync>(GetChannelName(action), (i) => + { + return Task.FromResult(true); + })).GetAwaiter() + .GetResult(); + } + + private string GetChannelName(CacheNotifyAction cacheNotifyAction) + { + return $"asc:channel:{cacheNotifyAction}:{typeof(T).FullName}".ToLower(); + } + + class RedisCachePubSubItem + { + public T0 Object { get; set; } + + public CacheNotifyAction Action { get; set; } + } +} + + + diff --git a/common/ASC.Common/protos/DistributedTaskCache.proto b/common/ASC.Common/protos/DistributedTaskCache.proto deleted file mode 100644 index 7f2bbb68c0c..00000000000 --- a/common/ASC.Common/protos/DistributedTaskCache.proto +++ /dev/null @@ -1,21 +0,0 @@ -syntax = "proto3"; - -package ASC.Common.Threading; - -message DistributedTaskCache { - string Id = 1; - int32 InstanceId = 2; - string Status = 3; - string Exception = 4; - repeated DistributedTaskCacheProp Props = 5; - string Key = 6; - double Percentage = 7; - bool IsCompleted = 8; - int32 StepCount = 9; - - message DistributedTaskCacheProp - { - string Key = 1; - string Value = 2; - } -} \ No newline at end of file diff --git a/common/ASC.Common/protos/NotifyItem.proto b/common/ASC.Common/protos/NotifyItem.proto deleted file mode 100644 index 4919bb1fe93..00000000000 --- a/common/ASC.Common/protos/NotifyItem.proto +++ /dev/null @@ -1,32 +0,0 @@ -syntax = "proto3"; -import "google/protobuf/wrappers.proto"; -package ASC.Notify.Model; - -message NotifyItem { - NotifyActionItem Action = 1; - string ObjectID = 2; - repeated Recipient Recipients = 3; - repeated string SenderNames = 4; - repeated Tag Tags = 5; - bool CheckSubsciption = 6; - int32 TenantId = 7; - string UserId = 8; - string BaseUrl = 9; -} - -message NotifyActionItem { - string ID = 1; -} - -message Recipient { - string ID = 1; - google.protobuf.StringValue Name = 2; - bool CheckActivation = 3; - repeated string Addresses = 4; - bool IsGroup = 5; -} - -message Tag { - string Tag = 1; - string Value = 2; -} \ No newline at end of file diff --git a/common/ASC.Common/protos/AscCacheItem.proto b/common/ASC.Common/protos/asc_cache_item.proto similarity index 73% rename from common/ASC.Common/protos/AscCacheItem.proto rename to common/ASC.Common/protos/asc_cache_item.proto index 8fbd2e7cfb1..64af604f94d 100644 --- a/common/ASC.Common/protos/AscCacheItem.proto +++ b/common/ASC.Common/protos/asc_cache_item.proto @@ -1,7 +1,7 @@ -syntax = "proto3"; - -package ASC.Common; - -message AscCacheItem { - bytes Id = 1; +syntax = "proto3"; + +package ASC.Common; + +message AscCacheItem { + string id = 1; } \ No newline at end of file diff --git a/common/ASC.Common/protos/distributed_task_cache.proto b/common/ASC.Common/protos/distributed_task_cache.proto new file mode 100644 index 00000000000..780710e04f0 --- /dev/null +++ b/common/ASC.Common/protos/distributed_task_cache.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; + +package ASC.Common.Threading; + +message DistributedTaskCache { + string id = 1; + int32 instance_id = 2; + string status = 3; + string exception = 4; + repeated DistributedTaskCacheProp props = 5; + string key = 6; + double percentage = 7; + bool is_completed = 8; + int32 step_count = 9; + + message DistributedTaskCacheProp + { + string key = 1; + string value = 2; + } +} \ No newline at end of file diff --git a/common/ASC.Common/protos/DistributedTaskCancelation.proto b/common/ASC.Common/protos/distributed_task_cancelation.proto similarity index 78% rename from common/ASC.Common/protos/DistributedTaskCancelation.proto rename to common/ASC.Common/protos/distributed_task_cancelation.proto index 83fbe222655..e6e96ef8ce2 100644 --- a/common/ASC.Common/protos/DistributedTaskCancelation.proto +++ b/common/ASC.Common/protos/distributed_task_cancelation.proto @@ -1,7 +1,7 @@ -syntax = "proto3"; - -package ASC.Common.Threading; - -message DistributedTaskCancelation { - string Id = 1; +syntax = "proto3"; + +package ASC.Common.Threading; + +message DistributedTaskCancelation { + string id = 1; } \ No newline at end of file diff --git a/common/ASC.Common/protos/notify_item.proto b/common/ASC.Common/protos/notify_item.proto new file mode 100644 index 00000000000..d0db117272e --- /dev/null +++ b/common/ASC.Common/protos/notify_item.proto @@ -0,0 +1,32 @@ +syntax = "proto3"; +import "google/protobuf/wrappers.proto"; +package ASC.Notify.Model; + +message NotifyItem { + NotifyActionItem action = 1; + string object_id = 2; + repeated Recipient recipients = 3; + repeated string sender_names = 4; + repeated Tag tags = 5; + bool check_subsciption = 6; + int32 tenant_id = 7; + string user_id = 8; + string base_url = 9; +} + +message NotifyActionItem { + string id = 1; +} + +message Recipient { + string id = 1; + google.protobuf.StringValue name = 2; + bool check_activation = 3; + repeated string addresses = 4; + bool is_group = 5; +} + +message Tag { + string tag = 1; + string value = 2; +} \ No newline at end of file diff --git a/common/ASC.Core.Common/ASC.Core.Common.csproj b/common/ASC.Core.Common/ASC.Core.Common.csproj index 03472ef3f89..f6a18017c4d 100644 --- a/common/ASC.Core.Common/ASC.Core.Common.csproj +++ b/common/ASC.Core.Common/ASC.Core.Common.csproj @@ -29,29 +29,29 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -61,25 +61,25 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/common/ASC.Core.Common/Caching/CachedUserService.cs b/common/ASC.Core.Common/Caching/CachedUserService.cs index 7981dfb673d..ce07a463b31 100644 --- a/common/ASC.Core.Common/Caching/CachedUserService.cs +++ b/common/ASC.Core.Common/Caching/CachedUserService.cs @@ -85,7 +85,7 @@ private void InvalidateCache(UserInfoCacheItem userInfo) { if (userInfo != null) { - var key = GetUserCacheKey(userInfo.Tenant, userInfo.ID.FromByteString()); + var key = GetUserCacheKey(userInfo.Tenant, new Guid(userInfo.Id)); Cache.Remove(key); } } @@ -275,14 +275,14 @@ public IEnumerable GetUsersAllTenants(IEnumerable userIds) public UserInfo SaveUser(int tenant, UserInfo user) { user = Service.SaveUser(tenant, user); - CacheUserInfoItem.Publish(new UserInfoCacheItem { ID = user.ID.ToByteString(), Tenant = tenant }, CacheNotifyAction.Any); + CacheUserInfoItem.Publish(new UserInfoCacheItem { Id = user.ID.ToString(), Tenant = tenant }, CacheNotifyAction.Any); return user; } public void RemoveUser(int tenant, Guid id) { Service.RemoveUser(tenant, id); - CacheUserInfoItem.Publish(new UserInfoCacheItem { Tenant = tenant, ID = id.ToByteString() }, CacheNotifyAction.Any); + CacheUserInfoItem.Publish(new UserInfoCacheItem { Tenant = tenant, Id = id.ToString() }, CacheNotifyAction.Any); } public byte[] GetUserPhoto(int tenant, Guid id) @@ -330,14 +330,14 @@ public Group GetGroup(int tenant, Guid id) public Group SaveGroup(int tenant, Group group) { group = Service.SaveGroup(tenant, group); - CacheGroupCacheItem.Publish(new GroupCacheItem { ID = group.Id.ToString() }, CacheNotifyAction.Any); + CacheGroupCacheItem.Publish(new GroupCacheItem { Id = group.Id.ToString() }, CacheNotifyAction.Any); return group; } public void RemoveGroup(int tenant, Guid id) { Service.RemoveGroup(tenant, id); - CacheGroupCacheItem.Publish(new GroupCacheItem { ID = id.ToString() }, CacheNotifyAction.Any); + CacheGroupCacheItem.Publish(new GroupCacheItem { Id = id.ToString() }, CacheNotifyAction.Any); } diff --git a/common/ASC.Core.Common/Core/UserGroupRef.cs b/common/ASC.Core.Common/Core/UserGroupRef.cs index 38a9c6593d9..7b7fc291dac 100644 --- a/common/ASC.Core.Common/Core/UserGroupRef.cs +++ b/common/ASC.Core.Common/Core/UserGroupRef.cs @@ -83,8 +83,8 @@ public static implicit operator UserGroupRef(UserGroupRefCacheItem cache) { var result = new UserGroupRef { - UserId = cache.UserId.FromByteString(), - GroupId = cache.GroupId.FromByteString() + UserId = new Guid(cache.UserId), + GroupId = new Guid(cache.GroupId) }; if (Enum.TryParse(cache.RefType, out var refType)) @@ -103,8 +103,8 @@ public static implicit operator UserGroupRefCacheItem(UserGroupRef cache) { return new UserGroupRefCacheItem { - GroupId = cache.GroupId.ToByteString(), - UserId = cache.UserId.ToByteString(), + GroupId = cache.GroupId.ToString(), + UserId = cache.UserId.ToString(), RefType = cache.RefType.ToString(), LastModified = cache.LastModified.Ticks, Removed = cache.Removed, diff --git a/common/ASC.Core.Common/Notify/Model/NotifyAction.cs b/common/ASC.Core.Common/Notify/Model/NotifyAction.cs index 58318c2f440..e2900b27584 100644 --- a/common/ASC.Core.Common/Notify/Model/NotifyAction.cs +++ b/common/ASC.Core.Common/Notify/Model/NotifyAction.cs @@ -49,12 +49,12 @@ public NotifyAction(string id, string name) public static implicit operator NotifyActionItem(NotifyAction cache) { - return new NotifyActionItem() { ID = cache.ID }; + return new NotifyActionItem() { Id = cache.ID }; } public static explicit operator NotifyAction(NotifyActionItem cache) { - return new NotifyAction(cache.ID); + return new NotifyAction(cache.Id); } public override bool Equals(object obj) diff --git a/common/ASC.Core.Common/protos/AzRecordCache.proto b/common/ASC.Core.Common/protos/AzRecordCache.proto deleted file mode 100644 index 1775498b5c3..00000000000 --- a/common/ASC.Core.Common/protos/AzRecordCache.proto +++ /dev/null @@ -1,15 +0,0 @@ -syntax = "proto3"; -import "google/protobuf/wrappers.proto"; -package ASC.Core; - -message AzRecordCache { - google.protobuf.StringValue SubjectId = 1; - - google.protobuf.StringValue ActionId = 2; - - google.protobuf.StringValue ObjectId = 3; - - google.protobuf.StringValue Reaction = 4; - - int32 Tenant = 5; -} \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/CreateClientProto.proto b/common/ASC.Core.Common/protos/CreateClientProto.proto deleted file mode 100644 index c0bfd0ea012..00000000000 --- a/common/ASC.Core.Common/protos/CreateClientProto.proto +++ /dev/null @@ -1,11 +0,0 @@ -syntax = "proto3"; - -package ASC.Core.Common.Notify; - -message CreateClientProto { - int32 TenantId = 1; - string Token = 2; - int32 TokenLifespan = 3; - string Proxy = 4; - string Time = 5; -} \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/EncryptionSettingsProto.proto b/common/ASC.Core.Common/protos/EncryptionSettingsProto.proto deleted file mode 100644 index 12e71258f07..00000000000 --- a/common/ASC.Core.Common/protos/EncryptionSettingsProto.proto +++ /dev/null @@ -1,17 +0,0 @@ -syntax = "proto3"; - -package ASC.Core.Encryption; - -message EncryptionSettingsProto { - string password = 1; - EncryprtionStatus Status = 2; - bool NotifyUsers = 3; - string ServerRootPath = 4; -} - -enum EncryprtionStatus { - Decrypted = 0; - EncryptionStarted = 1; - Encrypted = 2; - DecryptionStarted = 3; -} \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/NotifyInvoke.proto b/common/ASC.Core.Common/protos/NotifyInvoke.proto deleted file mode 100644 index 0f9aba7ff22..00000000000 --- a/common/ASC.Core.Common/protos/NotifyInvoke.proto +++ /dev/null @@ -1,10 +0,0 @@ -syntax = "proto3"; - -package ASC.Notify.Messages; - -message NotifyInvoke { - string Service = 1; - string Method = 2; - int32 Tenant = 3; - repeated string Parameters = 4; -} \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/NotifyMessage.proto b/common/ASC.Core.Common/protos/NotifyMessage.proto deleted file mode 100644 index 14e3a637a99..00000000000 --- a/common/ASC.Core.Common/protos/NotifyMessage.proto +++ /dev/null @@ -1,23 +0,0 @@ -syntax = "proto3"; - -package ASC.Notify.Messages; - -message NotifyMessage { - int32 Tenant = 1; - string Sender = 2; - string From = 3; - string To = 4; - string ReplyTo = 5; - string Subject = 6; - string ContentType = 7; - string Content = 8; - int64 CreationDate = 9; - int32 Priority = 10; - repeated NotifyMessageAttachment EmbeddedAttachments = 11; - string AutoSubmitted = 12; -} -message NotifyMessageAttachment { - string FileName = 1; - string ContentId = 2; - bytes Content = 3; -} \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/SubscriptionMethodCache.proto b/common/ASC.Core.Common/protos/SubscriptionMethodCache.proto deleted file mode 100644 index 9fb80effc09..00000000000 --- a/common/ASC.Core.Common/protos/SubscriptionMethodCache.proto +++ /dev/null @@ -1,15 +0,0 @@ -syntax = "proto3"; - -package ASC.Core; - -message SubscriptionMethodCache { - string RecipientId = 1; - - string ActionId = 2; - - string SourceId = 3; - - repeated string Methods = 4; - - int32 Tenant = 5; -} \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/SubscriptionRecord.proto b/common/ASC.Core.Common/protos/SubscriptionRecord.proto deleted file mode 100644 index d2a02087408..00000000000 --- a/common/ASC.Core.Common/protos/SubscriptionRecord.proto +++ /dev/null @@ -1,17 +0,0 @@ -syntax = "proto3"; - -package ASC.Core; - -message SubscriptionRecord { - string RecipientId = 1; - - string ActionId = 2; - - string ObjectId = 3; - - string SourceId = 4; - - bool Subscribed = 5; - - int32 Tenant = 6; -} \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/UserGroupRefCacheItem.proto b/common/ASC.Core.Common/protos/UserGroupRefCacheItem.proto deleted file mode 100644 index bd86dae4969..00000000000 --- a/common/ASC.Core.Common/protos/UserGroupRefCacheItem.proto +++ /dev/null @@ -1,12 +0,0 @@ -syntax = "proto3"; - -package ASC.Core.Caching; - -message UserGroupRefCacheItem { - bytes UserId = 1; - bytes GroupId = 2; - bool Removed = 3; - string RefType = 4; - int64 LastModified = 5; - int32 Tenant = 6; -} diff --git a/common/ASC.Core.Common/protos/az_record_cache.proto b/common/ASC.Core.Common/protos/az_record_cache.proto new file mode 100644 index 00000000000..81cc843d281 --- /dev/null +++ b/common/ASC.Core.Common/protos/az_record_cache.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; +import "google/protobuf/wrappers.proto"; +package ASC.Core; + +message AzRecordCache { + google.protobuf.StringValue subject_id = 1; + + google.protobuf.StringValue action_id = 2; + + google.protobuf.StringValue object_id = 3; + + google.protobuf.StringValue reaction = 4; + + int32 tenant = 5; +} \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/ConsumerCacheItem.proto b/common/ASC.Core.Common/protos/consumer_cache_item.proto similarity index 63% rename from common/ASC.Core.Common/protos/ConsumerCacheItem.proto rename to common/ASC.Core.Common/protos/consumer_cache_item.proto index 7c4ee11ca14..629e46c1fd2 100644 --- a/common/ASC.Core.Common/protos/ConsumerCacheItem.proto +++ b/common/ASC.Core.Common/protos/consumer_cache_item.proto @@ -1,8 +1,8 @@ -syntax = "proto3"; - -package ASC.Core.Common.Configuration; - -message ConsumerCacheItem { - string Name = 1; - int32 TenantId = 2; +syntax = "proto3"; + +package ASC.Core.Common.Configuration; + +message ConsumerCacheItem { + string name = 1; + int32 tenant_id = 2; } \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/create_client_proto.proto b/common/ASC.Core.Common/protos/create_client_proto.proto new file mode 100644 index 00000000000..26d02d59d8c --- /dev/null +++ b/common/ASC.Core.Common/protos/create_client_proto.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package ASC.Core.Common.Notify; + +message CreateClientProto { + int32 tenant_id = 1; + string token = 2; + int32 token_lifespan = 3; + string proxy = 4; + string time = 5; +} \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/DisableClientProto.proto b/common/ASC.Core.Common/protos/disable_client_proto.proto similarity index 78% rename from common/ASC.Core.Common/protos/DisableClientProto.proto rename to common/ASC.Core.Common/protos/disable_client_proto.proto index 1eff1e9df96..8d0a30e5ed2 100644 --- a/common/ASC.Core.Common/protos/DisableClientProto.proto +++ b/common/ASC.Core.Common/protos/disable_client_proto.proto @@ -3,5 +3,5 @@ package ASC.Core.Common.Notify; message DisableClientProto { - int32 TenantId= 1; + int32 tenant_id= 1; } \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/encryption_settings_proto.proto b/common/ASC.Core.Common/protos/encryption_settings_proto.proto new file mode 100644 index 00000000000..2b95954f1bd --- /dev/null +++ b/common/ASC.Core.Common/protos/encryption_settings_proto.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + +package ASC.Core.Encryption; + +message EncryptionSettingsProto { + string password = 1; + EncryprtionStatus status = 2; + bool notify_users = 3; + string server_root_path = 4; +} + +enum EncryprtionStatus { + DECRYPTED = 0; + ENCRYPTION_STARTED = 1; + ENCRYPTED = 2; + DECRYPTION_STARTED = 3; +} \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/GroupCacheItem.proto b/common/ASC.Core.Common/protos/group_cache_item.proto similarity index 74% rename from common/ASC.Core.Common/protos/GroupCacheItem.proto rename to common/ASC.Core.Common/protos/group_cache_item.proto index bc17b85572c..e8d3fa5e891 100644 --- a/common/ASC.Core.Common/protos/GroupCacheItem.proto +++ b/common/ASC.Core.Common/protos/group_cache_item.proto @@ -1,7 +1,7 @@ -syntax = "proto3"; - -package ASC.Core.Caching; - -message GroupCacheItem { - string ID = 1; +syntax = "proto3"; + +package ASC.Core.Caching; + +message GroupCacheItem { + string id = 1; } \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/notify_invoke.proto b/common/ASC.Core.Common/protos/notify_invoke.proto new file mode 100644 index 00000000000..166cf5668b9 --- /dev/null +++ b/common/ASC.Core.Common/protos/notify_invoke.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package ASC.Notify.Messages; + +message NotifyInvoke { + string service = 1; + string method = 2; + int32 tenant = 3; + repeated string parameters = 4; +} \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/notify_message.proto b/common/ASC.Core.Common/protos/notify_message.proto new file mode 100644 index 00000000000..c70bfd8a5c0 --- /dev/null +++ b/common/ASC.Core.Common/protos/notify_message.proto @@ -0,0 +1,23 @@ +syntax = "proto3"; + +package ASC.Notify.Messages; + +message NotifyMessage { + int32 tenant = 1; + string sender = 2; + string from = 3; + string to = 4; + string reply_to = 5; + string subject = 6; + string content_type = 7; + string content = 8; + int64 creation_date = 9; + int32 priority = 10; + repeated NotifyMessageAttachment embedded_attachments = 11; + string auto_submitted = 12; +} +message NotifyMessageAttachment { + string FileName = 1; + string ContentId = 2; + bytes Content = 3; +} \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/QuotaCacheItem.proto b/common/ASC.Core.Common/protos/quota_cache_item.proto similarity index 74% rename from common/ASC.Core.Common/protos/QuotaCacheItem.proto rename to common/ASC.Core.Common/protos/quota_cache_item.proto index 4e3424dd0a7..ef66f8c5e56 100644 --- a/common/ASC.Core.Common/protos/QuotaCacheItem.proto +++ b/common/ASC.Core.Common/protos/quota_cache_item.proto @@ -1,7 +1,7 @@ -syntax = "proto3"; - -package ASC.Core.Caching; - -message QuotaCacheItem { - string Key = 1; +syntax = "proto3"; + +package ASC.Core.Caching; + +message QuotaCacheItem { + string key = 1; } \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/RegisterUserProto.proto b/common/ASC.Core.Common/protos/register_user_proto.proto similarity index 55% rename from common/ASC.Core.Common/protos/RegisterUserProto.proto rename to common/ASC.Core.Common/protos/register_user_proto.proto index 1a91b33fb63..9bd6a44895c 100644 --- a/common/ASC.Core.Common/protos/RegisterUserProto.proto +++ b/common/ASC.Core.Common/protos/register_user_proto.proto @@ -3,7 +3,7 @@ package ASC.Core.Common.Notify; message RegisterUserProto { - string UserId= 1; - int32 TenantId= 2; - string Token= 3; + string user_id= 1; + int32 tenant_id= 2; + string token= 3; } diff --git a/common/ASC.Core.Common/protos/SettingsCacheItem.proto b/common/ASC.Core.Common/protos/settings_cache_item.proto similarity index 73% rename from common/ASC.Core.Common/protos/SettingsCacheItem.proto rename to common/ASC.Core.Common/protos/settings_cache_item.proto index 5ea510fd59b..b8bd4a1cac0 100644 --- a/common/ASC.Core.Common/protos/SettingsCacheItem.proto +++ b/common/ASC.Core.Common/protos/settings_cache_item.proto @@ -1,7 +1,7 @@ -syntax = "proto3"; - -package ASC.Core.Data; - -message SettingsCacheItem { - string Key = 1; +syntax = "proto3"; + +package ASC.Core.Data; + +message SettingsCacheItem { + string key = 1; } \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/subscription_method_cache.proto b/common/ASC.Core.Common/protos/subscription_method_cache.proto new file mode 100644 index 00000000000..8fc05e7bcc8 --- /dev/null +++ b/common/ASC.Core.Common/protos/subscription_method_cache.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package ASC.Core; + +message SubscriptionMethodCache { + string recipient_id = 1; + + string action_id = 2; + + string source_id = 3; + + repeated string methods = 4; + + int32 tenant = 5; +} \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/subscription_record.proto b/common/ASC.Core.Common/protos/subscription_record.proto new file mode 100644 index 00000000000..f21bc14034f --- /dev/null +++ b/common/ASC.Core.Common/protos/subscription_record.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + +package ASC.Core; + +message SubscriptionRecord { + string recipient_id = 1; + + string action_id = 2; + + string object_id = 3; + + string source_id = 4; + + bool subscribed = 5; + + int32 tenant = 6; +} \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/TariffCacheItem.proto b/common/ASC.Core.Common/protos/tariff_cache_item.proto similarity index 71% rename from common/ASC.Core.Common/protos/TariffCacheItem.proto rename to common/ASC.Core.Common/protos/tariff_cache_item.proto index f4dd7c07512..14f68940daa 100644 --- a/common/ASC.Core.Common/protos/TariffCacheItem.proto +++ b/common/ASC.Core.Common/protos/tariff_cache_item.proto @@ -1,7 +1,7 @@ -syntax = "proto3"; - -package ASC.Core.Billing; - -message TariffCacheItem { - int32 TenantId = 1; +syntax = "proto3"; + +package ASC.Core.Billing; + +message TariffCacheItem { + int32 tenant_id = 1; } \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/TenantCacheItem.proto b/common/ASC.Core.Common/protos/tenant_cache_item.proto similarity index 71% rename from common/ASC.Core.Common/protos/TenantCacheItem.proto rename to common/ASC.Core.Common/protos/tenant_cache_item.proto index c727da08893..6e43399a382 100644 --- a/common/ASC.Core.Common/protos/TenantCacheItem.proto +++ b/common/ASC.Core.Common/protos/tenant_cache_item.proto @@ -1,7 +1,7 @@ -syntax = "proto3"; - -package ASC.Core.Caching; - -message TenantCacheItem { - int32 TenantId = 1; +syntax = "proto3"; + +package ASC.Core.Caching; + +message TenantCacheItem { + int32 tenant_id = 1; } \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/TenantSetting.proto b/common/ASC.Core.Common/protos/tenant_setting.proto similarity index 73% rename from common/ASC.Core.Common/protos/TenantSetting.proto rename to common/ASC.Core.Common/protos/tenant_setting.proto index d150289d629..a9e0a9c0999 100644 --- a/common/ASC.Core.Common/protos/TenantSetting.proto +++ b/common/ASC.Core.Common/protos/tenant_setting.proto @@ -1,7 +1,7 @@ -syntax = "proto3"; - -package ASC.Core.Caching; - -message TenantSetting { - string Key = 1; +syntax = "proto3"; + +package ASC.Core.Caching; + +message TenantSetting { + string key = 1; } \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/user_group_ref_cache_item.proto b/common/ASC.Core.Common/protos/user_group_ref_cache_item.proto new file mode 100644 index 00000000000..43a1e327ce0 --- /dev/null +++ b/common/ASC.Core.Common/protos/user_group_ref_cache_item.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +package ASC.Core.Caching; + +message UserGroupRefCacheItem { + string user_id = 1; + string group_id = 2; + bool removed = 3; + string ref_type = 4; + int64 last_modified = 5; + int32 tenant = 6; +} diff --git a/common/ASC.Core.Common/protos/UserInfoCacheItem.proto b/common/ASC.Core.Common/protos/user_info_cache_item.proto similarity index 61% rename from common/ASC.Core.Common/protos/UserInfoCacheItem.proto rename to common/ASC.Core.Common/protos/user_info_cache_item.proto index 5f19f1d139a..3ba117ba43d 100644 --- a/common/ASC.Core.Common/protos/UserInfoCacheItem.proto +++ b/common/ASC.Core.Common/protos/user_info_cache_item.proto @@ -1,8 +1,8 @@ -syntax = "proto3"; - -package ASC.Core.Caching; - -message UserInfoCacheItem { - bytes ID = 1; - int32 Tenant = 2; +syntax = "proto3"; + +package ASC.Core.Caching; + +message UserInfoCacheItem { + string id = 1; + int32 tenant = 2; } \ No newline at end of file diff --git a/common/ASC.Core.Common/protos/UserPhotoCacheItem.proto b/common/ASC.Core.Common/protos/user_photo_cache_item.proto similarity index 74% rename from common/ASC.Core.Common/protos/UserPhotoCacheItem.proto rename to common/ASC.Core.Common/protos/user_photo_cache_item.proto index 0360fe83ed3..222eb422af9 100644 --- a/common/ASC.Core.Common/protos/UserPhotoCacheItem.proto +++ b/common/ASC.Core.Common/protos/user_photo_cache_item.proto @@ -1,7 +1,7 @@ -syntax = "proto3"; - -package ASC.Core.Caching; - -message UserPhotoCacheItem { - string Key = 1; +syntax = "proto3"; + +package ASC.Core.Caching; + +message UserPhotoCacheItem { + string key = 1; } \ No newline at end of file diff --git a/common/ASC.Data.Backup.Core/ASC.Data.Backup.Core.csproj b/common/ASC.Data.Backup.Core/ASC.Data.Backup.Core.csproj index d8ca0f0d762..d497d215970 100644 --- a/common/ASC.Data.Backup.Core/ASC.Data.Backup.Core.csproj +++ b/common/ASC.Data.Backup.Core/ASC.Data.Backup.Core.csproj @@ -8,15 +8,15 @@ - - + + true - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -29,8 +29,8 @@ - - + + diff --git a/common/ASC.Data.Backup.Core/BackupAjaxHandler.cs b/common/ASC.Data.Backup.Core/BackupAjaxHandler.cs index 694fd05bf90..ba1b96a747e 100644 --- a/common/ASC.Data.Backup.Core/BackupAjaxHandler.cs +++ b/common/ASC.Data.Backup.Core/BackupAjaxHandler.cs @@ -9,7 +9,7 @@ using ASC.Core.Common.Configuration; using ASC.Core.Users; using ASC.Data.Backup.Contracts; -using ASC.Data.Backup.Service; +using ASC.Data.Backup.Services; using ASC.MessagingSystem; using ASC.Notify.Cron; using ASC.Web.Core.PublicResources; diff --git a/common/ASC.Data.Backup.Core/Listerners/BackupListener.cs b/common/ASC.Data.Backup.Core/Listerners/BackupListener.cs deleted file mode 100644 index 6828fd591c4..00000000000 --- a/common/ASC.Data.Backup.Core/Listerners/BackupListener.cs +++ /dev/null @@ -1,42 +0,0 @@ - -using System; - -using ASC.Common; -using ASC.Common.Caching; -using ASC.Data.Backup.Contracts; -using ASC.Data.Backup.Service; - -using Microsoft.Extensions.DependencyInjection; - -namespace ASC.Data.Backup.Listerners -{ - [Singletone] - public class BackupListener - { - private ICacheNotify CacheDeleteSchedule { get; } - private IServiceProvider ServiceProvider { get; } - - public BackupListener(ICacheNotify cacheDeleteSchedule, IServiceProvider serviceProvider) - { - CacheDeleteSchedule = cacheDeleteSchedule; - ServiceProvider = serviceProvider; - } - - public void Start() - { - CacheDeleteSchedule.Subscribe((n) => DeleteScheldure(n), CacheNotifyAction.Insert); - } - - public void Stop() - { - CacheDeleteSchedule.Unsubscribe(CacheNotifyAction.Insert); - } - - public void DeleteScheldure(DeleteSchedule deleteSchedule) - { - using var scope = ServiceProvider.CreateScope(); - var backupService = scope.ServiceProvider.GetService(); - backupService.DeleteSchedule(deleteSchedule.TenantId); - } - } -} diff --git a/common/ASC.Data.Backup.Core/Service/BackupService.cs b/common/ASC.Data.Backup.Core/Service/BackupService.cs index 6e2a4f43d72..087e6f66562 100644 --- a/common/ASC.Data.Backup.Core/Service/BackupService.cs +++ b/common/ASC.Data.Backup.Core/Service/BackupService.cs @@ -42,7 +42,7 @@ using Newtonsoft.Json; -namespace ASC.Data.Backup.Service +namespace ASC.Data.Backup.Services { [Scope] public class BackupService : IBackupService diff --git a/common/ASC.Data.Backup.Core/Service/BackupSettings.cs b/common/ASC.Data.Backup.Core/Service/BackupSettings.cs index 6081f0bdcc1..552419eda7a 100644 --- a/common/ASC.Data.Backup.Core/Service/BackupSettings.cs +++ b/common/ASC.Data.Backup.Core/Service/BackupSettings.cs @@ -3,7 +3,7 @@ using ASC.Common.Utils; -namespace ASC.Data.Backup.Service +namespace ASC.Data.Backup.Services { public class BackupSettings { diff --git a/common/ASC.Data.Backup.Core/Service/BackupWorker.cs b/common/ASC.Data.Backup.Core/Service/BackupWorker.cs index 634a54d7d38..ff32c687e07 100644 --- a/common/ASC.Data.Backup.Core/Service/BackupWorker.cs +++ b/common/ASC.Data.Backup.Core/Service/BackupWorker.cs @@ -51,7 +51,7 @@ using Newtonsoft.Json; -namespace ASC.Data.Backup.Service +namespace ASC.Data.Backup.Services { [Singletone(Additional = typeof(BackupWorkerExtension))] public class BackupWorker diff --git a/common/ASC.Data.Backup.Core/Storage/BackupStorageFactory.cs b/common/ASC.Data.Backup.Core/Storage/BackupStorageFactory.cs index 1047310e08d..b7aadbd4544 100644 --- a/common/ASC.Data.Backup.Core/Storage/BackupStorageFactory.cs +++ b/common/ASC.Data.Backup.Core/Storage/BackupStorageFactory.cs @@ -33,7 +33,7 @@ using ASC.Core; using ASC.Data.Backup.Contracts; using ASC.Data.Backup.EF.Model; -using ASC.Data.Backup.Service; +using ASC.Data.Backup.Services; using ASC.Data.Backup.Utils; using Microsoft.Extensions.Options; diff --git a/common/ASC.Data.Backup.Core/protos/BackupProgress.proto b/common/ASC.Data.Backup.Core/protos/BackupProgress.proto deleted file mode 100644 index 0b3740f43ae..00000000000 --- a/common/ASC.Data.Backup.Core/protos/BackupProgress.proto +++ /dev/null @@ -1,18 +0,0 @@ -syntax = "proto3"; - -package ASC.Data.Backup.Contracts; - -message BackupProgress { - bool IsCompleted = 1; - int32 Progress = 2; - string Error = 3; - string Link = 4; - int32 TenantId = 5; - BackupProgressEnum BackupProgressEnum = 6; -} - -enum BackupProgressEnum { - Backup = 0; - Restore = 1; - Transfer = 2; -} \ No newline at end of file diff --git a/common/ASC.Data.Backup.Core/protos/backup_progress.proto b/common/ASC.Data.Backup.Core/protos/backup_progress.proto new file mode 100644 index 00000000000..142eb6a2b1a --- /dev/null +++ b/common/ASC.Data.Backup.Core/protos/backup_progress.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +package ASC.Data.Backup.Contracts; + +message BackupProgress { + bool is_completed = 1; + int32 progress = 2; + string error = 3; + string link = 4; + int32 tenant_id = 5; + BackupProgressEnum backup_progress_enum = 6; +} + +enum BackupProgressEnum { + BACKUP = 0; + RESTORE = 1; + TRANSFER = 2; +} \ No newline at end of file diff --git a/common/ASC.Data.Backup.Core/protos/DeleteSchedule.proto b/common/ASC.Data.Backup.Core/protos/delete_schedule.proto similarity index 77% rename from common/ASC.Data.Backup.Core/protos/DeleteSchedule.proto rename to common/ASC.Data.Backup.Core/protos/delete_schedule.proto index 89a20a8c0aa..82dd12d7c09 100644 --- a/common/ASC.Data.Backup.Core/protos/DeleteSchedule.proto +++ b/common/ASC.Data.Backup.Core/protos/delete_schedule.proto @@ -3,5 +3,5 @@ package ASC.Data.Backup.Contracts; message DeleteSchedule { - int32 TenantId = 1; + int32 tenant_id = 1; } diff --git a/common/ASC.Data.Storage/ASC.Data.Storage.csproj b/common/ASC.Data.Storage/ASC.Data.Storage.csproj index a6e77e865c6..80827e1fca3 100644 --- a/common/ASC.Data.Storage/ASC.Data.Storage.csproj +++ b/common/ASC.Data.Storage/ASC.Data.Storage.csproj @@ -22,11 +22,11 @@ - - - - - + + + + + @@ -38,7 +38,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -50,12 +50,12 @@ - - - - - - + + + + + + diff --git a/common/ASC.Data.Storage/Migration/MigrateServiceClient.cs b/common/ASC.Data.Storage/Migration/MigrateServiceClient.cs index 43deceb0616..4ee2df02162 100644 --- a/common/ASC.Data.Storage/Migration/MigrateServiceClient.cs +++ b/common/ASC.Data.Storage/Migration/MigrateServiceClient.cs @@ -102,7 +102,7 @@ public ServiceClient( public void Migrate(int tenant, StorageSettings storageSettings) { - var storSettings = new StorSettings { ID = storageSettings.ID.ToString(), Module = storageSettings.Module }; + var storSettings = new StorSettings { Id = storageSettings.ID.ToString(), Module = storageSettings.Module }; CacheMigrationNotify.Publish(new MigrationCache { @@ -114,7 +114,7 @@ public void Migrate(int tenant, StorageSettings storageSettings) public void UploadCdn(int tenantId, string relativePath, string mappedPath, CdnStorageSettings settings = null) { - var cdnStorSettings = new CdnStorSettings { ID = settings.ID.ToString(), Module = settings.Module }; + var cdnStorSettings = new CdnStorSettings { Id = settings.ID.ToString(), Module = settings.Module }; UploadCdnMigrationNotify.Publish(new MigrationUploadCdn { diff --git a/common/ASC.Data.Storage/protos/MigrationProgress.proto b/common/ASC.Data.Storage/protos/MigrationProgress.proto deleted file mode 100644 index 0b9ff4224d9..00000000000 --- a/common/ASC.Data.Storage/protos/MigrationProgress.proto +++ /dev/null @@ -1,11 +0,0 @@ -syntax = "proto3"; - -package ASC.Protos.Migration; - -message MigrationProgress{ - bool IsCompleted = 1; - double Progress = 2; - string Error = 3; - string Link = 4; - int32 TenantId = 5; -} diff --git a/common/ASC.Data.Storage/protos/MigrationUploadCdn.proto b/common/ASC.Data.Storage/protos/MigrationUploadCdn.proto deleted file mode 100644 index f2f1d6d475d..00000000000 --- a/common/ASC.Data.Storage/protos/MigrationUploadCdn.proto +++ /dev/null @@ -1,16 +0,0 @@ -syntax = "proto3"; - -package ASC.Protos.Migration; - -message MigrationUploadCdn { - int32 Tenant = 1; - string RelativePath = 2; - string MappedPath = 3; - CdnStorSettings CdnStorSettings = 4; -} - -message CdnStorSettings { - string ID = 1; - string Module = 2; -} - diff --git a/common/ASC.Data.Storage/protos/DataStoreCacheItem.proto b/common/ASC.Data.Storage/protos/data_store_cache_item.proto similarity index 57% rename from common/ASC.Data.Storage/protos/DataStoreCacheItem.proto rename to common/ASC.Data.Storage/protos/data_store_cache_item.proto index 27007b2ec38..002aacf4ac1 100644 --- a/common/ASC.Data.Storage/protos/DataStoreCacheItem.proto +++ b/common/ASC.Data.Storage/protos/data_store_cache_item.proto @@ -1,9 +1,9 @@ -syntax = "proto3"; - -package ASC.Core; - -message DataStoreCacheItem { - string Module = 1; +syntax = "proto3"; - string TenantId = 2; +package ASC.Core; + +message DataStoreCacheItem { + string module = 1; + + string tenant_id = 2; } \ No newline at end of file diff --git a/common/ASC.Data.Storage/protos/EncryptionStop.proto b/common/ASC.Data.Storage/protos/encryption_stop.proto similarity index 100% rename from common/ASC.Data.Storage/protos/EncryptionStop.proto rename to common/ASC.Data.Storage/protos/encryption_stop.proto diff --git a/common/ASC.Data.Storage/protos/MigrationCache.proto b/common/ASC.Data.Storage/protos/migration_cache.proto similarity index 53% rename from common/ASC.Data.Storage/protos/MigrationCache.proto rename to common/ASC.Data.Storage/protos/migration_cache.proto index 3555b4ab1f9..dc0955ede45 100644 --- a/common/ASC.Data.Storage/protos/MigrationCache.proto +++ b/common/ASC.Data.Storage/protos/migration_cache.proto @@ -3,12 +3,12 @@ syntax = "proto3"; package ASC.Protos.Migration; message MigrationCache { - int32 TenantId = 1; - StorSettings StorSettings = 2; + int32 tenant_id = 1; + StorSettings stor_settings = 2; } message StorSettings { - string ID = 1; - string Module = 2; + string id = 1; + string module = 2; } diff --git a/common/ASC.Data.Storage/protos/migration_progress.proto b/common/ASC.Data.Storage/protos/migration_progress.proto new file mode 100644 index 00000000000..fe1a7165cf5 --- /dev/null +++ b/common/ASC.Data.Storage/protos/migration_progress.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package ASC.Protos.Migration; + +message MigrationProgress{ + bool is_completed = 1; + double progress = 2; + string error = 3; + string link = 4; + int32 tenant_id = 5; +} diff --git a/common/ASC.Data.Storage/protos/migration_upload_cdn.proto b/common/ASC.Data.Storage/protos/migration_upload_cdn.proto new file mode 100644 index 00000000000..65a69732d5e --- /dev/null +++ b/common/ASC.Data.Storage/protos/migration_upload_cdn.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; + +package ASC.Protos.Migration; + +message MigrationUploadCdn { + int32 tenant = 1; + string relative_path = 2; + string mapped_path = 3; + CdnStorSettings cdn_stor_settings = 4; +} + +message CdnStorSettings { + string id = 1; + string module = 2; +} + diff --git a/common/ASC.Data.Storage/protos/ProgressEncryption.proto b/common/ASC.Data.Storage/protos/progress_encryption.proto similarity index 64% rename from common/ASC.Data.Storage/protos/ProgressEncryption.proto rename to common/ASC.Data.Storage/protos/progress_encryption.proto index 16dbd3f2582..235b2b5ad58 100644 --- a/common/ASC.Data.Storage/protos/ProgressEncryption.proto +++ b/common/ASC.Data.Storage/protos/progress_encryption.proto @@ -3,6 +3,6 @@ package ASC.Data.Storage.Encryption; message ProgressEncryption { - double Progress = 1; - int32 TenantId = 2; + double progress = 1; + int32 tenant_id = 2; } \ No newline at end of file diff --git a/common/ASC.FederatedLogin/ASC.FederatedLogin.csproj b/common/ASC.FederatedLogin/ASC.FederatedLogin.csproj index 8176a612b47..71605e7ea18 100644 --- a/common/ASC.FederatedLogin/ASC.FederatedLogin.csproj +++ b/common/ASC.FederatedLogin/ASC.FederatedLogin.csproj @@ -26,7 +26,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -37,7 +37,7 @@ - + diff --git a/common/ASC.FederatedLogin/protos/LinkerCacheItem.proto b/common/ASC.FederatedLogin/protos/linker_cache_item.proto similarity index 75% rename from common/ASC.FederatedLogin/protos/LinkerCacheItem.proto rename to common/ASC.FederatedLogin/protos/linker_cache_item.proto index cb9312b4452..8b37caa3898 100644 --- a/common/ASC.FederatedLogin/protos/LinkerCacheItem.proto +++ b/common/ASC.FederatedLogin/protos/linker_cache_item.proto @@ -1,7 +1,7 @@ -syntax = "proto3"; - -package ASC.FederatedLogin; - -message LinkerCacheItem { - string Obj = 1; +syntax = "proto3"; + +package ASC.FederatedLogin; + +message LinkerCacheItem { + string obj = 1; } \ No newline at end of file diff --git a/common/ASC.IPSecurity/ASC.IPSecurity.csproj b/common/ASC.IPSecurity/ASC.IPSecurity.csproj index 292cea489d9..9a2e9296e6d 100644 --- a/common/ASC.IPSecurity/ASC.IPSecurity.csproj +++ b/common/ASC.IPSecurity/ASC.IPSecurity.csproj @@ -14,7 +14,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -24,6 +24,6 @@ - + diff --git a/common/ASC.IPSecurity/protos/IPRestrictionItem.proto b/common/ASC.IPSecurity/protos/ip_restriction_item.proto similarity index 72% rename from common/ASC.IPSecurity/protos/IPRestrictionItem.proto rename to common/ASC.IPSecurity/protos/ip_restriction_item.proto index bdf27f8af0c..63314a47fad 100644 --- a/common/ASC.IPSecurity/protos/IPRestrictionItem.proto +++ b/common/ASC.IPSecurity/protos/ip_restriction_item.proto @@ -1,7 +1,7 @@ -syntax = "proto3"; - -package ASC.IPSecurity; - +syntax = "proto3"; + +package ASC.IPSecurity; + message IPRestrictionItem { - int32 TenantId = 1; + int32 tenant_id = 1; } \ No newline at end of file diff --git a/common/ASC.VoipService/ASC.VoipService.csproj b/common/ASC.VoipService/ASC.VoipService.csproj index 0d3f8982d85..43a83627c9e 100644 --- a/common/ASC.VoipService/ASC.VoipService.csproj +++ b/common/ASC.VoipService/ASC.VoipService.csproj @@ -22,7 +22,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -34,6 +34,6 @@ - + diff --git a/common/ASC.VoipService/protos/CachedVoipItem.proto b/common/ASC.VoipService/protos/cached_voip_item.proto similarity index 74% rename from common/ASC.VoipService/protos/CachedVoipItem.proto rename to common/ASC.VoipService/protos/cached_voip_item.proto index 3dc2088bab9..a49b56ca520 100644 --- a/common/ASC.VoipService/protos/CachedVoipItem.proto +++ b/common/ASC.VoipService/protos/cached_voip_item.proto @@ -1,7 +1,7 @@ -syntax = "proto3"; - -package ASC.VoipService.Dao; - +syntax = "proto3"; + +package ASC.VoipService.Dao; + message CachedVoipItem { - int32 Tenant = 1; + int32 tenant = 1; } \ No newline at end of file diff --git a/common/ASC.Webhooks.Core/ASC.Webhooks.Core.csproj b/common/ASC.Webhooks.Core/ASC.Webhooks.Core.csproj index 757b905bcd6..b96022a0351 100644 --- a/common/ASC.Webhooks.Core/ASC.Webhooks.Core.csproj +++ b/common/ASC.Webhooks.Core/ASC.Webhooks.Core.csproj @@ -15,11 +15,11 @@ - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -30,7 +30,7 @@ - + diff --git a/common/ASC.Webhooks.Core/proto/WebhookRequest.proto b/common/ASC.Webhooks.Core/proto/webhook_request.proto similarity index 80% rename from common/ASC.Webhooks.Core/proto/WebhookRequest.proto rename to common/ASC.Webhooks.Core/proto/webhook_request.proto index 2fc52bdcf76..cf18fab409d 100644 --- a/common/ASC.Webhooks.Core/proto/WebhookRequest.proto +++ b/common/ASC.Webhooks.Core/proto/webhook_request.proto @@ -3,5 +3,5 @@ syntax = "proto3"; package ASC.Web.Webhooks; message WebhookRequest { - int32 Id = 1; + int32 id = 1; }; \ No newline at end of file diff --git a/common/Tests/ASC.Core.Common.Tests/DbTenantServiceTest.cs b/common/Tests/ASC.Core.Common.Tests/DbTenantServiceTest.cs index 5f9797a3ed2..8931f295be7 100644 --- a/common/Tests/ASC.Core.Common.Tests/DbTenantServiceTest.cs +++ b/common/Tests/ASC.Core.Common.Tests/DbTenantServiceTest.cs @@ -21,9 +21,9 @@ * in every copy of the program you distribute. * Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks. * -*/ - - +*/ + +/* #if DEBUG namespace ASC.Core.Common.Tests { @@ -206,3 +206,4 @@ private void ValidateDomain(string domain, Type expectException) } } #endif +*/ \ No newline at end of file diff --git a/common/Tests/ASC.Core.Common.Tests/DbUserServiceTest.cs b/common/Tests/ASC.Core.Common.Tests/DbUserServiceTest.cs index f46c292b646..6ba75348246 100644 --- a/common/Tests/ASC.Core.Common.Tests/DbUserServiceTest.cs +++ b/common/Tests/ASC.Core.Common.Tests/DbUserServiceTest.cs @@ -21,9 +21,9 @@ * in every copy of the program you distribute. * Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks. * -*/ - - +*/ + +/* #if DEBUG namespace ASC.Core.Common.Tests { @@ -251,3 +251,4 @@ private void CompareGroups(Group g1, Group g2) } } #endif +*/ \ No newline at end of file diff --git a/common/Tests/ASC.Web.Api.Tests/ASC.Web.Api.Tests.csproj b/common/Tests/ASC.Web.Api.Tests/ASC.Web.Api.Tests.csproj index ad20bfb09ec..a5cd45612ed 100644 --- a/common/Tests/ASC.Web.Api.Tests/ASC.Web.Api.Tests.csproj +++ b/common/Tests/ASC.Web.Api.Tests/ASC.Web.Api.Tests.csproj @@ -9,7 +9,7 @@ - + diff --git a/common/Tests/ASC.Webhooks.Tests/ASC.Webhooks.Tests.csproj b/common/Tests/ASC.Webhooks.Tests/ASC.Webhooks.Tests.csproj index 76510b0ef5a..afcf5794a70 100644 --- a/common/Tests/ASC.Webhooks.Tests/ASC.Webhooks.Tests.csproj +++ b/common/Tests/ASC.Webhooks.Tests/ASC.Webhooks.Tests.csproj @@ -11,7 +11,7 @@ - + diff --git a/common/services/ASC.ApiSystem/ASC.ApiSystem.csproj b/common/services/ASC.ApiSystem/ASC.ApiSystem.csproj index 12116118822..2afb061d9e1 100644 --- a/common/services/ASC.ApiSystem/ASC.ApiSystem.csproj +++ b/common/services/ASC.ApiSystem/ASC.ApiSystem.csproj @@ -20,6 +20,8 @@ + + diff --git a/common/services/ASC.ApiSystem/Program.cs b/common/services/ASC.ApiSystem/Program.cs index e28b91f1e8a..f719305901a 100644 --- a/common/services/ASC.ApiSystem/Program.cs +++ b/common/services/ASC.ApiSystem/Program.cs @@ -93,6 +93,8 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .AddJsonFile("storage.json") .AddJsonFile("kafka.json") .AddJsonFile($"kafka.{hostingContext.HostingEnvironment.EnvironmentName}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{hostingContext.HostingEnvironment.EnvironmentName}.json", true) .AddEnvironmentVariables() .AddCommandLine(args) .AddInMemoryCollection(new Dictionary diff --git a/common/services/ASC.ApiSystem/Startup.cs b/common/services/ASC.ApiSystem/Startup.cs index e2544032288..a52b62d689b 100644 --- a/common/services/ASC.ApiSystem/Startup.cs +++ b/common/services/ASC.ApiSystem/Startup.cs @@ -40,9 +40,11 @@ using Microsoft.AspNetCore.HttpOverrides; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - - +using Microsoft.Extensions.Hosting; + +using StackExchange.Redis.Extensions.Core.Configuration; +using StackExchange.Redis.Extensions.Newtonsoft; + namespace ASC.ApiSystem { public class Startup : BaseWorkerStartup @@ -73,7 +75,17 @@ public override void ConfigureServices(IServiceCollection services) services.AddMemoryCache(); - diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>)); + var redisConfiguration = Configuration.GetSection("Redis").Get(); + + if (redisConfiguration != null) + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>)); + } + else + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(MemoryCacheNotify<>)); + } + diHelper.TryAdd(); diHelper.TryAdd(); diHelper.TryAdd(); @@ -82,7 +94,9 @@ public override void ConfigureServices(IServiceCollection services) services.AddAuthentication() .AddScheme("auth.allowskip", _ => { }) - .AddScheme("auth.allowskip.registerportal", _ => { }); + .AddScheme("auth.allowskip.registerportal", _ => { }); + + services.AddStackExchangeRedisExtensions(Configuration.GetSection("Redis").Get()); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/common/services/ASC.ClearEvents/Program.cs b/common/services/ASC.ClearEvents/Program.cs index 2214cf7600c..5ab33a691e1 100644 --- a/common/services/ASC.ClearEvents/Program.cs +++ b/common/services/ASC.ClearEvents/Program.cs @@ -39,12 +39,13 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - - +using Microsoft.Extensions.Hosting; + +using StackExchange.Redis.Extensions.Core.Configuration; + namespace ASC.Thumbnails.Svc -{ - public class Program +{ +public class Program { public async static Task Main(string[] args) { @@ -81,9 +82,19 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .ConfigureServices((hostContext, services) => { services.AddMemoryCache(); - var diHelper = new DIHelper(services); + var diHelper = new DIHelper(services); + + var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get(); + + if (redisConfiguration != null) + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>)); + } + else + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(MemoryCacheNotify<>)); + } - diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>)); services.AddHostedService(); diHelper.TryAdd(); }) diff --git a/common/services/ASC.Data.Backup/ASC.Data.Backup.csproj b/common/services/ASC.Data.Backup/ASC.Data.Backup.csproj index a4979374918..b524df23aaa 100644 --- a/common/services/ASC.Data.Backup/ASC.Data.Backup.csproj +++ b/common/services/ASC.Data.Backup/ASC.Data.Backup.csproj @@ -24,6 +24,8 @@ + + diff --git a/common/services/ASC.Data.Backup/Controllers/BackupController.cs b/common/services/ASC.Data.Backup/Api/BackupController.cs similarity index 70% rename from common/services/ASC.Data.Backup/Controllers/BackupController.cs rename to common/services/ASC.Data.Backup/Api/BackupController.cs index 67b805a5d32..59c3bb92748 100644 --- a/common/services/ASC.Data.Backup/Controllers/BackupController.cs +++ b/common/services/ASC.Data.Backup/Api/BackupController.cs @@ -6,8 +6,7 @@ using ASC.Common; using ASC.Core; using ASC.Data.Backup.Contracts; -using ASC.Data.Backup.ModelApi; -using ASC.Data.Backup.Models; +using ASC.Data.Backup.ApiModels; using ASC.Web.Api.Routing; using ASC.Web.Studio.Utility; @@ -22,18 +21,18 @@ namespace ASC.Data.Backup.Controllers [ApiController] public class BackupController { - private BackupAjaxHandler BackupHandler { get; } - private CoreBaseSettings CoreBaseSettings { get; } - private TenantExtra TenantExtra { get; } + private readonly BackupAjaxHandler _backupHandler; + private readonly CoreBaseSettings _coreBaseSettings; + private readonly TenantExtra _tenantExtra; public BackupController( BackupAjaxHandler backupAjaxHandler, CoreBaseSettings coreBaseSettings, TenantExtra tenantExtra) { - BackupHandler = backupAjaxHandler; - CoreBaseSettings = coreBaseSettings; - TenantExtra = tenantExtra; + _backupHandler = backupAjaxHandler; + _coreBaseSettings = coreBaseSettings; + _tenantExtra = tenantExtra; } /// /// Returns the backup schedule of the current portal @@ -43,12 +42,12 @@ public BackupController( [Read("getbackupschedule")] public BackupAjaxHandler.Schedule GetBackupSchedule() { - if (CoreBaseSettings.Standalone) + if (_coreBaseSettings.Standalone) { - TenantExtra.DemandControlPanelPermission(); + _tenantExtra.DemandControlPanelPermission(); } - return BackupHandler.GetSchedule(); + return _backupHandler.GetSchedule(); } /// @@ -61,23 +60,23 @@ public BackupAjaxHandler.Schedule GetBackupSchedule() /// Include mail in the backup /// Backup [Create("createbackupschedule")] - public bool CreateBackupScheduleFromBody([FromBody]BackupSchedule backupSchedule) + public bool CreateBackupScheduleFromBody([FromBody]BackupScheduleDto backupSchedule) { return CreateBackupSchedule(backupSchedule); } [Create("createbackupschedule")] [Consumes("application/x-www-form-urlencoded")] - public bool CreateBackupScheduleFromForm([FromForm]BackupSchedule backupSchedule) + public bool CreateBackupScheduleFromForm([FromForm]BackupScheduleDto backupSchedule) { return CreateBackupSchedule(backupSchedule); } - private bool CreateBackupSchedule(BackupSchedule backupSchedule) + private bool CreateBackupSchedule(BackupScheduleDto backupSchedule) { - if (CoreBaseSettings.Standalone) + if (_coreBaseSettings.Standalone) { - TenantExtra.DemandControlPanelPermission(); + _tenantExtra.DemandControlPanelPermission(); } var storageType = backupSchedule.StorageType == null ? BackupStorageType.Documents : (BackupStorageType)Int32.Parse(backupSchedule.StorageType); var storageParams = backupSchedule.StorageParams == null ? new Dictionary() : backupSchedule.StorageParams.ToDictionary(r => r.Key.ToString(), r => r.Value.ToString()); @@ -88,7 +87,7 @@ private bool CreateBackupSchedule(BackupSchedule backupSchedule) Hour = backupSchedule.CronParams.Hour == null ? 0 : Int32.Parse(backupSchedule.CronParams.Hour), Day = backupSchedule.CronParams.Day == null ? 0 : Int32.Parse(backupSchedule.CronParams.Day), }; - BackupHandler.CreateSchedule(storageType, storageParams, backupStored, cron, backupSchedule.BackupMail); + _backupHandler.CreateSchedule(storageType, storageParams, backupStored, cron, backupSchedule.BackupMail); return true; } @@ -99,12 +98,12 @@ private bool CreateBackupSchedule(BackupSchedule backupSchedule) [Delete("deletebackupschedule")] public bool DeleteBackupSchedule() { - if (CoreBaseSettings.Standalone) + if (_coreBaseSettings.Standalone) { - TenantExtra.DemandControlPanelPermission(); + _tenantExtra.DemandControlPanelPermission(); } - BackupHandler.DeleteSchedule(); + _backupHandler.DeleteSchedule(); return true; } @@ -118,28 +117,28 @@ public bool DeleteBackupSchedule() /// Backup /// Backup Progress [Create("startbackup")] - public BackupProgress StartBackupFromBody([FromBody]Models.Backup backup) + public BackupProgress StartBackupFromBody([FromBody]BackupDto backup) { return StartBackup(backup); } [Create("startbackup")] [Consumes("application/x-www-form-urlencoded")] - public BackupProgress StartBackupFromForm([FromForm]Models.Backup backup) + public BackupProgress StartBackupFromForm([FromForm]BackupDto backup) { return StartBackup(backup); } - private BackupProgress StartBackup(Models.Backup backup) + private BackupProgress StartBackup(BackupDto backup) { - if (CoreBaseSettings.Standalone) + if (_coreBaseSettings.Standalone) { - TenantExtra.DemandControlPanelPermission(); + _tenantExtra.DemandControlPanelPermission(); } var storageType = backup.StorageType == null ? BackupStorageType.Documents : (BackupStorageType)Int32.Parse(backup.StorageType); var storageParams = backup.StorageParams == null ? new Dictionary() : backup.StorageParams.ToDictionary(r => r.Key.ToString(), r => r.Value.ToString()); - BackupHandler.StartBackup(storageType, storageParams, backup.BackupMail); - return BackupHandler.GetBackupProgress(); + _backupHandler.StartBackup(storageType, storageParams, backup.BackupMail); + return _backupHandler.GetBackupProgress(); } /// @@ -150,12 +149,12 @@ private BackupProgress StartBackup(Models.Backup backup) [Read("getbackupprogress")] public BackupProgress GetBackupProgress() { - if (CoreBaseSettings.Standalone) + if (_coreBaseSettings.Standalone) { - TenantExtra.DemandControlPanelPermission(); + _tenantExtra.DemandControlPanelPermission(); } - return BackupHandler.GetBackupProgress(); + return _backupHandler.GetBackupProgress(); } /// @@ -166,12 +165,12 @@ public BackupProgress GetBackupProgress() [Read("getbackuphistory")] public List GetBackupHistory() { - if (CoreBaseSettings.Standalone) + if (_coreBaseSettings.Standalone) { - TenantExtra.DemandControlPanelPermission(); + _tenantExtra.DemandControlPanelPermission(); } - return BackupHandler.GetBackupHistory(); + return _backupHandler.GetBackupHistory(); } /// @@ -181,12 +180,12 @@ public List GetBackupHistory() [Delete("deletebackup/{id}")] public bool DeleteBackup(Guid id) { - if (CoreBaseSettings.Standalone) + if (_coreBaseSettings.Standalone) { - TenantExtra.DemandControlPanelPermission(); + _tenantExtra.DemandControlPanelPermission(); } - BackupHandler.DeleteBackup(id); + _backupHandler.DeleteBackup(id); return true; } @@ -198,12 +197,12 @@ public bool DeleteBackup(Guid id) [Delete("deletebackuphistory")] public bool DeleteBackupHistory() { - if (CoreBaseSettings.Standalone) + if (_coreBaseSettings.Standalone) { - TenantExtra.DemandControlPanelPermission(); + _tenantExtra.DemandControlPanelPermission(); } - BackupHandler.DeleteAllBackups(); + _backupHandler.DeleteAllBackups(); return true; } @@ -217,27 +216,27 @@ public bool DeleteBackupHistory() /// Backup /// Restore Progress [Create("startrestore")] - public BackupProgress StartBackupRestoreFromBody([FromBody]BackupRestore backupRestore) + public BackupProgress StartBackupRestoreFromBody([FromBody]BackupRestoreDto backupRestore) { return StartBackupRestore(backupRestore); } [Create("startrestore")] [Consumes("application/x-www-form-urlencoded")] - public BackupProgress StartBackupRestoreFromForm([FromForm]BackupRestore backupRestore) + public BackupProgress StartBackupRestoreFromForm([FromForm]BackupRestoreDto backupRestore) { return StartBackupRestore(backupRestore); } - private BackupProgress StartBackupRestore(BackupRestore backupRestore) + private BackupProgress StartBackupRestore(BackupRestoreDto backupRestore) { - if (CoreBaseSettings.Standalone) + if (_coreBaseSettings.Standalone) { - TenantExtra.DemandControlPanelPermission(); + _tenantExtra.DemandControlPanelPermission(); } var storageParams = backupRestore.StorageParams == null ? new Dictionary() : backupRestore.StorageParams.ToDictionary(r => r.Key.ToString(), r => r.Value.ToString()); - BackupHandler.StartRestore(backupRestore.BackupId, (BackupStorageType)Int32.Parse(backupRestore.StorageType.ToString()), storageParams, backupRestore.Notify); - return BackupHandler.GetBackupProgress(); + _backupHandler.StartRestore(backupRestore.BackupId, (BackupStorageType)Int32.Parse(backupRestore.StorageType.ToString()), storageParams, backupRestore.Notify); + return _backupHandler.GetBackupProgress(); } /// @@ -248,24 +247,24 @@ private BackupProgress StartBackupRestore(BackupRestore backupRestore) [Read("getrestoreprogress", true)] //NOTE: this method doesn't check payment!!! public BackupProgress GetRestoreProgress() { - if (CoreBaseSettings.Standalone) + if (_coreBaseSettings.Standalone) { - TenantExtra.DemandControlPanelPermission(); + _tenantExtra.DemandControlPanelPermission(); } - return BackupHandler.GetRestoreProgress(); + return _backupHandler.GetRestoreProgress(); } ///false [Read("backuptmp")] public object GetTempPath() { - if (CoreBaseSettings.Standalone) + if (_coreBaseSettings.Standalone) { - TenantExtra.DemandControlPanelPermission(); + _tenantExtra.DemandControlPanelPermission(); } - return BackupHandler.GetTmpFolder(); + return _backupHandler.GetTmpFolder(); } } } diff --git a/common/services/ASC.Data.Backup/ModelApi/Backup.cs b/common/services/ASC.Data.Backup/ApiModels/BackupDto.cs similarity index 80% rename from common/services/ASC.Data.Backup/ModelApi/Backup.cs rename to common/services/ASC.Data.Backup/ApiModels/BackupDto.cs index edd9583d3da..a79f9fe271f 100644 --- a/common/services/ASC.Data.Backup/ModelApi/Backup.cs +++ b/common/services/ASC.Data.Backup/ApiModels/BackupDto.cs @@ -3,11 +3,10 @@ using ASC.Api.Collections; -namespace ASC.Data.Backup.Models +namespace ASC.Data.Backup.ApiModels { - public class Backup + public class BackupDto { - public string StorageType { get; set; } public bool BackupMail { get; set; } public IEnumerable> StorageParams { get; set; } diff --git a/common/services/ASC.Data.Backup/ModelApi/BackupRestore.cs b/common/services/ASC.Data.Backup/ApiModels/BackupRestoreDto.cs similarity index 81% rename from common/services/ASC.Data.Backup/ModelApi/BackupRestore.cs rename to common/services/ASC.Data.Backup/ApiModels/BackupRestoreDto.cs index f34503b7dfd..694252a55ba 100644 --- a/common/services/ASC.Data.Backup/ModelApi/BackupRestore.cs +++ b/common/services/ASC.Data.Backup/ApiModels/BackupRestoreDto.cs @@ -2,9 +2,9 @@ using ASC.Api.Collections; -namespace ASC.Data.Backup.Models +namespace ASC.Data.Backup.ApiModels { - public class BackupRestore + public class BackupRestoreDto { public string BackupId { get; set; } public object StorageType { get; set; } diff --git a/common/services/ASC.Data.Backup/ModelApi/BackupSchedule.cs b/common/services/ASC.Data.Backup/ApiModels/BackupScheduleDto.cs similarity index 87% rename from common/services/ASC.Data.Backup/ModelApi/BackupSchedule.cs rename to common/services/ASC.Data.Backup/ApiModels/BackupScheduleDto.cs index 3d21bea195c..b4569fc525c 100644 --- a/common/services/ASC.Data.Backup/ModelApi/BackupSchedule.cs +++ b/common/services/ASC.Data.Backup/ApiModels/BackupScheduleDto.cs @@ -2,9 +2,9 @@ using ASC.Api.Collections; -namespace ASC.Data.Backup.ModelApi +namespace ASC.Data.Backup.ApiModels { - public class BackupSchedule + public class BackupScheduleDto { public string StorageType { get; set; } public IEnumerable> StorageParams { get; set; } diff --git a/common/services/ASC.Data.Backup/BackupCleanerService.cs b/common/services/ASC.Data.Backup/BackupCleanerService.cs deleted file mode 100644 index eccf93f26dd..00000000000 --- a/common/services/ASC.Data.Backup/BackupCleanerService.cs +++ /dev/null @@ -1,192 +0,0 @@ -/* - * - * (c) Copyright Ascensio System Limited 2010-2020 - * - * This program is freeware. You can redistribute it and/or modify it under the terms of the GNU - * General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html). - * In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that - * Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights. - * - * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR - * FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html - * - * You can contact Ascensio System SIA by email at sales@onlyoffice.com - * - * The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display - * Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3. - * - * Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains - * relevant author attributions when distributing the software. If the display of the logo in its graphic - * form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE" - * in every copy of the program you distribute. - * Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks. - * -*/ - - -using System; -using System.Linq; -using System.Threading; - -using ASC.Common; -using ASC.Common.Logging; -using ASC.Data.Backup.Storage; -using ASC.Files.Core; - -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; - -namespace ASC.Data.Backup.Service -{ - [Scope] - internal class BackupCleanerHelperService - { - private readonly ILog log; - - private BackupRepository BackupRepository { get; } - private BackupStorageFactory BackupStorageFactory { get; } - - public BackupCleanerHelperService( - IOptionsMonitor options, - BackupRepository backupRepository, - BackupStorageFactory backupStorageFactory) - { - log = options.CurrentValue; - BackupRepository = backupRepository; - BackupStorageFactory = backupStorageFactory; - } - - - internal void DeleteExpiredBackups(BackupCleanerService backupCleanerService) - { - log.Debug("started to clean expired backups"); - - var backupsToRemove = BackupRepository.GetExpiredBackupRecords(); - log.DebugFormat("found {0} backups which are expired", backupsToRemove.Count); - - if (!backupCleanerService.IsStarted) return; - foreach (var scheduledBackups in BackupRepository.GetScheduledBackupRecords().GroupBy(r => r.TenantId)) - { - if (!backupCleanerService.IsStarted) return; - var schedule = BackupRepository.GetBackupSchedule(scheduledBackups.Key); - if (schedule != null) - { - var scheduledBackupsToRemove = scheduledBackups.OrderByDescending(r => r.CreatedOn).Skip(schedule.BackupsStored).ToList(); - if (scheduledBackupsToRemove.Any()) - { - log.DebugFormat("only last {0} scheduled backup records are to keep for tenant {1} so {2} records must be removed", schedule.BackupsStored, schedule.TenantId, scheduledBackupsToRemove.Count); - backupsToRemove.AddRange(scheduledBackupsToRemove); - } - } - else - { - backupsToRemove.AddRange(scheduledBackups); - } - } - - foreach (var backupRecord in backupsToRemove) - { - if (!backupCleanerService.IsStarted) return; - try - { - var backupStorage = BackupStorageFactory.GetBackupStorage(backupRecord); - if (backupStorage == null) continue; - - backupStorage.Delete(backupRecord.StoragePath); - - BackupRepository.DeleteBackupRecord(backupRecord.Id); - } - catch (ProviderInfoArgumentException error) - { - log.Warn("can't remove backup record " + backupRecord.Id, error); - if (DateTime.UtcNow > backupRecord.CreatedOn.AddMonths(6)) - { - BackupRepository.DeleteBackupRecord(backupRecord.Id); - } - } - catch (Exception error) - { - log.Warn("can't remove backup record: " + backupRecord.Id, error); - } - } - } - } - - [Singletone(Additional = typeof(BackupCleanerServiceExtension))] - public class BackupCleanerService - { - private readonly object cleanerLock = new object(); - private Timer CleanTimer { get; set; } - internal bool IsStarted { get; set; } - private ILog Log { get; set; } - public TimeSpan Period { get; set; } - private IServiceProvider ServiceProvider { get; set; } - - public BackupCleanerService( - IOptionsMonitor options, - IServiceProvider serviceProvider) - { - ServiceProvider = serviceProvider; - Log = options.CurrentValue; - Period = TimeSpan.FromMinutes(15); - } - - - public void Start() - { - if (!IsStarted && Period > TimeSpan.Zero) - { - Log.Info("starting backup cleaner service..."); - CleanTimer = new Timer(_ => DeleteExpiredBackups(), null, TimeSpan.Zero, Period); - Log.Info("backup cleaner service started"); - IsStarted = true; - } - } - - public void Stop() - { - if (IsStarted) - { - Log.Info("stopping backup cleaner service..."); - if (CleanTimer != null) - { - CleanTimer.Change(Timeout.Infinite, Timeout.Infinite); - CleanTimer.Dispose(); - CleanTimer = null; - } - Log.Info("backup cleaner service stopped"); - IsStarted = false; - } - } - - private void DeleteExpiredBackups() - { - if (Monitor.TryEnter(cleanerLock)) - { - try - { - - using var scope = ServiceProvider.CreateScope(); - var backupCleanerHelperService = scope.ServiceProvider.GetService(); - backupCleanerHelperService.DeleteExpiredBackups(this); - } - catch (Exception error) - { - Log.Error("error while cleaning expired backup records: {0}", error); - } - finally - { - Monitor.Exit(cleanerLock); - } - } - } - } - - public class BackupCleanerServiceExtension - { - public static void Register(DIHelper services) - { - services.TryAdd(); - } - } -} diff --git a/common/services/ASC.Data.Backup/BackupSchedulerService.cs b/common/services/ASC.Data.Backup/BackupSchedulerService.cs deleted file mode 100644 index b26a3033f51..00000000000 --- a/common/services/ASC.Data.Backup/BackupSchedulerService.cs +++ /dev/null @@ -1,187 +0,0 @@ -/* - * - * (c) Copyright Ascensio System Limited 2010-2020 - * - * This program is freeware. You can redistribute it and/or modify it under the terms of the GNU - * General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html). - * In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that - * Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights. - * - * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR - * FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html - * - * You can contact Ascensio System SIA by email at sales@onlyoffice.com - * - * The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display - * Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3. - * - * Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains - * relevant author attributions when distributing the software. If the display of the logo in its graphic - * form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE" - * in every copy of the program you distribute. - * Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks. - * -*/ - - -using System; -using System.Linq; -using System.Threading; - -using ASC.Common; -using ASC.Common.Logging; -using ASC.Core; -using ASC.Core.Billing; -using ASC.Data.Backup.Storage; - -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; - -namespace ASC.Data.Backup.Service -{ - [Scope] - internal class BackupSchedulerServiceHelper - { - private ILog Log { get; } - private PaymentManager PaymentManager { get; } - private BackupWorker BackupWorker { get; } - private BackupRepository BackupRepository { get; } - private Schedule Schedule { get; } - private TenantManager TenantManager { get; } - private CoreBaseSettings CoreBaseSettings { get; } - - public BackupSchedulerServiceHelper( - IOptionsMonitor options, - PaymentManager paymentManager, - BackupWorker backupWorker, - BackupRepository backupRepository, - Schedule schedule, - TenantManager tenantManager, - CoreBaseSettings coreBaseSettings) - { - PaymentManager = paymentManager; - BackupWorker = backupWorker; - BackupRepository = backupRepository; - Schedule = schedule; - TenantManager = tenantManager; - CoreBaseSettings = coreBaseSettings; - Log = options.CurrentValue; - } - - public void ScheduleBackupTasks(BackupSchedulerService backupSchedulerService) - { - Log.DebugFormat("started to schedule backups"); - var backupsToSchedule = BackupRepository.GetBackupSchedules().Where(schedule => Schedule.IsToBeProcessed(schedule)).ToList(); - Log.DebugFormat("{0} backups are to schedule", backupsToSchedule.Count); - foreach (var schedule in backupsToSchedule) - { - if (!backupSchedulerService.IsStarted) - { - return; - } - try - { - if (CoreBaseSettings.Standalone || TenantManager.GetTenantQuota(schedule.TenantId).AutoBackup) - { - var tariff = PaymentManager.GetTariff(schedule.TenantId); - if (tariff.State < TariffState.Delay) - { - schedule.LastBackupTime = DateTime.UtcNow; - BackupRepository.SaveBackupSchedule(schedule); - Log.DebugFormat("Start scheduled backup: {0}, {1}, {2}, {3}", schedule.TenantId, schedule.BackupMail, schedule.StorageType, schedule.StorageBasePath); - BackupWorker.StartScheduledBackup(schedule); - } - else - { - Log.DebugFormat("Skip portal {0} not paid", schedule.TenantId); - } - } - else - { - Log.DebugFormat("Skip portal {0} haven't access", schedule.TenantId); - } - } - catch (Exception error) - { - Log.Error("error while scheduling backups: {0}", error); - } - } - } - } - - [Singletone(Additional = typeof(BackupSchedulerServiceExtension))] - public class BackupSchedulerService - { - private readonly object schedulerLock = new object(); - private Timer SchedulerTimer { get; set; } - internal bool IsStarted { get; set; } - public TimeSpan Period { get; set; } - private ILog Log { get; } - private IServiceProvider ServiceProvider { get; } - - public BackupSchedulerService( - IOptionsMonitor options, - IServiceProvider serviceProvider) - { - Log = options.CurrentValue; - Period = TimeSpan.FromMinutes(15); - ServiceProvider = serviceProvider; - } - - public void Start() - { - if (!IsStarted && Period > TimeSpan.Zero) - { - Log.Info("staring backup scheduler service..."); - SchedulerTimer = new Timer(_ => ScheduleBackupTasks(), null, TimeSpan.Zero, Period); - Log.Info("backup scheduler service service started"); - IsStarted = true; - } - } - - public void Stop() - { - if (IsStarted) - { - Log.Info("stoping backup scheduler service..."); - if (SchedulerTimer != null) - { - SchedulerTimer.Change(Timeout.Infinite, Timeout.Infinite); - SchedulerTimer.Dispose(); - SchedulerTimer = null; - } - Log.Info("backup scheduler service stoped"); - IsStarted = false; - } - } - - private void ScheduleBackupTasks() - { - if (Monitor.TryEnter(schedulerLock)) - { - try - { - using var scope = ServiceProvider.CreateScope(); - var backupSchedulerServiceHelper = scope.ServiceProvider.GetService(); - backupSchedulerServiceHelper.ScheduleBackupTasks(this); - } - catch (Exception error) - { - Log.Error("error while scheduling backups: {0}", error); - } - finally - { - Monitor.Exit(schedulerLock); - } - } - } - } - - public class BackupSchedulerServiceExtension - { - public static void Register(DIHelper services) - { - services.TryAdd(); - } - } -} diff --git a/common/services/ASC.Data.Backup/Program.cs b/common/services/ASC.Data.Backup/Program.cs index ef4dcd44ebe..80cc78036b7 100644 --- a/common/services/ASC.Data.Backup/Program.cs +++ b/common/services/ASC.Data.Backup/Program.cs @@ -70,7 +70,9 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .AddJsonFile($"notify.{env}.json", true) .AddJsonFile("backup.json") .AddJsonFile("kafka.json") - .AddJsonFile($"kafka.{env}.json", true) + .AddJsonFile($"kafka.{env}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{env}.json", true) .AddEnvironmentVariables() .AddCommandLine(args) .AddInMemoryCollection(new Dictionary diff --git a/common/services/ASC.Data.Backup/Services/BackupCleanerService.cs b/common/services/ASC.Data.Backup/Services/BackupCleanerService.cs new file mode 100644 index 00000000000..4929fc4323b --- /dev/null +++ b/common/services/ASC.Data.Backup/Services/BackupCleanerService.cs @@ -0,0 +1,149 @@ +/* + * + * (c) Copyright Ascensio System Limited 2010-2020 + * + * This program is freeware. You can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html). + * In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that + * Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights. + * + * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html + * + * You can contact Ascensio System SIA by email at sales@onlyoffice.com + * + * The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display + * Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3. + * + * Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains + * relevant author attributions when distributing the software. If the display of the logo in its graphic + * form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE" + * in every copy of the program you distribute. + * Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks. + * +*/ + + +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +using ASC.Common; +using ASC.Common.Logging; +using ASC.Common.Utils; +using ASC.Data.Backup.Storage; +using ASC.ElasticSearch.Service; +using ASC.Files.Core; + +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Options; + +namespace ASC.Data.Backup.Services +{ + [Singletone] + internal sealed class BackupCleanerService : IHostedService, IDisposable + { + private Timer _timer; + private readonly ILog _logger; + private readonly TimeSpan _period; + + private readonly IServiceScopeFactory _scopeFactory; + + public BackupCleanerService( + ConfigurationExtension configuration, + IOptionsMonitor options, + IServiceScopeFactory scopeFactory) + { + _scopeFactory = scopeFactory; + _logger = options.CurrentValue; + _period = configuration.GetSetting("backup").Cleaner.Period; + } + + public Task StartAsync(CancellationToken cancellationToken) + { + _logger.Info("starting backup cleaner service..."); + + _timer = new Timer(DeleteExpiredBackups, null, TimeSpan.Zero, _period); + + _logger.Info("backup cleaner service started"); + + return Task.CompletedTask; + } + + public void DeleteExpiredBackups(object state) + { + using var serviceScope = _scopeFactory.CreateScope(); + + var backupRepository = serviceScope.ServiceProvider.GetRequiredService(); + var backupStorageFactory = serviceScope.ServiceProvider.GetRequiredService(); + + _logger.Debug("started to clean expired backups"); + + var backupsToRemove = backupRepository.GetExpiredBackupRecords(); + + _logger.DebugFormat("found {0} backups which are expired", backupsToRemove.Count); + + foreach (var scheduledBackups in backupRepository.GetScheduledBackupRecords().GroupBy(r => r.TenantId)) + { + var schedule = backupRepository.GetBackupSchedule(scheduledBackups.Key); + + if (schedule != null) + { + var scheduledBackupsToRemove = scheduledBackups.OrderByDescending(r => r.CreatedOn).Skip(schedule.BackupsStored).ToList(); + if (scheduledBackupsToRemove.Any()) + { + _logger.DebugFormat("only last {0} scheduled backup records are to keep for tenant {1} so {2} records must be removed", schedule.BackupsStored, schedule.TenantId, scheduledBackupsToRemove.Count); + backupsToRemove.AddRange(scheduledBackupsToRemove); + } + } + else + { + backupsToRemove.AddRange(scheduledBackups); + } + } + + foreach (var backupRecord in backupsToRemove) + { + try + { + var backupStorage = backupStorageFactory.GetBackupStorage(backupRecord); + if (backupStorage == null) continue; + + backupStorage.Delete(backupRecord.StoragePath); + + backupRepository.DeleteBackupRecord(backupRecord.Id); + } + catch (ProviderInfoArgumentException error) + { + _logger.Warn("can't remove backup record " + backupRecord.Id, error); + + if (DateTime.UtcNow > backupRecord.CreatedOn.AddMonths(6)) + { + backupRepository.DeleteBackupRecord(backupRecord.Id); + } + } + catch (Exception error) + { + _logger.Warn("can't remove backup record: " + backupRecord.Id, error); + } + } + } + + public Task StopAsync(CancellationToken cancellationToken) + { + _logger.Info("stopping backup cleaner service..."); + + _timer?.Change(Timeout.Infinite, 0); + _logger.Info("backup cleaner service stopped"); + + return Task.CompletedTask; + } + + public void Dispose() + { + _timer?.Dispose(); + } + } +} \ No newline at end of file diff --git a/common/services/ASC.Data.Backup/Services/BackupListenerService.cs b/common/services/ASC.Data.Backup/Services/BackupListenerService.cs new file mode 100644 index 00000000000..03e64356375 --- /dev/null +++ b/common/services/ASC.Data.Backup/Services/BackupListenerService.cs @@ -0,0 +1,52 @@ + +using System; +using System.Threading; +using System.Threading.Tasks; + +using ASC.Common; +using ASC.Common.Caching; +using ASC.Data.Backup.Contracts; + +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +namespace ASC.Data.Backup.Services +{ + [Singletone] + internal sealed class BackupListenerService : IHostedService + { + private readonly ICacheNotify _cacheDeleteSchedule; + private readonly IServiceScopeFactory _scopeFactory; + + public BackupListenerService(ICacheNotify cacheDeleteSchedule, + IServiceScopeFactory scopeFactory) + { + _cacheDeleteSchedule = cacheDeleteSchedule; + _scopeFactory = scopeFactory; + } + + public void DeleteScheldure(DeleteSchedule deleteSchedule) + { + using (var scope = _scopeFactory.CreateScope()) + { + var backupService = scope.ServiceProvider.GetService(); + + backupService.DeleteSchedule(deleteSchedule.TenantId); + } + } + + public Task StartAsync(CancellationToken cancellationToken) + { + _cacheDeleteSchedule.Subscribe((n) => DeleteScheldure(n), CacheNotifyAction.Insert); + + return Task.CompletedTask; + } + + public Task StopAsync(CancellationToken cancellationToken) + { + _cacheDeleteSchedule.Unsubscribe(CacheNotifyAction.Insert); + + return Task.CompletedTask; + } + } +} diff --git a/common/services/ASC.Data.Backup/Services/BackupSchedulerService.cs b/common/services/ASC.Data.Backup/Services/BackupSchedulerService.cs new file mode 100644 index 00000000000..cc5dc12df8c --- /dev/null +++ b/common/services/ASC.Data.Backup/Services/BackupSchedulerService.cs @@ -0,0 +1,145 @@ +/* + * + * (c) Copyright Ascensio System Limited 2010-2020 + * + * This program is freeware. You can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html). + * In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that + * Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights. + * + * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html + * + * You can contact Ascensio System SIA by email at sales@onlyoffice.com + * + * The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display + * Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3. + * + * Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains + * relevant author attributions when distributing the software. If the display of the logo in its graphic + * form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE" + * in every copy of the program you distribute. + * Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks. + * +*/ + + +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +using ASC.Common; +using ASC.Common.Logging; +using ASC.Common.Utils; +using ASC.Core; +using ASC.Core.Billing; +using ASC.Data.Backup.Storage; +using ASC.ElasticSearch.Service; + +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Options; + +namespace ASC.Data.Backup.Services +{ + [Singletone] + internal sealed class BackupSchedulerService : IHostedService, IDisposable + { + private readonly TimeSpan _period; + private Timer _timer; + private readonly ILog _logger; + + private readonly BackupWorker _backupWorker; + private readonly CoreBaseSettings _coreBaseSettings; + private readonly IServiceScopeFactory _scopeFactory; + + public BackupSchedulerService( + IOptionsMonitor options, + IServiceScopeFactory scopeFactory, + ConfigurationExtension configuration, + CoreBaseSettings coreBaseSettings, + BackupWorker backupWorker) + { + _logger = options.CurrentValue; + _coreBaseSettings = coreBaseSettings; + _backupWorker = backupWorker; + _period = configuration.GetSetting("backup").Scheduler.Period; + _scopeFactory = scopeFactory; + } + + public Task StartAsync(CancellationToken cancellationToken) + { + _logger.Info("starting backup scheduler service..."); + + _timer = new Timer(ScheduleBackupTasks, null, TimeSpan.Zero, _period); + + _logger.Info("backup scheduler service started"); + + return Task.CompletedTask; + } + + public void ScheduleBackupTasks(object state) + { + using var serviceScope = _scopeFactory.CreateScope(); + + var paymentManager = serviceScope.ServiceProvider.GetRequiredService(); + var backupRepository = serviceScope.ServiceProvider.GetRequiredService(); ; + var backupSchedule = serviceScope.ServiceProvider.GetRequiredService(); + var tenantManager = serviceScope.ServiceProvider.GetRequiredService(); + + _logger.DebugFormat("started to schedule backups"); + + var backupsToSchedule = backupRepository.GetBackupSchedules().Where(schedule => backupSchedule.IsToBeProcessed(schedule)).ToList(); + + _logger.DebugFormat("{0} backups are to schedule", backupsToSchedule.Count); + + foreach (var schedule in backupsToSchedule) + { + try + { + if (_coreBaseSettings.Standalone || tenantManager.GetTenantQuota(schedule.TenantId).AutoBackup) + { + var tariff = paymentManager.GetTariff(schedule.TenantId); + if (tariff.State < TariffState.Delay) + { + schedule.LastBackupTime = DateTime.UtcNow; + + backupRepository.SaveBackupSchedule(schedule); + _logger.DebugFormat("Start scheduled backup: {0}, {1}, {2}, {3}", schedule.TenantId, schedule.BackupMail, schedule.StorageType, schedule.StorageBasePath); + _backupWorker.StartScheduledBackup(schedule); + } + else + { + _logger.DebugFormat("Skip portal {0} not paid", schedule.TenantId); + } + } + else + { + _logger.DebugFormat("Skip portal {0} haven't access", schedule.TenantId); + } + } + catch (Exception error) + { + _logger.Error("error while scheduling backups: {0}", error); + } + } + + } + + public Task StopAsync(CancellationToken cancellationToken) + { + _logger.Info("stopping backup cleaner service..."); + + _timer?.Change(Timeout.Infinite, 0); + + _logger.Info("backup cleaner service stopped"); + + return Task.CompletedTask; + } + public void Dispose() + { + _timer?.Dispose(); + } + } +} diff --git a/common/services/ASC.Data.Backup/BackupServiceLauncher.cs b/common/services/ASC.Data.Backup/Services/BackupWorkerService.cs similarity index 54% rename from common/services/ASC.Data.Backup/BackupServiceLauncher.cs rename to common/services/ASC.Data.Backup/Services/BackupWorkerService.cs index 991dccefa6d..16185181778 100644 --- a/common/services/ASC.Data.Backup/BackupServiceLauncher.cs +++ b/common/services/ASC.Data.Backup/Services/BackupWorkerService.cs @@ -29,71 +29,44 @@ using ASC.Common; using ASC.Common.Utils; -using ASC.Data.Backup.Listerners; using ASC.Web.Studio.Core.Notify; using Microsoft.Extensions.Hosting; -namespace ASC.Data.Backup.Service +namespace ASC.Data.Backup.Services { [Singletone] - internal class BackupServiceLauncher : IHostedService + internal sealed class BackupWorkerService : IHostedService { - private BackupCleanerService CleanerService { get; set; } - private BackupSchedulerService SchedulerService { get; set; } - private BackupWorker BackupWorker { get; set; } - private ConfigurationExtension Configuration { get; set; } - private BackupListener BackupListener { get; set; } - public NotifyConfiguration NotifyConfiguration { get; } + private readonly BackupWorker _backupWorker; + private readonly ConfigurationExtension _configuration; + private readonly NotifyConfiguration _notifyConfiguration; - public BackupServiceLauncher( - BackupCleanerService cleanerService, - BackupSchedulerService schedulerService, + public BackupWorkerService( BackupWorker backupWorker, ConfigurationExtension configuration, - BackupListener backupListener, NotifyConfiguration notifyConfiguration) { - CleanerService = cleanerService; - SchedulerService = schedulerService; - BackupWorker = backupWorker; - Configuration = configuration; - BackupListener = backupListener; - NotifyConfiguration = notifyConfiguration; + _backupWorker = backupWorker; + _configuration = configuration; + _notifyConfiguration = notifyConfiguration; } public Task StartAsync(CancellationToken cancellationToken) { - NotifyConfiguration.Configure(); + _notifyConfiguration.Configure(); - var settings = Configuration.GetSetting("backup"); + var settings = _configuration.GetSetting("backup"); - BackupWorker.Start(settings); - BackupListener.Start(); - - CleanerService.Period = settings.Cleaner.Period; - CleanerService.Start(); - - SchedulerService.Period = settings.Scheduler.Period; - SchedulerService.Start(); + _backupWorker.Start(settings); return Task.CompletedTask; } public Task StopAsync(CancellationToken cancellationToken) { - BackupWorker.Stop(); - BackupListener.Stop(); - if (CleanerService != null) - { - CleanerService.Stop(); - CleanerService = null; - } - if (SchedulerService != null) - { - SchedulerService.Stop(); - SchedulerService = null; - } + _backupWorker.Stop(); + return Task.CompletedTask; } } diff --git a/common/services/ASC.Data.Backup/Startup.cs b/common/services/ASC.Data.Backup/Startup.cs index a4a59493d70..585e16a64a6 100644 --- a/common/services/ASC.Data.Backup/Startup.cs +++ b/common/services/ASC.Data.Backup/Startup.cs @@ -27,18 +27,22 @@ using ASC.Common; using ASC.Common.Threading; using ASC.Data.Backup.Controllers; -using ASC.Data.Backup.Service; +using ASC.Data.Backup.Services; using ASC.Web.Studio.Core.Notify; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using StackExchange.Redis.Extensions.Core.Configuration; +using StackExchange.Redis.Extensions.Newtonsoft; + namespace ASC.Data.Backup { public class Startup : BaseStartup { - public Startup(IConfiguration configuration, IHostEnvironment hostEnvironment) : base(configuration, hostEnvironment) + public Startup(IConfiguration configuration, IHostEnvironment hostEnvironment) + : base(configuration, hostEnvironment) { } @@ -53,11 +57,23 @@ public override void ConfigureServices(IServiceCollection services) DIHelper.TryAdd(); DIHelper.TryAdd(); - DIHelper.TryAdd(); + DIHelper.TryAdd(); + DIHelper.TryAdd(); + + DIHelper.TryAdd(); + DIHelper.TryAdd(); + DIHelper.TryAdd(); + DIHelper.TryAdd(); + NotifyConfigurationExtension.Register(DIHelper); - services.AddHostedService(); + services.AddHostedService(); + services.AddHostedService(); + services.AddHostedService(); + services.AddHostedService(); + + services.AddStackExchangeRedisExtensions(Configuration.GetSection("Redis").Get()); } } } diff --git a/common/services/ASC.Data.Storage.Encryption/ASC.Data.Storage.Encryption.csproj b/common/services/ASC.Data.Storage.Encryption/ASC.Data.Storage.Encryption.csproj index 06320b6789c..0e87816a9d2 100644 --- a/common/services/ASC.Data.Storage.Encryption/ASC.Data.Storage.Encryption.csproj +++ b/common/services/ASC.Data.Storage.Encryption/ASC.Data.Storage.Encryption.csproj @@ -23,11 +23,13 @@ true - + all runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/common/services/ASC.Data.Storage.Encryption/Program.cs b/common/services/ASC.Data.Storage.Encryption/Program.cs index cfb8ca70887..24017ce4d6b 100644 --- a/common/services/ASC.Data.Storage.Encryption/Program.cs +++ b/common/services/ASC.Data.Storage.Encryption/Program.cs @@ -98,7 +98,9 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .AddJsonFile("notify.json") .AddJsonFile($"notify.{env}.json", true) .AddJsonFile("kafka.json") - .AddJsonFile($"kafka.{env}.json", true) + .AddJsonFile($"kafka.{env}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{env}.json", true) .AddEnvironmentVariables(); }) .ConfigureNLogLogging(); diff --git a/common/services/ASC.Data.Storage.Encryption/Startup.cs b/common/services/ASC.Data.Storage.Encryption/Startup.cs index 38fcb19c811..b968301ebe7 100644 --- a/common/services/ASC.Data.Storage.Encryption/Startup.cs +++ b/common/services/ASC.Data.Storage.Encryption/Startup.cs @@ -28,8 +28,11 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - +using Microsoft.Extensions.Hosting; + +using StackExchange.Redis.Extensions.Core.Configuration; +using StackExchange.Redis.Extensions.Newtonsoft; + namespace ASC.Data.Storage.Encryption { public class Startup : BaseStartup @@ -45,7 +48,8 @@ public override void ConfigureServices(IServiceCollection services) DIHelper.TryAdd(); - services.AddHostedService(); + services.AddHostedService(); + services.AddStackExchangeRedisExtensions(Configuration.GetSection("Redis").Get()); } } } diff --git a/common/services/ASC.Data.Storage.Migration/ASC.Data.Storage.Migration.csproj b/common/services/ASC.Data.Storage.Migration/ASC.Data.Storage.Migration.csproj index cbae83f112c..d3e4fcf863a 100644 --- a/common/services/ASC.Data.Storage.Migration/ASC.Data.Storage.Migration.csproj +++ b/common/services/ASC.Data.Storage.Migration/ASC.Data.Storage.Migration.csproj @@ -10,6 +10,8 @@ + + diff --git a/common/services/ASC.Data.Storage.Migration/Program.cs b/common/services/ASC.Data.Storage.Migration/Program.cs index 8a4f34357d3..6cb4e8dd82c 100644 --- a/common/services/ASC.Data.Storage.Migration/Program.cs +++ b/common/services/ASC.Data.Storage.Migration/Program.cs @@ -14,8 +14,11 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - +using Microsoft.Extensions.Hosting; + +using StackExchange.Redis.Extensions.Core.Configuration; +using StackExchange.Redis.Extensions.Newtonsoft; + namespace ASC.Data.Storage.Migration { public class Program @@ -52,6 +55,8 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .AddJsonFile($"notify.{env}.json", true) .AddJsonFile("kafka.json") .AddJsonFile($"kafka.{env}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{env}.json", true) .AddEnvironmentVariables() .AddCommandLine(args) .AddInMemoryCollection(new Dictionary @@ -64,7 +69,19 @@ public static IHostBuilder CreateHostBuilder(string[] args) => { services.AddMemoryCache(); var diHelper = new DIHelper(services); - diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>)); + + var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get(); + + if (redisConfiguration != null) + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>)); + + services.AddStackExchangeRedisExtensions(redisConfiguration); + } + else + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(MemoryCacheNotify<>)); + } diHelper.RegisterProducts(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath); diff --git a/common/services/ASC.ElasticSearch/ASC.ElasticSearch.csproj b/common/services/ASC.ElasticSearch/ASC.ElasticSearch.csproj index 0fe01f7cfcc..60ab191dcdd 100644 --- a/common/services/ASC.ElasticSearch/ASC.ElasticSearch.csproj +++ b/common/services/ASC.ElasticSearch/ASC.ElasticSearch.csproj @@ -24,11 +24,11 @@ - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -43,6 +43,6 @@ - + \ No newline at end of file diff --git a/common/services/ASC.ElasticSearch/protos/SearchItem.proto b/common/services/ASC.ElasticSearch/protos/SearchItem.proto deleted file mode 100644 index 486eff724ed..00000000000 --- a/common/services/ASC.ElasticSearch/protos/SearchItem.proto +++ /dev/null @@ -1,17 +0,0 @@ -syntax = "proto3"; - -package ASC.ElasticSearch; - -message ClearIndexAction { - string Id = 1; -} - -message ReIndexAction { - int32 Tenant = 1; - repeated string Names = 2; -} - -message IndexAction { - string Indexing = 1; - int64 LastIndexed = 2; -} \ No newline at end of file diff --git a/common/services/ASC.ElasticSearch/protos/search_item.proto b/common/services/ASC.ElasticSearch/protos/search_item.proto new file mode 100644 index 00000000000..2699b7b8de4 --- /dev/null +++ b/common/services/ASC.ElasticSearch/protos/search_item.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + +package ASC.ElasticSearch; + +message ClearIndexAction { + string id = 1; +} + +message ReIndexAction { + int32 tenant = 1; + repeated string names = 2; +} + +message IndexAction { + string indexing = 1; + int64 last_indexed = 2; +} \ No newline at end of file diff --git a/common/services/ASC.Notify/ASC.Notify.csproj b/common/services/ASC.Notify/ASC.Notify.csproj index cdb92b566b4..85e4b03643a 100644 --- a/common/services/ASC.Notify/ASC.Notify.csproj +++ b/common/services/ASC.Notify/ASC.Notify.csproj @@ -18,6 +18,8 @@ + + diff --git a/common/services/ASC.Notify/Program.cs b/common/services/ASC.Notify/Program.cs index 9f6a50c95b6..e2461948169 100644 --- a/common/services/ASC.Notify/Program.cs +++ b/common/services/ASC.Notify/Program.cs @@ -18,6 +18,9 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using StackExchange.Redis.Extensions.Core.Configuration; +using StackExchange.Redis.Extensions.Newtonsoft; + namespace ASC.Notify { public class Program @@ -54,6 +57,8 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .AddJsonFile($"notify.{env}.json", true) .AddJsonFile("kafka.json") .AddJsonFile($"kafka.{env}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{env}.json", true) .AddEnvironmentVariables() .AddCommandLine(args) .AddInMemoryCollection(new Dictionary @@ -67,7 +72,19 @@ public static IHostBuilder CreateHostBuilder(string[] args) => services.AddMemoryCache(); var diHelper = new DIHelper(services); - diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>)); + var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get(); + + if (redisConfiguration != null) + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>)); + + services.AddStackExchangeRedisExtensions(redisConfiguration); + } + else + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(MemoryCacheNotify<>)); + } + diHelper.RegisterProducts(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath); services.Configure(hostContext.Configuration.GetSection("notify")); diff --git a/common/services/ASC.Radicale/ASC.Radicale.csproj b/common/services/ASC.Radicale/ASC.Radicale.csproj index b9fe6acdfcf..0c2a7b9cde3 100644 --- a/common/services/ASC.Radicale/ASC.Radicale.csproj +++ b/common/services/ASC.Radicale/ASC.Radicale.csproj @@ -22,6 +22,8 @@ + + diff --git a/common/services/ASC.Radicale/Program.cs b/common/services/ASC.Radicale/Program.cs index 7c2233f6042..f6b42907459 100644 --- a/common/services/ASC.Radicale/Program.cs +++ b/common/services/ASC.Radicale/Program.cs @@ -40,12 +40,15 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - +using Microsoft.Extensions.Hosting; + +using StackExchange.Redis.Extensions.Core.Configuration; +using StackExchange.Redis.Extensions.Newtonsoft; + namespace ASC.Radicale +{ +public class Program { - public class Program - { public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); @@ -71,10 +74,12 @@ public static IHostBuilder CreateHostBuilder(string[] args) => config .AddJsonFile("appsettings.json") .AddJsonFile("storage.json") - .AddJsonFile("kafka.json") + .AddJsonFile("kafka.json") + .AddJsonFile($"kafka.{env}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{env}.json", true) .AddJsonFile($"appsettings.services.json", true) //.AddJsonFile("radicale.json") - .AddJsonFile($"kafka.{env}.json", true) .AddJsonFile($"appsettings.{env}.json", true) .AddJsonFile($"radicale.{env}.json", true) .AddEnvironmentVariables() @@ -88,12 +93,26 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .ConfigureServices((hostContext, services) => { services.AddMemoryCache(); - var diHelper = new DIHelper(services); - diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>)); + var diHelper = new DIHelper(services); + + var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get(); + + if (redisConfiguration != null) + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>)); + + services.AddStackExchangeRedisExtensions(redisConfiguration); + } + else + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(MemoryCacheNotify<>)); + } + diHelper.RegisterProducts(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath); services.AddHostedService(); - diHelper.TryAdd(); + diHelper.TryAdd(); + }) .ConfigureContainer((context, builder) => { diff --git a/common/services/ASC.Socket.IO.Svc/ASC.Socket.IO.Svc.csproj b/common/services/ASC.Socket.IO.Svc/ASC.Socket.IO.Svc.csproj index 7cdc10fa69b..3836a8b140f 100644 --- a/common/services/ASC.Socket.IO.Svc/ASC.Socket.IO.Svc.csproj +++ b/common/services/ASC.Socket.IO.Svc/ASC.Socket.IO.Svc.csproj @@ -21,6 +21,8 @@ + + diff --git a/common/services/ASC.Socket.IO.Svc/Program.cs b/common/services/ASC.Socket.IO.Svc/Program.cs index c231c363cf6..c3a35465162 100644 --- a/common/services/ASC.Socket.IO.Svc/Program.cs +++ b/common/services/ASC.Socket.IO.Svc/Program.cs @@ -40,12 +40,14 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - - +using Microsoft.Extensions.Hosting; + +using StackExchange.Redis.Extensions.Core.Configuration; +using StackExchange.Redis.Extensions.Newtonsoft; + namespace ASC.Socket.IO.Svc -{ - public class Program +{ +public class Program { public async static Task Main(string[] args) { @@ -74,8 +76,10 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .AddJsonFile("appsettings.json") .AddJsonFile("storage.json") .AddJsonFile("kafka.json") - .AddJsonFile("socket.json") .AddJsonFile($"kafka.{env}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{env}.json", true) + .AddJsonFile("socket.json") .AddJsonFile($"appsettings.{env}.json", true) .AddJsonFile($"socket.{env}.json", true) .AddEnvironmentVariables() @@ -90,11 +94,25 @@ public static IHostBuilder CreateHostBuilder(string[] args) => { services.AddMemoryCache(); var diHelper = new DIHelper(services); - diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>)); + + var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get(); + + if (redisConfiguration != null) + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>)); + + services.AddStackExchangeRedisExtensions(redisConfiguration); + } + else + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(MemoryCacheNotify<>)); + } + diHelper.RegisterProducts(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath); services.AddHostedService(); diHelper.TryAdd(); + }) .ConfigureContainer((context, builder) => { diff --git a/common/services/ASC.SsoAuth.Svc/ASC.SsoAuth.Svc.csproj b/common/services/ASC.SsoAuth.Svc/ASC.SsoAuth.Svc.csproj index b8311a34644..d3c015797b2 100644 --- a/common/services/ASC.SsoAuth.Svc/ASC.SsoAuth.Svc.csproj +++ b/common/services/ASC.SsoAuth.Svc/ASC.SsoAuth.Svc.csproj @@ -21,6 +21,8 @@ + + diff --git a/common/services/ASC.SsoAuth.Svc/Program.cs b/common/services/ASC.SsoAuth.Svc/Program.cs index 52fb9be5822..109503abfc9 100644 --- a/common/services/ASC.SsoAuth.Svc/Program.cs +++ b/common/services/ASC.SsoAuth.Svc/Program.cs @@ -41,12 +41,14 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - - +using Microsoft.Extensions.Hosting; + +using StackExchange.Redis.Extensions.Core.Configuration; +using StackExchange.Redis.Extensions.Newtonsoft; + namespace ASC.Socket.IO.Svc -{ - public class Program +{ +public class Program { public async static Task Main(string[] args) { @@ -74,9 +76,11 @@ public static IHostBuilder CreateHostBuilder(string[] args) => config .AddJsonFile("appsettings.json") .AddJsonFile("storage.json") - .AddJsonFile("kafka.json") + .AddJsonFile("kafka.json") + .AddJsonFile($"kafka.{env}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{env}.json", true) .AddJsonFile("ssoauth.json") - .AddJsonFile($"kafka.{env}.json", true) .AddJsonFile($"appsettings.{env}.json", true) .AddJsonFile($"ssoauth.{env}.json", true) .AddEnvironmentVariables() @@ -91,11 +95,25 @@ public static IHostBuilder CreateHostBuilder(string[] args) => { services.AddMemoryCache(); var diHelper = new DIHelper(services); - diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>)); + + var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get(); + + if (redisConfiguration != null) + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>)); + + services.AddStackExchangeRedisExtensions(redisConfiguration); + } + else + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(MemoryCacheNotify<>)); + } + diHelper.RegisterProducts(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath); services.AddHostedService(); diHelper.TryAdd(); + }) .ConfigureContainer((context, builder) => { diff --git a/common/services/ASC.Studio.Notify/ASC.Studio.Notify.csproj b/common/services/ASC.Studio.Notify/ASC.Studio.Notify.csproj index 6958d850d8b..c83caa5d671 100644 --- a/common/services/ASC.Studio.Notify/ASC.Studio.Notify.csproj +++ b/common/services/ASC.Studio.Notify/ASC.Studio.Notify.csproj @@ -16,6 +16,8 @@ + + diff --git a/common/services/ASC.Studio.Notify/Program.cs b/common/services/ASC.Studio.Notify/Program.cs index 2d7ab1da66a..15207d452c7 100644 --- a/common/services/ASC.Studio.Notify/Program.cs +++ b/common/services/ASC.Studio.Notify/Program.cs @@ -19,6 +19,9 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using StackExchange.Redis.Extensions.Core.Configuration; +using StackExchange.Redis.Extensions.Newtonsoft; + namespace ASC.Studio.Notify { public class Program @@ -55,6 +58,8 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .AddJsonFile($"notify.{env}.json", true) .AddJsonFile("kafka.json") .AddJsonFile($"kafka.{env}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{env}.json", true) .AddEnvironmentVariables() .AddCommandLine(args) .AddInMemoryCollection(new Dictionary @@ -67,12 +72,26 @@ public static IHostBuilder CreateHostBuilder(string[] args) => { services.AddMemoryCache(); var diHelper = new DIHelper(services); - diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>)); + + var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get(); + + if (redisConfiguration != null) + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>)); + + services.AddStackExchangeRedisExtensions(redisConfiguration); + } + else + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(MemoryCacheNotify<>)); + } + diHelper.RegisterProducts(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath); services.AddHostedService(); diHelper.TryAdd(); NotifyConfigurationExtension.Register(diHelper); diHelper.TryAdd(); + }) .ConfigureContainer((context, builder) => { diff --git a/common/services/ASC.TelegramService/ASC.TelegramService.csproj b/common/services/ASC.TelegramService/ASC.TelegramService.csproj index 93585acbd28..6af4b5c61b7 100644 --- a/common/services/ASC.TelegramService/ASC.TelegramService.csproj +++ b/common/services/ASC.TelegramService/ASC.TelegramService.csproj @@ -18,6 +18,8 @@ + + diff --git a/common/services/ASC.TelegramService/Program.cs b/common/services/ASC.TelegramService/Program.cs index cc2b79f536d..8d75d545359 100644 --- a/common/services/ASC.TelegramService/Program.cs +++ b/common/services/ASC.TelegramService/Program.cs @@ -98,7 +98,9 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .AddJsonFile("notify.json") .AddJsonFile($"notify.{env}.json", true) .AddJsonFile("kafka.json") - .AddJsonFile($"kafka.{env}.json", true) + .AddJsonFile($"kafka.{env}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{env}.json", true) .AddEnvironmentVariables(); }) .ConfigureNLogLogging(); diff --git a/common/services/ASC.TelegramService/Startup.cs b/common/services/ASC.TelegramService/Startup.cs index 7fa92ac86d7..dae85e81812 100644 --- a/common/services/ASC.TelegramService/Startup.cs +++ b/common/services/ASC.TelegramService/Startup.cs @@ -28,11 +28,14 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - +using Microsoft.Extensions.Hosting; + +using StackExchange.Redis.Extensions.Core.Configuration; +using StackExchange.Redis.Extensions.Newtonsoft; + namespace ASC.TelegramService -{ - public class Startup : BaseStartup +{ + public class Startup : BaseStartup { public Startup(IConfiguration configuration, IHostEnvironment hostEnvironment) : base(configuration, hostEnvironment) { @@ -45,7 +48,8 @@ public override void ConfigureServices(IServiceCollection services) DIHelper.TryAdd(); - services.AddHostedService(); + services.AddHostedService(); + services.AddStackExchangeRedisExtensions(Configuration.GetSection("Redis").Get()); } } } diff --git a/common/services/ASC.Thumbnails.Svc/ASC.Thumbnails.Svc.csproj b/common/services/ASC.Thumbnails.Svc/ASC.Thumbnails.Svc.csproj index 7366c400fe7..d1f0915050e 100644 --- a/common/services/ASC.Thumbnails.Svc/ASC.Thumbnails.Svc.csproj +++ b/common/services/ASC.Thumbnails.Svc/ASC.Thumbnails.Svc.csproj @@ -27,6 +27,8 @@ + + \ No newline at end of file diff --git a/common/services/ASC.Thumbnails.Svc/Program.cs b/common/services/ASC.Thumbnails.Svc/Program.cs index a1543a6767d..c11c8454ec5 100644 --- a/common/services/ASC.Thumbnails.Svc/Program.cs +++ b/common/services/ASC.Thumbnails.Svc/Program.cs @@ -40,12 +40,14 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - - +using Microsoft.Extensions.Hosting; + +using StackExchange.Redis.Extensions.Core.Configuration; +using StackExchange.Redis.Extensions.Newtonsoft; + namespace ASC.Thumbnails.Svc -{ - public class Program +{ +public class Program { public async static Task Main(string[] args) { @@ -73,9 +75,11 @@ public static IHostBuilder CreateHostBuilder(string[] args) => config .AddJsonFile("appsettings.json") .AddJsonFile("storage.json") - .AddJsonFile("kafka.json") - .AddJsonFile("thumb.json") + .AddJsonFile("kafka.json") .AddJsonFile($"kafka.{env}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{env}.json", true) + .AddJsonFile("thumb.json") .AddJsonFile($"appsettings.{env}.json", true) .AddJsonFile($"thumb.{env}.json", true) .AddEnvironmentVariables() @@ -91,9 +95,22 @@ public static IHostBuilder CreateHostBuilder(string[] args) => services.AddMemoryCache(); var diHelper = new DIHelper(services); - diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>)); + var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get(); + + if (redisConfiguration != null) + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>)); + + services.AddStackExchangeRedisExtensions(redisConfiguration); + } + else + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(MemoryCacheNotify<>)); + } + services.AddHostedService(); - diHelper.TryAdd(); + diHelper.TryAdd(); + }) .ConfigureContainer((context, builder) => { diff --git a/common/services/ASC.UrlShortener.Svc/ASC.UrlShortener.Svc.csproj b/common/services/ASC.UrlShortener.Svc/ASC.UrlShortener.Svc.csproj index e0798a28ef2..5a9230af8c0 100644 --- a/common/services/ASC.UrlShortener.Svc/ASC.UrlShortener.Svc.csproj +++ b/common/services/ASC.UrlShortener.Svc/ASC.UrlShortener.Svc.csproj @@ -18,6 +18,8 @@ + + diff --git a/common/services/ASC.UrlShortener.Svc/Program.cs b/common/services/ASC.UrlShortener.Svc/Program.cs index f3a8c32cce5..0a5dc6868da 100644 --- a/common/services/ASC.UrlShortener.Svc/Program.cs +++ b/common/services/ASC.UrlShortener.Svc/Program.cs @@ -39,15 +39,17 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - - +using Microsoft.Extensions.Hosting; + +using StackExchange.Redis.Extensions.Core.Configuration; +using StackExchange.Redis.Extensions.Newtonsoft; + namespace ASC.UrlShortener.Svc -{ - public class Program - { - public async static Task Main(string[] args) - { +{ +public class Program +{ +public async static Task Main(string[] args) +{ var host = CreateHostBuilder(args).Build(); await host.RunAsync(); @@ -79,6 +81,8 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .AddJsonFile("storage.json") .AddJsonFile("kafka.json") .AddJsonFile($"kafka.{env}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{env}.json", true) .AddEnvironmentVariables() .AddCommandLine(args) .AddInMemoryCollection(new Dictionary @@ -94,7 +98,10 @@ public static IHostBuilder CreateHostBuilder(string[] args) => var diHelper = new DIHelper(services); services.AddHostedService(); - diHelper.TryAdd(); + diHelper.TryAdd(); + + services.AddStackExchangeRedisExtensions(hostContext.Configuration.GetSection("Redis").Get()); + }) .ConfigureContainer((context, builder) => { diff --git a/common/services/ASC.Webhooks.Service/ASC.Webhooks.Service.csproj b/common/services/ASC.Webhooks.Service/ASC.Webhooks.Service.csproj index 2096dea7988..4656bc88dd8 100644 --- a/common/services/ASC.Webhooks.Service/ASC.Webhooks.Service.csproj +++ b/common/services/ASC.Webhooks.Service/ASC.Webhooks.Service.csproj @@ -8,6 +8,8 @@ + + diff --git a/common/services/ASC.Webhooks.Service/Program.cs b/common/services/ASC.Webhooks.Service/Program.cs index 1fdd02c81a4..a5972ecf316 100644 --- a/common/services/ASC.Webhooks.Service/Program.cs +++ b/common/services/ASC.Webhooks.Service/Program.cs @@ -17,6 +17,9 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using StackExchange.Redis.Extensions.Core.Configuration; +using StackExchange.Redis.Extensions.Newtonsoft; + namespace ASC.Webhooks.Service { public class Program @@ -56,6 +59,8 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .AddJsonFile("storage.json") .AddJsonFile("kafka.json") .AddJsonFile($"kafka.{env}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{env}.json", true) .AddEnvironmentVariables() .AddCommandLine(args); }) @@ -65,12 +70,24 @@ public static IHostBuilder CreateHostBuilder(string[] args) => var diHelper = new DIHelper(services); - diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>)); + var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get(); + + if (redisConfiguration != null) + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>)); + + services.AddStackExchangeRedisExtensions(redisConfiguration); + } + else + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(MemoryCacheNotify<>)); + } diHelper.TryAdd(); services.AddHostedService(); diHelper.TryAdd(); + }) .ConfigureContainer((context, builder) => { diff --git a/config/redis.json b/config/redis.json new file mode 100644 index 00000000000..40af8fe1885 --- /dev/null +++ b/config/redis.json @@ -0,0 +1,5 @@ +{ + "Redis": { + + } +} diff --git a/config/redis.test.json b/config/redis.test.json new file mode 100644 index 00000000000..fb4f1283685 --- /dev/null +++ b/config/redis.test.json @@ -0,0 +1,14 @@ +{ + "Redis": { + "Ssl": false, + "ConnectTimeout": 5000, + "SyncTimeout": 60000, + "ConnectRetry": 2, + "Database": 0, + "Hosts": [ + { + "Host": "127.0.0.1", + "Port": "6379" + }] + } +} \ No newline at end of file diff --git a/products/ASC.CRM/BackgroundTasks/ASC.CRM.BackgroundTasks.csproj b/products/ASC.CRM/BackgroundTasks/ASC.CRM.BackgroundTasks.csproj index dab536c2bf3..0afd78882bb 100644 --- a/products/ASC.CRM/BackgroundTasks/ASC.CRM.BackgroundTasks.csproj +++ b/products/ASC.CRM/BackgroundTasks/ASC.CRM.BackgroundTasks.csproj @@ -3,6 +3,10 @@ net6.0 false + + + + diff --git a/products/ASC.CRM/BackgroundTasks/Program.cs b/products/ASC.CRM/BackgroundTasks/Program.cs index 197b3b3e0a5..ec4495a527a 100644 --- a/products/ASC.CRM/BackgroundTasks/Program.cs +++ b/products/ASC.CRM/BackgroundTasks/Program.cs @@ -17,6 +17,8 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using StackExchange.Redis.Extensions.Core.Configuration; +using StackExchange.Redis.Extensions.Newtonsoft; namespace ASC.CRM.BackgroundTasks { @@ -58,6 +60,8 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .AddJsonFile($"notify.{env}.json", true) .AddJsonFile("kafka.json") .AddJsonFile($"kafka.{env}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{env}.json", true) .AddEnvironmentVariables() .AddCommandLine(args); }) @@ -67,7 +71,18 @@ public static IHostBuilder CreateHostBuilder(string[] args) => var diHelper = new DIHelper(services); - diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>)); + var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get(); + + if (redisConfiguration != null) + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>)); + + services.AddStackExchangeRedisExtensions(redisConfiguration); + } + else + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(MemoryCacheNotify<>)); + } diHelper.RegisterProducts(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath); @@ -81,6 +96,7 @@ public static IHostBuilder CreateHostBuilder(string[] args) => diHelper.TryAdd(); diHelper.TryAdd(); diHelper.TryAdd(); + }) .ConfigureContainer((context, builder) => { diff --git a/products/ASC.CRM/Server/ASC.CRM.csproj b/products/ASC.CRM/Server/ASC.CRM.csproj index 5f55544984e..6b18e4cd4d5 100644 --- a/products/ASC.CRM/Server/ASC.CRM.csproj +++ b/products/ASC.CRM/Server/ASC.CRM.csproj @@ -37,12 +37,14 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive + + @@ -178,7 +180,7 @@ - + diff --git a/products/ASC.CRM/Server/Program.cs b/products/ASC.CRM/Server/Program.cs index b2613fdcb9f..7893ad88618 100644 --- a/products/ASC.CRM/Server/Program.cs +++ b/products/ASC.CRM/Server/Program.cs @@ -67,6 +67,8 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .AddJsonFile("storage.json") .AddJsonFile("kafka.json") .AddJsonFile($"kafka.{hostingContext.HostingEnvironment.EnvironmentName}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{hostingContext.HostingEnvironment.EnvironmentName}.json", true) .AddEnvironmentVariables() .AddCommandLine(args) .AddInMemoryCollection(new Dictionary diff --git a/products/ASC.CRM/Server/proto/ContactPhotoManagerCacheItem.proto b/products/ASC.CRM/Server/proto/contact_photo_manager_cache_item.proto similarity index 100% rename from products/ASC.CRM/Server/proto/ContactPhotoManagerCacheItem.proto rename to products/ASC.CRM/Server/proto/contact_photo_manager_cache_item.proto diff --git a/products/ASC.Calendar/Server/ASC.Calendar.csproj b/products/ASC.Calendar/Server/ASC.Calendar.csproj index 4b66ffcc18d..927df1f9fad 100644 --- a/products/ASC.Calendar/Server/ASC.Calendar.csproj +++ b/products/ASC.Calendar/Server/ASC.Calendar.csproj @@ -21,6 +21,8 @@ + + diff --git a/products/ASC.Calendar/Server/Program.cs b/products/ASC.Calendar/Server/Program.cs index fcf2433e55d..b5f21380778 100644 --- a/products/ASC.Calendar/Server/Program.cs +++ b/products/ASC.Calendar/Server/Program.cs @@ -73,6 +73,8 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .AddJsonFile("storage.json") .AddJsonFile("kafka.json") .AddJsonFile($"kafka.{hostingContext.HostingEnvironment.EnvironmentName}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{hostingContext.HostingEnvironment.EnvironmentName}.json", true) .AddEnvironmentVariables() .AddCommandLine(args) .AddInMemoryCollection(new Dictionary diff --git a/products/ASC.Calendar/Server/Startup.cs b/products/ASC.Calendar/Server/Startup.cs index b6de24882ea..dc74d919096 100644 --- a/products/ASC.Calendar/Server/Startup.cs +++ b/products/ASC.Calendar/Server/Startup.cs @@ -11,6 +11,10 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using StackExchange.Redis.Extensions.Core.Configuration; + +using StackExchange.Redis.Extensions.Newtonsoft; + namespace ASC.Calendar { public class Startup : BaseStartup @@ -39,6 +43,9 @@ public override void ConfigureServices(IServiceCollection services) DIHelper.TryAdd(); NotifyConfigurationExtension.Register(DIHelper); + + services.AddStackExchangeRedisExtensions(Configuration.GetSection("Redis").Get()); + } public override void Configure(IApplicationBuilder app, IWebHostEnvironment env) diff --git a/products/ASC.Files/Core/ASC.Files.Core.csproj b/products/ASC.Files/Core/ASC.Files.Core.csproj index a865c361b92..3addf4d1e08 100644 --- a/products/ASC.Files/Core/ASC.Files.Core.csproj +++ b/products/ASC.Files/Core/ASC.Files.Core.csproj @@ -8,13 +8,13 @@ - - - - - - - + + + + + + + @@ -23,7 +23,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -38,13 +38,13 @@ - - - - - - - + + + + + + + diff --git a/products/ASC.Files/Core/proto/BoxCacheItem.proto b/products/ASC.Files/Core/proto/BoxCacheItem.proto deleted file mode 100644 index 03676f58475..00000000000 --- a/products/ASC.Files/Core/proto/BoxCacheItem.proto +++ /dev/null @@ -1,10 +0,0 @@ -syntax = "proto3"; - -package ASC.Files.Thirdparty.Box; - -message BoxCacheItem { - bool ResetAll = 1; - bool IsFile = 2; - bool IsFileExists = 3; - string Key = 4; -} \ No newline at end of file diff --git a/products/ASC.Files/Core/proto/DropboxCacheItem.proto b/products/ASC.Files/Core/proto/DropboxCacheItem.proto deleted file mode 100644 index 3a2ec9eb418..00000000000 --- a/products/ASC.Files/Core/proto/DropboxCacheItem.proto +++ /dev/null @@ -1,10 +0,0 @@ -syntax = "proto3"; - -package ASC.Files.Thirdparty.Dropbox; - -message DropboxCacheItem { - bool ResetAll = 1; - bool IsFile = 2; - bool IsFileExists = 3; - string Key = 4; -} \ No newline at end of file diff --git a/products/ASC.Files/Core/proto/GoogleDriveCacheItem.proto b/products/ASC.Files/Core/proto/GoogleDriveCacheItem.proto deleted file mode 100644 index 206b40ebc12..00000000000 --- a/products/ASC.Files/Core/proto/GoogleDriveCacheItem.proto +++ /dev/null @@ -1,12 +0,0 @@ -syntax = "proto3"; - -package ASC.Files.Thirdparty.GoogleDrive; - -message GoogleDriveCacheItem { - bool ResetAll = 1; - bool ResetEntry = 2; - bool ResetChilds = 3; - string Key = 4; - bool ChildFolder = 5; - bool ChildFolderExist = 6; -} \ No newline at end of file diff --git a/products/ASC.Files/Core/proto/ThumbnailRequest.proto b/products/ASC.Files/Core/proto/ThumbnailRequest.proto deleted file mode 100644 index 8b9f6be34cc..00000000000 --- a/products/ASC.Files/Core/proto/ThumbnailRequest.proto +++ /dev/null @@ -1,9 +0,0 @@ -syntax = "proto3"; - -package ASC.Web.Files; - -message ThumbnailRequest { - int32 Tenant = 1; - repeated int32 Files = 2; - string BaseUrl = 3; -} \ No newline at end of file diff --git a/products/ASC.Files/Core/proto/box_cache_item.proto b/products/ASC.Files/Core/proto/box_cache_item.proto new file mode 100644 index 00000000000..77cff3e1bd4 --- /dev/null +++ b/products/ASC.Files/Core/proto/box_cache_item.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package ASC.Files.Thirdparty.Box; + +message BoxCacheItem { + bool reset_all = 1; + bool is_file = 2; + bool is_file_exists = 3; + string key = 4; +} \ No newline at end of file diff --git a/products/ASC.Files/Core/proto/dropbox_cache_item.proto b/products/ASC.Files/Core/proto/dropbox_cache_item.proto new file mode 100644 index 00000000000..11927bee4f5 --- /dev/null +++ b/products/ASC.Files/Core/proto/dropbox_cache_item.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package ASC.Files.Thirdparty.Dropbox; + +message DropboxCacheItem { + bool reset_all = 1; + bool is_file = 2; + bool is_file_exists = 3; + string key = 4; +} \ No newline at end of file diff --git a/products/ASC.Files/Core/proto/google_drive_cache_item.proto b/products/ASC.Files/Core/proto/google_drive_cache_item.proto new file mode 100644 index 00000000000..d634dcc49ed --- /dev/null +++ b/products/ASC.Files/Core/proto/google_drive_cache_item.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +package ASC.Files.Thirdparty.GoogleDrive; + +message GoogleDriveCacheItem { + bool reset_all = 1; + bool reset_entry = 2; + bool reset_childs = 3; + string key = 4; + bool child_folder = 5; + bool child_folder_exist = 6; +} \ No newline at end of file diff --git a/products/ASC.Files/Core/proto/OneDriveCacheItem.proto b/products/ASC.Files/Core/proto/one_drive_cache_item.proto similarity index 66% rename from products/ASC.Files/Core/proto/OneDriveCacheItem.proto rename to products/ASC.Files/Core/proto/one_drive_cache_item.proto index 49de719aa9b..90ef8abdaad 100644 --- a/products/ASC.Files/Core/proto/OneDriveCacheItem.proto +++ b/products/ASC.Files/Core/proto/one_drive_cache_item.proto @@ -3,6 +3,6 @@ syntax = "proto3"; package ASC.Files.Thirdparty.OneDrive; message OneDriveCacheItem { - bool ResetAll = 1; - string Key = 2; + bool reset_all = 1; + string key = 2; } \ No newline at end of file diff --git a/products/ASC.Files/Core/proto/ProviderAccountCacheItem.proto b/products/ASC.Files/Core/proto/provider_account_cache_item.proto similarity index 81% rename from products/ASC.Files/Core/proto/ProviderAccountCacheItem.proto rename to products/ASC.Files/Core/proto/provider_account_cache_item.proto index c5c5bbbca23..4ea5ddba90e 100644 --- a/products/ASC.Files/Core/proto/ProviderAccountCacheItem.proto +++ b/products/ASC.Files/Core/proto/provider_account_cache_item.proto @@ -3,5 +3,5 @@ syntax = "proto3"; package ASC.Files.Thirdparty; message ProviderAccountCacheItem { - string Key = 1; + string key = 1; } \ No newline at end of file diff --git a/products/ASC.Files/Core/proto/SharePointProviderCacheItem.proto b/products/ASC.Files/Core/proto/share_point_provider_cache_item.proto similarity index 66% rename from products/ASC.Files/Core/proto/SharePointProviderCacheItem.proto rename to products/ASC.Files/Core/proto/share_point_provider_cache_item.proto index 36cf0e0b44e..50a271da573 100644 --- a/products/ASC.Files/Core/proto/SharePointProviderCacheItem.proto +++ b/products/ASC.Files/Core/proto/share_point_provider_cache_item.proto @@ -3,6 +3,6 @@ syntax = "proto3"; package ASC.Files.Thirdparty.SharePoint; message SharePointProviderCacheItem { - string FileKey = 1; - string FolderKey = 2; + string file_key = 1; + string folder_key = 2; } \ No newline at end of file diff --git a/products/ASC.Files/Core/proto/thumbnail_request.proto b/products/ASC.Files/Core/proto/thumbnail_request.proto new file mode 100644 index 00000000000..2b16ae08132 --- /dev/null +++ b/products/ASC.Files/Core/proto/thumbnail_request.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package ASC.Web.Files; + +message ThumbnailRequest { + int32 tenant = 1; + repeated int32 files = 2; + string base_url = 3; +} \ No newline at end of file diff --git a/products/ASC.Files/Server/ASC.Files.csproj b/products/ASC.Files/Server/ASC.Files.csproj index 63b21a2e37b..6191d4ffc6b 100644 --- a/products/ASC.Files/Server/ASC.Files.csproj +++ b/products/ASC.Files/Server/ASC.Files.csproj @@ -21,6 +21,8 @@ + + diff --git a/products/ASC.Files/Server/Program.cs b/products/ASC.Files/Server/Program.cs index 302baa18db0..ec928e616c8 100644 --- a/products/ASC.Files/Server/Program.cs +++ b/products/ASC.Files/Server/Program.cs @@ -73,6 +73,8 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .AddJsonFile("storage.json") .AddJsonFile("kafka.json") .AddJsonFile($"kafka.{hostingContext.HostingEnvironment.EnvironmentName}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{hostingContext.HostingEnvironment.EnvironmentName}.json", true) .AddEnvironmentVariables() .AddCommandLine(args) .AddInMemoryCollection(new Dictionary diff --git a/products/ASC.Files/Server/Startup.cs b/products/ASC.Files/Server/Startup.cs index aa20ff056a5..bd5e7b825c9 100644 --- a/products/ASC.Files/Server/Startup.cs +++ b/products/ASC.Files/Server/Startup.cs @@ -11,7 +11,10 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Hosting; + +using StackExchange.Redis.Extensions.Core.Configuration; +using StackExchange.Redis.Extensions.Newtonsoft; namespace ASC.Files { @@ -41,6 +44,8 @@ public override void ConfigureServices(IServiceCollection services) DIHelper.TryAdd(); NotifyConfigurationExtension.Register(DIHelper); + + services.AddStackExchangeRedisExtensions(Configuration.GetSection("Redis").Get()); } public override void Configure(IApplicationBuilder app, IWebHostEnvironment env) diff --git a/products/ASC.Files/Service/ASC.Files.Service.csproj b/products/ASC.Files/Service/ASC.Files.Service.csproj index eb812ca123d..9d546106329 100644 --- a/products/ASC.Files/Service/ASC.Files.Service.csproj +++ b/products/ASC.Files/Service/ASC.Files.Service.csproj @@ -16,6 +16,8 @@ + + diff --git a/products/ASC.Files/Service/Program.cs b/products/ASC.Files/Service/Program.cs index e4c4d7e2618..23b4532c7d3 100644 --- a/products/ASC.Files/Service/Program.cs +++ b/products/ASC.Files/Service/Program.cs @@ -20,6 +20,9 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using StackExchange.Redis.Extensions.Core.Configuration; +using StackExchange.Redis.Extensions.Newtonsoft; + namespace ASC.Files.Service { public class Program @@ -56,6 +59,8 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .AddJsonFile($"notify.{env}.json", true) .AddJsonFile("kafka.json") .AddJsonFile($"kafka.{env}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{env}.json", true) .AddJsonFile("elastic.json", true) .AddEnvironmentVariables() .AddCommandLine(args) @@ -71,7 +76,18 @@ public static IHostBuilder CreateHostBuilder(string[] args) => var diHelper = new DIHelper(services); - diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>)); + var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get(); + + if (redisConfiguration != null) + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>)); + + services.AddStackExchangeRedisExtensions(redisConfiguration); + } + else + { + diHelper.TryAdd(typeof(ICacheNotify<>), typeof(MemoryCacheNotify<>)); + } diHelper.RegisterProducts(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath); diff --git a/products/ASC.Files/Tests/ASC.Files.Tests.csproj b/products/ASC.Files/Tests/ASC.Files.Tests.csproj index a238b46e80d..c5c4c9ec46e 100644 --- a/products/ASC.Files/Tests/ASC.Files.Tests.csproj +++ b/products/ASC.Files/Tests/ASC.Files.Tests.csproj @@ -19,7 +19,7 @@ - + @@ -30,9 +30,9 @@ - + - + diff --git a/products/ASC.Mail/Server/ASC.Mail.csproj b/products/ASC.Mail/Server/ASC.Mail.csproj index ac741f5d8a0..850c7d4ff2d 100644 --- a/products/ASC.Mail/Server/ASC.Mail.csproj +++ b/products/ASC.Mail/Server/ASC.Mail.csproj @@ -10,6 +10,8 @@ + + diff --git a/products/ASC.Mail/Server/Program.cs b/products/ASC.Mail/Server/Program.cs index c20c70705c7..f1acc198a7e 100644 --- a/products/ASC.Mail/Server/Program.cs +++ b/products/ASC.Mail/Server/Program.cs @@ -47,6 +47,8 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .AddJsonFile("storage.json") .AddJsonFile("kafka.json") .AddJsonFile($"kafka.{hostingContext.HostingEnvironment.EnvironmentName}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{hostingContext.HostingEnvironment.EnvironmentName}.json", true) .AddEnvironmentVariables() .AddCommandLine(args) .AddInMemoryCollection(new Dictionary diff --git a/products/ASC.Mail/Server/Startup.cs b/products/ASC.Mail/Server/Startup.cs index 0d09a614715..75335e52e7b 100644 --- a/products/ASC.Mail/Server/Startup.cs +++ b/products/ASC.Mail/Server/Startup.cs @@ -9,6 +9,9 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using StackExchange.Redis.Extensions.Core.Configuration; +using StackExchange.Redis.Extensions.Newtonsoft; + namespace ASC.Mail { public class Startup : BaseStartup @@ -24,6 +27,8 @@ public override void ConfigureServices(IServiceCollection services) Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); base.ConfigureServices(services); + + services.AddStackExchangeRedisExtensions(Configuration.GetSection("Redis").Get()); } public override void Configure(IApplicationBuilder app, IWebHostEnvironment env) diff --git a/products/ASC.People/Server/ASC.People.csproj b/products/ASC.People/Server/ASC.People.csproj index 27c2945ebb6..2e9ca05bb95 100644 --- a/products/ASC.People/Server/ASC.People.csproj +++ b/products/ASC.People/Server/ASC.People.csproj @@ -26,6 +26,8 @@ + + diff --git a/products/ASC.People/Server/Program.cs b/products/ASC.People/Server/Program.cs index 12409ef8afe..4017ed58631 100644 --- a/products/ASC.People/Server/Program.cs +++ b/products/ASC.People/Server/Program.cs @@ -69,6 +69,8 @@ public static IHostBuilder CreateHostBuilder(string[] args) .AddJsonFile("storage.json") .AddJsonFile("kafka.json") .AddJsonFile($"kafka.{hostingContext.HostingEnvironment.EnvironmentName}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{hostingContext.HostingEnvironment.EnvironmentName}.json", true) .AddEnvironmentVariables() .AddCommandLine(args) .AddInMemoryCollection(new Dictionary diff --git a/products/ASC.People/Server/Startup.cs b/products/ASC.People/Server/Startup.cs index 927fd8a7d0b..ab1340ced5c 100644 --- a/products/ASC.People/Server/Startup.cs +++ b/products/ASC.People/Server/Startup.cs @@ -5,11 +5,14 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - +using Microsoft.Extensions.Hosting; + +using StackExchange.Redis.Extensions.Core.Configuration; +using StackExchange.Redis.Extensions.Newtonsoft; + namespace ASC.People -{ - public class Startup : BaseStartup +{ +public class Startup : BaseStartup { public override bool ConfirmAddScheme { get => true; } @@ -22,7 +25,9 @@ public override void ConfigureServices(IServiceCollection services) base.ConfigureServices(services); DIHelper.TryAdd(); - DIHelper.TryAdd(); + DIHelper.TryAdd(); + + services.AddStackExchangeRedisExtensions(Configuration.GetSection("Redis").Get()); } } } \ No newline at end of file diff --git a/products/ASC.Projects/Server/ASC.Projects.csproj b/products/ASC.Projects/Server/ASC.Projects.csproj index 37e034f792f..6147c353a29 100644 --- a/products/ASC.Projects/Server/ASC.Projects.csproj +++ b/products/ASC.Projects/Server/ASC.Projects.csproj @@ -10,6 +10,8 @@ + + diff --git a/products/ASC.Projects/Server/Program.cs b/products/ASC.Projects/Server/Program.cs index c7d02eb957a..07ea75208f1 100644 --- a/products/ASC.Projects/Server/Program.cs +++ b/products/ASC.Projects/Server/Program.cs @@ -69,6 +69,8 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .AddJsonFile("storage.json") .AddJsonFile("kafka.json") .AddJsonFile($"kafka.{hostingContext.HostingEnvironment.EnvironmentName}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{hostingContext.HostingEnvironment.EnvironmentName}.json", true) .AddEnvironmentVariables() .AddCommandLine(args) .AddInMemoryCollection(new Dictionary diff --git a/products/ASC.Projects/Server/Startup.cs b/products/ASC.Projects/Server/Startup.cs index 7470890b4d1..3d5e35b6275 100644 --- a/products/ASC.Projects/Server/Startup.cs +++ b/products/ASC.Projects/Server/Startup.cs @@ -9,6 +9,9 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using StackExchange.Redis.Extensions.Core.Configuration; +using StackExchange.Redis.Extensions.Newtonsoft; + namespace ASC.Projects { public class Startup : BaseStartup @@ -24,6 +27,8 @@ public override void ConfigureServices(IServiceCollection services) Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); base.ConfigureServices(services); + + services.AddStackExchangeRedisExtensions(Configuration.GetSection("Redis").Get()); } public override void Configure(IApplicationBuilder app, IWebHostEnvironment env) diff --git a/web/ASC.Web.Api/ASC.Web.Api.csproj b/web/ASC.Web.Api/ASC.Web.Api.csproj index 86fd6999fd3..2c0093f5766 100644 --- a/web/ASC.Web.Api/ASC.Web.Api.csproj +++ b/web/ASC.Web.Api/ASC.Web.Api.csproj @@ -24,6 +24,8 @@ + + diff --git a/web/ASC.Web.Api/Program.cs b/web/ASC.Web.Api/Program.cs index f79fc93f873..836553f1dc0 100644 --- a/web/ASC.Web.Api/Program.cs +++ b/web/ASC.Web.Api/Program.cs @@ -68,6 +68,8 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .AddJsonFile("storage.json") .AddJsonFile("kafka.json") .AddJsonFile($"kafka.{hostingContext.HostingEnvironment.EnvironmentName}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{hostingContext.HostingEnvironment.EnvironmentName}.json", true) .AddEnvironmentVariables() .AddCommandLine(args) .AddInMemoryCollection(new Dictionary diff --git a/web/ASC.Web.Api/Startup.cs b/web/ASC.Web.Api/Startup.cs index eecedb371a7..9290236b371 100644 --- a/web/ASC.Web.Api/Startup.cs +++ b/web/ASC.Web.Api/Startup.cs @@ -5,8 +5,11 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - +using Microsoft.Extensions.Hosting; + +using StackExchange.Redis.Extensions.Core.Configuration; +using StackExchange.Redis.Extensions.Newtonsoft; + namespace ASC.Web.Api { public class Startup : BaseStartup @@ -30,7 +33,9 @@ public override void ConfigureServices(IServiceCollection services) DIHelper.TryAdd(); DIHelper.TryAdd(); DIHelper.TryAdd(); - DIHelper.TryAdd(); + DIHelper.TryAdd(); + + services.AddStackExchangeRedisExtensions(Configuration.GetSection("Redis").Get()); } } } diff --git a/web/ASC.Web.Core/ASC.Web.Core.csproj b/web/ASC.Web.Core/ASC.Web.Core.csproj index 49684aba690..b17ec7ac5e8 100644 --- a/web/ASC.Web.Core/ASC.Web.Core.csproj +++ b/web/ASC.Web.Core/ASC.Web.Core.csproj @@ -203,16 +203,16 @@ - - - - - + + + + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/web/ASC.Web.Core/Notify/StudioNotifyServiceHelper.cs b/web/ASC.Web.Core/Notify/StudioNotifyServiceHelper.cs index f3816152580..495118221e5 100644 --- a/web/ASC.Web.Core/Notify/StudioNotifyServiceHelper.cs +++ b/web/ASC.Web.Core/Notify/StudioNotifyServiceHelper.cs @@ -85,14 +85,14 @@ public void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[ if (objectID != null) { - item.ObjectID = objectID; + item.ObjectId = objectID; } if (recipients != null) { foreach (var r in recipients) { - var recipient = new Recipient { ID = r.ID, Name = r.Name }; + var recipient = new Recipient { Id = r.ID, Name = r.Name }; if (r is IDirectRecipient d) { recipient.Addresses.AddRange(d.Addresses); diff --git a/web/ASC.Web.Core/Notify/StudioNotifyServiceSender.cs b/web/ASC.Web.Core/Notify/StudioNotifyServiceSender.cs index 197177bbfc7..061291e4d88 100644 --- a/web/ASC.Web.Core/Notify/StudioNotifyServiceSender.cs +++ b/web/ASC.Web.Core/Notify/StudioNotifyServiceSender.cs @@ -99,8 +99,8 @@ public void OnMessage(NotifyItem item) client.SendNoticeToAsync( (NotifyAction)item.Action, - item.ObjectID, - item.Recipients?.Select(r => r.IsGroup ? new RecipientsGroup(r.ID, r.Name) : (IRecipient)new DirectRecipient(r.ID, r.Name, r.Addresses.ToArray(), r.CheckActivation)).ToArray(), + item.ObjectId, + item.Recipients?.Select(r => r.IsGroup ? new RecipientsGroup(r.Id, r.Name) : (IRecipient)new DirectRecipient(r.Id, r.Name, r.Addresses.ToArray(), r.CheckActivation)).ToArray(), item.SenderNames.Any() ? item.SenderNames.ToArray() : null, item.CheckSubsciption, item.Tags.Select(r => new TagValue(r.Tag_, r.Value)).ToArray()); diff --git a/web/ASC.Web.Core/Users/UserPhotoManager.cs b/web/ASC.Web.Core/Users/UserPhotoManager.cs index e60b91b47a8..be4dc9f3347 100644 --- a/web/ASC.Web.Core/Users/UserPhotoManager.cs +++ b/web/ASC.Web.Core/Users/UserPhotoManager.cs @@ -117,13 +117,13 @@ public UserPhotoManagerCache(ICacheNotify notify) CacheNotify.Subscribe((data) => { - var userId = new Guid(data.UserID.ToByteArray()); + var userId = new Guid(data.UserId); Photofiles.GetOrAdd(data.Size, (r) => new ConcurrentDictionary())[userId] = data.FileName; }, CacheNotifyAction.InsertOrUpdate); CacheNotify.Subscribe((data) => { - var userId = new Guid(data.UserID.ToByteArray()); + var userId = new Guid(data.UserId); try { @@ -153,19 +153,19 @@ public bool SetCacheLoadedForTenant(bool isLoaded, int tenantId) return isLoaded ? TenantDiskCache.Add(tenantId) : TenantDiskCache.Remove(tenantId); } - public void ClearCache(Guid userID) + public void ClearCache(Guid userID, int tenantId) { if (CacheNotify != null) { - CacheNotify.Publish(new UserPhotoManagerCacheItem { UserID = Google.Protobuf.ByteString.CopyFrom(userID.ToByteArray()) }, CacheNotifyAction.Remove); + CacheNotify.Publish(new UserPhotoManagerCacheItem { UserId = userID.ToString(), TenantId = tenantId }, CacheNotifyAction.Remove); } } - public void AddToCache(Guid userID, Size size, string fileName) + public void AddToCache(Guid userID, Size size, string fileName, int tenantId) { if (CacheNotify != null) { - CacheNotify.Publish(new UserPhotoManagerCacheItem { UserID = Google.Protobuf.ByteString.CopyFrom(userID.ToByteArray()), Size = UserPhotoManager.ToCache(size), FileName = fileName }, CacheNotifyAction.InsertOrUpdate); + CacheNotify.Publish(new UserPhotoManagerCacheItem { UserId = userID.ToString(), Size = UserPhotoManager.ToCache(size), FileName = fileName, TenantId = tenantId }, CacheNotifyAction.InsertOrUpdate); } } @@ -326,8 +326,6 @@ public string GetDefaultRetinaPhotoURL() return defaultRetinaPhotoURL ??= GetDefaultPhotoAbsoluteWebPath(RetinaFotoSize); } - - public static Size OriginalFotoSize { get; } = new Size(1280, 1280); public static Size RetinaFotoSize { get; } = new Size(360, 360); @@ -375,7 +373,7 @@ public string GetPhotoAbsoluteWebPath(Guid userID) photoUrl = SaveOrUpdatePhoto(userID, data, -1, new Size(-1, -1), false, out fileName); } - UserPhotoManagerCache.AddToCache(userID, Size.Empty, fileName); + UserPhotoManagerCache.AddToCache(userID, Size.Empty, fileName, tenant.TenantId); return photoUrl; } @@ -422,7 +420,7 @@ private string GetSizedPhotoAbsoluteWebPath(Guid userID, Size size, out bool isd //empty photo. cache default var photoUrl = GetDefaultPhotoAbsoluteWebPath(size); - UserPhotoManagerCache.AddToCache(userID, size, "default"); + UserPhotoManagerCache.AddToCache(userID, size, "default", tenant.TenantId); isdef = true; return photoUrl; } @@ -501,7 +499,7 @@ private void LoadDiskCache() //Parse size size = new Size(int.Parse(match.Groups["width"].Value), int.Parse(match.Groups["height"].Value)); } - UserPhotoManagerCache.AddToCache(parsedUserId, size, fileName); + UserPhotoManagerCache.AddToCache(parsedUserId, size, fileName, tenant.TenantId); } } } @@ -539,7 +537,7 @@ public void RemovePhoto(Guid idUser) } UserManager.SaveUserPhoto(idUser, null); - UserPhotoManagerCache.ClearCache(idUser); + UserPhotoManagerCache.ClearCache(idUser, tenant.TenantId); } public void SyncPhoto(Guid userID, byte[] data) @@ -547,7 +545,7 @@ public void SyncPhoto(Guid userID, byte[] data) data = TryParseImage(data, -1, OriginalFotoSize, out _, out int width, out int height); UserManager.SaveUserPhoto(userID, data); SetUserPhotoThumbnailSettings(userID, width, height); - UserPhotoManagerCache.ClearCache(userID); + UserPhotoManagerCache.ClearCache(userID, tenant.TenantId); } @@ -562,7 +560,7 @@ private string SaveOrUpdatePhoto(Guid userID, byte[] data, long maxFileSize, Siz { UserManager.SaveUserPhoto(userID, data); SetUserPhotoThumbnailSettings(userID, width, height); - UserPhotoManagerCache.ClearCache(userID); + UserPhotoManagerCache.ClearCache(userID, tenant.TenantId); } @@ -731,7 +729,7 @@ private void ResizeImage(ResizeWorkerItem item) using var stream2 = new MemoryStream(data); item.DataStore.Save(fileName, stream2).ToString(); - UserPhotoManagerCache.AddToCache(item.UserId, item.Size, fileName); + UserPhotoManagerCache.AddToCache(item.UserId, item.Size, fileName, tenant.TenantId); } catch (ArgumentException error) { @@ -844,7 +842,7 @@ public string SaveThumbnail(Guid userID, Image img, IImageFormat format) photoUrl = store.Save(fileName, s).ToString(); } - UserPhotoManagerCache.AddToCache(userID, size, fileName); + UserPhotoManagerCache.AddToCache(userID, size, fileName, tenant.TenantId); return photoUrl; } diff --git a/web/ASC.Web.Core/protos/UserPhotoManagerCacheItem.proto b/web/ASC.Web.Core/protos/UserPhotoManagerCacheItem.proto deleted file mode 100644 index c3391acf930..00000000000 --- a/web/ASC.Web.Core/protos/UserPhotoManagerCacheItem.proto +++ /dev/null @@ -1,22 +0,0 @@ -syntax = "proto3"; - -package ASC.Web.Core.Users; - -message UserPhotoManagerCacheItem { - bytes UserID = 1; - - CacheSize Size = 2; - - string FileName = 3; - - int32 TenantId = 4; -} - -enum CacheSize { - Max = 0; - Retina = 1; - Big = 2; - Medium = 3; - Small = 4; - Original = 5; -} \ No newline at end of file diff --git a/web/ASC.Web.Core/protos/MailServiceHelperCache.proto b/web/ASC.Web.Core/protos/mail_service_helper_cache.proto similarity index 77% rename from web/ASC.Web.Core/protos/MailServiceHelperCache.proto rename to web/ASC.Web.Core/protos/mail_service_helper_cache.proto index 6caae52b3f0..b04b0be070f 100644 --- a/web/ASC.Web.Core/protos/MailServiceHelperCache.proto +++ b/web/ASC.Web.Core/protos/mail_service_helper_cache.proto @@ -1,8 +1,8 @@ - -syntax = "proto3"; - -package ASC.Web.Core; - -message MailServiceHelperCache { - string Key = 1; + +syntax = "proto3"; + +package ASC.Web.Core; + +message MailServiceHelperCache { + string key = 1; } \ No newline at end of file diff --git a/web/ASC.Web.Core/protos/SmsKeyCacheKey.proto b/web/ASC.Web.Core/protos/sms_key_cache_key.proto similarity index 75% rename from web/ASC.Web.Core/protos/SmsKeyCacheKey.proto rename to web/ASC.Web.Core/protos/sms_key_cache_key.proto index d68cbac20df..1122566b94e 100644 --- a/web/ASC.Web.Core/protos/SmsKeyCacheKey.proto +++ b/web/ASC.Web.Core/protos/sms_key_cache_key.proto @@ -1,8 +1,8 @@ - -syntax = "proto3"; - -package ASC.Web.Core; - -message SmsKeyCacheKey { - string Key = 1; + +syntax = "proto3"; + +package ASC.Web.Core; + +message SmsKeyCacheKey { + string key = 1; } \ No newline at end of file diff --git a/web/ASC.Web.Core/protos/TenantLogoCacheItem.proto b/web/ASC.Web.Core/protos/tenant_logo_cache_item.proto similarity index 78% rename from web/ASC.Web.Core/protos/TenantLogoCacheItem.proto rename to web/ASC.Web.Core/protos/tenant_logo_cache_item.proto index ec2552a457e..a3e22dab05e 100644 --- a/web/ASC.Web.Core/protos/TenantLogoCacheItem.proto +++ b/web/ASC.Web.Core/protos/tenant_logo_cache_item.proto @@ -1,8 +1,8 @@ - -syntax = "proto3"; - -package ASC.Web.Core.WhiteLabel; - -message TenantLogoCacheItem { - string Key = 1; + +syntax = "proto3"; + +package ASC.Web.Core.WhiteLabel; + +message TenantLogoCacheItem { + string key = 1; } \ No newline at end of file diff --git a/web/ASC.Web.Core/protos/user_photo_manager_cache_item.proto b/web/ASC.Web.Core/protos/user_photo_manager_cache_item.proto new file mode 100644 index 00000000000..cad031badb3 --- /dev/null +++ b/web/ASC.Web.Core/protos/user_photo_manager_cache_item.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; + +package ASC.Web.Core.Users; + +message UserPhotoManagerCacheItem { + string user_id = 1; + CacheSize size = 2; + string file_name = 3; + int32 tenant_id = 4; +} + +enum CacheSize { + MAX = 0; + RETINA = 1; + BIG = 2; + MEDIUM = 3; + SMALL = 4; + ORIGINAL = 5; +} \ No newline at end of file diff --git a/web/ASC.Web.Core/protos/WebItemSecurityNotifier.proto b/web/ASC.Web.Core/protos/web_item_security_notifier.proto similarity index 73% rename from web/ASC.Web.Core/protos/WebItemSecurityNotifier.proto rename to web/ASC.Web.Core/protos/web_item_security_notifier.proto index a2f37ba536f..3e5e0c166d6 100644 --- a/web/ASC.Web.Core/protos/WebItemSecurityNotifier.proto +++ b/web/ASC.Web.Core/protos/web_item_security_notifier.proto @@ -1,8 +1,8 @@ - -syntax = "proto3"; - -package ASC.Web.Core; - -message WebItemSecurityNotifier { - int32 Tenant = 1; + +syntax = "proto3"; + +package ASC.Web.Core; + +message WebItemSecurityNotifier { + int32 tenant = 1; } \ No newline at end of file diff --git a/web/ASC.Web.Studio/ASC.Web.Studio.csproj b/web/ASC.Web.Studio/ASC.Web.Studio.csproj index e4a7429970e..769d7a616a5 100644 --- a/web/ASC.Web.Studio/ASC.Web.Studio.csproj +++ b/web/ASC.Web.Studio/ASC.Web.Studio.csproj @@ -17,6 +17,8 @@ + + diff --git a/web/ASC.Web.Studio/Program.cs b/web/ASC.Web.Studio/Program.cs index fb8a125ffb8..4c09f77e21e 100644 --- a/web/ASC.Web.Studio/Program.cs +++ b/web/ASC.Web.Studio/Program.cs @@ -68,6 +68,8 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .AddJsonFile("storage.json") .AddJsonFile("kafka.json") .AddJsonFile($"kafka.{hostingContext.HostingEnvironment.EnvironmentName}.json", true) + .AddJsonFile("redis.json") + .AddJsonFile($"redis.{hostingContext.HostingEnvironment.EnvironmentName}.json", true) .AddEnvironmentVariables() .AddCommandLine(args) .AddInMemoryCollection(new Dictionary diff --git a/web/ASC.Web.Studio/Startup.cs b/web/ASC.Web.Studio/Startup.cs index 7dfd55a8e77..304e70ef11c 100644 --- a/web/ASC.Web.Studio/Startup.cs +++ b/web/ASC.Web.Studio/Startup.cs @@ -10,8 +10,11 @@ using Microsoft.AspNetCore.HttpOverrides; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - +using Microsoft.Extensions.Hosting; + +using StackExchange.Redis.Extensions.Core.Configuration; +using StackExchange.Redis.Extensions.Newtonsoft; + namespace ASC.Web.Studio { public class Startup : BaseStartup @@ -33,6 +36,8 @@ public override void ConfigureServices(IServiceCollection services) DIHelper.TryAdd(); DIHelper.TryAdd(); DIHelper.TryAdd(); + + services.AddStackExchangeRedisExtensions(Configuration.GetSection("Redis").Get()); } public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)