/* This has been moved to a separate class * //card list * private DmcC input1; * private DmcDvi input2; * private DmcHd input3; * private DmcS input4; * private DmcC input5; * private Dmc4kHd input6; * private DmcVga input7; * private DmcStr input8; * * private Dmc4kCoHdSingle output1_2; * private Dmc4kHdoSingle output3_4; * private DmcStroSingle output5_6; * private DmcCoHdSingle output7_8; */ /// <summary> /// ControlSystem Constructor. Starting point for the SIMPL#Pro program. /// Use the constructor to: /// * Initialize the maximum number of threads (max = 400) /// * Register devices /// * Register event handlers /// * Add Console Commands /// /// Please be aware that the constructor needs to exit quickly; if it doesn't /// exit in time, the SIMPL#Pro program will exit. /// /// You cannot send / receive data in the constructor /// </summary> public TSW750_w_DMMD8x8() : base() { try { Thread.MaxNumberOfUserThreads = 20; //Subscribe to the controller events (System, Program, and Ethernet) CrestronEnvironment.SystemEventHandler += new SystemEventHandler(ControlSystem_ControllerSystemEventHandler); CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(ControlSystem_ControllerProgramEventHandler); CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(ControlSystem_ControllerEthernetEventHandler); ErrorLog.Notice("*** : Constructor"); ErrorLog.Notice("*** : Current Time is {0}", DateTime.Now); myServer = new HttpCwsServer("api"); myServer.Routes.Add(new HttpCwsRoute("roomname") { Name = "ROOMNAME" }); myServer.HttpRequestHandler = new Server_Handler(this); myServer.Register(); //TSW Panel myPanel = new Tsw750(0x20, this); myPanel.Description = "Touchpanel"; myPanel.OnlineStatusChange += new OnlineStatusChangeEventHandler(Device_OnlineStatusChange); if (myPanel.Register() != eDeviceRegistrationUnRegistrationResponse.Success) { ErrorLog.Error("TDS: Error in Registering myPanel: {0}", myPanel.RegistrationFailureReason); } else { myPanel.SigChange += MyPanel_SigChange; } //DM Frame myFrame = DMFrameMaker.DMFrame(0x19, this); /* * myFrame = new DmMd8x8(0x19, this); * input1 = new DmcC(1, myFrame); * input2 = new DmcDvi(2, myFrame); * input3 = new DmcHd(3, myFrame); * input4 = new DmcS(4, myFrame); * input5 = new DmcC(5, myFrame); * input6 = new Dmc4kHd(6, myFrame); * input7 = new DmcVga(7, myFrame); * input8 = new DmcStr(8, myFrame); * output1_2 = new Dmc4kCoHdSingle(1, myFrame); * output3_4 = new Dmc4kHdoSingle(2, myFrame); * output5_6 = new DmcStroSingle(3, myFrame); * output7_8 = new DmcCoHdSingle(4, myFrame); * * myFrame.VideoEnter.BoolValue = true; */ myFrame.Description = "DigitalMedia Switcher"; myFrame.OnlineStatusChange += new OnlineStatusChangeEventHandler(Device_OnlineStatusChange); if (myFrame.Register() != eDeviceRegistrationUnRegistrationResponse.Success) { ErrorLog.Error("TDS: Error in Registering myFrame: {0}", myFrame.RegistrationFailureReason); } else { myFrame.DMOutputChange += MyFrame_DMOutputChange; } } catch (Exception e) { ErrorLog.Error("TDS: Error in the constructor: {0}", e.Message); } }
/// <summary> /// Initializes a new instance of the <see cref="CwsConsoleWriter"/> class. /// </summary> /// <param name="cwsServer">The <see cref="HttpCwsServer"/> to register with.</param> /// <param name="routePath">The name of the CWS route the console should be created at, such as: "/console/program01/".</param> /// <param name="websocketPort">The port the websocket server should listen on.</param> public CwsConsoleWriter(HttpCwsServer cwsServer, string routePath, int websocketPort) : this(cwsServer, routePath, false, websocketPort, false) { }
/// <summary> /// Initializes a new instance of the <see cref="CwsConsoleWriter"/> class. /// </summary> /// <param name="cwsServer">The <see cref="HttpCwsServer"/> to register with.</param> /// <param name="routePath">The name of the CWS route the console should be created at, such as: "/console/program01/".</param> /// <param name="websocketPort">The port the websocket server should listen on.</param> /// <param name="authenticateRoute"><see langword="true"/> to authenticate the route. Only valid on 4-Series processors.</param> public CwsConsoleWriter(HttpCwsServer cwsServer, string routePath, int websocketPort, bool authenticateRoute) : this(cwsServer, routePath, false, websocketPort, authenticateRoute) { }
/// <summary> /// Initializes a new instance of the <see cref="CwsConsoleWriter"/> class. /// </summary> /// <param name="cwsServer">The <see cref="HttpCwsServer"/> to register with.</param> /// <param name="websocketPort">The port the websocket server should listen on.</param> /// <param name="authenticateRoute"><see langword="true"/> to authenticate the route. Only valid on 4-Series processors.</param> public CwsConsoleWriter(HttpCwsServer cwsServer, int websocketPort, bool authenticateRoute) : this(cwsServer, "console" + InitialParametersClass.ApplicationNumber.ToString().PadLeft(2, '0'), false, websocketPort, authenticateRoute) { }
/// <summary> /// Initializes a new instance of the <see cref="CwsConsoleWriter"/> class. /// </summary> /// <param name="cwsServer">The <see cref="HttpCwsServer"/> to register with.</param> /// <param name="secureWebsocket"><see langword="true"/> to indicate the websocket server should use a secure TCP server; otherwise <see langword="false"/>.</param> /// <param name="websocketPort">The port the websocket server should listen on.</param> public CwsConsoleWriter(HttpCwsServer cwsServer, bool secureWebsocket, int websocketPort) : this(cwsServer, "console" + InitialParametersClass.ApplicationNumber.ToString().PadLeft(2, '0'), secureWebsocket, websocketPort) { }
/// <summary> /// The default Constructor. /// </summary> /// <param name="path"></param> public WebScriptingServer(string path) { _path = path; _server = new HttpCwsServer(path); _server.Register(); Debug.WriteSuccess("HttpCwsServer", "Started for path: {0}", _path); Debug.WriteInfo("HttpCwsServer", "Base URL: {0}", BaseUrlDns); Debug.WriteInfo("HttpCwsServer", "Base URL: {0}", BaseUrlIp); _server.ReceivedRequestEvent += (sender, args) => { #if DEBUG CrestronConsole.PrintLine("Incoming http request from {0} {1}", args.Context.Request.UserHostAddress, args.Context.Request.UserHostName); CrestronConsole.PrintLine("Request AbsolutePath: {0}", args.Context.Request.Url.AbsolutePath); CrestronConsole.PrintLine("Request AbsoluteUri: {0}", args.Context.Request.Url.AbsoluteUri); CrestronConsole.PrintLine("Request PhysicalPath: {0}", args.Context.Request.PhysicalPath); CrestronConsole.PrintLine("Request PathAndQuery: {0}", args.Context.Request.Url.PathAndQuery); CrestronConsole.PrintLine("Request Query: {0}", args.Context.Request.Url.Query); CrestronConsole.PrintLine("Request Path: {0}", args.Context.Request.Path); CrestronConsole.PrintLine("Request Method: {0}", args.Context.Request.HttpMethod); #endif try { if (args.Context.Request.RouteData != null) { #if DEBUG CrestronConsole.PrintLine("Request handler: {0}", args.Context.Request.RouteData.RouteHandler.GetType()); CrestronConsole.PrintLine("Route URL Pattern: {0}", args.Context.Request.RouteData.Route.Url); #endif } else if (RootHandler == null) { #if DEBUG CrestronConsole.PrintLine("Request has no handler!"); #endif HandleError(args.Context, 404, "Not Found", "The requested resource does not exist"); } else if (args.Context.Request.PhysicalPath != string.Format("\\HTML\\{0}", _path) && args.Context.Request.PhysicalPath != string.Format("\\HTML\\{0}\\", _path)) { #if DEBUG CrestronConsole.PrintLine("Request handler: {0}", RootHandler.GetType()); #endif RootHandler.ProcessRequest(args.Context); } } catch (Exception e) { CloudLog.Exception("Error in ApiServer main request handler", e); HandleError(args.Context, 500, "Server Error", string.Format("{0}<BR>{1}", e.Message, e.StackTrace)); } }; CrestronEnvironment.ProgramStatusEventHandler += type => { if (type == eProgramStatusEventType.Stopping) { _server.Dispose(); } }; }
/// <summary> /// Start the CWS server with the previously set path /// </summary> public void StartServer() { ErrorLog.Notice($"{LogHeader} Starting CWS API Server"); try { this.cwsServerLock.Enter(); if (this.cwsServer == null) { ErrorLog.Notice($"{LogHeader} Starting CWS API Server"); this.cwsServer = new HttpCwsServer(this.cwsPath); this.cwsServer.ReceivedRequestEvent += new HttpCwsRequestEventHandler(this.ReceivedRequestEvent); // Example GET route // There are a couple of things to keep in mind: // {data} defines a variable that can be used later in your code // DUMMY is a shorter name that can be used to "find" your route later on //this.cwsServer.Routes.Add(new HttpCwsRoute("dummygetroute/{data}") { Name = "DUMMYGET" }); // TODO: Level1. Add your own HTTP CWS Route called "helloworld" this.cwsServer.Routes.Add(new HttpCwsRoute("helloworld/{data}") { Name = "HELLOWORLD" }); // Example POST route // Not necessary for Level1, this was added as a reference this.cwsServer.Routes.Add(new HttpCwsRoute("holamundo") { Name = "holamundo" }); //Level2 this.cwsServer.Routes.Add(new HttpCwsRoute("interlockstatus") { Name = "interlockstatus" }); // Level 3 this.cwsServer.Routes.Add(new HttpCwsRoute("getslider") { Name = "getslider" }); this.cwsServer.Routes.Add(new HttpCwsRoute("postslider") { Name = "postslider" }); this.cwsServer.Routes.Add(new HttpCwsRoute("log") { Name = "log" }); // register the server this.cwsServer.Register(); ErrorLog.Notice($"{LogHeader} Started CWS API Server"); } else { throw new InvalidOperationException("CWS API Server is already running"); } } catch (Exception e) { ErrorLog.Error(LogHeader + "Exception in StartServer(): {0}", e.Message); } finally { this.cwsServerLock.Leave(); } }
public MvServerHandler(HttpCwsServer _Server) { this.Server = _Server; }
public _Server_Handler(HttpCwsServer _Server, string slotNumber) { this._Server = _Server; this.slotNumber = slotNumber; }
public RestfulRelayServer(CrestronCollection <Relay> relay_collection, string hostname) { try { _numberOfRelays = relay_collection.Count; _relays = relay_collection; _root = "http://" + hostname; notifier = new HttpClient(); // To ensure that the template.json file appears in the control system's application directory, // set "Build Action" to "Content" and "Copy to Output Directory" to "Copy always" in the file's Properties menu _cjTemplate = File.ReadToEnd(Directory.GetApplicationDirectory() + "\\template.json", Encoding.UTF8); // set up subscription lists for the Relay collection and for each Relay sublists = new List <Dictionary <string, Subscription> >(NumberOfRelays + 1); // Both the collection and each relay gets its own subscription dictionary for (int i = 0; i < NumberOfRelays + 1; i++) { sublists.Add(new Dictionary <string, Subscription>()); // client will use a GuID to locate the subscription resource if it wants to DELETE it. } // start up the server server = new HttpCwsServer("/api"); /* * URL Routing table: * /relays * /relays/web-hooks * /relays/web-hooks/{subid} * /relays/{id} * /relays/{id}/web-hooks * /relays/{id}/web-hooks/{subid} */ // subscribe to events server.ReceivedRequestEvent += new HttpCwsRequestEventHandler(server_ReceivedRequestEvent); server.HttpRequestHandler = new DefaultHandler(this); // This is the default handler. It will process unrouted requests. foreach (Relay r in relay_collection) { r.StateChange += new RelayEventHandler(r_StateChange); } // Add each route to server's routing table: In this example, each route is // associated with its own RouteHandler class, which will process the HTTP request and write its response. // Other designs might use a single route handler that interprets the full requested path and performs the // route handling in this handler's ProcessRequest method // The order in which you add the routes matters. The HttpCwsServer will search in this order for a route matching // the requested URL, stopping at the first match it finds and calling the corresponding handler's // ProcessRequest method, or that of the HttpRequestHandler (called "DefaultHandler" in this example) // if no route-specific handler exists. HttpCwsRoute route = new HttpCwsRoute("relays") { Name = "relay_collection" }; // do not include the leading '/' in the HttpCwsRoute constructor route.RouteHandler = new RelaysHandler(this); server.Routes.Add(route); route = new HttpCwsRoute("relays/web-hooks") { Name = "relay_collection_subscriptions" }; route.RouteHandler = new RelaysWebhooksHandler(this); server.Routes.Add(route); route = new HttpCwsRoute("relays/web-hooks/{subid}") { Name = "relay_collection_subscription" }; route.RouteHandler = new RelaysWebhooksSubidHandler(this); server.Routes.Add(route); route = new HttpCwsRoute("relays/{id}") { Name = "individual_relay" }; route.RouteHandler = new RelaysIdHandler(this); server.Routes.Add(route); route = new HttpCwsRoute("relays/{id}/web-hooks") { Name = "individual_relay_subscriptions" }; route.RouteHandler = new RelaysIdWebhooksHandler(this); server.Routes.Add(route); route = new HttpCwsRoute("relays/{id}/web-hooks/{subid}") { Name = "individual_relay_subscription" }; route.RouteHandler = new RelaysIdWebhooksSubidHandler(this); server.Routes.Add(route); // Start receiving HTTP requests server.Register(); } catch (Exception e) { CrestronConsole.PrintLine("Error in the RestfulRelayServer constructor: " + e.Message); } finally { } }