Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Commit

Permalink
fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
guanwantony committed Apr 6, 2021
1 parent 32720f6 commit c9f998b
Show file tree
Hide file tree
Showing 15 changed files with 232 additions and 92 deletions.
23 changes: 21 additions & 2 deletions Src/NCloud.Core/Abstractions/IFileManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace NCloud.Core.Abstractions
{
using NCloud.Core.Model;
using System.Collections.Generic;
using NCloud.Core.Model;

/// <summary>
/// Defines the <see cref="IFileManager" />.
Expand All @@ -28,14 +28,20 @@ public interface IFileManager
/// <returns>The <see cref="string"/>.</returns>
public string GetRootId();

/// <summary>
/// The GetRootId.
/// </summary>
/// <returns>The <see cref="string"/>.</returns>
public string GetBaseId();

/// <summary>
/// The GetSupportExtraFileOperations.
/// </summary>
/// <returns>The <see cref="FileOperations[]"/>.</returns>
sealed public List<FileOperations> GetSupportExtraFileOperations()
{
List<FileOperations> list = new List<FileOperations>();
if(this is IStreamable)
if (this is IStreamable)
{
list.Add(FileOperations.Stream);
}
Expand All @@ -45,9 +51,11 @@ sealed public List<FileOperations> GetSupportExtraFileOperations()
}
return list;
}

/// <summary>
/// The GetSupportExtraFileOperations.
/// </summary>
/// <param name="operations">The operations<see cref="FileOperations"/>.</param>
/// <returns>The <see cref="FileOperations[]"/>.</returns>
sealed public bool IsSupport(FileOperations operations)
{
Expand All @@ -68,8 +76,19 @@ sealed public bool IsSupport(FileOperations operations)
/// </summary>
public enum FileOperations
{
/// <summary>
/// Defines the Upload.
/// </summary>
Upload,

/// <summary>
/// Defines the Stream.
/// </summary>
Stream,

/// <summary>
/// Defines the Redirect.
/// </summary>
Redirect
}
}
7 changes: 7 additions & 0 deletions Src/NCloud.Core/Abstractions/IFileManagerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ public interface IFileManagerFactory
/// <returns>The <see cref="IFileManager"/>.</returns>
public IFileManager GetFileManager(string baseId);

/// <summary>
/// The GetFileManagerByUrl.
/// </summary>
/// <param name="url">The url<see cref="string"/>.</param>
/// <returns>The <see cref="IFileManager"/>.</returns>
public IFileManager GetFileManagerByUrl(string url);

/// <summary>
/// The AddDriver.
/// </summary>
Expand Down
10 changes: 9 additions & 1 deletion Src/NCloud.Core/Abstractions/IFileManagerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ public interface IFileManagerProvider
/// The GetFileManager.
/// </summary>
/// <param name="url">The url<see cref="string"/>.</param>
/// <param name="id">The id<see cref="string"/>.</param>
/// <returns>The <see cref="IFileManager"/>.</returns>
IFileManager GreateFileManager(string url);
IFileManager GreateFileManager(string url, out string id);

/// <summary>
/// The GetFileMangerBaseIdByUrl.
/// </summary>
/// <param name="url">The url<see cref="string"/>.</param>
/// <returns>The <see cref="string"/>.</returns>
string GetFileMangerBaseIdByUrl(string url);

/// <summary>
/// The IsSupport.
Expand Down
13 changes: 10 additions & 3 deletions Src/NCloud.Core/Abstractions/ISystemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,25 @@ public interface ISystemHelper
public string CreateFileManagerBaseId(string url);

/// <summary>
/// The GetFileManagerDisplayName.
/// The GetParentId.
/// </summary>
/// <param name="url">The url<see cref="string"/>.</param>
/// <returns>The <see cref="string"/>.</returns>
public string GetFileManagerDisplayName(string url);
public string GetParentId(string url);

/// <summary>
/// The GetParentBaseId.
/// </summary>
/// <param name="url">The url<see cref="string"/>.</param>
/// <returns>The <see cref="string"/>.</returns>
public string GetParentBaseId(string url);

/// <summary>
/// The GetFileManagerDisplayName.
/// </summary>
/// <param name="url">The url<see cref="string"/>.</param>
/// <returns>The <see cref="string"/>.</returns>
public string GetFileManagerRootPath(string url);
public string GetFileManagerDisplayName(string url);

/// <summary>
/// The GetFileIdByPath.
Expand Down
10 changes: 9 additions & 1 deletion Src/NCloud.React/Controllers/Api/FileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.AspNetCore.Mvc;
using NCloud.Core.Abstractions;
using NCloud.React.Model.Response;
using NCloud.React.Service;

/// <summary>
/// 文件操作API.
Expand All @@ -20,15 +21,22 @@ public class FileController : IDynamicApiController
/// </summary>
private readonly ISystemHelper systemHelper;

/// <summary>
/// Defines the rootManagerInitializer.
/// </summary>
private readonly RootManagerInitializer rootManagerInitializer;

/// <summary>
/// Initializes a new instance of the <see cref="FileController"/> class.
/// </summary>
/// <param name="factory">The factory<see cref="IFileManagerFactory"/>.</param>
/// <param name="systemHelper">The fileIdGenerator<see cref="ISystemHelper"/>.</param>
public FileController(IFileManagerFactory factory, ISystemHelper systemHelper)
/// <param name="rootManagerInitializer">The rootManagerInitializer<see cref="RootManagerInitializer"/>.</param>
public FileController(IFileManagerFactory factory, ISystemHelper systemHelper, RootManagerInitializer rootManagerInitializer)
{
this.factory = factory;
this.systemHelper = systemHelper;
this.rootManagerInitializer = rootManagerInitializer;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using Furion.ConfigurableOptions;

/// <summary>
/// Defines the <see cref="DevelopInitFilesOptions" />.
/// Defines the <see cref="InitFilesOptions" />.
/// </summary>
public class DevelopInitFilesOptions : IConfigurableOptions
public class InitFilesOptions : IConfigurableOptions
{
/// <summary>
/// Gets or sets the Urls.
Expand Down
21 changes: 12 additions & 9 deletions Src/NCloud.React/Service/FileManager/DefaultFileManagerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public class DefaultFileManagerFactory : IFileManagerFactory
/// <summary>
/// Initializes a new instance of the <see cref="DefaultFileManagerFactory"/> class.
/// </summary>
/// <param name="providers">The drivers<see cref="List{IDriver}"/>.</param>
/// <param name="providers">The drivers<see cref="IEnumerable{IDriver}"/>.</param>
/// <param name="systemHelper">The fileIdGenerator<see cref="ISystemHelper"/>.</param>
public DefaultFileManagerFactory(List<IFileManagerProvider> providers, ISystemHelper systemHelper)
public DefaultFileManagerFactory(IEnumerable<IFileManagerProvider> providers, ISystemHelper systemHelper)
{
this.providers = providers;
this.providers = new List<IFileManagerProvider>(providers);
this.fileManagers = new Dictionary<string, IFileManager>();
this.systemHelper = systemHelper;
}
Expand All @@ -44,8 +44,11 @@ public DefaultFileManagerFactory(List<IFileManagerProvider> providers, ISystemHe
/// <returns>The <see cref="IFileManager"/>.</returns>
public IFileManager GetFileManager(string baseId)
{
var url = this.systemHelper.GetFilePathById(baseId);
return GetFileManagerByUrl(url);
if (this.fileManagers.ContainsKey(baseId))
{
return fileManagers[baseId];
}
return null;
}

/// <summary>
Expand All @@ -55,16 +58,16 @@ public IFileManager GetFileManager(string baseId)
/// <returns>The <see cref="IFileManager"/>.</returns>
public IFileManager GetFileManagerByUrl(string url)
{
var baseId = this.systemHelper.CreateFileManagerBaseId(url);
IFileManagerProvider driver = this.providers.Where(e => e.IsSupport(url)).First();
var baseId = driver.GetFileMangerBaseIdByUrl(url);
if (this.fileManagers.ContainsKey(baseId))
{
return fileManagers[baseId];
}
else
{
IFileManagerProvider driver = this.providers.Where(e => e.IsSupport(url)).First();
IFileManager manager = driver.GreateFileManager(url);
this.fileManagers[baseId] = manager;
IFileManager manager = driver.GreateFileManager(url,out var id);
this.fileManagers[id] = manager;
return manager;
}
}
Expand Down
5 changes: 5 additions & 0 deletions Src/NCloud.React/Service/FileManager/LocalFileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public LocalFileManager(ISystemHelper helper, string root, string name, string b
this.logger.LogInformation($"Loading rootPath:{rootPath} name:{name} baseId:{baseId}");
}

public string GetBaseId()
{
return this.GetBaseId();
}

/// <summary>
/// The GetDownloadUrl.
/// </summary>
Expand Down
31 changes: 15 additions & 16 deletions Src/NCloud.React/Service/FileManager/LocalFileManagerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ public class LocalFileManagerProvider : IFileManagerProvider
/// </summary>
private readonly ILogger<LocalFileManager> logger;

/// <summary>
/// Defines the parentId.
/// </summary>
private readonly string parentId;

/// <summary>
/// Defines the parentBaseId.
/// </summary>
private readonly string parentBaseId;

/// <summary>
/// Initializes a new instance of the <see cref="LocalFileManagerProvider"/> class.
/// </summary>
Expand All @@ -46,25 +36,34 @@ public LocalFileManagerProvider(ISystemHelper helper, ILogger<LocalFileManager>
{
this.helper = helper;
this.logger = logger;
this.parentId = helper.GetRootId();
this.parentBaseId = helper.GetRootBaseId();
}

/// <summary>
/// The GetFileMangerBaseIdByUrl.
/// </summary>
/// <param name="url">The url<see cref="string"/>.</param>
/// <returns>The <see cref="string"/>.</returns>
public string GetFileMangerBaseIdByUrl(string url)
{
return helper.CreateFileManagerBaseId(url);
}

/// <summary>
/// The GreateFileManager.
/// </summary>
/// <param name="url">The url<see cref="string"/>.</param>
/// <param name="id">The id<see cref="string"/>.</param>
/// <returns>The <see cref="IFileManager"/>.</returns>
public IFileManager GreateFileManager(string url)
public IFileManager GreateFileManager(string url, out string id)
{
if (!((IFileManagerProvider)this).IsSupport(url))
{
throw Oops.Oh(10001, url);
}
var baseId = helper.CreateFileManagerBaseId(url);
var rootPath = helper.GetFileManagerRootPath(url);
id = helper.CreateFileManagerBaseId(url);
var rootPath = UrlUtils.GetParam(url, "root");
var displayName = helper.GetFileManagerDisplayName(url);
return new LocalFileManager(helper, rootPath, displayName, baseId, this.parentBaseId, this.parentId, this.logger);
return new LocalFileManager(helper, rootPath, displayName, id, helper.GetParentBaseId(url), helper.GetParentId(url), this.logger);
}

/// <summary>
Expand Down
Loading

0 comments on commit c9f998b

Please sign in to comment.