chore: move all files to file-scoped namespace

This commit is contained in:
Andrew Welker 2025-07-04 16:02:32 -05:00 committed by Neil Dorin
parent aaa5b0532b
commit 3ece4f0b7b
522 changed files with 39628 additions and 45678 deletions

View file

@ -3,38 +3,37 @@ using System.Net.WebSockets;
using System.Threading;
using System.Threading.Tasks;
namespace PepperDash.Essentials.Fusion
namespace PepperDash.Essentials.Fusion;
public class EssentialsHuddleSpaceFusionSystemControllerBase
{
public class EssentialsHuddleSpaceFusionSystemControllerBase
private ClientWebSocket _webSocket;
public EssentialsHuddleSpaceFusionSystemControllerBase()
{
private ClientWebSocket _webSocket;
_webSocket = new ClientWebSocket();
}
public EssentialsHuddleSpaceFusionSystemControllerBase()
{
_webSocket = new ClientWebSocket();
}
public async Task ConnectAsync(Uri uri)
{
await _webSocket.ConnectAsync(uri, CancellationToken.None);
}
public async Task ConnectAsync(Uri uri)
{
await _webSocket.ConnectAsync(uri, CancellationToken.None);
}
public async Task SendAsync(string message)
{
var buffer = System.Text.Encoding.UTF8.GetBytes(message);
await _webSocket.SendAsync(new ArraySegment<byte>(buffer), WebSocketMessageType.Text, true, CancellationToken.None);
}
public async Task SendAsync(string message)
{
var buffer = System.Text.Encoding.UTF8.GetBytes(message);
await _webSocket.SendAsync(new ArraySegment<byte>(buffer), WebSocketMessageType.Text, true, CancellationToken.None);
}
public async Task<string> ReceiveAsync()
{
var buffer = new byte[1024];
var result = await _webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
return System.Text.Encoding.UTF8.GetString(buffer, 0, result.Count);
}
public async Task<string> ReceiveAsync()
{
var buffer = new byte[1024];
var result = await _webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
return System.Text.Encoding.UTF8.GetString(buffer, 0, result.Count);
}
public async Task CloseAsync()
{
await _webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None);
}
public async Task CloseAsync()
{
await _webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None);
}
}

View file

@ -7,127 +7,117 @@ using Crestron.SimplSharp.Net.Http;
using PepperDash.Core;
using Serilog.Events;
namespace PepperDash.Essentials
namespace PepperDash.Essentials;
public class HttpLogoServer
{
/// <summary>
/// HTTP server for serving logo images and files
///
/// </summary>
public class HttpLogoServer
readonly HttpServer _server;
/// <summary>
///
/// </summary>
readonly string _fileDirectory;
/// <summary>
///
/// </summary>
public static Dictionary<string, string> ExtensionContentTypes;
/// <summary>
///
/// </summary>
/// <param name="port"></param>
/// <param name="directory"></param>
public HttpLogoServer(int port, string directory)
{
/// <summary>
/// The HTTP server instance
/// </summary>
readonly HttpServer _server;
/// <summary>
/// The directory containing files to serve
/// </summary>
readonly string _fileDirectory;
/// <summary>
/// Dictionary mapping file extensions to content types
/// </summary>
public static Dictionary<string, string> ExtensionContentTypes;
/// <summary>
/// Initializes a new instance of the HttpLogoServer class
/// </summary>
/// <param name="port">Port number for the HTTP server</param>
/// <param name="directory">Directory containing files to serve</param>
public HttpLogoServer(int port, string directory)
{
ExtensionContentTypes = new Dictionary<string, string>
ExtensionContentTypes = new Dictionary<string, string>
{
//{ ".css", "text/css" },
//{ ".htm", "text/html" },
//{ ".html", "text/html" },
//{ ".css", "text/css" },
//{ ".htm", "text/html" },
//{ ".html", "text/html" },
{ ".jpg", "image/jpeg" },
{ ".jpeg", "image/jpeg" },
//{ ".js", "application/javascript" },
//{ ".json", "application/json" },
//{ ".map", "application/x-navimap" },
//{ ".js", "application/javascript" },
//{ ".json", "application/json" },
//{ ".map", "application/x-navimap" },
{ ".pdf", "application/pdf" },
{ ".png", "image/png" },
//{ ".txt", "text/plain" },
//{ ".txt", "text/plain" },
};
_server = new HttpServer {Port = port};
_fileDirectory = directory;
_server.OnHttpRequest += Server_OnHttpRequest;
_server.Open();
_server = new HttpServer {Port = port};
_fileDirectory = directory;
_server.OnHttpRequest += Server_OnHttpRequest;
_server.Open();
CrestronEnvironment.ProgramStatusEventHandler += CrestronEnvironment_ProgramStatusEventHandler;
}
CrestronEnvironment.ProgramStatusEventHandler += CrestronEnvironment_ProgramStatusEventHandler;
}
/// <summary>
/// Handles incoming HTTP requests and serves files from the configured directory
/// </summary>
/// <param name="sender">The HTTP server instance</param>
/// <param name="args">HTTP request arguments</param>
void Server_OnHttpRequest(object sender, OnHttpRequestArgs args)
/// <summary>
///
/// </summary>
void Server_OnHttpRequest(object sender, OnHttpRequestArgs args)
{
var path = args.Request.Path;
Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "HTTP Request with path: '{requestPath:l}'", args.Request.Path);
try
{
var path = args.Request.Path;
Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "HTTP Request with path: '{requestPath:l}'", args.Request.Path);
try
if (File.Exists(_fileDirectory + path))
{
if (File.Exists(_fileDirectory + path))
{
var filePath = path.Replace('/', '\\');
var localPath = string.Format(@"{0}{1}", _fileDirectory, filePath);
var filePath = path.Replace('/', '\\');
var localPath = string.Format(@"{0}{1}", _fileDirectory, filePath);
Debug.LogMessage(LogEventLevel.Verbose, "HTTP Logo Server attempting to find file: '{localPath:l}'", localPath);
if (File.Exists(localPath))
{
args.Response.Header.ContentType = GetContentType(new FileInfo(localPath).Extension);
args.Response.ContentStream = new FileStream(localPath, FileMode.Open, FileAccess.Read);
}
else
{
Debug.LogMessage(LogEventLevel.Verbose, "HTTP Logo Server Cannot find file '{localPath:l}'", localPath);
args.Response.ContentString = string.Format("Not found: '{0}'", filePath);
args.Response.Code = 404;
}
Debug.LogMessage(LogEventLevel.Verbose, "HTTP Logo Server attempting to find file: '{localPath:l}'", localPath);
if (File.Exists(localPath))
{
args.Response.Header.ContentType = GetContentType(new FileInfo(localPath).Extension);
args.Response.ContentStream = new FileStream(localPath, FileMode.Open, FileAccess.Read);
}
else
{
Debug.LogMessage(LogEventLevel.Verbose, "HTTP Logo Server: '{file:l}' does not exist", _fileDirectory + path);
args.Response.ContentString = string.Format("Not found: '{0}'", _fileDirectory + path);
Debug.LogMessage(LogEventLevel.Verbose, "HTTP Logo Server Cannot find file '{localPath:l}'", localPath);
args.Response.ContentString = string.Format("Not found: '{0}'", filePath);
args.Response.Code = 404;
}
}
catch (Exception ex)
else
{
Debug.LogMessage(LogEventLevel.Error, "Exception getting file: {exception}", ex.Message, ex.StackTrace);
Debug.LogMessage(LogEventLevel.Verbose, "Stack Trace: {stackTrace}", ex.StackTrace);
args.Response.Code = 400;
args.Response.ContentString = string.Format("invalid request");
Debug.LogMessage(LogEventLevel.Verbose, "HTTP Logo Server: '{file:l}' does not exist", _fileDirectory + path);
args.Response.ContentString = string.Format("Not found: '{0}'", _fileDirectory + path);
args.Response.Code = 404;
}
}
/// <summary>
/// Handles program status events and closes the server when the program is stopping
/// </summary>
/// <param name="programEventType">The program status event type</param>
void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType programEventType)
catch (Exception ex)
{
if (programEventType == eProgramStatusEventType.Stopping)
_server.Close();
}
Debug.LogMessage(LogEventLevel.Error, "Exception getting file: {exception}", ex.Message, ex.StackTrace);
Debug.LogMessage(LogEventLevel.Verbose, "Stack Trace: {stackTrace}", ex.StackTrace);
/// <summary>
/// Gets the content type for a file based on its extension
/// </summary>
/// <param name="extension">The file extension</param>
/// <returns>The corresponding content type string</returns>
/// <summary>
/// GetContentType method
/// </summary>
public static string GetContentType(string extension)
{
var type = ExtensionContentTypes.ContainsKey(extension) ? ExtensionContentTypes[extension] : "text/plain";
return type;
args.Response.Code = 400;
args.Response.ContentString = string.Format("invalid request");
}
}
/// <summary>
///
/// </summary>
void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType programEventType)
{
if (programEventType == eProgramStatusEventType.Stopping)
_server.Close();
}
/// <summary>
///
/// </summary>
/// <param name="extension"></param>
/// <returns></returns>
public static string GetContentType(string extension)
{
var type = ExtensionContentTypes.ContainsKey(extension) ? ExtensionContentTypes[extension] : "text/plain";
return type;
}
}