Beispiel #1
0
        public static RESTPath Combine(params string[] paths)
        {
            var restPath = new RESTPath();
            var segments = paths.SelectMany(p => p.Split('/'));

            String path = "";
            int segmentCount = 0;
            foreach(var segment in segments)
            {
                if (segment == String.Empty)
                    continue;

                var trimSegment = segment.Trim('/');
                if (trimSegment.StartsWith("{") && trimSegment.EndsWith("}"))
                {
                    restPath.Parameters.Add(segmentCount, trimSegment.Trim('{', '}'));
                    path += "/[a-zA-Z0-9]+"; 
                } 
                else
                    path += "/" + trimSegment;

                segmentCount++;
            }
            if (restPath.Parameters.Count > 0)
                restPath.ContainsParameters = true;

            restPath.Path = path;

            return restPath;
        }
Beispiel #2
0
        private List<object> ExtractParameters(MethodInfo method, RESTPath path, HttpRequest request)
        {
            var parameters = new List<object>();
            var methodParams = method.GetParameters();
            var requestSegments = request.Path.AbsolutePath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            foreach(var param in methodParams)
            {
                if (param.GetCustomAttribute(typeof(Body)) != null)
                    parameters.Add(request.Content);
                else
                    parameters.Add(
                        requestSegments[path.Parameters.Single(p => p.Value.Equals(param.Name)).Key]);
            }

            return parameters;
        }
Beispiel #3
0
        public static RESTPath Combine(params string[] paths)
        {
            var restPath = new RESTPath();
            var segments = paths.SelectMany(p => p.Split('/'));

            String path         = "";
            int    segmentCount = 0;

            foreach (var segment in segments)
            {
                if (segment == String.Empty)
                {
                    continue;
                }

                var trimSegment = segment.Trim('/');
                if (trimSegment.StartsWith("{") && trimSegment.EndsWith("}"))
                {
                    restPath.Parameters.Add(segmentCount, trimSegment.Trim('{', '}'));
                    path += "/[a-zA-Z0-9]+";
                }
                else
                {
                    path += "/" + trimSegment;
                }

                segmentCount++;
            }
            if (restPath.Parameters.Count > 0)
            {
                restPath.ContainsParameters = true;
            }

            restPath.Path = path;

            return(restPath);
        }