using System.Collections.Generic;
using System.Linq;
using Crestron.SimplSharp.WebScripting;
using Newtonsoft.Json;
using PepperDash.Core.Web.RequestHandlers;
namespace PepperDash.Essentials.WebApiHandlers
{
///
/// Represents a ActionPathsHandler
///
public class ActionPathsHandler : WebApiBaseRequestHandler
{
private readonly MobileControlSystemController mcController;
///
/// Create an instance of the class.
///
///
public ActionPathsHandler(MobileControlSystemController controller) : base(true)
{
mcController = controller;
}
///
/// Handle a request to get the action paths
///
/// Request Context
protected override void HandleGet(HttpCwsContext context)
{
var response = JsonConvert.SerializeObject(new ActionPathsResponse(mcController));
context.Response.StatusCode = 200;
context.Response.ContentType = "application/json";
context.Response.Headers.Add("Content-Type", "application/json");
context.Response.Write(response, false);
context.Response.End();
}
}
///
/// Represents a ActionPathsResponse
///
public class ActionPathsResponse
{
[JsonIgnore]
private readonly MobileControlSystemController mcController;
///
/// Registered action paths for this system
///
[JsonProperty("actionPaths")]
public List ActionPaths => mcController.GetActionDictionaryPaths().Select((path) => new ActionPath { MessengerKey = path.Item1, Path = path.Item2 }).ToList();
///
/// Create an instance of the class.
///
///
public ActionPathsResponse(MobileControlSystemController mcController)
{
this.mcController = mcController;
}
}
///
/// Represents a ActionPath
///
public class ActionPath
{
///
/// Gets or sets the MessengerKey
///
[JsonProperty("messengerKey")]
public string MessengerKey { get; set; }
///
/// Gets or sets the Path
///
[JsonProperty("path")]
public string Path { get; set; }
}
}