예제 #1
0
파일: Program.cs 프로젝트: osbornm/Playr
        static void Main(string[] args)
        {
            var config = new HttpSelfHostConfiguration(ApplicationSettings.apiBaseUrl);
            config.MaxReceivedMessageSize = 1024 * 1024 * 1024;
            config.MessageHandlers.Add(new CorsHandler());
            Routes.RegisterRoutes(config.Routes);
            var apiServer = new HttpSelfHostServer(config);
            apiServer.OpenAsync().Wait();
            var signalrServer = new Server(ApplicationSettings.signalrBaseUrl);
            signalrServer.MapHubs("/signalr");
            signalrServer.Start();

            Helpers.InitializeDocumentStore();
            var itunes = new iTunesAppClass();
            Start(itunes);

            Console.WriteLine("API is avalible at " + ApplicationSettings.apiBaseUrl);
            Console.WriteLine("Singlar Nortifications avalible at " + ApplicationSettings.signalrBaseUrl);
            Console.WriteLine("See http://github.com/osbornm/playr for more information on setup.");
            Console.WriteLine();
            Console.WriteLine("Press any key to stop server...");
            Console.ReadLine();

            // Stop Everything
            apiServer.CloseAsync().Wait();
            signalrServer.Stop();
            Stop(itunes);
            Marshal.ReleaseComObject(itunes);
        }
예제 #2
0
        static void Main(string[] args)
        {
            Debug.Listeners.Add(new ConsoleTraceListener());
            Debug.AutoFlush = true;
            FleckLog.Level = LogLevel.Debug;

            // Web socket server
            var wss = new WebSocketServer("ws://*****:*****@"..\..\www");

            // Hijack the negotiation request
            server.OnProcessRequest = hostContext =>
            {
                // The server supports websockets
                hostContext.Items[HostConstants.SupportsWebSockets] = true;

                // In negotiation, we tell the client the url of the web socket server for this connection
                hostContext.Items[HostConstants.WebSocketServerUrl] = wss.Location + hostContext.Request.Url.LocalPath.Replace("/negotiate", "");
            };

            wss.Start(socket =>
            {
                PersistentConnection connection;
                if (server.TryGetConnection(socket.ConnectionInfo.Path, out connection))
                {
                    // Initalize the connection
                    connection.Initialize(server.DependencyResolver);

                    var req = new FleckWebSocketRequest(socket.ConnectionInfo, wss.IsSecure);
                    var hostContext = new HostContext(req, null, null);

                    // Stack the socket in the items collection so the transport can use it
                    hostContext.Items["Fleck.IWebSocketConnection"] = socket;

                    try
                    {
                        connection.ProcessRequestAsync(hostContext).ContinueWith(task =>
                        {
                            Console.WriteLine(task.Exception.GetBaseException());
                        },
                        TaskContinuationOptions.OnlyOnFaulted);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }
                }
                else
                {
                    socket.Close();
                }
            });


            // HACK: Need to make it easier to plug this in cleaner
            var transportManager = (TransportManager)server.DependencyResolver.Resolve<ITransportManager>();

            // Register the websocket transport
            transportManager.Register("webSockets", context => GetFleckWebSocketTransport(server.DependencyResolver, context));

            server.MapConnection<Raw>("/raw");
            server.EnableHubs();

            server.Start();
            fileServer.Start();

            Process.Start("http://localhost:8081/public/raw/index.htm");

            Console.ReadKey();

            server.Stop();
            fileServer.Stop();
        }