コード例 #1
0
        public MetadataModuleRouteMetadataProviderFixture()
        {
            this.resolver = A.Fake<IMetadataModuleResolver>();
            this.module = A.Fake<INancyModule>();
            this.route = new RouteDescription("NamedDescription", "GET", "/things", ctx => true);
            this.metadataModule = new FakeNancyMetadataModule();
            this.metadataModule.Describe[this.route.Name] = desc => { return Metadata; };

            this.provider = new MetadataModuleRouteMetadataProvider(this.resolver);
        }
コード例 #2
0
ファイル: Route.cs プロジェクト: nathanpalmer/Nancy
        public Route(RouteDescription description, Func<dynamic, Response> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            this.Description = description;
            this.Action = action;
        }
コード例 #3
0
ファイル: Route.cs プロジェクト: afwilliams/Nancy
        /// <summary>
        /// Initializes a new instance of the <see cref="Route"/> type, with the specified <see cref="RouteDescription"/>.
        /// </summary>
        /// <param name="description"></param>
        /// <param name="action">The action that should take place when the route is invoked.</param>
        public Route(RouteDescription description, Func<dynamic, CancellationToken, Task<dynamic>> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            this.Description = description;
            this.Action = action;
        }
コード例 #4
0
ファイル: Route.cs プロジェクト: williware/Nancy
        /// <summary>
        /// Initializes a new instance of the <see cref="Route"/> type, with the specified <see cref="RouteDescription"/>.
        /// </summary>
        /// <param name="description"></param>
        /// <param name="action">The action that should take place when the route is invoked.</param>
        public Route(RouteDescription description, Func<dynamic, dynamic> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            this.Description = description;
            this.Action = action;
        }
コード例 #5
0
ファイル: RouteResolver.cs プロジェクト: dineshkummarc/Nancy
        private static Regex BuildRegexMatcher(RouteDescription description)
        {
            var segments =
                description.GetModuleQualifiedPath().Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries);

            var parameterizedSegments =
                GetParameterizedSegments(segments);

            var pattern =
                string.Concat(@"^/", string.Join("/", parameterizedSegments), @"$");

            return(new Regex(pattern, RegexOptions.IgnoreCase));
        }
コード例 #6
0
ファイル: RouteResolver.cs プロジェクト: meadiagenic/Nancy
        private static Regex BuildRegexMatcher(RouteDescription description)
        {
            var segments =
                description.GetModuleQualifiedPath().Split(new[] {"/"}, StringSplitOptions.RemoveEmptyEntries);

            var parameterizedSegments =
                GetParameterizedSegments(segments);

            var pattern =
                string.Concat(@"^/", string.Join("/", parameterizedSegments), @"$");

            return new Regex(pattern, RegexOptions.IgnoreCase);
        }
コード例 #7
0
ファイル: RouteResolver.cs プロジェクト: dineshkummarc/Nancy
        private static int GetSegmentCount(RouteDescription description)
        {
            var moduleQualifiedPath =
                description.GetModuleQualifiedPath();

            var indexOfFirstParameter =
                moduleQualifiedPath.IndexOf('{');

            if (indexOfFirstParameter > -1)
            {
                moduleQualifiedPath = moduleQualifiedPath.Substring(0, indexOfFirstParameter);
            }

            return(moduleQualifiedPath.Split('/').Count());
        }
コード例 #8
0
        /// <summary>
        /// Gets the <see cref="T:System.Type" /> of the metadata that is created by the provider.
        /// </summary>
        /// <param name="module">The <see cref="T:Nancy.INancyModule" /> instance that the route is declared in.</param>
        /// <param name="routeDescription">A <see cref="T:Nancy.Routing.RouteDescription" /> for the route.</param>
        /// <returns>
        /// A <see cref="T:System.Type" /> instance, or <see langword="null" /> if nothing is found.
        /// </returns>
        public Type GetMetadataType(INancyModule module, RouteDescription routeDescription)
        {
            if (String.IsNullOrWhiteSpace(routeDescription.Name))
                return null;

            // TODO: Yikes, what an ugly hack. We need to figure out a better way to identify routes than their name. [asbjornu]
            switch (routeDescription.Name)
            {
                case JsonSchema:
                case ClientAssembly:
                case ClientNugetPackage:
                case ClientNugetPackageVersioned:
                    return typeof(PomonaRouteMetadata);
            }

            return null;
        }
コード例 #9
0
ファイル: RouteResolver.cs プロジェクト: dineshkummarc/Nancy
        private static RouteParameters GetParameters(RouteDescription description, GroupCollection groups)
        {
            var segments =
                new ReadOnlyCollection <string>(
                    description.Path.Split(new[] { "/" },
                                           StringSplitOptions.RemoveEmptyEntries).ToList());

            var parameters =
                from segment in segments
                where segment.IsParameterized()
                select segment.GetParameterName();

            dynamic data =
                new RouteParameters();

            foreach (var parameter in parameters)
            {
                data[parameter] = groups[parameter].Value;
            }

            return(data);
        }
コード例 #10
0
ファイル: RouteResolver.cs プロジェクト: meadiagenic/Nancy
        private static RouteParameters GetParameters(RouteDescription description, GroupCollection groups)
        {
            var segments =
                new ReadOnlyCollection<string>(
                    description.Path.Split(new[] { "/" },
                    StringSplitOptions.RemoveEmptyEntries).ToList());

            var parameters =
                from segment in segments
                where segment.IsParameterized()
                select segment.GetParameterName();

            dynamic data =
                new RouteParameters();

            foreach (var parameter in parameters)
            {
                data[parameter] = groups[parameter].Value;
            }

            return data;
        }
コード例 #11
0
        /// <summary>
        /// Gets the metadata for the provided route.
        /// </summary>
        /// <param name="module">The <see cref="T:Nancy.INancyModule" /> instance that the route is declared in.</param>
        /// <param name="routeDescription">A <see cref="T:Nancy.Routing.RouteDescription" /> for the route.</param>
        /// <returns>
        /// An object representing the metadata for the given route, or <see langword="null" /> if nothing is found.
        /// </returns>
        public object GetMetadata(INancyModule module, RouteDescription routeDescription)
        {
            if (String.IsNullOrWhiteSpace(routeDescription.Name))
                return null;

            // TODO: Yikes, what an ugly hack. We need to figure out a better way to identify routes than their name. [asbjornu]
            switch (routeDescription.Name)
            {
                case JsonSchema:
                    return new PomonaRouteMetadata
                    {
                        ContentType = "application/json",
                        Method = HttpMethod.Get,
                        Relation = "json-schema",
                    };

                case ClientAssembly:
                    return new PomonaRouteMetadata
                    {
                        ContentType = "binary/octet-stream",
                        Method = HttpMethod.Get,
                        Relation = "client-assembly",
                    };

                case ClientNugetPackage:
                case ClientNugetPackageVersioned:
                    return new PomonaRouteMetadata
                    {
                        ContentType = "application/zip",
                        Method = HttpMethod.Get,
                        Relation = "nuget-package",
                    };
            }

            return null;
        }
コード例 #12
0
ファイル: Route.cs プロジェクト: wh20160213/Nancy
 public static Route FromSync(RouteDescription description, Func <dynamic, dynamic> syncFunc)
 {
     return(new Route(description, Wrap(syncFunc)));
 }
コード例 #13
0
ファイル: RouteResolver.cs プロジェクト: meadiagenic/Nancy
        private static int GetSegmentCount(RouteDescription description)
        {
            var moduleQualifiedPath =
                description.GetModuleQualifiedPath();

            var indexOfFirstParameter =
                moduleQualifiedPath.IndexOf('{');

            if (indexOfFirstParameter > -1)
                moduleQualifiedPath = moduleQualifiedPath.Substring(0, indexOfFirstParameter);

            return moduleQualifiedPath.Split('/').Count();
        }
コード例 #14
0
 public MetadataModuleFixture()
 {
     this.route = new RouteDescription("NamedDescription", "GET", "/things", ctx => true);
     this.metadataModule = new FakeNancyMetadataModule();
 }
コード例 #15
0
        //public DefaultRouteMetadataProvider(IRouteDescriptionProvider routeDescriptionProvider)
        //{
        //    _routeDescriptionProvider = routeDescriptionProvider;
        //}

        public Type GetMetadataType(INancyModule module, RouteDescription routeDescription)
        {
            return null;
        }
コード例 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Route"/> type, with the specified <see cref="RouteDescription"/>.
 /// </summary>
 /// <param name="description">An <see cref="RouteDescription"/> instance.</param>
 protected Route(RouteDescription description)
 {
     this.Description = description;
 }
コード例 #17
0
 public object GetMetadata(INancyModule module, RouteDescription routeDescription)
 {
     var description = _routeDescriptionProvider.GetDescription(module, routeDescription.Path);
     return new DefaultRouteMetadata(routeDescription.Method, routeDescription.Path, description);
 }
コード例 #18
0
 /// <summary>
 /// Gets the metadata for the provided route.
 /// </summary>
 /// <param name="module">The <see cref="INancyModule"/> instance that the route is declared in.</param>
 /// <param name="routeDescription">A <see cref="RouteDescription"/> for the route.</param>
 /// <returns>An instance of <typeparamref name="TMetadata"/>.</returns>
 protected abstract TMetadata GetRouteMetadata(INancyModule module, RouteDescription routeDescription);
コード例 #19
0
 /// <summary>
 /// Gets the metadata for the provided route.
 /// </summary>
 /// <param name="module">The <see cref="INancyModule" /> instance that the route is declared in.</param>
 /// <param name="routeDescription">A <see cref="RouteDescription" /> for the route.</param>
 /// <returns>An instance of <typeparamref name="TMetadata"/>.</returns>
 public object GetMetadata(INancyModule module, RouteDescription routeDescription)
 {
     return(this.GetRouteMetadata(module, routeDescription));
 }
コード例 #20
0
 /// <summary>
 /// Gets the <see cref="Type"/> of the metadata that is created by the provider.
 /// </summary>
 /// <param name="module">The <see cref="INancyModule"/> instance that the route is declared in.</param>
 /// <param name="routeDescription">A <see cref="RouteDescription"/> for the route.</param>
 /// <returns>A <see cref="Type"/> instance, or null if none are found.</returns>
 public Type GetMetadataType(INancyModule module, RouteDescription routeDescription)
 {
     return(typeof(TMetadata));
 }
コード例 #21
0
ファイル: Route.cs プロジェクト: RadifMasud/Nancy
 /// <summary>
 /// Initializes a new instance of the <see cref="Route"/> type, with the specified <see cref="RouteDescription"/>.
 /// </summary>
 /// <param name="description"></param>
 protected Route(RouteDescription description)
 {
     this.Description = description;
 }
コード例 #22
0
ファイル: RouteResolver.cs プロジェクト: pwlodek/Nancy
        private static int GetSegmentCount(RouteDescription description)
        {
            var workingCopyOfPath = description.Path;

            var indexOfFirstParameter =
                workingCopyOfPath.IndexOf('{');

            if (indexOfFirstParameter > -1)
                workingCopyOfPath = workingCopyOfPath.Substring(0, indexOfFirstParameter);

            return workingCopyOfPath.Split('/').Count();
        }
コード例 #23
0
        /// <summary>
        /// Gets the metadata for the provided route by obtaining it from an associated <see cref="IMetadataModule"/>.
        /// </summary>
        /// <param name="module">The <see cref="INancyModule"/> instance that the route is declared in.</param>
        /// <param name="routeDescription">A <see cref="RouteDescription"/> for the route.</param>
        /// <returns>An object representing the metadata for the given route, or null if none are found.</returns>
        public object GetMetadata(INancyModule module, RouteDescription routeDescription)
        {
            var metadataModule = this.resolver.GetMetadataModule(module);

            return metadataModule != null ? metadataModule.GetMetadata(routeDescription) : null;
        }
コード例 #24
0
        /// <summary>
        /// Gets the <see cref="Type"/> of the metadata that is created by the provider.
        /// </summary>
        /// <param name="module">The <see cref="INancyModule"/> instance that the route is declared in.</param>
        /// <param name="routeDescription">A <see cref="RouteDescription"/> for the route.</param>
        /// <returns>A <see cref="Type"/> instance, or null if none are found.</returns>
        public Type GetMetadataType(INancyModule module, RouteDescription routeDescription)
        {
            var metadataModule = this.resolver.GetMetadataModule(module);

            return metadataModule != null ? metadataModule.MetadataType : null;
        }
コード例 #25
0
ファイル: Route.cs プロジェクト: afwilliams/Nancy
 /// <summary>
 /// Creates a route from a sync delegate signature
 /// </summary>
 /// <param name="description"></param>
 /// <param name="syncFunc">The action that should take place when the route is invoked.</param>
 /// <returns>A Route instance</returns>
 public static Route FromSync(RouteDescription description, Func<dynamic, dynamic> syncFunc)
 {
     return new Route(description, Wrap(syncFunc));
 }
コード例 #26
0
 public SwaggerRouteMetadata(RouteDescription desc) : this(desc.Path, desc.Method) { }