Files
Essentials/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetTieLinesRequestHandler.cs
2024-06-24 14:57:07 -05:00

34 lines
1.1 KiB
C#

using Crestron.SimplSharp.WebScripting;
using Newtonsoft.Json;
using PepperDash.Core.Web.RequestHandlers;
using System.Linq;
using System.Text;
namespace PepperDash.Essentials.Core.Web.RequestHandlers
{
public class GetTieLinesRequestHandler : WebApiBaseRequestHandler
{
public GetTieLinesRequestHandler() : base(true) { }
protected override void HandleGet(HttpCwsContext context)
{
var tieLineString = JsonConvert.SerializeObject(TieLineCollection.Default.Select((tl) => new
{
sourceKey = tl.SourcePort.ParentDevice.Key,
sourcePort = tl.SourcePort.Key,
destinationKey = tl.DestinationPort.ParentDevice.Key,
destinationPort = tl.DestinationPort.Key,
type = tl.Type.ToString(),
}));
context.Response.StatusCode = 200;
context.Response.StatusDescription = "OK";
context.Response.ContentType = "application/json";
context.Response.ContentEncoding = Encoding.UTF8;
context.Response.Write(tieLineString, false);
context.Response.End();
}
}
}