Пример #1
0
 private static TDestination[] MapItemToArray <TSource, TDestination>(TSource source)
 {
     return(new[]
     {
         GetMapping <TSource, TDestination>()(source)
     });
 }
Пример #2
0
 private static TDestination MapArrayToItem <TSource, TDestination>(TSource[] sourceList)
 {
     if (sourceList == null || sourceList.Length == 0 || sourceList[0] == null)
     {
         return(default(TDestination));
     }
     return(GetMapping <TSource, TDestination>()(sourceList[0]));
 }
Пример #3
0
 private static TDestination MapIEnumerableToItem <TSource, TDestination>(IEnumerable <TSource> sourceList)
 {
     foreach (var item in sourceList)
     {
         if (item == null)
         {
             return(default(TDestination));
         }
         return(GetMapping <TSource, TDestination>()(item));
     }
     return(default(TDestination));
 }
Пример #4
0
 internal static TDestination MapClass <TSource, TDestination>(TSource source) =>
 GetMapping <TSource, TDestination>()(source);
Пример #5
0
 internal static TDestination MapClass <TSource, TDestination>(TSource source)
 {
     return(GetMapping <TSource, TDestination>()(source));
 }
Пример #6
0
        public static void RunWith(HttpListenerContext context)
        {
            string path       = context.Request.Url.PathAndQuery;
            string httpMethod = context.Request.HttpMethod;

            try
            {
                HttpMethod method = (HttpMethod)Enum.Parse(typeof(HttpMethod), httpMethod, true);
                switch (method)
                {
                case HttpMethod.GET:
                    GetResponse(GetMapping.FindPath(path, method, context), context);
                    break;

                case HttpMethod.POST:
                    GetResponse(PostMapping.FindPath(path, method, context), context);
                    break;

                case HttpMethod.DELETE:
                    GetResponse(DeleteMapping.FindPath(path, method, context), context);
                    break;

                case HttpMethod.PUT:
                    GetResponse(PutMapping.FindPath(path, method, context), context);
                    break;

                case HttpMethod.PATCH:
                    GetResponse(PatchMapping.FindPath(path, method, context), context);
                    break;

                case HttpMethod.OPTIONS:
                    var requestedMethod  = Enum.Parse <HttpMethod>(context.Request.Headers.Get("Access-Control-Request-Method"));
                    var requestedHeaders = context.Request.Headers.Get("Access-Control-Request-Headers");
                    var response         = AbstractMapping.HandleOptionsRequest(path, requestedMethod, requestedHeaders);
                    SendResponse(response, context);
                    break;

                default:
                    throw new ServerRequestMethodNotSupportedException($"{httpMethod} is not supported", context);
                }
            }
            catch (ServerRequestMethodNotSupportedException ex)
            {
                ExceptionHandler.HandleException(ex, context);
            }
            catch (ServerEndpointNotValidException ex)
            {
                ExceptionHandler.HandleException(ex, context);
            }
            catch (Exception ex)
            {
                try
                {
                    throw new InternalServerErrorException(ex.Message, context, ex);
                }
                catch (InternalServerErrorException e)
                {
                    ExceptionHandler.HandleException(e, context);
                }
            }
        }