public override string DoInBackGround(string receivedData)
        {
            try
            {
                SocketRequest req = new SocketRequest(basicController, "RunAction", new System.Collections.Generic.List <RequestParameter>(),
                                                      preProcessor.clientSocket);

                Stopwatch s = new Stopwatch();
                s.Start();
                object resultObject = basicController.RunAction(receivedData, req);
                s.Stop();

                string resultString = string.Empty;

                if (resultObject != null)
                {
                    resultString = (resultObject.GetType() == typeof(string)
                        ? resultObject.ToString()
                        : JsonConvert.SerializeObject(resultObject, AppServerConfigurator.SerializerSettings));
                }

                byte[] resultBytes = coreServer.GetConfiguration().ServerEncoding.GetBytes(resultString);
                preProcessor.clientSocket.Send(resultBytes);
            }
            catch (Exception ex)
            {
                preProcessor.clientSocket.Send(encoder.ConvertToByteArray($"Error: {ex.Message}"));
                logger.WriteLog($"Basic Server Module Error: {ex.Message}", ServerLogType.ERROR);
            }

            preProcessor.Dispose();
            return(string.Empty);
        }
        public override string DoInBackGround(string receivedData)
        {
            var srv = Server.GlobalInstance;

            LogController.WriteLog(new ServerLog($"Basic Server Module: Begin Request"));
            LogController.WriteLog(new ServerLog($"Received Data: {receivedData}"));

            IBasicServerController controller = (IBasicServerController)Activator.CreateInstance(srv.BasicServerControllerType, null);

            try
            {
                Stopwatch s = new Stopwatch();
                s.Start();
                ActionResult result = controller.RunAction(receivedData);
                s.Stop();

                string resultToJson = JsonConvert.SerializeObject(result);

                byte[] resultBytes = srv.ServerEncoding.GetBytes(resultToJson);
                PreProcess.ClientSocket.Send(resultBytes);
                LogController.WriteLog(new ServerLog($"Request completed in ~{s.ElapsedMilliseconds}ms"));
            }
            catch (Exception ex)
            {
                PreProcess.ClientSocket.Send(srv.ServerEncoding.GetBytes($"Error: {ex.Message}"));
                LogController.WriteLog(new ServerLog($"Basic Server Module Error: {ex.Message}", ServerLogType.ERROR));
            }

            PreProcess.Dispose();

            return(string.Empty);
        }
Esempio n. 3
0
        public override string DoInBackGround(string receivedData)
        {
            try
            {
                Stopwatch s = new Stopwatch();
                s.Start();
                ActionResult result = basicController.RunAction(receivedData);
                s.Stop();

                string resultToJson = JsonConvert.SerializeObject(result, AppServerConfigurator.SerializerSettings);

                byte[] resultBytes = coreServer.GetConfiguration().ServerEncoding.GetBytes(resultToJson);
                preProcessor.clientSocket.Send(resultBytes);
            }
            catch (Exception ex)
            {
                preProcessor.clientSocket.Send(encoder.ConvertToByteArray($"Error: {ex.Message}"));
                logger.WriteLog($"Basic Server Module Error: {ex.Message}", ServerLogType.ERROR);
            }

            preProcessor.Dispose();
            return(string.Empty);
        }