冰箱设置页面读配置文件信息修改
This commit is contained in:
parent
30c807ecd5
commit
8aaee587fa
|
@ -30,19 +30,15 @@ namespace DM_Weight.ViewModels
|
|||
set
|
||||
{
|
||||
SetProperty(ref _temperatureRange, value);
|
||||
//更新配置文件中冰箱温度区间
|
||||
CommonClass.SaveAppSetting("temperatureRange", _temperatureRange);
|
||||
}
|
||||
}
|
||||
//温度不在范围超时时间
|
||||
private string _outRangeTime = ConfigurationManager.AppSettings["OutRangeTime"].ToString();
|
||||
private string _outRangeTime = CommonClass.ReadAppSetting("OutRangeTime").ToString();
|
||||
public string OutRangeTime
|
||||
{
|
||||
get => _outRangeTime; set
|
||||
{
|
||||
SetProperty(ref _outRangeTime, value);
|
||||
//更新配置文件中冰箱温度区间
|
||||
CommonClass.SaveAppSetting("OutRangeTime", _outRangeTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +85,7 @@ namespace DM_Weight.ViewModels
|
|||
{
|
||||
get => _alarmState;
|
||||
set => SetProperty(ref _alarmState, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -126,42 +122,60 @@ namespace DM_Weight.ViewModels
|
|||
await _portUtil.FridgeOff(1);
|
||||
Thread.Sleep(100);
|
||||
CommonClass.SaveAppSetting("FridgeState", "1");
|
||||
|
||||
//Configuration _configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
||||
//_configuration.AppSettings.Settings["FridgeState"].Value = "1";
|
||||
//_configuration.Save();
|
||||
//ConfigurationManager.RefreshSection("FridgeState");
|
||||
}
|
||||
else
|
||||
{
|
||||
await _portUtil.FridegOpen(1);
|
||||
Thread.Sleep(100);
|
||||
CommonClass.SaveAppSetting("FridgeState", "0");
|
||||
//Configuration _configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
||||
//_configuration.AppSettings.Settings["FridgeState"].Value = "0";
|
||||
//_configuration.Save();
|
||||
//ConfigurationManager.RefreshSection("FridgeState");
|
||||
//冰箱打开定时获取冰箱温度
|
||||
_eventAggregator.GetEvent<FridgeEvent>().Publish();
|
||||
}
|
||||
}
|
||||
//发送警报使能/失能指令
|
||||
if (AlarmState)
|
||||
{
|
||||
await _portUtil.FridgeAlarmOff(1);
|
||||
Thread.Sleep(100);
|
||||
CommonClass.SaveAppSetting("AlarmState", "1");
|
||||
//Configuration _configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
||||
//_configuration.AppSettings.Settings["AlarmState"].Value = "1";
|
||||
//_configuration.Save();
|
||||
//ConfigurationManager.RefreshSection("AlarmState");
|
||||
}
|
||||
else
|
||||
{
|
||||
await _portUtil.FridgeAlarmOn(1);
|
||||
Thread.Sleep(100);
|
||||
CommonClass.SaveAppSetting("AlarmState", "0");
|
||||
}
|
||||
|
||||
//Configuration _configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
||||
//_configuration.AppSettings.Settings["AlarmState"].Value = "0";
|
||||
//_configuration.Save();
|
||||
//ConfigurationManager.RefreshSection("AlarmState");
|
||||
}
|
||||
//设定冰箱1温度区间
|
||||
string[] range = ConfigurationManager.AppSettings["temperatureRange"].Split('-');
|
||||
//string[] range = ConfigurationManager.AppSettings["temperatureRange"].Split('-');
|
||||
string[] newRange = TemperatureRange.Split('-');
|
||||
if (range.Length >= 2)
|
||||
if (newRange.Length >= 2)
|
||||
{
|
||||
bool bMix = float.TryParse(range[0], out float Min);
|
||||
bool bMax = float.TryParse(range[1], out float Max);
|
||||
bool bMix = float.TryParse(newRange[0], out float Min);
|
||||
bool bMax = float.TryParse(newRange[1], out float Max);
|
||||
|
||||
if (bMix && bMax)
|
||||
{
|
||||
if (Min != Convert.ToSingle(newRange[0]))
|
||||
{
|
||||
//设定冰箱温度最小值
|
||||
await _portUtil.FridgeMinSetting(Convert.ToSingle(newRange[0]), 1);
|
||||
await _portUtil.FridgeMinSetting(Convert.ToSingle(newRange[0]),1);
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
if (Max != Convert.ToSingle(newRange[1]))
|
||||
|
@ -172,8 +186,22 @@ namespace DM_Weight.ViewModels
|
|||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
//Configuration _configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
||||
//_configuration.AppSettings.Settings["TemperatureRange"].Value = c;
|
||||
//_configuration.Save();
|
||||
//ConfigurationManager.RefreshSection("TemperatureRange");
|
||||
CommonClass.SaveAppSetting("TemperatureRange", TemperatureRange);
|
||||
}
|
||||
|
||||
//超时时间
|
||||
if (OutRangeTime != null)
|
||||
{
|
||||
//Configuration _configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
||||
//_configuration.AppSettings.Settings["OutRangeTime"].Value = OutRangeTime;
|
||||
//_configuration.Save();
|
||||
//ConfigurationManager.RefreshSection("OutRangeTime");
|
||||
CommonClass.SaveAppSetting("OutRangeTime", OutRangeTime);
|
||||
}
|
||||
|
||||
|
||||
_portUtil.FridgeOperate = false;
|
||||
AlertMsg alertMsg = new AlertMsg
|
||||
|
@ -181,7 +209,7 @@ namespace DM_Weight.ViewModels
|
|||
Message = $"保存成功",
|
||||
Type = MsgType.SUCCESS
|
||||
};
|
||||
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
||||
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -194,18 +222,18 @@ namespace DM_Weight.ViewModels
|
|||
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
||||
_portUtil.FridgeOperate = false;
|
||||
}
|
||||
}
|
||||
//手动实现调用配置的逻辑 规避修改配置文件后不起作用的问题
|
||||
public int ReadAppSetting(string key)
|
||||
{
|
||||
string xPath = "/configuration/appSettings//add[@key='" + key + "']";
|
||||
XmlDocument doc = new XmlDocument();
|
||||
string exeFileName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
|
||||
doc.Load(exeFileName + ".dll.config");
|
||||
XmlNode node = doc.SelectSingleNode(xPath);
|
||||
logger.Info($"xPath:{xPath} exeFileName:{exeFileName} ReadAppSetting key:{key} value:{node.Attributes["value"].Value}");
|
||||
return Convert.ToInt32(node.Attributes["value"].Value);
|
||||
}
|
||||
//手动实现调用配置的逻辑 规避修改配置文件后不起作用的问题
|
||||
//public int ReadAppSetting(string key)
|
||||
//{
|
||||
// string xPath = "/configuration/appSettings//add[@key='" + key + "']";
|
||||
// XmlDocument doc = new XmlDocument();
|
||||
// string exeFileName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
|
||||
// doc.Load(exeFileName + ".dll.config");
|
||||
// XmlNode node = doc.SelectSingleNode(xPath);
|
||||
// logger.Info($"xPath:{xPath} exeFileName:{exeFileName} ReadAppSetting key:{key} value:{node.Attributes["value"].Value}");
|
||||
// return Convert.ToInt32(node.Attributes["value"].Value);
|
||||
//}
|
||||
|
||||
public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
|
||||
{
|
||||
|
@ -213,9 +241,9 @@ namespace DM_Weight.ViewModels
|
|||
|
||||
public void OnNavigatedTo(NavigationContext navigationContext)
|
||||
{
|
||||
FridgeState = ReadAppSetting("FridgeState").Equals(1);
|
||||
|
||||
AlarmState = ReadAppSetting("AlarmState").Equals(1);
|
||||
FridgeState =CommonClass.ReadAppSetting("FridgeState").Equals("1");
|
||||
|
||||
AlarmState = CommonClass.ReadAppSetting("AlarmState").Equals("1");
|
||||
|
||||
GetTemperature();
|
||||
}
|
||||
|
@ -227,7 +255,7 @@ namespace DM_Weight.ViewModels
|
|||
|
||||
public void OnNavigatedFrom(NavigationContext navigationContext)
|
||||
{
|
||||
}
|
||||
}
|
||||
//获取冰箱温度值,如有更改则保存更改
|
||||
private async Task GetTemperature()
|
||||
{
|
||||
|
|
|
@ -692,6 +692,7 @@ namespace DM_Weight.ViewModels
|
|||
{
|
||||
try
|
||||
{
|
||||
FridgeState = CommonClass.ReadAppSetting("FridgeState");
|
||||
if (!_portUtil.FridgeOperate && FridgeState.Equals("0"))
|
||||
{
|
||||
string retStr = string.Empty;
|
||||
|
|
Loading…
Reference in New Issue