// Copyright (C) 2024, The Duplicati Team
// https://duplicati.com, hello@duplicati.com
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Linq;
using Duplicati.Library.RestAPI;
using Duplicati.Server.Serialization.Interface;
namespace Duplicati.Server.Serializable
{
///
/// The server config
///
public static class ServerSettings
{
///
/// Shared implementation for reporting dynamic modules
///
private class DynamicModule : IDynamicModule
{
///
/// Constructor for backend interface
///
public DynamicModule(Duplicati.Library.Interface.IBackend backend)
{
this.Key = backend.ProtocolKey;
this.Description = backend.Description;
this.DisplayName = backend.DisplayName;
if (backend.SupportedCommands != null)
this.Options = backend.SupportedCommands.ToArray();
}
///
/// Constructor for compression module interface
///
public DynamicModule(Duplicati.Library.Interface.ICompression module)
{
this.Key = module.FilenameExtension;
this.Description = module.Description;
this.DisplayName = module.DisplayName;
if (module.SupportedCommands != null)
this.Options = module.SupportedCommands.ToArray();
}
///
/// Constructor for encryption module interface
///
public DynamicModule(Duplicati.Library.Interface.IEncryption module)
{
this.Key = module.FilenameExtension;
this.Description = module.Description;
this.DisplayName = module.DisplayName;
if (module.SupportedCommands != null)
this.Options = module.SupportedCommands.ToArray();
}
///
/// Constructor for generic module interface
///
public DynamicModule(Duplicati.Library.Interface.IGenericModule module)
{
this.Key = module.Key;
this.Description = module.Description;
this.DisplayName = module.DisplayName;
if (module.SupportedCommands != null)
this.Options = module.SupportedCommands.ToArray();
}
///
/// Constructor for webmodule interface
///
public DynamicModule(Duplicati.Library.Interface.IWebModule module)
{
this.Key = module.Key;
this.Description = module.Description;
this.DisplayName = module.DisplayName;
if (module.SupportedCommands != null)
this.Options = module.SupportedCommands.ToArray();
}
///
/// The module key
///
public string Key { get; private set; }
///
/// The localized module description
///
public string Description { get; private set; }
///
/// Gets the localized display name
///
/// The display name.
public string DisplayName { get; private set; }
///
/// The options supported by the module
///
public Duplicati.Library.Interface.ICommandLineArgument[] Options { get; private set; }
}
///
/// Gets all supported options
///
public static Duplicati.Library.Interface.ICommandLineArgument[] Options
{
get
{
return new Duplicati.Library.Main.Options(new System.Collections.Generic.Dictionary()).SupportedCommands.ToArray();
}
}
///
/// The backend modules known by the server
///
public static IDynamicModule[] BackendModules
{
get
{
return
(from n in Library.DynamicLoader.BackendLoader.Backends
select new DynamicModule(n))
.ToArray();
}
}
///
/// The encryption modules known by the server
///
public static IDynamicModule[] EncryptionModules
{
get
{
return
(from n in Library.DynamicLoader.EncryptionLoader.Modules
select new DynamicModule(n))
.ToArray();
}
}
///
/// The compression modules known by the server
///
public static IDynamicModule[] CompressionModules
{
get
{
return
(from n in Library.DynamicLoader.CompressionLoader.Modules
select new DynamicModule(n))
.ToArray();
}
}
///
/// The generic modules known by the server
///
public static IDynamicModule[] GenericModules
{
get
{
return
(from n in Library.DynamicLoader.GenericLoader.Modules
select new DynamicModule(n))
.ToArray();
}
}
///
/// The web modules known by the server
///
public static IDynamicModule[] WebModules
{
get
{
return
(from n in Library.DynamicLoader.WebLoader.Modules
select new DynamicModule(n))
.ToArray();
}
}
///
/// The web modules known by the server
///
public static IDynamicModule[] ConnectionModules
{
get
{
return
(from n in Library.DynamicLoader.GenericLoader.Modules
where n is Library.Interface.IConnectionModule
select new DynamicModule(n))
.ToArray();
}
}
///
/// The server modules known by the server
///
public static object[] ServerModules
{
get
{
return
(from n in Library.DynamicLoader.GenericLoader.Modules
where n is Library.Interface.IGenericServerModule
select n)
.ToArray();
}
}
///
/// The filters that are applied to all backups
///
public static IFilter[] Filters
{
get { return FIXMEGlobal.DataConnection.Filters; }
}
///
/// The settings applied to all backups by default
///
public static ISetting[] Settings
{
get { return FIXMEGlobal.DataConnection.Settings; }
}
}
}