Пример #1
0
        public void Send(SessionState sessionState, ISendProtocol sendProtocol, EventTypes eventType, Int32 refNum)
        {
            var header = new Header
            {
                eventType = eventType.ToString(),
                refNum    = refNum,
            };

            try
            {
                header.message = sendProtocol?.SerializeJSON(new Message
                {
                    sessionState = sessionState,
                    header       = header,
                });
            }
            catch (Exception ex)
            {
                ex.Log();
            }
            var json = JsonConvert.SerializeObject(new object[] {
                header.eventType.ToString(),
                header.refNum,
                header.message,
            });

            WebAsyncSocket.Send(sessionState, connectionState, json);
        }
Пример #2
0
        public static void Shutdown()
        {
            var threadShutdownWait_InMilliseconds = ConfigManager.GetValue <int>("ThreadShutdownWait_InMilliseconds", 2500).Value;

            isShutDown = true;

            new Business.MSG_SERVERDOWN
            {
                reason     = ServerDownFlags.SD_ServerDown,
                whyMessage = "Server going down!",
            }.SendToServer(null, null);

            Thread.Sleep(threadShutdownWait_InMilliseconds);

            PalaceAsyncSocket.Shutdown();
            PalaceAsyncSocket.Dispose();
            WebAsyncSocket.Shutdown();
            WebAsyncSocket.Dispose();
            SessionManager.Dispose();
            PluginManager.Dispose();
            ThreadController.serverShutdown.Set();
            ThreadController.Dispose();
        }
Пример #3
0
        public static void Init()
        {
            threadManageConnections_InMilliseconds = ConfigManager.GetValue <int>("ThreadManageConnections_InMilliseconds", 750).Value;
            threadRefreshSettings_InMilliseconds   = ConfigManager.GetValue <int>("ThreadRefreshSettings_InMilliseconds", 15000).Value;
            threadManageAssets_InMilliseconds      = ConfigManager.GetValue <int>("ThreadManageAssets_InMilliseconds", 100).Value;
            threadManageFiles_InMilliseconds       = ConfigManager.GetValue <int>("ThreadManageFiles_InMilliseconds", 100).Value;
            threadManageQueue_InMilliseconds       = ConfigManager.GetValue <int>("ThreadManageQueue_InMilliseconds", 100).Value;
            threadAbortWait_InMilliseconds         = ConfigManager.GetValue <int>("ThreadAbortWait_InMilliseconds", 1000).Value;
            threadPause_InMilliseconds             = ConfigManager.GetValue <int>("ThreadPause_InMilliseconds", 500).Value;
            //threadWait_InMilliseconds = ConfigManager.GetValue<int>("ThreadWait_InMilliseconds", 60000).Value;
            threadManageAssetsMax = ConfigManager.GetValue <int>("ThreadManageAssetsMax", 4).Value;
            threadManageFilesMax  = ConfigManager.GetValue <int>("ThreadManageFilesMax", 4).Value;
            threadManageQueueMax  = ConfigManager.GetValue <int>("ThreadManageQueueMax", 4).Value;

            manageAssetsOutboundQueueSignalEvent.Reset();
            manageFilesQueueSignalEvent.Reset();
            manageMessagesQueueSignalEvent.Reset();
            serverShutdown.Reset();

            for (var j = 0; j < threadManageQueueMax; j++)
            {
                Action manageQueue = () =>
                {
                    do
                    {
                        SessionManager.ManageMessages();

                        manageMessagesQueueSignalEvent.WaitOne();

                        Thread.Sleep(threadManageQueue_InMilliseconds);
                    } while (!IsThreadAborted());
                };
                tasks[$"{nameof(manageQueue)}-{j}"] = Task.Factory.StartNew(manageQueue, cancelTokenSrc.Token);
            }

            for (var j = 0; j < threadManageFilesMax; j++)
            {
                Action manageFiles = () =>
                {
                    do
                    {
                        FileLoader.ManageFiles();

                        manageFilesQueueSignalEvent.WaitOne();

                        Thread.Sleep(threadManageFiles_InMilliseconds);
                    } while (!IsThreadAborted());
                };
                tasks[$"{nameof(manageFiles)}-{j}"] = Task.Factory.StartNew(manageFiles, cancelTokenSrc.Token);
            }


            for (var j = 0; j < threadManageAssetsMax; j++)
            {
                Action manageAssetsOutboundQueue = () =>
                {
                    do
                    {
                        AssetLoader.ManageAssetsOutboundQueue();

                        manageAssetsOutboundQueueSignalEvent.WaitOne();

                        Thread.Sleep(threadManageAssets_InMilliseconds);
                    } while (!IsThreadAborted());
                };
                tasks[$"{nameof(manageAssetsOutboundQueue)}-{j}"] = Task.Factory.StartNew(manageAssetsOutboundQueue, cancelTokenSrc.Token);
            }

            Action manageAssetsInboundQueue = () =>
            {
                do
                {
                    AssetLoader.ManageAssetsInboundQueue();

                    manageAssetsInboundQueueSignalEvent.WaitOne();

                    Thread.Sleep(threadManageAssets_InMilliseconds);
                } while (!IsThreadAborted());
            };

            tasks[nameof(manageAssetsInboundQueue)] = Task.Factory.StartNew(manageAssetsInboundQueue, cancelTokenSrc.Token);

            Action manageConnections = () =>
            {
                do
                {
                    PalaceAsyncSocket.ManageConnections();
                    //ProxyAsyncSocket.ManageConnections();
                    WebAsyncSocket.ManageConnections();

                    Thread.Sleep(threadManageConnections_InMilliseconds);
                } while (!IsThreadAborted());
            };

            tasks[nameof(manageConnections)] = Task.Factory.StartNew(manageConnections, cancelTokenSrc.Token);

            Action refreshSettings = () =>
            {
                do
                {
                    ServerState.RefreshSettings();

                    Thread.Sleep(threadRefreshSettings_InMilliseconds);
                } while (!IsThreadAborted());
            };

            tasks[nameof(refreshSettings)] = Task.Factory.StartNew(refreshSettings, cancelTokenSrc.Token);

            Action palaceAsyncSocket = () =>
            {
                do
                {
                    PalaceAsyncSocket.Init();

                    Thread.Sleep(threadRefreshSettings_InMilliseconds);
                } while (!IsThreadAborted());
            };

            tasks[nameof(palaceAsyncSocket)] = Task.Factory.StartNew(palaceAsyncSocket, cancelTokenSrc.Token);

            //Action proxyAsyncSocket = () =>
            //{
            //    do
            //    {
            //        ProxyAsyncSocket.Init();

            //        Thread.Sleep(threadRefreshSettings_InMilliseconds);
            //    } while (!IsThreadAborted());
            //};
            //tasks[nameof(proxyAsyncSocket)] = Task.Factory.StartNew(proxyAsyncSocket, cancelTokenSrc.Token);
#if (DEBUG)
            Action consoleInputThread = () =>
            {
                do
                {
                    var line = Console.ReadLine();

                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    using (var dbContext = Database.For <ThePalaceEntities>())
                    {
                        CommandsEngine.Eval(dbContext, 0xFFFFFFFF, 0, line);
                    }
                } while (!IsThreadAborted());
            };
            tasks[nameof(consoleInputThread)] = Task.Factory.StartNew(consoleInputThread, cancelTokenSrc.Token);
#endif
            WebAsyncSocket.Init();

            do
            {
                serverShutdown.WaitOne();
            } while (!IsThreadAborted());
        }
Пример #4
0
 protected override void OnMessage(MessageEventArgs e)
 {
     WebAsyncSocket.Receive(connectionState, e);
 }
Пример #5
0
 protected override void OnClose(CloseEventArgs e)
 {
     WebAsyncSocket.DropConnection(connectionState);
 }
Пример #6
0
 protected override void OnOpen()
 {
     connectionState = WebAsyncSocket.Accept(this);
 }
Пример #7
0
 public void DropConnection()
 {
     WebAsyncSocket.DropConnection(connectionState);
 }
Пример #8
0
 public bool IsConnected()
 {
     return(WebAsyncSocket.IsConnected(connectionState));
 }