using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using ServerCore; using MODULE_ID = System.UInt32; using SORT_ORDER_NO = System.Int32; namespace ServerBase; public partial class S3Connector : S3ConnectorBase, IModule, IInitializer { private readonly ModuleContext m_module_context; public S3Connector(ModuleContext moduleContext) : base() { m_module_context = moduleContext; } private static (string accessKey, string secretKey, string regionName) getConfigParamsOrThrow(ModuleContext context) { if (context.getConfigParam() is not ConfigParam param) throw new InvalidCastException("IConfigParam must be of type S3ConnectorBase.ConfigParam !!!"); return ( param.AccessKey ?? throw new InvalidOperationException("AccessKey is null !!!"), param.SecretKey ?? throw new InvalidOperationException("SecretKey is null !!!"), param.Region ?? throw new InvalidOperationException("Region is null !!!") ); } public async Task onInit() { var err_msg = string.Empty; var result = new Result(); var module_context = getModuleContext(); var config_param = module_context.getConfigParam() as ConfigParam; NullReferenceCheckHelper.throwIfNull(config_param, () => $"config_param is null !!!"); var is_success = createS3Client(config_param.AccessKey, config_param.SecretKey, config_param.Region); if (false == is_success) { err_msg = $"Failed to createS3Client() !!! : {config_param.toBasicString()}"; result.setFail(ServerErrorCode.S3ClientCreateFailed, err_msg); Log.getLogger().error(result.toBasicString()); return result; } return await Task.FromResult(result); } public async Task startModule() { var result = new Result(); return await Task.FromResult(result); } public async Task stopModule() { var result = new Result(); return await Task.FromResult(result); } public ModuleContext getModuleContext() => m_module_context; }