예제 #1
0
        public void Add(Type paperType)
        {
            var spec = PaperSpec.GetSpec(paperType);

            typeIndex.Add(spec.Type, spec);
            pathIndex.Add(spec.Route, spec);
        }
예제 #2
0
        public static PaperSpec GetSpec(Type paperType)
        {
            var spec = new PaperSpec();

            spec.Type        = paperType;
            spec.Route       = GetRoute(paperType);
            spec.UriTemplate = GetUriTemplate(spec.Route, paperType);
            return(spec);
        }
예제 #3
0
        public PaperContext(IInjector injector, object paper, IPaperCatalog catalog, string requestUri)
        {
            requestUri = SanitizeRequestUri(requestUri);

            var paperSpec = PaperSpec.GetSpec(paper as Type ?? paper.GetType());
            var template  = paperSpec.UriTemplate;
            var prefix    = ApiPrefix ?? "";

            if (!prefix.StartsWith("/"))
            {
                prefix = "/" + prefix;
            }
            while (prefix.EndsWith("/"))
            {
                prefix = prefix.Substring(0, prefix.Length - 1);
            }

            if (!template.StartsWith("/"))
            {
                template = "/" + template;
            }
            while (template.EndsWith("/"))
            {
                template = template.Substring(0, template.Length - 1);
            }

            var composedTemplate = $"{prefix}{template}";

            var uriTemplate = new UriTemplate(template);

            uriTemplate.SetArgsFromUri(requestUri);

            var args = uriTemplate.CreateArgs();

            this.Injector     = injector;
            this.Paper        = paper;
            this.PaperCatalog = catalog;
            this.RequestUri   = requestUri;
            this.UriTemplate  = template;
            this.PathArgs     = args;
        }