115 lines
3.4 KiB
C#
115 lines
3.4 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.IO;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig
|
|
{
|
|
/// <summary>
|
|
/// Configuration of meter
|
|
/// </summary>
|
|
public class ProccessConfig
|
|
{
|
|
/// <summary>
|
|
/// ctor
|
|
/// </summary>
|
|
public ProccessConfig()
|
|
{
|
|
UseRegisterWatchService = false;
|
|
UseErrorLogger = false;
|
|
AutoUpdateFiles = false;
|
|
ProductionMode = true;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public ProccessConfig(String file)
|
|
{
|
|
var configFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), nameof(Genesis), file);
|
|
|
|
if (!File.Exists(configFile))
|
|
{
|
|
configFile = Path.Combine(file);
|
|
if (!File.Exists(configFile))
|
|
{
|
|
UseRegisterWatchService = false;
|
|
UseErrorLogger = false;
|
|
return;
|
|
}
|
|
}
|
|
|
|
using (var tr = new StreamReader(configFile))
|
|
{
|
|
var meterConfig = JsonConvert.DeserializeObject<ProccessConfig>(tr.ReadToEnd());
|
|
UseRegisterWatchService = meterConfig.UseRegisterWatchService;
|
|
RegisterWatchServiceUrl = meterConfig.RegisterWatchServiceUrl;
|
|
UseMinMaxCheck = meterConfig.UseMinMaxCheck;
|
|
UseErrorLogger = meterConfig.UseErrorLogger;
|
|
ErrorLoggerServiceUrl = meterConfig.ErrorLoggerServiceUrl;
|
|
UseCalibrationLogger = meterConfig.UseCalibrationLogger;
|
|
CalibrationLoggerServiceUrl = meterConfig.CalibrationLoggerServiceUrl;
|
|
AutoUpdateFiles = meterConfig.AutoUpdateFiles;
|
|
ProductionMode = meterConfig.ProductionMode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public void Update(String file)
|
|
{
|
|
var configFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), nameof(Genesis), file);
|
|
|
|
if (!File.Exists(configFile))
|
|
{
|
|
configFile = Path.Combine(file);
|
|
}
|
|
|
|
File.WriteAllText(file, JsonConvert.SerializeObject(this));
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public Boolean UseRegisterWatchService { get; set; }
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public String RegisterWatchServiceUrl { get; set; }
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public Boolean UseMinMaxCheck { get; set; }
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public Boolean UseErrorLogger { get; set; }
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public String ErrorLoggerServiceUrl { get; set; }
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public Boolean UseCalibrationLogger { get; set; }
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public String CalibrationLoggerServiceUrl { get; set; }
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public bool AutoUpdateFiles { get; set; }
|
|
|
|
[DefaultValue(true)]
|
|
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
|
|
|
|
public bool ProductionMode { get; set; } = true;
|
|
}
|
|
}
|