Example #1
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);
        }
Example #2
0
        /// <summary>
        /// Disposes of resources.
        /// </summary>
        public void Dispose()
        {
            if (consoleRoute != null)
            {
                if (server != null)
                {
                    server.RemoveRoute(consoleRoute);
                }

                consoleRoute = null;
            }

            if (consoleRouteHandler != null)
            {
                consoleRouteHandler.Dispose();
                consoleRouteHandler = null;
            }

            server = null;
        }