Combined projects into one solution

This commit is contained in:
Heath Volmer
2017-03-21 08:54:41 -06:00
parent 858c93b006
commit 41bbb5bec2
4 changed files with 272 additions and 247 deletions

View File

@@ -2,6 +2,23 @@
Microsoft Visual Studio Solution File, Format Version 10.00 Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008 # Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PepperDashEssentials", "PepperDashEssentials\PepperDashEssentials.csproj", "{1BED5BA9-88C4-4365-9362-6F4B128071D3}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PepperDashEssentials", "PepperDashEssentials\PepperDashEssentials.csproj", "{1BED5BA9-88C4-4365-9362-6F4B128071D3}"
ProjectSection(ProjectDependencies) = postProject
{892B761C-E479-44CE-BD74-243E9214AF13} = {892B761C-E479-44CE-BD74-243E9214AF13}
{9199CE8A-0C9F-4952-8672-3EED798B284F} = {9199CE8A-0C9F-4952-8672-3EED798B284F}
{A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5} = {A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PepperDash_Essentials_Core", "..\..\essentials-core\PepperDashEssentialsBase\PepperDashEssentialsBase\PepperDash_Essentials_Core.csproj", "{A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Essentials Devices Common", "..\..\essentials-devices-common\Essentials Devices Common\Essentials Devices Common\Essentials Devices Common.csproj", "{892B761C-E479-44CE-BD74-243E9214AF13}"
ProjectSection(ProjectDependencies) = postProject
{A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5} = {A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Essentials_DM", "..\..\essentials-dm\Essentials_DM\Essentials_DM\Essentials_DM.csproj", "{9199CE8A-0C9F-4952-8672-3EED798B284F}"
ProjectSection(ProjectDependencies) = postProject
{A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5} = {A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5}
EndProjectSection
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -13,6 +30,18 @@ Global
{1BED5BA9-88C4-4365-9362-6F4B128071D3}.Debug|Any CPU.Build.0 = Debug|Any CPU {1BED5BA9-88C4-4365-9362-6F4B128071D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1BED5BA9-88C4-4365-9362-6F4B128071D3}.Release|Any CPU.ActiveCfg = Release|Any CPU {1BED5BA9-88C4-4365-9362-6F4B128071D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1BED5BA9-88C4-4365-9362-6F4B128071D3}.Release|Any CPU.Build.0 = Release|Any CPU {1BED5BA9-88C4-4365-9362-6F4B128071D3}.Release|Any CPU.Build.0 = Release|Any CPU
{A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5}.Release|Any CPU.Build.0 = Release|Any CPU
{892B761C-E479-44CE-BD74-243E9214AF13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{892B761C-E479-44CE-BD74-243E9214AF13}.Debug|Any CPU.Build.0 = Debug|Any CPU
{892B761C-E479-44CE-BD74-243E9214AF13}.Release|Any CPU.ActiveCfg = Release|Any CPU
{892B761C-E479-44CE-BD74-243E9214AF13}.Release|Any CPU.Build.0 = Release|Any CPU
{9199CE8A-0C9F-4952-8672-3EED798B284F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9199CE8A-0C9F-4952-8672-3EED798B284F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9199CE8A-0C9F-4952-8672-3EED798B284F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9199CE8A-0C9F-4952-8672-3EED798B284F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@@ -1,266 +1,266 @@
using System; //using System;
using System.Collections.Generic; //using System.Collections.Generic;
using System.Linq; //using System.Linq;
using System.Text; //using System.Text;
using Crestron.SimplSharp; //using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO; //using Crestron.SimplSharp.CrestronIO;
using Crestron.SimplSharp.Net.Http; //using Crestron.SimplSharp.Net.Http;
using Newtonsoft.Json; //using Newtonsoft.Json;
using Newtonsoft.Json.Linq; //using Newtonsoft.Json.Linq;
using PepperDash.Essentials.Core; //using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Http; //using PepperDash.Essentials.Core.Http;
using PepperDash.Core; //using PepperDash.Core;
namespace PepperDash.Essentials //namespace PepperDash.Essentials
{ //{
public class EssentialsHttpApiHandler // public class EssentialsHttpApiHandler
{ // {
string ConfigPath; // string ConfigPath;
string PresetsPathPrefix; // string PresetsPathPrefix;
EssentialsHttpServer Server; // EssentialsHttpServer Server;
/// <summary> // /// <summary>
/// // ///
/// </summary> // /// </summary>
/// <param name="server">HTTP server to attach to</param> // /// <param name="server">HTTP server to attach to</param>
/// <param name="configPath">The full path to configuration file</param> // /// <param name="configPath">The full path to configuration file</param>
/// <param name="presetsListPath">The folder prefix for the presets path, eq "\HTML\presets\"</param> // /// <param name="presetsListPath">The folder prefix for the presets path, eq "\HTML\presets\"</param>
public EssentialsHttpApiHandler(EssentialsHttpServer server, string configPath, string presetsPathPrefix) // public EssentialsHttpApiHandler(EssentialsHttpServer server, string configPath, string presetsPathPrefix)
{ // {
if (server == null) throw new ArgumentNullException("server"); // if (server == null) throw new ArgumentNullException("server");
Server = server; // Server = server;
ConfigPath = configPath; // ConfigPath = configPath;
PresetsPathPrefix = presetsPathPrefix; // PresetsPathPrefix = presetsPathPrefix;
server.ApiRequest += Server_ApiRequest; // server.ApiRequest += Server_ApiRequest;
} // }
void Server_ApiRequest(object sender, Crestron.SimplSharp.Net.Http.OnHttpRequestArgs args) // void Server_ApiRequest(object sender, Crestron.SimplSharp.Net.Http.OnHttpRequestArgs args)
{
try
{
var path = args.Request.Path.ToLower();
if (path == "/api/config")
HandleApiConfig(args);
else if (path.StartsWith("/api/presetslist/"))
HandleApiPresetsList(args);
else if (path == "/api/presetslists")
HandleApiGetPresetsLists(args.Request, args.Response);
else
{
args.Response.Code = 404;
return;
}
args.Response.Header.SetHeaderValue("Access-Control-Allow-Origin", "*");
args.Response.Header.SetHeaderValue("Access-Control-Allow-Methods", "GET, POST, PATCH, PUT, DELETE, OPTIONS");
}
catch (Exception e)
{
Debug.Console(1, "Uncaught HTTP server error: \n{0}", e);
args.Response.Code = 500;
}
}
/// <summary>
/// GET will return the running configuration. POST will attempt to take in a new config
/// and restart the program.
/// </summary>
void HandleApiConfig(OnHttpRequestArgs args)
{
var request = args.Request;
if (request.Header.RequestType == "GET")
{
if (File.Exists(ConfigPath))
{
Debug.Console(2, "Sending config:{0}", ConfigPath);
args.Response.Header.ContentType = EssentialsHttpServer.GetContentType(new FileInfo(ConfigPath).Extension);
args.Response.ContentStream = new FileStream(ConfigPath, FileMode.Open, FileAccess.Read);
}
}
else if (request.Header.RequestType == "POST")
{
Debug.Console(2, "Post type: '{0}'", request.Header.ContentType);
// Make sure we're receiving at least good json
Debug.Console(1, "Receving new config");
if (GetContentStringJson(args) == null)
return;
//---------------------------- try to move these into common method
// Move current file aside
var bakPath = ConfigPath + ".bak";
if (File.Exists(bakPath))
File.Delete(bakPath);
File.Move(ConfigPath, bakPath);
// Write the file
using (FileStream fs = File.Open(ConfigPath, FileMode.OpenOrCreate))
using (StreamWriter sw = new StreamWriter(fs))
{
try
{
sw.Write(args.Request.ContentString);
}
catch (Exception e)
{
string err = string.Format("Error writing received config file:\r{0}", e);
CrestronConsole.PrintLine(err);
ErrorLog.Warn(err);
// Put file back
File.Move(ConfigPath + ".bak", ConfigPath);
args.Response.Code = 500;
return;
}
}
// If client says "yeah, restart" and has a good token
// Restart program
string consoleResponse = null;
var restart = CrestronConsole.SendControlSystemCommand("progreset -p:" +
InitialParametersClass.ApplicationNumber, ref consoleResponse);
if (!restart) Debug.Console(0, "CAN'T DO THAT YO: {0}", consoleResponse);
}
}
void HandleApiPresetsList(OnHttpRequestArgs args)
{
var listPath = PresetsPathPrefix + args.Request.Path.Remove(0, 17);
Debug.Console(2, "Checking for preset list '{0}'", listPath);
if (args.Request.Header.RequestType == "GET")
{
if (File.Exists(listPath))
{
Debug.Console(2, "Sending presets file:{0}", listPath);
args.Response.Header.ContentType = EssentialsHttpServer.GetContentType(new FileInfo(listPath).Extension);
args.Response.ContentStream = new FileStream(listPath, FileMode.Open, FileAccess.Read);
}
}
else if (args.Request.Header.RequestType == "POST")
{
// Make sure we're receiving at least good json
Debug.Console(1, "Receving new presets");
if (GetContentStringJson(args) == null)
return;
//---------------------------- try to move these into common method
// Move current file aside
var bakPath = listPath + ".new";
Debug.Console(2, "Moving presets file to {0}", bakPath);
if(File.Exists(bakPath))
File.Delete(bakPath);
File.Move(listPath, bakPath);
Debug.Console(2, "Writing new file");
// Write the file
using (FileStream fs = File.OpenWrite(listPath))
using (StreamWriter sw = new StreamWriter(fs))
{
try
{
Debug.Console(2, "Writing {1}, {0} bytes", args.Request.ContentString.Length, listPath);
sw.Write(args.Request.ContentString);
}
catch (Exception e)
{
string err = string.Format("Error writing received presets file:\r{0}", e);
CrestronConsole.PrintLine(err);
ErrorLog.Warn(err);
// Put file back
File.Move(listPath + ".bak", listPath);
args.Response.Code = 500;
return;
}
}
}
}
void HandleApiGetPresetsLists(HttpServerRequest request, HttpServerResponse response)
{
if (request.Header.RequestType != "GET")
{
response.Code = 404; // This should be a 405 with an allow header
return;
}
if (Directory.Exists(PresetsPathPrefix))
{
//CrestronConsole.PrintLine("Parsing presets directory");
List<string> files = Directory.GetFiles(PresetsPathPrefix, "*.json")
.ToList().Select(f => Path.GetFileName(f)).ToList();
if (files.Count > 0)
files.Sort();
var json = JsonConvert.SerializeObject(files);
response.Header.ContentType = "application/json";
response.ContentString = json;
}
// //CrestronConsole.PrintLine("Found {0} files", files.Count);
// JObject jo = new JObject();
// JArray ja = new JArray();
// foreach (var filename in files)
// { // {
// try // try
// { // {
// using (StreamReader sr = new StreamReader(filename)) // var path = args.Request.Path.ToLower();
// {
// JObject tempJo = JObject.Parse(sr.ReadToEnd()); // if (path == "/api/config")
// if (tempJo.Value<string>("content").Equals("presetsList")) // HandleApiConfig(args);
// { // else if (path.StartsWith("/api/presetslist/"))
// var jItem = new JObject(); // make a new object // HandleApiPresetsList(args);
// jItem.Add("Name", tempJo["name"]); // else if (path == "/api/presetslists")
// jItem.Add("File", filename); // HandleApiGetPresetsLists(args.Request, args.Response);
// jItem.Add("Url", Uri.EscapeUriString(new Uri(
// filename.Replace("\\html", "")
// .Replace("\\HTML", "")
// .Replace('\\', '/'), UriKind.Relative).ToString()));
// ja.Add(jItem); // add to array
// }
// else // else
// CrestronConsole.PrintLine("Cannot use presets file '{0}'", filename);
// }
// }
// catch
// { // {
// // ignore failures - maybe delete them // args.Response.Code = 404;
// CrestronConsole.PrintLine("Unable to read presets file '{0}'", filename); // return;
// }
// args.Response.Header.SetHeaderValue("Access-Control-Allow-Origin", "*");
// args.Response.Header.SetHeaderValue("Access-Control-Allow-Methods", "GET, POST, PATCH, PUT, DELETE, OPTIONS");
// }
// catch (Exception e)
// {
// Debug.Console(1, "Uncaught HTTP server error: \n{0}", e);
// args.Response.Code = 500;
// } // }
// } // }
// jo.Add("PresetChannelLists", ja);
// //CrestronConsole.PrintLine(jo.ToString()); // /// <summary>
// /// GET will return the running configuration. POST will attempt to take in a new config
// /// and restart the program.
// /// </summary>
// void HandleApiConfig(OnHttpRequestArgs args)
// {
// var request = args.Request;
// if (request.Header.RequestType == "GET")
// {
// if (File.Exists(ConfigPath))
// {
// Debug.Console(2, "Sending config:{0}", ConfigPath);
// args.Response.Header.ContentType = EssentialsHttpServer.GetContentType(new FileInfo(ConfigPath).Extension);
// args.Response.ContentStream = new FileStream(ConfigPath, FileMode.Open, FileAccess.Read);
// }
// }
// else if (request.Header.RequestType == "POST")
// {
// Debug.Console(2, "Post type: '{0}'", request.Header.ContentType);
// // Make sure we're receiving at least good json
// Debug.Console(1, "Receving new config");
// if (GetContentStringJson(args) == null)
// return;
// //---------------------------- try to move these into common method
// // Move current file aside
// var bakPath = ConfigPath + ".bak";
// if (File.Exists(bakPath))
// File.Delete(bakPath);
// File.Move(ConfigPath, bakPath);
// // Write the file
// using (FileStream fs = File.Open(ConfigPath, FileMode.OpenOrCreate))
// using (StreamWriter sw = new StreamWriter(fs))
// {
// try
// {
// sw.Write(args.Request.ContentString);
// }
// catch (Exception e)
// {
// string err = string.Format("Error writing received config file:\r{0}", e);
// CrestronConsole.PrintLine(err);
// ErrorLog.Warn(err);
// // Put file back
// File.Move(ConfigPath + ".bak", ConfigPath);
// args.Response.Code = 500;
// return;
// }
// }
// // If client says "yeah, restart" and has a good token
// // Restart program
// string consoleResponse = null;
// var restart = CrestronConsole.SendControlSystemCommand("progreset -p:" +
// InitialParametersClass.ApplicationNumber, ref consoleResponse);
// if (!restart) Debug.Console(0, "CAN'T DO THAT YO: {0}", consoleResponse);
// }
// }
// void HandleApiPresetsList(OnHttpRequestArgs args)
// {
// var listPath = PresetsPathPrefix + args.Request.Path.Remove(0, 17);
// Debug.Console(2, "Checking for preset list '{0}'", listPath);
// if (args.Request.Header.RequestType == "GET")
// {
// if (File.Exists(listPath))
// {
// Debug.Console(2, "Sending presets file:{0}", listPath);
// args.Response.Header.ContentType = EssentialsHttpServer.GetContentType(new FileInfo(listPath).Extension);
// args.Response.ContentStream = new FileStream(listPath, FileMode.Open, FileAccess.Read);
// }
// }
// else if (args.Request.Header.RequestType == "POST")
// {
// // Make sure we're receiving at least good json
// Debug.Console(1, "Receving new presets");
// if (GetContentStringJson(args) == null)
// return;
// //---------------------------- try to move these into common method
// // Move current file aside
// var bakPath = listPath + ".new";
// Debug.Console(2, "Moving presets file to {0}", bakPath);
// if(File.Exists(bakPath))
// File.Delete(bakPath);
// File.Move(listPath, bakPath);
// Debug.Console(2, "Writing new file");
// // Write the file
// using (FileStream fs = File.OpenWrite(listPath))
// using (StreamWriter sw = new StreamWriter(fs))
// {
// try
// {
// Debug.Console(2, "Writing {1}, {0} bytes", args.Request.ContentString.Length, listPath);
// sw.Write(args.Request.ContentString);
// }
// catch (Exception e)
// {
// string err = string.Format("Error writing received presets file:\r{0}", e);
// CrestronConsole.PrintLine(err);
// ErrorLog.Warn(err);
// // Put file back
// File.Move(listPath + ".bak", listPath);
// args.Response.Code = 500;
// return;
// }
// }
// }
// }
// void HandleApiGetPresetsLists(HttpServerRequest request, HttpServerResponse response)
// {
// if (request.Header.RequestType != "GET")
// {
// response.Code = 404; // This should be a 405 with an allow header
// return;
// }
// if (Directory.Exists(PresetsPathPrefix))
// {
// //CrestronConsole.PrintLine("Parsing presets directory");
// List<string> files = Directory.GetFiles(PresetsPathPrefix, "*.json")
// .ToList().Select(f => Path.GetFileName(f)).ToList();
// if (files.Count > 0)
// files.Sort();
// var json = JsonConvert.SerializeObject(files);
// response.Header.ContentType = "application/json"; // response.Header.ContentType = "application/json";
// response.ContentString = jo.ToString(); // response.ContentString = json;
// } // }
//else
// CrestronConsole.PrintLine("No presets files in directory");
}
/// <summary> // // //CrestronConsole.PrintLine("Found {0} files", files.Count);
/// Simply does what it says // // JObject jo = new JObject();
/// </summary> // // JArray ja = new JArray();
JObject GetContentStringJson(OnHttpRequestArgs args)
{
//var content = args.Request.ContentString;
//Debug.Console(1, "{0}", content);
try // // foreach (var filename in files)
{ // // {
// just see if it parses properly // // try
return JObject.Parse(args.Request.ContentString); // // {
} // // using (StreamReader sr = new StreamReader(filename))
catch (Exception e) // // {
{ // // JObject tempJo = JObject.Parse(sr.ReadToEnd());
string err = string.Format("JSON Error reading config file:\r{0}", e); // // if (tempJo.Value<string>("content").Equals("presetsList"))
CrestronConsole.PrintLine(err); // // {
ErrorLog.Warn(err); // // var jItem = new JObject(); // make a new object
args.Response.Code = 400; // Bad request // // jItem.Add("Name", tempJo["name"]);
return null; // // jItem.Add("File", filename);
} // // jItem.Add("Url", Uri.EscapeUriString(new Uri(
} // // filename.Replace("\\html", "")
} // // .Replace("\\HTML", "")
} // // .Replace('\\', '/'), UriKind.Relative).ToString()));
// // ja.Add(jItem); // add to array
// // }
// // else
// // CrestronConsole.PrintLine("Cannot use presets file '{0}'", filename);
// // }
// // }
// // catch
// // {
// // // ignore failures - maybe delete them
// // CrestronConsole.PrintLine("Unable to read presets file '{0}'", filename);
// // }
// // }
// // jo.Add("PresetChannelLists", ja);
// // //CrestronConsole.PrintLine(jo.ToString());
// // response.Header.ContentType = "application/json";
// // response.ContentString = jo.ToString();
// //}
// //else
// // CrestronConsole.PrintLine("No presets files in directory");
// }
// /// <summary>
// /// Simply does what it says
// /// </summary>
// JObject GetContentStringJson(OnHttpRequestArgs args)
// {
// //var content = args.Request.ContentString;
// //Debug.Console(1, "{0}", content);
// try
// {
// // just see if it parses properly
// return JObject.Parse(args.Request.ContentString);
// }
// catch (Exception e)
// {
// string err = string.Format("JSON Error reading config file:\r{0}", e);
// CrestronConsole.PrintLine(err);
// ErrorLog.Warn(err);
// args.Response.Code = 400; // Bad request
// return null;
// }
// }
// }
//}

View File

@@ -75,10 +75,6 @@
<HintPath>..\..\..\essentials-devices-common\Essentials Devices Common\Essentials Devices Common\bin\Essentials Devices Common.dll</HintPath> <HintPath>..\..\..\essentials-devices-common\Essentials Devices Common\Essentials Devices Common\bin\Essentials Devices Common.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="EssentialsHttpServer, Version=1.0.0.21365, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\essentials-http-server\EssentialsHttpServer\bin\EssentialsHttpServer.dll</HintPath>
</Reference>
<Reference Include="mscorlib" /> <Reference Include="mscorlib" />
<Reference Include="PepperDashCorePortalSync, Version=1.0.0.27069, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="PepperDashCorePortalSync, Version=1.0.0.27069, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>