AcceptRequest() public method

public AcceptRequest ( DataReader reader ) : System.Threading.Tasks.Task
reader Windows.Storage.Streams.DataReader
return System.Threading.Tasks.Task
Esempio n. 1
0
        private async void HandleRequest(StreamSocket socket)
        {
            var reader = new DataReader(socket.InputStream)
            {
                InputStreamOptions = InputStreamOptions.Partial
            };
            var writer = new DataWriter(socket.OutputStream)
            {
                UnicodeEncoding = UnicodeEncoding.Utf8
            };

            var acceptedRequest = new AcceptedRequest();
            await acceptedRequest.AcceptRequest(reader);

            string response;

            try
            {
                var commandRespnose = this.requestHandlerFunc(acceptedRequest.Request, acceptedRequest.Content);
                response = HttpResponseHelper.ResponseString(commandRespnose.HttpStatusCode, commandRespnose.Content);
            }
            catch (NotImplementedException ex)
            {
                response = HttpResponseHelper.ResponseString(HttpStatusCode.NotImplemented, ex.Message);
            }

            writer.WriteString(response);
            await writer.StoreAsync();

            socket.Dispose();

            if (this.ShouldStopAfterResponse)
            {
                this.Stop();
            }
        }
        private async void HandleRequest(StreamSocket socket)
        {
            var reader = new DataReader(socket.InputStream) { InputStreamOptions = InputStreamOptions.Partial };
            var writer = new DataWriter(socket.OutputStream) { UnicodeEncoding = UnicodeEncoding.Utf8 };

            var acceptedRequest = new AcceptedRequest();
            await acceptedRequest.AcceptRequest(reader);

            string response;
            try
            {
                var commandRespnose = this.requestHandlerFunc(acceptedRequest.Request, acceptedRequest.Content);
                response = HttpResponseHelper.ResponseString(commandRespnose.HttpStatusCode, commandRespnose.Content);
            }
            catch (NotImplementedException ex)
            {
                response = HttpResponseHelper.ResponseString(HttpStatusCode.NotImplemented, ex.Message);
            }

            writer.WriteString(response);
            await writer.StoreAsync();

            socket.Dispose();

            if (this.ShouldStopAfterResponse)
            {
                this.Stop();
            }
        }