Пример #1
0
 public async Task <ActionResult <string> > Get()
 {
     try
     {
         this.SetHeaders();
         string guid     = GetGuid(HttpContext);
         string response = String.Format(_context.HttpProfiles.First().HttpGetResponse, await _internalListener.Read(guid));
         return(Ok(response));
     }
     catch (ControllerNotFoundException e)
     {
         string response = String.Format(_context.HttpProfiles.First().HttpGetResponse, e.Message);
         return(NotFound(response));
     }
 }
Пример #2
0
        public async Task <ActionResult <string> > Get()
        {
            string guid = "";

            try
            {
                this.SetHeaders();
                guid = GetGuid(HttpContext);
                string response = String.Format(_context.HttpProfiles.First().HttpGetResponse.Replace("{DATA}", "{0}").Replace("{GUID}", "{1}"), await _internalListener.Read(guid), guid);
                return(Ok(response));
            }
            catch (ControllerNotFoundException e)
            {
                string response = String.Format(_context.HttpProfiles.First().HttpGetResponse.Replace("{DATA}", "{0}").Replace("{GUID}", "{1}"), e.Message, guid);
                return(NotFound(response));
            }
        }
Пример #3
0
        public async Task <ActionResult <string> > Route()
        {
            string guid = "";

            try
            {
                this.SetHeaders();
                guid = GetGuid(HttpContext);
                if (HttpContext.Request.Method == "GET")
                {
                    string response = String.Format(_context.HttpProfiles.First().HttpGetResponse.Replace("{", "{{").Replace("}", "}}").Replace("{{DATA}}", "{0}").Replace("{{GUID}}", "{1}"), await _internalListener.Read(guid), guid);
                    return(Ok(response));
                }
                else if (HttpContext.Request.Method == "POST")
                {
                    using StreamReader reader = new StreamReader(Request.Body, System.Text.Encoding.UTF8);
                    string body = await reader.ReadToEndAsync();

                    string ExtractedMessage = body.ParseExact(_context.HttpProfiles.First().HttpPostRequest.Replace("{", "{{").Replace("}", "}}").Replace("{{DATA}}", "{0}").Replace("{{GUID}}", "{1}")).FirstOrDefault();
                    string guidToRead       = await _internalListener.Write(guid, ExtractedMessage);

                    string postRead = await _internalListener.Read(guidToRead);

                    string response = String.Format(_context.HttpProfiles.First().HttpPostResponse.Replace("{", "{{").Replace("}", "}}").Replace("{{DATA}}", "{0}").Replace("{{GUID}}", "{1}"), postRead, guid);
                    return(Ok(response));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (ControllerNotFoundException e)
            {
                string response = String.Format(_context.HttpProfiles.First().HttpGetResponse.Replace("{DATA}", "{0}").Replace("{GUID}", "{1}"), e.Message, guid);
                return(NotFound(response));
            }
            catch (Exception e)
            {
                string response = String.Format(_context.HttpProfiles.First().HttpGetResponse.Replace("{DATA}", "{0}").Replace("{GUID}", "{1}"), e.Message, guid);
                return(NotFound(response));
            }
        }