Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        /// <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="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>
        /// <param name="authenticateRoute"><see langword="true"/> to authenticate the route. Only valid on 4-Series processors.</param>
        public CwsConsoleWriter(HttpCwsServer cwsServer, string routePath, bool secureWebsocket, int websocketPort, bool authenticateRoute)
        {
            if (cwsServer == null)
            {
                throw new ArgumentNullException("cwsServer");
            }

            this.server = cwsServer;

            try
            {
                if (CrestronEnvironment.ProgramCompatibility == eCrestronSeries.Series3 || CrestronEnvironment.ProgramCompatibility == eCrestronSeries.Unspecified)
                {
                    consoleRoute = new HttpCwsRoute(routePath);
                }
                else
                {
                    consoleRoute = new HttpCwsRoute(routePath, authenticateRoute);
                }
            }
            catch
            {
                consoleRoute = new HttpCwsRoute(routePath);
            }

            consoleRouteHandler       = new ConsoleRoute(websocketPort, secureWebsocket);
            consoleRoute.RouteHandler = consoleRouteHandler;
            cwsServer.AddRoute(this.consoleRoute);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Add a handler to a route
        /// </summary>
        /// <param name="handler">The request handler to deal with incoming routes</param>
        /// <param name="url">The URL pattern for the route.</param>
        /// <remarks>
        /// URL pattern cannot start with a '/' or '~' character and it cannot contain a '?' character.
        ///             It should not also start with the virtual folder the server is registered for,
        ///             i.e. {device}/Presets/{id}/Recall is correct while /API/{device}/Presets/{id}/Recall is not in both ways.
        ///
        /// </remarks>
        public void RegisterHandler(BaseRequestHandler handler, string url)
        {
            var route = new HttpCwsRoute(url)
            {
                RouteHandler = handler
            };

#if DEBUG
            CrestronConsole.PrintLine("Added route for {0}, url: {1}", handler.Name, route.Url);
#endif

            _server.AddRoute(route);
        }