ASCU_ALL/ApiServer/Controllers/ParamsController.cs
2024-09-22 04:27:05 +05:00

159 lines
3.5 KiB
C#

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using Newtonsoft;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
using NLog;
using DataClient.Struct;
using System.IO;
using ApiServer.ApiStruct;
namespace ApiServer.Controllers
{
[ApiController, Route("[controller]")]
public class ParamsController : ControllerBase
{
private Logger log = LogManager.GetCurrentClassLogger();
[HttpPost, Route("getanalogs")]
public ParamsGetAnalogClient GetAnalogs([FromBody] object value)
{
try
{
var getResult = JsonConvert.DeserializeObject<ParamsGetAnalogApi>(
value.ToString());
log.Info("Ask analog params for \"" + getResult.Name + "\"");
return new ParamsGetAnalogClient()
{
Analog_params = Configuration.GetAnalogParams(getResult.Name)
};
}
catch (Exception e)
{
log.Error(e);
return new ParamsGetAnalogClient();
}
}
[HttpPost, Route("getmetrics")]
public ParamsGetMetricClient GetMetrics([FromBody] object value)
{
try
{
log.Info("Ask metrics");
return new ParamsGetMetricClient()
{
Metrics = Configuration.GetMetricsArray()
};
}
catch (Exception e)
{
log.Error(e);
return new ParamsGetMetricClient();
}
}
[HttpPost, Route("gettechcyclename")]
public ParamsGetTechCycleNameClient GetTechCycleName([FromBody] object value)
{
try
{
log.Info("Ask tech cycle name");
return new ParamsGetTechCycleNameClient()
{
Name = Configuration.GetTechCycleNames()
};
}
catch (Exception e)
{
log.Warn(e);
return new ParamsGetTechCycleNameClient();
}
}
[HttpPost, Route("gettechcyclecolor")]
public ParamsGetTechCycleColorClient GetTechCycleColor([FromBody] object value)
{
try
{
log.Info("Ask tech cycle color");
return new ParamsGetTechCycleColorClient()
{
Color = Configuration.GetTechCycleColor()
};
}
catch (Exception e)
{
log.Warn(e);
return new ParamsGetTechCycleColorClient();
}
}
[HttpPost, Route("getstatestruct")]
public ParamsGetStateStructClient GetStateStruct([FromBody] object value)
{
try
{
log.Info("Ask state struct");
return new ParamsGetStateStructClient()
{
StateStruct = Configuration.GetStateStructArray()
};
}
catch (Exception e)
{
log.Warn(e);
return new ParamsGetStateStructClient();
}
}
[HttpPost, Route("getprotectstate")]
public ParamsGetProtectStateClient GetProtectState([FromBody] object value)
{
try
{
var getResult = JsonConvert.DeserializeObject<ParamsGetProtectStateApi>(
value.ToString());
log.Info("Ask protect state for vdp: " + getResult.Name);
return new ParamsGetProtectStateClient()
{
ProtectState = Configuration.GetProtectState(getResult.Name)
};
}
catch (Exception e)
{
log.Warn(e);
return new ParamsGetProtectStateClient();
}
}
[HttpPost, Route("getdiscret")]
public ParamsGetDiscretClient GetDiscrets([FromBody] object value)
{
try
{
var getResult = JsonConvert.DeserializeObject<ParamsGetDiscretApi>(
value.ToString());
log.Info("Ask discret params for \"" + getResult.Name + "\"");
return new ParamsGetDiscretClient()
{
Discret_params = Configuration.GetDiscretParams(getResult.Name)
};
}
catch (Exception e)
{
log.Error(e);
return new ParamsGetDiscretClient();
}
}
}
}