laatzen/Common/Service/MeterProcessState/Controllers/ConfigurationJsonController.cs
Stoyan Zlatev 4a5d625b5c GET: /api/configurationjson - added,
TODO: define the latest json source file in the prebuild events for this project
TODO: assembly signing disabled because of runtime errors
2023-09-29 10:01:28 +02:00

34 lines
1.1 KiB
C#

using Newtonsoft.Json;
using System.IO;
using System.Text;
using System.Web;
using System.Web.Http;
namespace Xylem.Common.Service.MeterProcessState.Controllers
{
[RoutePrefix("api/ConfigurationJson")]
public class ConfigurationJsonController : ApiController
{
[HttpGet]
public IHttpActionResult Get()
{
try
{
var currentDirectory = HttpContext.Current.Request.MapPath("..");
var files = Directory.GetFiles(currentDirectory);
var configurationJsonFilePath = Path.Combine(currentDirectory, "configuration.json");
var configurationJsonContent = File.ReadAllText(configurationJsonFilePath);
var configurationJson = JsonConvert.DeserializeObject(configurationJsonContent);
var serializerSettings = new JsonSerializerSettings();
return this.Json(configurationJson, serializerSettings, Encoding.UTF8);
}
catch
{
return this.BadRequest("Unable to find or load ...\\configuration.json");
}
}
}
}