diff --git a/Sources/Octockup.Server/Controllers/BackupController.cs b/Sources/Octockup.Server/Controllers/BackupController.cs index 5ab8650..9b33750 100644 --- a/Sources/Octockup.Server/Controllers/BackupController.cs +++ b/Sources/Octockup.Server/Controllers/BackupController.cs @@ -6,6 +6,7 @@ using Gridify.EntityFramework; using Microsoft.AspNetCore.Mvc; using Octockup.Server.Database; +using Octockup.Server.Extensions; using Octockup.Server.Models.Dto; using Octockup.Server.Providers.Storage; using Microsoft.AspNetCore.Authorization; @@ -45,7 +46,7 @@ public IEnumerable GetProviders() return _storageProviders.Select(p => new StorageProviderInfo() { Name = p.Name, - Parameters = p.Parameters + Parameters = p.GetParametersKeys() }); } } diff --git a/Sources/Octockup.Server/Extensions/ServiceCollectionExtensions.cs b/Sources/Octockup.Server/Extensions/ServiceCollectionExtensions.cs index 45d780a..9f49a50 100644 --- a/Sources/Octockup.Server/Extensions/ServiceCollectionExtensions.cs +++ b/Sources/Octockup.Server/Extensions/ServiceCollectionExtensions.cs @@ -21,7 +21,7 @@ public static IServiceCollection AddDbContext(this IServiceCollection string filename = FileSystemHelpers.GetFilePath(databaseFile); return services .AddDbContext(options => options - .UseSqlite("Data Source=" + databaseFile) + .UseSqlite("Data Source=" + filename) .UseLazyLoadingProxies()); } diff --git a/Sources/Octockup.Server/Extensions/StorageProviderExtensions.cs b/Sources/Octockup.Server/Extensions/StorageProviderExtensions.cs new file mode 100644 index 0000000..ea48d40 --- /dev/null +++ b/Sources/Octockup.Server/Extensions/StorageProviderExtensions.cs @@ -0,0 +1,19 @@ +using Octockup.Server.Providers.Storage; + +namespace Octockup.Server.Extensions +{ + public static class StorageProviderExtensions + { + public static IEnumerable GetParametersKeys(this IStorageProvider storageProvider) + { + // storageProvider is IStorageProvider but actually is IStorageProvider<>, get generic type + var type = storageProvider + .GetType() + .GetInterfaces() + .First(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IStorageProvider<>)) + .GetGenericArguments() + .First(); + return type.GetProperties().Select(p => p.Name); + } + } +} diff --git a/Sources/Octockup.Server/Program.cs b/Sources/Octockup.Server/Program.cs index 9f6e4aa..ef456df 100644 --- a/Sources/Octockup.Server/Program.cs +++ b/Sources/Octockup.Server/Program.cs @@ -18,6 +18,7 @@ public static void Main(string[] args) builder.Services.AddControllers(); builder.Services .AddStorageProvider() + .AddStorageProvider() .AddHttpContextAccessor() .AddValidatorsFromAssemblyContaining() .AddFluentValidationAutoValidation() diff --git a/Sources/Octockup.Server/Providers/Storage/BaseStorageParameters.cs b/Sources/Octockup.Server/Providers/Storage/BaseStorageParameters.cs new file mode 100644 index 0000000..d02f450 --- /dev/null +++ b/Sources/Octockup.Server/Providers/Storage/BaseStorageParameters.cs @@ -0,0 +1,11 @@ +namespace Octockup.Server.Providers.Storage +{ + public class BaseStorageParameters + { + public string RemoteHost { get; set; } = string.Empty; + public int RemotePort { get; set; } + public string Username { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public string RemotePath { get; set; } = string.Empty; + } +} \ No newline at end of file diff --git a/Sources/Octockup.Server/Providers/Storage/FtpProvider.cs b/Sources/Octockup.Server/Providers/Storage/FtpProvider.cs index 3febd48..6c6d3b4 100644 --- a/Sources/Octockup.Server/Providers/Storage/FtpProvider.cs +++ b/Sources/Octockup.Server/Providers/Storage/FtpProvider.cs @@ -2,19 +2,14 @@ namespace Octockup.Server.Providers.Storage { - public class FtpProvider : IStorageProvider + public class FtpProvider : IStorageProvider { public string Name => "FTP"; - - public IEnumerable Parameters => - [ - "RemoteHost", "RemotePort", "RemotePath", - "Username", "Password" - ]; + public BaseStorageParameters Parameters { get; set; } = null!; public IEnumerable GetAllFiles() { throw new NotImplementedException(); } } -} +} \ No newline at end of file diff --git a/Sources/Octockup.Server/Providers/Storage/IStorageProvider.cs b/Sources/Octockup.Server/Providers/Storage/IStorageProvider.cs index f32b470..43d1e7d 100644 --- a/Sources/Octockup.Server/Providers/Storage/IStorageProvider.cs +++ b/Sources/Octockup.Server/Providers/Storage/IStorageProvider.cs @@ -2,10 +2,14 @@ namespace Octockup.Server.Providers.Storage { + public interface IStorageProvider : IStorageProvider where TParams : class + { + TParams Parameters { get; set; } + } + public interface IStorageProvider { string Name { get; } - IEnumerable Parameters { get; } IEnumerable GetAllFiles(); } } \ No newline at end of file diff --git a/Sources/Octockup.Server/Providers/Storage/ScpProvider.cs b/Sources/Octockup.Server/Providers/Storage/ScpProvider.cs index 3b19cce..c216ee6 100644 --- a/Sources/Octockup.Server/Providers/Storage/ScpProvider.cs +++ b/Sources/Octockup.Server/Providers/Storage/ScpProvider.cs @@ -2,11 +2,10 @@ namespace Octockup.Server.Providers.Storage { - public class ScpProvider : IStorageProvider + public class ScpProvider : IStorageProvider { - public string Name => throw new NotImplementedException(); - - public IEnumerable Parameters => throw new NotImplementedException(); + public string Name => "SCP"; + public BaseStorageParameters Parameters { get; set; } = null!; public IEnumerable GetAllFiles() {