2019-06-04 14:43:20 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) Copyright Ascensio System Limited 2010-2018
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2020-08-26 07:07:12 +00:00
|
|
|
using System;
|
|
|
|
|
2020-08-27 14:01:37 +00:00
|
|
|
using ASC.Common;
|
2020-08-21 08:05:27 +00:00
|
|
|
using ASC.Common.Caching;
|
2020-08-26 07:07:12 +00:00
|
|
|
using ASC.Common.Threading.Progress;
|
2019-06-04 14:43:20 +00:00
|
|
|
using ASC.Data.Storage.Configuration;
|
2020-08-21 08:05:27 +00:00
|
|
|
using ASC.Migration;
|
2019-06-04 14:43:20 +00:00
|
|
|
|
2020-08-26 07:07:12 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
2019-06-04 14:43:20 +00:00
|
|
|
namespace ASC.Data.Storage.Migration
|
|
|
|
{
|
2020-08-27 14:01:37 +00:00
|
|
|
public class ServiceClientListener
|
|
|
|
{
|
|
|
|
public ICacheNotify<MigrationProgress> ProgressMigrationNotify { get; }
|
|
|
|
public IServiceProvider ServiceProvider { get; }
|
|
|
|
|
|
|
|
public ServiceClientListener(
|
|
|
|
ICacheNotify<MigrationProgress> progressMigrationNotify,
|
|
|
|
IServiceProvider serviceProvider)
|
|
|
|
{
|
|
|
|
ProgressMigrationNotify = progressMigrationNotify;
|
|
|
|
ServiceProvider = serviceProvider;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void GetProgress()
|
|
|
|
{
|
|
|
|
ProgressMigrationNotify.Subscribe(n =>
|
|
|
|
{
|
|
|
|
using var scope = ServiceProvider.CreateScope();
|
|
|
|
var service = scope.ServiceProvider.GetService<ServiceClient>();
|
|
|
|
service.GetProgress(n.TenantId);
|
|
|
|
},
|
|
|
|
CacheNotifyAction.Insert);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-21 08:05:27 +00:00
|
|
|
public class ServiceClient : IService
|
2019-06-04 14:43:20 +00:00
|
|
|
{
|
2020-08-27 14:01:37 +00:00
|
|
|
public ServiceClientListener ServiceClientListener { get; }
|
2020-08-26 07:07:12 +00:00
|
|
|
public ICacheNotify<MigrationCache> CacheMigrationNotify { get; }
|
2020-08-27 14:01:37 +00:00
|
|
|
public ICacheNotify<MigrationUploadCdn> UploadCdnMigrationNotify { get; }
|
2020-08-26 07:07:12 +00:00
|
|
|
public IServiceProvider ServiceProvider { get; }
|
|
|
|
public ICache Cache { get; }
|
2020-08-21 08:05:27 +00:00
|
|
|
|
2020-08-26 07:07:12 +00:00
|
|
|
public ServiceClient(
|
2020-08-27 14:01:37 +00:00
|
|
|
ServiceClientListener serviceClientListener,
|
2020-08-26 07:07:12 +00:00
|
|
|
ICacheNotify<MigrationCache> cacheMigrationNotify,
|
2020-08-27 14:01:37 +00:00
|
|
|
ICacheNotify<MigrationUploadCdn> uploadCdnMigrationNotify,
|
2020-08-26 07:07:12 +00:00
|
|
|
IServiceProvider serviceProvider,
|
|
|
|
ICache cache)
|
2020-08-21 08:05:27 +00:00
|
|
|
{
|
2020-08-27 14:01:37 +00:00
|
|
|
ServiceClientListener = serviceClientListener;
|
2020-08-26 07:07:12 +00:00
|
|
|
CacheMigrationNotify = cacheMigrationNotify;
|
2020-08-27 14:01:37 +00:00
|
|
|
UploadCdnMigrationNotify = uploadCdnMigrationNotify;
|
2020-08-26 07:07:12 +00:00
|
|
|
ServiceProvider = serviceProvider;
|
|
|
|
Cache = cache;
|
2020-08-21 08:05:27 +00:00
|
|
|
}
|
|
|
|
|
2019-06-04 14:43:20 +00:00
|
|
|
public void Migrate(int tenant, StorageSettings storageSettings)
|
|
|
|
{
|
2020-08-27 14:01:37 +00:00
|
|
|
var storSettings = new StorSettings { ID = storageSettings.ID.ToString(), Module = storageSettings.Module };
|
2020-08-21 08:05:27 +00:00
|
|
|
|
2020-08-26 07:07:12 +00:00
|
|
|
CacheMigrationNotify.Publish(new MigrationCache
|
2020-08-21 08:05:27 +00:00
|
|
|
{
|
2020-08-27 14:01:37 +00:00
|
|
|
TenantId = tenant,
|
2020-08-21 08:05:27 +00:00
|
|
|
StorSettings = storSettings
|
|
|
|
},
|
|
|
|
CacheNotifyAction.Insert);
|
2019-06-04 14:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void UploadCdn(int tenantId, string relativePath, string mappedPath, CdnStorageSettings settings = null)
|
|
|
|
{
|
2020-08-27 14:01:37 +00:00
|
|
|
var cdnStorSettings = new CdnStorSettings { ID = settings.ID.ToString(), Module = settings.Module };
|
2020-08-21 08:05:27 +00:00
|
|
|
|
2020-08-27 14:01:37 +00:00
|
|
|
UploadCdnMigrationNotify.Publish(new MigrationUploadCdn
|
2020-08-21 08:05:27 +00:00
|
|
|
{
|
2020-08-27 14:01:37 +00:00
|
|
|
Tenant = tenantId,
|
2020-08-21 08:05:27 +00:00
|
|
|
RelativePath = relativePath,
|
|
|
|
MappedPath = mappedPath,
|
|
|
|
CdnStorSettings = cdnStorSettings
|
|
|
|
},
|
|
|
|
CacheNotifyAction.Insert);
|
2019-06-04 14:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public double GetProgress(int tenant)
|
|
|
|
{
|
2020-08-27 14:01:37 +00:00
|
|
|
ServiceClientListener.GetProgress();
|
2020-08-26 07:07:12 +00:00
|
|
|
|
2020-08-27 14:01:37 +00:00
|
|
|
var cache = Cache.Get<MigrationProgress>(GetCacheKey(tenant));
|
2020-08-21 08:05:27 +00:00
|
|
|
|
2020-08-26 07:07:12 +00:00
|
|
|
var progress = (ProgressBase)StorageUploader.GetProgress(tenant) ?? StaticUploader.GetProgress(tenant);
|
|
|
|
|
|
|
|
return progress != null ? progress.Percentage : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
private string GetCacheKey(int tenantId)
|
|
|
|
{
|
|
|
|
return typeof(MigrationProgress).FullName + tenantId;
|
2019-06-04 14:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void StopMigrate()
|
|
|
|
{
|
2020-08-26 07:07:12 +00:00
|
|
|
CacheMigrationNotify.Publish(new MigrationCache(), CacheNotifyAction.InsertOrUpdate);
|
2019-06-04 14:43:20 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-27 14:01:37 +00:00
|
|
|
|
|
|
|
public static class ServiceClientExtension
|
|
|
|
{
|
|
|
|
public static DIHelper AddServiceClient(this DIHelper services)
|
|
|
|
{
|
|
|
|
services.TryAddScoped<ServiceClient>();
|
|
|
|
services.TryAddSingleton<ServiceClientListener>();
|
|
|
|
|
|
|
|
return services;
|
|
|
|
}
|
|
|
|
}
|
2019-06-04 14:43:20 +00:00
|
|
|
}
|