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

36 lines
905 B
C#

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