/// <summary> /// Start the HTTP Server /// </summary> public void Start() { try { _ServerLock.Enter(); if (_Server == null) { CrestronConsole.PrintLine("Starting RESTful CWS API HTTP Server"); _Server = new HttpCwsServer("/API/" + ProgramNumber + "/"); _Server.HttpRequestHandler = new _Server_Handler(_Server, ProgramNumber); _Server.Routes.Add(new HttpCwsRoute("configuration") { Name = "CONFIGURATION.GET" }); _Server.Routes.Add(new HttpCwsRoute("configuration/set") { Name = "CONFIGURATION.SET" }); // register the server _Server.Register(); CrestronConsole.PrintLine("Started RESTful CWS API HTTP Server"); } else { throw new InvalidOperationException("Server is already running"); } } finally { _ServerLock.Leave(); } }
/// <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 TSR310_w_SmartObject() : 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(); } catch (Exception e) { ErrorLog.Error("Error in the constructor: {0}", e.Message); } }
public override void InitializeSystem() { try { _api = new HttpCwsServer("/api"); var hello = new HttpCwsRoute("hello/"); hello.RouteHandler = new HelloRequest(); _api.AddRoute(hello); var helloName = new HttpCwsRoute("hello/{NAME}"); helloName.RouteHandler = new HelloRequest(); _api.AddRoute(helloName); var roomHandler = new RoomRequest(); var room = new HttpCwsRoute("room"); room.RouteHandler = roomHandler; _api.AddRoute(room); var roomProp = new HttpCwsRoute("room/{PROPERTY}"); roomProp.RouteHandler = roomHandler; _api.AddRoute(roomProp); _api.Register(); } catch (Exception e) { ErrorLog.Error("Error in InitializeSystem: {0}", e.Message); } }
public MvCwsInterface() { Server = new HttpCwsServer("/mv"); Server.HttpRequestHandler = new MvServerHandler(Server); Server.Routes.Add(new HttpCwsRoute("variables") { Name = "VARIABLES" }); Server.Register(); }
/// <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 ControlSystem() : base() { try { Thread.MaxNumberOfUserThreads = 20; // myEISC = new VirtualControlEISCClient(0x15, "10.71.4.120", this); // myEISC = new EthernetIntersystemCommunications(0x15, "10.71.4.120", this); // myEISC = new EISCServer(0x15, this); myEISC = new EISCClient(0x15, "10.71.4.120", this); myEISC.Description = "Test for EISC from 3-series"; myEISC.OnlineStatusChange += MyEISC_OnlineStatusChange; if (myEISC.Register() != eDeviceRegistrationUnRegistrationResponse.Success) { ErrorLog.Error("TDS: Error in registration of EISC = {0}", myEISC.RegistrationFailureReason); } else { myEISC.SigChange += MyEISC_SigChange; } //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(); } catch (Exception e) { ErrorLog.Error("Error in the constructor: {0}", e.Message); } }
int rlyID; // ID of the relay subscribed to. Ranges between 1 and the maximum number of relays on the server public RelayMonitor(string myHostname) { client = new HttpClient(); listener = new HttpCwsServer("/listen"); listener.ReceivedRequestEvent += new HttpCwsRequestEventHandler(listener_ReceivedRequestEvent); listener.HttpRequestHandler = new DefaultHandler(this); // this handler will process all requests made to the listener listenUrl = new UrlParser("http://" + myHostname + "/cws/listen/" + Guid.NewGuid().ToString()); // register listener to begin receiving POST notifications if (listener.Register()) { CrestronConsole.PrintLine("Registered notification listener"); } else { CrestronConsole.PrintLine("Failed to register notification listener"); } }
public override void InitializeSystem() { try { myServer = new HttpCwsServer("/api"); myServer.ReceivedRequestEvent += new HttpCwsRequestEventHandler(myServerReceivedRequestEvent); myServer.Routes.Add(new HttpCwsRoute("ver") { Name = "shversion" }); myServer.Register(); CrestronConsole.SendControlSystemCommand("progcomments:1", ref cmdResponse); CrestronConsole.SendControlSystemCommand("ver", ref versionResponse); var adapterId = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(EthernetAdapterType.EthernetLANAdapter); macAddress = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_MAC_ADDRESS, adapterId); } catch (Exception e) { ErrorLog.Error("Error in InitializeSystem: {0}", e.Message); } }
/// <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 ControlSystem() { try { server = new HttpCwsServer("/"); server.HttpRequestHandler = new RequestHandler(); server.ReceivedRequestEvent += new HttpCwsRequestEventHandler(server_ReceivedRequestEvent); if (!server.Register()) { CrestronConsole.PrintLine("CWS server registration failed"); server.Dispose(); return; } //Subscribe to the controller events (System, Program, and Ethernet) CrestronEnvironment.SystemEventHandler += new SystemEventHandler(ControlSystem_ControllerSystemEventHandler); CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(ControlSystem_ControllerProgramEventHandler); } catch (Exception e) { ErrorLog.Error("Error in the constructor: {0}", e.Message); } }
/* 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> /// 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(); } }; }
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 { } }