69 lines
2.2 KiB
C#
69 lines
2.2 KiB
C#
namespace Xylem.Common.Service.MeterProcessState.Controllers
|
|
{
|
|
using LaaPackages.SqlClient;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using System;
|
|
using System.Configuration;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Web;
|
|
using System.Web.Http;
|
|
|
|
[RoutePrefix("configurationjson")]
|
|
public class ConfigurationJsonController : ApiController
|
|
{
|
|
[HttpGet]
|
|
[Route]
|
|
public IHttpActionResult Get()
|
|
{
|
|
var message = String.Empty;
|
|
var configurationText = String.Empty;
|
|
|
|
try
|
|
{
|
|
var connectionString = ConfigurationManager.ConnectionStrings["Default"].ConnectionString;
|
|
var configurationBytes = SqlConnection
|
|
.CreateSqlConnection(connectionString)
|
|
.CreateCommand(@"
|
|
SELECT TOP 1 f.FileContent
|
|
FROM FileClusterStore AS fcs
|
|
JOIN FileMapToCluster AS fmc
|
|
ON fcs.FileId = fmc.FileMapToCluster_FileClusterId
|
|
JOIN [File] AS f
|
|
ON fmc.FileMapToCluster_FileId = f.FileId
|
|
WHERE FileCategoryID = 2
|
|
ORDER BY f.FileId DESC")
|
|
.FirstOrDefault(x => x.GetValue<Byte[]>(0));
|
|
configurationText = Encoding.ASCII.GetString(configurationBytes);
|
|
}
|
|
catch (Exception dbe)
|
|
{
|
|
message = dbe.Message;
|
|
|
|
try
|
|
{
|
|
var configurationPath = HttpContext.Current.Request.MapPath("configuration.json");
|
|
configurationText = File.ReadAllText(configurationPath);
|
|
}
|
|
catch (Exception fe)
|
|
{
|
|
message = fe.Message;
|
|
}
|
|
}
|
|
|
|
try
|
|
{
|
|
var configurationJson = JsonConvert.DeserializeObject(configurationText);
|
|
|
|
return this.Json(configurationJson, new JsonSerializerSettings(), Encoding.UTF8);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return this.BadRequest($"{e.Message}{Environment.NewLine}{message}");
|
|
}
|
|
}
|
|
}
|
|
}
|