DocSpace-client/web/ASC.Web.Core/Files/DocumentServiceLicense.cs
pavelbannov 320a1f2250 Merge branch 'develop' into feature/backend-refactor
# Conflicts:
#	common/ASC.Api.Core/Core/BaseStartup.cs
#	common/ASC.Common/Caching/AscCache.cs
#	common/ASC.Common/Data/StreamExtension.cs
#	common/ASC.Common/Utils/RandomString.cs
#	common/ASC.Core.Common/Billing/CouponManager.cs
#	common/ASC.Core.Common/Billing/License/LicenseReader.cs
#	common/ASC.Core.Common/Core/UserGroupRef.cs
#	common/ASC.Core.Common/Data/DbTenantService.cs
#	common/ASC.Core.Common/Notify/Jabber/JabberServiceClientWcf.cs
#	common/ASC.Core.Common/Notify/Telegram/Dao/CachedTelegramDao.cs
#	common/ASC.Data.Backup.Core/Core/DbHelper.cs
#	common/ASC.Data.Backup.Core/Storage/BackupRepository.cs
#	common/ASC.Data.Backup.Core/Tasks/Data/TableInfo.cs
#	common/ASC.Data.Storage/BaseStorage.cs
#	common/ASC.Data.Storage/DiscStorage/DiscDataStore.cs
#	common/ASC.Data.Storage/GoogleCloud/GoogleCloudStorage.cs
#	common/ASC.Data.Storage/RackspaceCloud/RackspaceCloudStorage.cs
#	common/ASC.Data.Storage/S3/S3Storage.cs
#	common/ASC.Notify.Textile/JabberStyler.cs
#	common/ASC.Textile/Blocks/GlyphBlockModifier.cs
#	common/ASC.Textile/States/TableRowFormatterState.cs
#	common/services/ASC.ApiSystem/Classes/CommonMethods.cs
#	common/services/ASC.ApiSystem/Controllers/PortalController.cs
#	common/services/ASC.ClearEvents/Program.cs
#	common/services/ASC.TelegramService/Startup.cs
#	common/services/ASC.UrlShortener.Svc/Program.cs
#	products/ASC.Files/Core/Core/Entries/File.cs
#	products/ASC.Files/Core/Core/Entries/FileEntry.cs
#	products/ASC.Files/Core/Core/Entries/FileHelper.cs
#	products/ASC.Files/Core/Core/Entries/Folder.cs
#	products/ASC.Files/Core/Core/FileStorageService.cs
#	products/ASC.Files/Core/Core/Thirdparty/ProviderDao/ProviderDaoBase.cs
#	products/ASC.Files/Core/Helpers/ThirdpartyConfiguration.cs
#	products/ASC.Files/Core/HttpHandlers/FileHandler.ashx.cs
#	products/ASC.Files/Core/Services/DocumentService/Configuration.cs
#	products/ASC.Files/Core/Services/DocumentService/DocumentServiceConnector.cs
#	products/ASC.Files/Core/Services/DocumentService/DocumentServiceTracker.cs
#	products/ASC.Files/Core/Services/WCFService/FileOperations/FileDownloadOperation.cs
#	products/ASC.Files/Core/Services/WCFService/FileOperations/FileMoveCopyOperation.cs
#	products/ASC.Files/Core/Utils/EntryManager.cs
#	products/ASC.Files/Server/Helpers/FilesControllerHelper.cs
#	products/ASC.Files/Server/Startup.cs
#	products/ASC.Files/Service/Thumbnail/Builder.cs
#	products/ASC.Files/Service/Thumbnail/FileDataProvider.cs
#	products/ASC.People/Server/Startup.cs
#	web/ASC.Web.Core/Files/DocumentService.cs
#	web/ASC.Web.Core/Files/DocumentServiceLicense.cs
#	web/ASC.Web.Core/QuotaSync.cs
#	web/ASC.Web.Core/Sms/SmsKeyStorage.cs
#	web/ASC.Web.Core/Users/UserManagerWrapper.cs
#	web/ASC.Web.HealthChecks.UI/Program.cs
#	web/ASC.Web.Studio/Startup.cs
2022-02-10 13:16:33 +03:00

93 lines
3.2 KiB
C#

/*
*
* (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.
*
*/
namespace ASC.Web.Core.Files
{
[Scope]
public class DocumentServiceLicense
{
private static readonly TimeSpan CACHE_EXPIRATION = TimeSpan.FromMinutes(15);
private ICache Cache { get; }
public CoreBaseSettings CoreBaseSettings { get; }
private FilesLinkUtility FilesLinkUtility { get; }
private FileUtility FileUtility { get; }
private IHttpClientFactory ClientFactory { get; }
public DocumentServiceLicense(
ICache cache,
CoreBaseSettings coreBaseSettings,
FilesLinkUtility filesLinkUtility,
FileUtility fileUtility,
IHttpClientFactory clientFactory)
{
Cache = cache;
CoreBaseSettings = coreBaseSettings;
FilesLinkUtility = filesLinkUtility;
FileUtility = fileUtility;
ClientFactory = clientFactory;
}
private CommandResponse GetDocumentServiceLicense()
{
if (!CoreBaseSettings.Standalone) return null;
if (string.IsNullOrEmpty(FilesLinkUtility.DocServiceCommandUrl)) return null;
var cacheKey = "DocumentServiceLicense";
var commandResponse = Cache.Get<CommandResponse>(cacheKey);
if (commandResponse == null)
{
commandResponse = DocumentService.CommandRequest(
FileUtility,
FilesLinkUtility.DocServiceCommandUrl,
DocumentService.CommandMethod.License,
null,
null,
null,
null,
FileUtility.SignatureSecret,
ClientFactory
);
Cache.Insert(cacheKey, commandResponse, DateTime.UtcNow.Add(CACHE_EXPIRATION));
}
return commandResponse;
}
public Dictionary<string, DateTime> GetLicenseQuota()
{
var commandResponse = GetDocumentServiceLicense();
if (commandResponse == null
|| commandResponse.Quota == null
|| commandResponse.Quota.Users == null)
return null;
var result = new Dictionary<string, DateTime>();
commandResponse.Quota.Users.ForEach(user => result.Add(user.UserId, user.Expire));
return result;
}
public License GetLicense()
{
var commandResponse = GetDocumentServiceLicense();
if (commandResponse == null)
return null;
return commandResponse.License;
}
}
}