v3.8.4.8 1、实现实时更新配置文件。2、调整简化代码实现。3、DEBUG...
This commit is contained in:
parent
7da0d1c193
commit
7a36a3f2c3
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
</startup>
|
||||
</configuration>
|
@ -1,11 +1,8 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
|
||||
@ -36,7 +33,7 @@ namespace net.nutcore.aliddns
|
||||
xmlDoc.Load(configFilePath);
|
||||
if(xmlDoc.SelectSingleNode("configuration") == null)
|
||||
{
|
||||
Console.WriteLine("Config file setting error! New config file is creating now!");
|
||||
Console.WriteLine("Config file setting error! New config file is created now!");
|
||||
FileInfo fileInfo = new FileInfo(configFilePath);
|
||||
fileInfo.MoveTo(configFilePath + ".bak");
|
||||
CreatNewConfig(configFilePath);
|
||||
@ -55,18 +52,18 @@ namespace net.nutcore.aliddns
|
||||
XmlNodeList oldNodes = xmlDoc.SelectSingleNode("configuration").ChildNodes;
|
||||
foreach (XmlNode node in oldNodes)
|
||||
{
|
||||
Console.WriteLine(node.Name.ToString()+" : "+node.InnerText.ToString());
|
||||
Console.WriteLine(node.Name.ToString() + " : " + node.InnerText.ToString());
|
||||
SaveAppSetting(node.Name.ToString(), node.InnerText.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
configFile = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
|
||||
//GetAllAppSettings();
|
||||
GetAllAppSettings();
|
||||
}
|
||||
catch(Exception error)
|
||||
{
|
||||
Console.WriteLine("Class AppConfigHelper running error!" + error);
|
||||
Console.WriteLine("Class AppConfigHelper running error! " + error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,15 +162,12 @@ namespace net.nutcore.aliddns
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取<appsettings></appsettings>下所有键和值
|
||||
/// 获取<appSettings></appSettings>下所有键和值
|
||||
/// </summary>
|
||||
public ArrayList GetAllAppSettings()
|
||||
public string[] GetAllAppSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
ArrayList list = new ArrayList() ;
|
||||
//var appSettings = ConfigurationManager.AppSettings;
|
||||
|
||||
if (configFile.AppSettings.Settings.Count == 0)
|
||||
{
|
||||
Console.WriteLine("AppSettings is empty.");
|
||||
@ -181,33 +175,22 @@ namespace net.nutcore.aliddns
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
foreach (var key in configFile.AppSettings.Settings.AllKeys)
|
||||
{
|
||||
//list.Add(configFile.AppSettings.Settings[key].Value);
|
||||
Console.WriteLine("Key: {0} Value: {1}", key, configFile.AppSettings.Settings[key].Value);
|
||||
}*/
|
||||
list.Add(configFile.AppSettings.Settings.AllKeys);
|
||||
foreach (var key in list)
|
||||
Console.WriteLine(key.ToString());
|
||||
/*
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
Console.WriteLine(list[i].ToString());
|
||||
}*/
|
||||
|
||||
return list;
|
||||
}
|
||||
return configFile.AppSettings.Settings.AllKeys;
|
||||
}
|
||||
}
|
||||
catch (ConfigurationErrorsException)
|
||||
{
|
||||
Console.WriteLine("Error reading app settings");
|
||||
Console.WriteLine("GetAllAppSettings() run error!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除<appsettings></appsettings>下指定键
|
||||
/// 移除<appSettings></appSettings>下指定键
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
public void DelAppSetting(string key)
|
||||
@ -262,7 +245,7 @@ namespace net.nutcore.aliddns
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断appSettings中是否有此项键名
|
||||
/// 判断appSettings中是否有指定键名
|
||||
/// </summary>
|
||||
/// /// <param name="strKey">键名</param>
|
||||
public bool AppSettingsKeyExists(string strKey)
|
||||
@ -278,19 +261,16 @@ namespace net.nutcore.aliddns
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取设置文件中某个键的值
|
||||
/// 修改配置文件指定键和值
|
||||
/// </summary>
|
||||
/// <param name="strKey">键名</param>
|
||||
public static string GetValueByKey(string strKey)
|
||||
{
|
||||
ConfigurationManager.RefreshSection("appSettings");
|
||||
return ConfigurationManager.AppSettings[strKey];
|
||||
}
|
||||
/// <param name="strKey"></param>
|
||||
/// <param name="value"></param>
|
||||
public static void ModifyAppSettings(string strKey, string value)
|
||||
{
|
||||
var doc = new XmlDocument();
|
||||
//获得配置文件的全路径
|
||||
var strFileName = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
|
||||
//var strFileName = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
|
||||
var strFileName = configFilePath;
|
||||
doc.Load(strFileName);
|
||||
|
||||
//找出名称为“add”的所有元素
|
||||
|
@ -9,7 +9,6 @@ using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml;
|
||||
using static Aliyun.Acs.Alidns.Model.V20150109.DescribeSubDomainRecordsResponse;
|
||||
|
||||
namespace net.nutcore.aliddns
|
||||
@ -179,113 +178,6 @@ namespace net.nutcore.aliddns
|
||||
|
||||
}
|
||||
|
||||
private bool saveConfigFile()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (accessKeyId.Text == "" || accessKeySecret.Text == "" || recordId.Text == "" || fullDomainName.Text == "" || newSeconds.Text == "" || comboBox_whatIsUrl.Text == "")
|
||||
{
|
||||
textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "任何值都不能为空!无法填写请输入null或0!" + "\r\n");
|
||||
return false;
|
||||
}
|
||||
string accessKeyId_encrypt = EncryptHelper.AESEncrypt(accessKeyId.Text);
|
||||
string accessKeySecret_encrypt = EncryptHelper.AESEncrypt(accessKeySecret.Text);
|
||||
string ExePath = System.AppDomain.CurrentDomain.BaseDirectory;
|
||||
string config_file = ExePath + "aliddns_config.xml";
|
||||
XmlTextWriter textWriter = new XmlTextWriter(config_file, null);
|
||||
textWriter.WriteStartDocument(); //文档开始
|
||||
|
||||
textWriter.WriteComment("AlidnsAutoCheckTool");
|
||||
textWriter.WriteComment("Version:Beta 1.0");
|
||||
//Start config file
|
||||
textWriter.WriteStartElement("configuration"); //设置项目开始
|
||||
|
||||
textWriter.WriteStartElement("AccessKeyID", "");
|
||||
textWriter.WriteString(accessKeyId_encrypt);
|
||||
textWriter.WriteEndElement();
|
||||
|
||||
textWriter.WriteStartElement("AccessKeySecret", "");
|
||||
textWriter.WriteString(accessKeySecret_encrypt);
|
||||
textWriter.WriteEndElement();
|
||||
|
||||
textWriter.WriteStartElement("RecordID", "");
|
||||
textWriter.WriteString(recordId.Text);
|
||||
textWriter.WriteEndElement();
|
||||
|
||||
textWriter.WriteStartElement("fullDomainName", "");
|
||||
textWriter.WriteString(fullDomainName.Text);
|
||||
textWriter.WriteEndElement();
|
||||
|
||||
textWriter.WriteStartElement("WaitingTime", "");
|
||||
textWriter.WriteString(newSeconds.Text);
|
||||
textWriter.WriteEndElement();
|
||||
|
||||
textWriter.WriteStartElement("autoUpdate", "");
|
||||
if (checkBox_autoUpdate.Checked == true)
|
||||
textWriter.WriteString("On");
|
||||
else
|
||||
textWriter.WriteString("Off");
|
||||
textWriter.WriteEndElement();
|
||||
|
||||
textWriter.WriteStartElement("whatIsUrl", "");
|
||||
textWriter.WriteString(comboBox_whatIsUrl.Text);
|
||||
textWriter.WriteEndElement();
|
||||
|
||||
textWriter.WriteStartElement("autoBoot", "");
|
||||
if (checkBox_autoBoot.Checked == true)
|
||||
textWriter.WriteString("On");
|
||||
else
|
||||
textWriter.WriteString("Off");
|
||||
textWriter.WriteEndElement();
|
||||
|
||||
textWriter.WriteStartElement("minimized", "");
|
||||
if (checkBox_minimized.Checked == true)
|
||||
textWriter.WriteString("On");
|
||||
else
|
||||
textWriter.WriteString("Off");
|
||||
textWriter.WriteEndElement();
|
||||
|
||||
textWriter.WriteStartElement("logautosave", "");
|
||||
if (checkBox_logAutoSave.Checked == true)
|
||||
textWriter.WriteString("On");
|
||||
else
|
||||
textWriter.WriteString("Off");
|
||||
textWriter.WriteEndElement();
|
||||
|
||||
textWriter.WriteStartElement("TTL", "");
|
||||
textWriter.WriteString(textBox_TTL.Text);
|
||||
textWriter.WriteEndElement();
|
||||
|
||||
textWriter.WriteStartElement("autoCheckUpdate", "");
|
||||
if (checkUpdate == false)
|
||||
textWriter.WriteString("Off");
|
||||
else
|
||||
textWriter.WriteString("On");
|
||||
textWriter.WriteEndElement();
|
||||
|
||||
textWriter.WriteStartElement("ngrokauto", "");
|
||||
if (checkBox_ngrok.Checked == false)
|
||||
textWriter.WriteString("Off");
|
||||
else
|
||||
textWriter.WriteString("On");
|
||||
textWriter.WriteEndElement();
|
||||
|
||||
textWriter.WriteEndElement(); //设置项目结束
|
||||
textWriter.WriteEndDocument();//文档结束
|
||||
textWriter.Close(); //文档保存关闭
|
||||
|
||||
label_nextUpdateSeconds.Text = newSeconds.Text;
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "运行出错!信息: " + error + "\r\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private string getLocalIP()
|
||||
{
|
||||
try
|
||||
@ -662,12 +554,12 @@ namespace net.nutcore.aliddns
|
||||
{
|
||||
if (checkBox_logAutoSave.Checked == true)
|
||||
{
|
||||
cfg.SaveAppSetting("ngrokauto", "On");
|
||||
cfg.SaveAppSetting("logautosave", "On");
|
||||
textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "日志自动转储启用成功!日志超过1万行将自动转储。" + "\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
cfg.SaveAppSetting("ngrokauto", "Off");
|
||||
cfg.SaveAppSetting("logautosave", "Off");
|
||||
textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "日志自动转储取消!" + "\r\n");
|
||||
}
|
||||
}
|
||||
@ -838,7 +730,7 @@ namespace net.nutcore.aliddns
|
||||
|
||||
private async void checkBox_ngrok_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
|
||||
if (checkBox_ngrok.Checked == true)
|
||||
{
|
||||
button_ngrok.Enabled = false;
|
||||
|
@ -141,9 +141,6 @@
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="alidns.ico" />
|
||||
<Content Include="alidns_gray.ico" />
|
||||
|
Loading…
Reference in New Issue
Block a user