示例#1
0
        private void BuildEntryPointDescription(
            IApiDocumentation apiDocumentation,
            ControllerInfo entryPointControllerInfo,
            IHttpControllerDescriptionBuilder <EntryPointDescriptionController> entryPointControllerDescriptionBuilder)
        {
            var classUri = apiDocumentation.Context.Mappings.MappingFor(typeof(IApiDocumentation)).Classes.Select(item => item.Uri).FirstOrDefault();
            var apiDocumentationClass = apiDocumentation.Context.Create <IClass>(classUri);
            var baseUri = apiDocumentation.Context.BaseUriSelector.SelectBaseUri(new EntityId(new Uri("/", UriKind.Relative)));

            foreach (OperationInfo <Verb> operation in entryPointControllerInfo.Operations)
            {
                var url = (Uri)operation.Url;
                if (operation.UrlTemplate != null)
                {
                    var template  = new UriTemplate(baseUri + operation.UrlTemplate.TrimStart('/'));
                    var variables = operation.UnderlyingMethod.GetParameters().ToDictionary(parameter => parameter.Name, parameter => (object)parameter.DefaultValue.ToString());
                    url = template.ResolveUri(variables);
                }

                var operationId        = new EntityId(url.Combine(baseUri));
                var supportedOperation = operation.AsOperation(apiDocumentation, operationId);
                supportedOperation.MediaTypes.AddRange(ApiDescriptionBuilder.RdfMediaTypes);
                supportedOperation.Label = operation.UnderlyingMethod.Name;
                supportedOperation.Method.Add(operation.ProtocolSpecificCommand.ToString());
                var returned = apiDocumentation.Context.Create <IClass>(apiDocumentation.CreateBlankId());
                returned.SubClassOf.Add(apiDocumentationClass);
                supportedOperation.Returns.Add(returned);
                apiDocumentationClass.SupportedOperations.Add(supportedOperation);
            }

            apiDocumentation.SupportedClasses.Add(apiDocumentationClass);
        }
示例#2
0
        internal HttpUrl BuildUrl(string url, IDictionary <string, object> uriArguments)
        {
            var template = new UriTemplate(BaseUrl.ToString() + url);
            var result   = template.ResolveUri(uriArguments.ToDictionary(entry => entry.Key, entry => (object)(entry.Value != null ? entry.Value.ToString() : null)));

            return((HttpUrl)UrlParser.Parse(Regex.Replace(result.ToString(), "%([0-9]+)", match => Convert.ToChar(UInt32.Parse(match.Groups[1].Value, NumberStyles.HexNumber)).ToString())));
        }
示例#3
0
        public void ResolveUriRelative()
        {
            var template = new UriTemplate("{/paths*}{?q1,q2}{#f*}");

            var actual = template.ResolveUri(UriKind.RelativeOrAbsolute, new Dictionary <string, object>
            {
                { "paths", new string[] { "foo", "bar" } },
                { "q1", "abc" },
                { "f", new Dictionary <string, string> {
                      { "key1", "val1" }, { "key2", null }
                  } }
            });

            Assert.AreEqual(new Uri("/foo/bar?q1=abc#key1=val1,key2=", UriKind.Relative), actual);
        }
示例#4
0
        public void ResolveUri()
        {
            var template = new UriTemplate("http://example.com{/paths*}{?q1,q2}{#f*}");

            var actual = template.ResolveUri(new Dictionary <string, object>
            {
                { "paths", new string[] { "foo", "bar" } },
                { "q1", "abc" },
                { "f", new Dictionary <string, string> {
                      { "key1", "val1" }, { "key2", null }
                  } }
            });

            Assert.AreEqual(new Uri("http://example.com/foo/bar?q1=abc#key1=val1,key2="), actual);
        }