Exemple #1
0
        private void BuildDescription(DescriptionContext context, IClass specializationType)
        {
            Uri graphUri = _namedGraphSelectorFactory.NamedGraphSelector.SelectGraph(specializationType.Id, null, null);

            context.ApiDocumentation.SupportedClasses.Add(specializationType);
            var description = _descriptionBuilder.BuildDescriptor();

            foreach (OperationInfo <Verb> operation in description.Operations)
            {
                IIriTemplate template;
                var          operationDefinition = BuildOperation(context, operation, out template);
                IResource    operationOwner      = DetermineOperationOwner(operation, context, specializationType);
                if (template != null)
                {
                    ITemplatedLink templatedLink = context.ApiDocumentation.Context.Create <ITemplatedLink>(template.Id.Uri.AbsoluteUri.Replace("#template", "#withTemplate"));
                    templatedLink.SupportedOperations.Add(operationDefinition);
                    context.ApiDocumentation.Context.Store.ReplacePredicateValues(
                        operationOwner.Id,
                        Node.ForUri(templatedLink.Id.Uri),
                        () => new[] { Node.ForUri(template.Id.Uri) },
                        graphUri,
                        CultureInfo.InvariantCulture);
                }
                else
                {
                    (operationOwner is ISupportedOperationsOwner ? ((ISupportedOperationsOwner)operationOwner).SupportedOperations : operationOwner.Operations).Add(operationDefinition);
                }
            }
        }
        private static ILink CreateInstanceFrom(this ILink result, ITemplatedLink templatedLink)
        {
            var proxy = result.Unwrap();

            proxy.SetProperty(RelationPropertyInfo, templatedLink.Relation);
            result.SupportedOperations.AddRange(templatedLink.SupportedOperations);
            result.Type.Remove(hydra.TemplatedLink);
            result.Type.Add(hydra.Link);
            return(result);
        }
 /// <summary>Expands an URI template with given variables.</summary>
 /// <param name="templatedLink">Templated link.</param>
 /// <param name="mappedVariables">Template variables mapping builder.</param>
 /// <returns>Expanded templated resource.</returns>
 public static ILink ExpandTarget(ITemplatedLink templatedLink, Action <MappingsBuilder> mappedVariables)
 {
     return(TemplatedResource <ILink> .ExpandTarget(templatedLink, mappedVariables, GetNextIri())
            .CreateInstanceFrom(templatedLink));
 }
 /// <summary>Expands an URI template with given variables.</summary>
 /// <param name="templatedLink">Templated link.</param>
 /// <param name="mappedVariables">Template variables with value.</param>
 /// <returns>Expanded templated resource.</returns>
 public static ILink ExpandTarget(ITemplatedLink templatedLink, IDictionary <string, string> mappedVariables)
 {
     return(TemplatedResource <ILink> .ExpandTarget(templatedLink, mappedVariables, GetNextIri())
            .CreateInstanceFrom(templatedLink));
 }