laatzen/Common/Service/MeterProcessState/Controllers/JsonConfigurationController.cs

36 lines
905 B
C#
Raw Normal View History

2023-08-30 14:41:56 +00:00
namespace Xylem.Common.Service.MeterProcessState.Controllers
{
using Newtonsoft.Json;
2023-08-30 14:41:56 +00:00
using System.IO;
using System.Web;
2023-08-30 14:41:56 +00:00
using System.Web.Http;
2023-08-31 09:09:16 +00:00
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
2023-08-30 14:41:56 +00:00
public class JsonConfigurationController : ApiController
{
[HttpGet]
public IHttpActionResult Get()
{
var dir = HttpContext.Current.Request.MapPath("../");
Directory.CreateDirectory(dir);
var file = Path.Combine(dir, "configuration.json");
2023-08-31 09:09:16 +00:00
if (!File.Exists(file))
2023-08-30 14:41:56 +00:00
{
2023-08-31 09:09:16 +00:00
File.WriteAllText(file, string.Empty);
}
2023-08-30 14:41:56 +00:00
2023-08-31 09:09:16 +00:00
var reader = new GenesisConfigurationReader(file);
2023-08-30 14:41:56 +00:00
2023-08-31 09:09:16 +00:00
return this.Json(reader.Value, new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
});
2023-08-30 14:41:56 +00:00
}
}
}