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

32 lines
845 B
C#
Raw Normal View History

2023-08-30 14:41:56 +00:00
namespace Xylem.Common.Service.MeterProcessState.Controllers
{
using System.IO;
using System.Text;
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
return this.Json(reader.Value, GenesisConfigurationReader.SerializerSettings, Encoding.UTF8);
2023-08-30 14:41:56 +00:00
}
}
}