示例#1
0
        protected override void RequestHandler(HttpConnectionHandler request)
        {
            Log.Add(LogLevel.Debug, "TriggerReceiver", String.Format("Received request on /{0}", request.RequestUriParts[0]));

            if (request.Method == HttpMethod.Post)
            {
                /*switch (request.RequestUriParts[0])
                 * {
                 *  case RequestUri:
                 *      ProcessRequest(request);
                 *      break;
                 *  default:
                 *      request.ResultCode = HttpResult.NotFound;
                 *      break;
                 * }*/
                if (request.RequestUriParts[0].Equals(RequestUri))
                {
                    ProcessRequest(request);
                }
                else
                {
                    request.ResultCode = HttpResult.NotFound;
                }
            }
            else
            {
                request.ResultCode = HttpResult.MethodNotAllowed;
            }
        }
示例#2
0
        protected override void RequestHandler(HttpConnectionHandler request)
        {
            Log.Add(LogLevel.Debug, "TriggerReceiver", String.Format("Received request on /{0}", request.RequestUriParts[0]));

            if (request.Method == HttpMethod.Post)
            {
                /*switch (request.RequestUriParts[0])
                {
                    case RequestUri:
                        ProcessRequest(request);
                        break;
                    default:
                        request.ResultCode = HttpResult.NotFound;
                        break;
                }*/
                if (request.RequestUriParts[0].Equals(RequestUri))
                {
                    ProcessRequest(request);
                }
                else
                {
                    request.ResultCode = HttpResult.NotFound;
                }
            }
            else
            {
                request.ResultCode = HttpResult.MethodNotAllowed;
            }
            
        }
示例#3
0
        private void ProcessRequest(HttpConnectionHandler handler)
        {
            try
            {
                int    length       = int.Parse(handler.GetRequestHeader("Content-Length"));
                byte[] requestBytes = new byte[length];
                handler.RequestStream.Read(requestBytes, 0, length);

                string xml = Encoding.UTF8.GetString(requestBytes);

                var result = ProcessRequestString(xml);

                switch (result)
                {
                case RequestProcessingResult.Success:
                    handler.ResultCode = HttpResult.Ok;
                    break;

                case RequestProcessingResult.Error:
                    handler.ResultCode = HttpResult.InternalServerError;
                    break;

                case RequestProcessingResult.XmlError:
                    handler.ResultCode = HttpResult.BadRequest;
                    break;

                case RequestProcessingResult.ApiKeyError:
                    handler.ResultCode = HttpResult.Forbidden;
                    break;

                case RequestProcessingResult.UnknownRequest:
                    handler.ResultCode = HttpResult.NotImplemented;
                    break;
                }
            }
            catch (FormatException ex)
            {
                Log.AddException("TriggerReceiver", ex);
                handler.ResultCode = HttpResult.BadRequest;
            }
            catch (UnauthorizedAccessException ex)
            {
                Log.AddException("TriggerReceiver", ex);
                handler.ResultCode = HttpResult.Forbidden;
            }
            catch (Exception ex)
            {
                Log.AddException("TriggerReceiver", ex);
                handler.ResultCode = HttpResult.InternalServerError;
            }
        }
示例#4
0
        private void AsyncAcceptClient(IAsyncResult asyncResult)
        {
            if (!_runThread)
                return;

            TcpClient newClient = _listener.EndAcceptTcpClient(asyncResult);

            HttpConnectionHandler newHandler = new HttpConnectionHandler(newClient, CheckCredentials);
            newHandler.RequestHandler = RequestHandler;
            
            newHandler.StartProcessing();

            _listener.BeginAcceptTcpClient(new AsyncCallback(AsyncAcceptClient), null);
        }
示例#5
0
        private void AsyncAcceptClient(IAsyncResult asyncResult)
        {
            if (!_runThread)
            {
                return;
            }

            TcpClient newClient = _listener.EndAcceptTcpClient(asyncResult);

            HttpConnectionHandler newHandler = new HttpConnectionHandler(newClient, CheckCredentials);

            newHandler.RequestHandler = RequestHandler;

            newHandler.StartProcessing();

            _listener.BeginAcceptTcpClient(new AsyncCallback(AsyncAcceptClient), null);
        }
示例#6
0
        private void ProcessRequest(HttpConnectionHandler handler)
        {
            try
            {
                int length = int.Parse(handler.GetRequestHeader("Content-Length"));
                byte[] requestBytes = new byte[length];
                handler.RequestStream.Read(requestBytes, 0, length);

                string xml = Encoding.UTF8.GetString(requestBytes);

                var result = ProcessRequestString(xml);

                switch (result)
                {
                        case RequestProcessingResult.Success:
                        handler.ResultCode = HttpResult.Ok;
                        break;

                        case RequestProcessingResult.Error:
                        handler.ResultCode = HttpResult.InternalServerError;
                        break;

                        case RequestProcessingResult.XmlError:
                        handler.ResultCode = HttpResult.BadRequest;
                        break;

                        case RequestProcessingResult.ApiKeyError:
                        handler.ResultCode = HttpResult.Forbidden;
                        break;

                        case RequestProcessingResult.UnknownRequest:
                        handler.ResultCode = HttpResult.NotImplemented;
                        break;
                }

                
            }
            catch (FormatException ex)
            {
                Log.AddException("TriggerReceiver", ex);
                handler.ResultCode = HttpResult.BadRequest;
            }
            catch (UnauthorizedAccessException ex)
            {
                Log.AddException("TriggerReceiver", ex);
                handler.ResultCode = HttpResult.Forbidden;
            }
            catch (Exception ex)
            {
                Log.AddException("TriggerReceiver", ex);
                handler.ResultCode = HttpResult.InternalServerError;
            }
            
        }
示例#7
0
 protected abstract void RequestHandler(HttpConnectionHandler request);
示例#8
0
 protected abstract void RequestHandler(HttpConnectionHandler request);