Exemple #1
0
 public WebSocketServerMiddleware(RequestDelegate next,
                                  WebSocketDelegate process,
                                  WebSocketServerOptions options,
                                  ILoggerFactory loggerFactory)
 {
     m_next    = next ?? throw new ArgumentNullException(nameof(next));
     m_process = process ?? throw new ArgumentNullException(nameof(process));
     m_options = options ?? throw new ArgumentNullException(nameof(options));
     m_logger  = loggerFactory.CreateLogger <WebSocketServerMiddleware>();
 }
Exemple #2
0
        private static void Main(string[] args)
        {
            Message = null;

            Message = "Loading...";

            Console.Title = Message;

            XmlConfigurator.ConfigureAndWatch(new FileInfo("_appengine.config"));

            Database = new Database();
            GameData = new EmbeddedData();

            InstanceId = Guid.NewGuid().ToString();

            Manager = new ISManager();
            Manager.Run();

            Log.Info("Initializing AppEngine...");

            AppEngineManager = new AppEngineManager(Restart);
            AppEngineManager.Start();

            Console.Title = Settings.APPENGINE.TITLE;

            while (Console.ReadKey(true).Key != ConsoleKey.Escape)
            {
                ;
            }

            Database.Connection.Dispose();

            AppEngineManager._shutdown = true;

            Log.Warn("Terminating AppEngine, disposing all instances.");

            var webSocketIAsyncResult = new WebSocketDelegate(AppEngineManager.SafeShutdown).BeginInvoke(new AsyncCallback(AppEngineManager.SafeDispose), null);

            webSocketIAsyncResult.AsyncWaitHandle.WaitOne(5000, true);
        }
        private void RestartThread()
        {
            Thread parallel_thread = new Thread(() =>
            {
                Thread.Sleep(ToMiliseconds(Settings.NETWORKING.RESTART.RESTART_DELAY_MINUTES));
                int i = 5;
                do
                {
                    Log.Info($"AppEngine is restarting in {i} second{(i > 1 ? "s" : "")}...");
                    Thread.Sleep(1000);
                    i--;
                } while (i != 0);

                IAsyncResult webSocketIAsyncResult = new WebSocketDelegate(SafeShutdown).BeginInvoke(new AsyncCallback(SafeDispose), null);

                if (webSocketIAsyncResult.AsyncWaitHandle.WaitOne())
                {
                    Process.Start(Settings.APPENGINE.FILE);
                }
            });

            parallel_thread.Start();
        }
 public static IApplicationBuilder UseWebSocketServer(this IApplicationBuilder app, WebSocketDelegate process)
 => UseWebSocketServer(app, process, new WebSocketServerOptions());
        public static IApplicationBuilder UseWebSocketServer(this IApplicationBuilder app, WebSocketDelegate process, WebSocketServerOptions options)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }
            if (process == null)
            {
                throw new ArgumentNullException(nameof(process));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(app.UseMiddleware <WebSocketServerMiddleware>(process, options));
        }