Files: thirdparty refactoring
This commit is contained in:
parent
8f455e388f
commit
ff36878397
@ -41,5 +41,6 @@ namespace ASC.Files.Core
|
||||
|
||||
bool CheckAccess();
|
||||
void InvalidateStorage();
|
||||
void UpdateTitle(string newtitle);
|
||||
}
|
||||
}
|
@ -86,7 +86,10 @@ namespace ASC.Files.Thirdparty.Box
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
BoxProviderInfo.Dispose();
|
||||
if (BoxProviderInfo != null)
|
||||
{
|
||||
BoxProviderInfo.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
protected string MappingID(string id, bool saveIfNotExist = false)
|
||||
|
@ -30,8 +30,6 @@ using ASC.Common;
|
||||
using ASC.Files.Core;
|
||||
using ASC.Files.Core.Security;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace ASC.Files.Thirdparty.Box
|
||||
{
|
||||
internal class BoxDaoSelector : RegexDaoSelectorBase<BoxProviderInfo>, IDaoSelector
|
||||
@ -63,27 +61,8 @@ namespace ASC.Files.Thirdparty.Box
|
||||
{
|
||||
return base.GetSecurityDao<BoxSecurityDao>(id);
|
||||
}
|
||||
|
||||
public override string GetIdCode(string id)
|
||||
{
|
||||
if (id != null)
|
||||
{
|
||||
var match = Selector.Match(id);
|
||||
if (match.Success)
|
||||
{
|
||||
return match.Groups["id"].Value;
|
||||
}
|
||||
}
|
||||
return base.GetIdCode(id);
|
||||
}
|
||||
|
||||
public override void RenameProvider(BoxProviderInfo boxProviderInfo, string newTitle)
|
||||
{
|
||||
var dbDao = ServiceProvider.GetService<CachedProviderAccountDao>();
|
||||
dbDao.UpdateProviderInfo(boxProviderInfo.ID, newTitle, null, boxProviderInfo.RootFolderType);
|
||||
boxProviderInfo.UpdateTitle(newTitle); //This will update cached version too
|
||||
}
|
||||
}
|
||||
|
||||
public static class BoxDaoSelectorExtention
|
||||
{
|
||||
public static DIHelper AddBoxDaoSelectorService(this DIHelper services)
|
||||
|
@ -135,7 +135,7 @@ namespace ASC.Files.Thirdparty.Box
|
||||
CacheReset();
|
||||
}
|
||||
|
||||
internal void UpdateTitle(string newtitle)
|
||||
public void UpdateTitle(string newtitle)
|
||||
{
|
||||
CustomerTitle = newtitle;
|
||||
}
|
||||
|
@ -86,7 +86,10 @@ namespace ASC.Files.Thirdparty.Dropbox
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
DropboxProviderInfo.Dispose();
|
||||
if (DropboxProviderInfo != null)
|
||||
{
|
||||
DropboxProviderInfo.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
protected string MappingID(string id, bool saveIfNotExist = false)
|
||||
|
@ -25,14 +25,11 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Files.Core;
|
||||
using ASC.Files.Core.Security;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace ASC.Files.Thirdparty.Dropbox
|
||||
{
|
||||
internal class DropboxDaoSelector : RegexDaoSelectorBase<DropboxProviderInfo>, IDaoSelector
|
||||
@ -64,27 +61,6 @@ namespace ASC.Files.Thirdparty.Dropbox
|
||||
{
|
||||
return base.GetSecurityDao<DropboxSecurityDao>(id);
|
||||
}
|
||||
|
||||
public override string GetIdCode(string id)
|
||||
{
|
||||
if (id != null)
|
||||
{
|
||||
var match = Selector.Match(Convert.ToString(id, CultureInfo.InvariantCulture));
|
||||
if (match.Success)
|
||||
{
|
||||
return match.Groups["id"].Value;
|
||||
}
|
||||
throw new ArgumentException("Id is not a Dropbox id");
|
||||
}
|
||||
return base.GetIdCode(id);
|
||||
}
|
||||
|
||||
public override void RenameProvider(DropboxProviderInfo dropboxProviderInfo, string newTitle)
|
||||
{
|
||||
var dbDao = ServiceProvider.GetService<CachedProviderAccountDao>();
|
||||
dbDao.UpdateProviderInfo(dropboxProviderInfo.ID, newTitle, null, dropboxProviderInfo.RootFolderType);
|
||||
dropboxProviderInfo.UpdateTitle(newTitle); //This will update cached version too
|
||||
}
|
||||
}
|
||||
|
||||
public static class DropboxDaoSelectorExtention
|
||||
|
@ -118,7 +118,7 @@ namespace ASC.Files.Thirdparty.Dropbox
|
||||
CacheReset();
|
||||
}
|
||||
|
||||
internal void UpdateTitle(string newtitle)
|
||||
public void UpdateTitle(string newtitle)
|
||||
{
|
||||
CustomerTitle = newtitle;
|
||||
}
|
||||
|
@ -92,7 +92,10 @@ namespace ASC.Files.Thirdparty.GoogleDrive
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GoogleDriveProviderInfo.Dispose();
|
||||
if (GoogleDriveProviderInfo != null)
|
||||
{
|
||||
GoogleDriveProviderInfo.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
protected string MappingID(string id, bool saveIfNotExist = false)
|
||||
|
@ -30,8 +30,6 @@ using ASC.Common;
|
||||
using ASC.Files.Core;
|
||||
using ASC.Files.Core.Security;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace ASC.Files.Thirdparty.GoogleDrive
|
||||
{
|
||||
internal class GoogleDriveDaoSelector : RegexDaoSelectorBase<GoogleDriveProviderInfo>, IDaoSelector
|
||||
@ -62,26 +60,6 @@ namespace ASC.Files.Thirdparty.GoogleDrive
|
||||
{
|
||||
return base.GetSecurityDao<GoogleDriveSecurityDao>(id);
|
||||
}
|
||||
|
||||
public override string GetIdCode(string id)
|
||||
{
|
||||
if (id != null)
|
||||
{
|
||||
var match = Selector.Match(id);
|
||||
if (match.Success)
|
||||
{
|
||||
return match.Groups["id"].Value;
|
||||
}
|
||||
}
|
||||
return base.GetIdCode(id);
|
||||
}
|
||||
|
||||
public override void RenameProvider(GoogleDriveProviderInfo googleDriveProviderInfo, string newTitle)
|
||||
{
|
||||
var dbDao = ServiceProvider.GetService<CachedProviderAccountDao>();
|
||||
dbDao.UpdateProviderInfo(googleDriveProviderInfo.ID, newTitle, null, googleDriveProviderInfo.RootFolderType);
|
||||
googleDriveProviderInfo.UpdateTitle(newTitle); //This will update cached version too
|
||||
}
|
||||
}
|
||||
|
||||
public static class GoogleDriveDaoSelectorExtention
|
||||
|
@ -148,7 +148,7 @@ namespace ASC.Files.Thirdparty.GoogleDrive
|
||||
CacheReset();
|
||||
}
|
||||
|
||||
internal void UpdateTitle(string newtitle)
|
||||
public void UpdateTitle(string newtitle)
|
||||
{
|
||||
CustomerTitle = newtitle;
|
||||
}
|
||||
|
@ -24,12 +24,14 @@
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
|
||||
using ASC.Files.Core;
|
||||
using ASC.Files.Core.Security;
|
||||
|
||||
namespace ASC.Files.Thirdparty
|
||||
{
|
||||
internal interface IDaoSelector
|
||||
internal interface IDaoSelector : IDisposable
|
||||
{
|
||||
bool IsMatch(string id);
|
||||
IFileDao<string> GetFileDao(string id);
|
||||
|
12
products/ASC.Files/Server/Core/Thirdparty/IThirdPartyProviderDao.cs
vendored
Normal file
12
products/ASC.Files/Server/Core/Thirdparty/IThirdPartyProviderDao.cs
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
using ASC.Files.Core;
|
||||
using ASC.Files.Core.Thirdparty;
|
||||
|
||||
namespace ASC.Files.Thirdparty
|
||||
{
|
||||
internal interface IThirdPartyProviderDao<T> : IDisposable where T : class, IProviderInfo
|
||||
{
|
||||
void Init(BaseProviderInfo<T> t1, RegexDaoSelectorBase<T> selectorBase);
|
||||
}
|
||||
}
|
@ -84,7 +84,10 @@ namespace ASC.Files.Thirdparty.OneDrive
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
OneDriveProviderInfo.Dispose();
|
||||
if (OneDriveProviderInfo != null)
|
||||
{
|
||||
OneDriveProviderInfo.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
protected string MappingID(string id, bool saveIfNotExist = false)
|
||||
|
@ -30,8 +30,6 @@ using ASC.Common;
|
||||
using ASC.Files.Core;
|
||||
using ASC.Files.Core.Security;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace ASC.Files.Thirdparty.OneDrive
|
||||
{
|
||||
internal class OneDriveDaoSelector : RegexDaoSelectorBase<OneDriveProviderInfo>, IDaoSelector
|
||||
@ -63,27 +61,6 @@ namespace ASC.Files.Thirdparty.OneDrive
|
||||
{
|
||||
return base.GetSecurityDao<OneDriveSecurityDao>(id);
|
||||
}
|
||||
|
||||
public override string GetIdCode(string id)
|
||||
{
|
||||
if (id != null)
|
||||
{
|
||||
var match = Selector.Match(id);
|
||||
if (match.Success)
|
||||
{
|
||||
return match.Groups["id"].Value;
|
||||
}
|
||||
}
|
||||
return base.GetIdCode(id);
|
||||
}
|
||||
|
||||
|
||||
public override void RenameProvider(OneDriveProviderInfo onedriveProviderInfo, string newTitle)
|
||||
{
|
||||
var dbDao = ServiceProvider.GetService<CachedProviderAccountDao>();
|
||||
dbDao.UpdateProviderInfo(onedriveProviderInfo.ID, newTitle, null, onedriveProviderInfo.RootFolderType);
|
||||
onedriveProviderInfo.UpdateTitle(newTitle); //This will update cached version too
|
||||
}
|
||||
}
|
||||
|
||||
public static class OneDriveDaoSelectorExtention
|
||||
|
@ -119,10 +119,11 @@ namespace ASC.Files.Thirdparty.OneDrive
|
||||
CacheReset();
|
||||
}
|
||||
|
||||
internal void UpdateTitle(string newtitle)
|
||||
public void UpdateTitle(string newtitle)
|
||||
{
|
||||
CustomerTitle = newtitle;
|
||||
}
|
||||
|
||||
internal Item GetOneDriveItem(string itemId)
|
||||
{
|
||||
return OneDriveProviderInfoHelper.GetOneDriveItem(Storage, ID, itemId);
|
||||
|
@ -263,8 +263,7 @@ namespace ASC.Files.Thirdparty.ProviderDao
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
//TODO
|
||||
//throw new NotImplementedException();
|
||||
Selectors.ForEach(r => r.Dispose());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using ASC.Files.Core;
|
||||
@ -35,7 +36,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace ASC.Files.Thirdparty
|
||||
{
|
||||
internal abstract class RegexDaoSelectorBase<T> : IDaoSelector<T>, IDisposable where T : class, IProviderInfo
|
||||
internal abstract class RegexDaoSelectorBase<T> : IDaoSelector<T> where T : class, IProviderInfo
|
||||
{
|
||||
public IServiceProvider ServiceProvider { get; }
|
||||
public IDaoFactory DaoFactory { get; }
|
||||
@ -43,6 +44,8 @@ namespace ASC.Files.Thirdparty
|
||||
protected internal abstract string Name { get; }
|
||||
protected internal abstract string Id { get; }
|
||||
|
||||
private Dictionary<string, IThirdPartyProviderDao<T>> Providers { get; set; }
|
||||
|
||||
protected RegexDaoSelectorBase(
|
||||
IServiceProvider serviceProvider,
|
||||
IDaoFactory daoFactory)
|
||||
@ -50,6 +53,7 @@ namespace ASC.Files.Thirdparty
|
||||
ServiceProvider = serviceProvider;
|
||||
DaoFactory = daoFactory;
|
||||
Selector = new Regex(@"^" + Id + @"-(?'id'\d+)(-(?'path'.*)){0,1}$", RegexOptions.Singleline | RegexOptions.Compiled);
|
||||
Providers = new Dictionary<string, IThirdPartyProviderDao<T>>();
|
||||
}
|
||||
|
||||
public virtual string ConvertId(string id)
|
||||
@ -71,9 +75,17 @@ namespace ASC.Files.Thirdparty
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string GetIdCode(string id)
|
||||
public string GetIdCode(string id)
|
||||
{
|
||||
return null;
|
||||
if (id != null)
|
||||
{
|
||||
var match = Selector.Match(id);
|
||||
if (match.Success)
|
||||
{
|
||||
return match.Groups["id"].Value;
|
||||
}
|
||||
}
|
||||
throw new ArgumentException($"Id is not a {Name} id");
|
||||
}
|
||||
|
||||
public virtual bool IsMatch(string id)
|
||||
@ -103,10 +115,14 @@ namespace ASC.Files.Thirdparty
|
||||
|
||||
private T1 GetDao<T1>(string id) where T1 : IThirdPartyProviderDao<T>
|
||||
{
|
||||
if (Providers.ContainsKey(id)) return (T1)Providers[id];
|
||||
|
||||
var res = ServiceProvider.GetService<T1>();
|
||||
|
||||
res.Init(GetInfo(id), this);
|
||||
|
||||
Providers.Add(id, res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -130,7 +146,12 @@ namespace ASC.Files.Thirdparty
|
||||
throw new ArgumentException($"Id is not {Name} id");
|
||||
}
|
||||
|
||||
public abstract void RenameProvider(T provider, string newTitle);
|
||||
public void RenameProvider(T provider, string newTitle)
|
||||
{
|
||||
var dbDao = ServiceProvider.GetService<CachedProviderAccountDao>();
|
||||
dbDao.UpdateProviderInfo(provider.ID, newTitle, null, provider.RootFolderType);
|
||||
provider.UpdateTitle(newTitle); //This will update cached version too
|
||||
}
|
||||
|
||||
protected virtual T GetProviderInfo(int linkId)
|
||||
{
|
||||
@ -147,13 +168,10 @@ namespace ASC.Files.Thirdparty
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
//TODO
|
||||
//throw new NotImplementedException();
|
||||
foreach (var p in Providers)
|
||||
{
|
||||
p.Value.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal interface IThirdPartyProviderDao<T> where T : class, IProviderInfo
|
||||
{
|
||||
void Init(BaseProviderInfo<T> t1, RegexDaoSelectorBase<T> selectorBase);
|
||||
}
|
||||
}
|
@ -207,5 +207,13 @@ namespace ASC.Files.Thirdparty.SharePoint
|
||||
{
|
||||
return MappingID(id, false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (ProviderInfo != null)
|
||||
{
|
||||
ProviderInfo.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,8 +30,6 @@ using ASC.Common;
|
||||
using ASC.Files.Core;
|
||||
using ASC.Files.Core.Security;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace ASC.Files.Thirdparty.SharePoint
|
||||
{
|
||||
internal class SharePointDaoSelector : RegexDaoSelectorBase<SharePointProviderInfo>, IDaoSelector
|
||||
@ -76,26 +74,6 @@ namespace ASC.Files.Thirdparty.SharePoint
|
||||
}
|
||||
return base.ConvertId(null);
|
||||
}
|
||||
|
||||
public override string GetIdCode(string id)
|
||||
{
|
||||
if (id != null)
|
||||
{
|
||||
var match = Selector.Match(id);
|
||||
if (match.Success)
|
||||
{
|
||||
return match.Groups["id"].Value;
|
||||
}
|
||||
}
|
||||
return base.GetIdCode(id);
|
||||
}
|
||||
|
||||
public override void RenameProvider(SharePointProviderInfo sharePointProviderInfo, string newTitle)
|
||||
{
|
||||
var dbDao = ServiceProvider.GetService<CachedProviderAccountDao>();
|
||||
dbDao.UpdateProviderInfo(sharePointProviderInfo.ID, newTitle, null, sharePointProviderInfo.RootFolderType);
|
||||
sharePointProviderInfo.UpdateTitle(newTitle); //This will update cached version too
|
||||
}
|
||||
}
|
||||
|
||||
public static class SharePointDaoSelectorExtention
|
||||
|
@ -95,7 +95,7 @@ namespace ASC.Files.Thirdparty.SharePoint
|
||||
SharePointProviderInfoHelper.Invalidate();
|
||||
}
|
||||
|
||||
internal void UpdateTitle(string newtitle)
|
||||
public void UpdateTitle(string newtitle)
|
||||
{
|
||||
CustomerTitle = newtitle;
|
||||
}
|
||||
|
@ -571,5 +571,13 @@ namespace ASC.Files.Thirdparty.Sharpbox
|
||||
var staticText = match.Value.Substring(string.Format(" ({0})", index).Length);
|
||||
return string.Format(" ({0}){1}", index + 1, staticText);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (SharpBoxProviderInfo != null)
|
||||
{
|
||||
SharpBoxProviderInfo.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -30,8 +30,6 @@ using ASC.Common;
|
||||
using ASC.Files.Core;
|
||||
using ASC.Files.Core.Security;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace ASC.Files.Thirdparty.Sharpbox
|
||||
{
|
||||
internal class SharpBoxDaoSelector : RegexDaoSelectorBase<SharpBoxProviderInfo>, IDaoSelector
|
||||
@ -63,26 +61,6 @@ namespace ASC.Files.Thirdparty.Sharpbox
|
||||
{
|
||||
return base.GetSecurityDao<SharpBoxSecurityDao>(id);
|
||||
}
|
||||
|
||||
public override string GetIdCode(string id)
|
||||
{
|
||||
if (id != null)
|
||||
{
|
||||
var match = Selector.Match(id);
|
||||
if (match.Success)
|
||||
{
|
||||
return match.Groups["id"].Value;
|
||||
}
|
||||
}
|
||||
return base.GetIdCode(id);
|
||||
}
|
||||
|
||||
public override void RenameProvider(SharpBoxProviderInfo sharpBoxProviderInfo, string newTitle)
|
||||
{
|
||||
var dbDao = ServiceProvider.GetService<CachedProviderAccountDao>();
|
||||
dbDao.UpdateProviderInfo(sharpBoxProviderInfo.ID, newTitle, null, sharpBoxProviderInfo.RootFolderType);
|
||||
sharpBoxProviderInfo.UpdateTitle(newTitle); //This will update cached version too
|
||||
}
|
||||
}
|
||||
|
||||
public static class SharpBoxDaoSelectorExtention
|
||||
|
@ -79,7 +79,7 @@ namespace ASC.Files.Thirdparty.Sharpbox
|
||||
get => Wrapper.Storage != null && Wrapper.Storage.IsOpened;
|
||||
}
|
||||
|
||||
internal void UpdateTitle(string newtitle)
|
||||
public void UpdateTitle(string newtitle)
|
||||
{
|
||||
CustomerTitle = newtitle;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user