From f8df2fe46825b3b45c587ac8f93358289a19bc3f Mon Sep 17 00:00:00 2001 From: ShaoHua <345265198@qq.com> Date: Sun, 23 Apr 2023 00:03:52 +0800 Subject: [PATCH] change Platform to a EnumType --- .../Common/Config/Options/DomainOption.cs | 4 ++-- .../Common/Config/Options/PlatformEnum.cs | 24 +++++++++++++++++++ Hua.DDNS/Jobs/AppJob.cs | 4 ++-- Hua.DDNS/appsettings.json | 2 +- 4 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 Hua.DDNS/Common/Config/Options/PlatformEnum.cs diff --git a/Hua.DDNS/Common/Config/Options/DomainOption.cs b/Hua.DDNS/Common/Config/Options/DomainOption.cs index 02594a6..7d74405 100644 --- a/Hua.DDNS/Common/Config/Options/DomainOption.cs +++ b/Hua.DDNS/Common/Config/Options/DomainOption.cs @@ -12,9 +12,9 @@ namespace Hua.DDNS.Common.Config.Options public class DomainOption { /// - /// platform from [Ali,Tencent] + /// platform from 1 Ali 2 Tencent /// - public string Platform { get; set; } + public PlatformEnum Platform { get; set; } /// /// Id, the id and key from AliCould or DnsPod diff --git a/Hua.DDNS/Common/Config/Options/PlatformEnum.cs b/Hua.DDNS/Common/Config/Options/PlatformEnum.cs new file mode 100644 index 0000000..e4bf83a --- /dev/null +++ b/Hua.DDNS/Common/Config/Options/PlatformEnum.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Hua.DDNS.Common.Config.Options +{ + /// + /// DDNS Platform + /// + public enum PlatformEnum + { + /// + /// Ali + /// + Ali = 1, + + /// + /// Tencent + /// + Tencent + } +} diff --git a/Hua.DDNS/Jobs/AppJob.cs b/Hua.DDNS/Jobs/AppJob.cs index 3f84c45..01cc666 100644 --- a/Hua.DDNS/Jobs/AppJob.cs +++ b/Hua.DDNS/Jobs/AppJob.cs @@ -66,7 +66,7 @@ namespace Hua.DDNS.Jobs //更新Ip记录 switch (_domainOption.Platform) { - case "Tencent": + case PlatformEnum.Tencent: var _dnspodClient = new DnspodClient( // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密 // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取 @@ -97,7 +97,7 @@ namespace Hua.DDNS.Jobs }); break; - case "Ali": + case PlatformEnum.Ali: var aliClient = new AlibabaCloud.SDK.Alidns20150109.Client(new Config() { // 您的 AccessKey ID diff --git a/Hua.DDNS/appsettings.json b/Hua.DDNS/appsettings.json index a09b405..de273e0 100644 --- a/Hua.DDNS/appsettings.json +++ b/Hua.DDNS/appsettings.json @@ -14,7 +14,7 @@ }, "Domain": { - "Platform": "Ali", + "Platform": 1, //1 Ali 2 Tencent // Access Id/Secret Id "Id": "Id", // Access Key/Secret Key