Ejemplo n.º 1
0
        /// <summary>Expands an URI template with given variables.</summary>
        /// <param name="pointingResource">Pointing resource.</param>
        /// <param name="mappedVariables">Template variables mapping builder.</param>
        /// <param name="iri">Iri of the newly created instance of <typeparamref name="T" />.</param>
        /// <returns>Expanded templated resource.</returns>
        public static T ExpandTarget(IPointingResource pointingResource, Action <MappingsBuilder> mappedVariables, Iri iri)
        {
            var iriTemplate = (IIriTemplate)pointingResource.Unwrap().GetProperty(JsonLdHypermediaProcessor.IriTemplatePropertyInfo);
            var builder     = new MappingsBuilder(iriTemplate.Mappings);

            mappedVariables(builder);
            return(ExpandTarget(pointingResource, builder.Complete(), iri));
        }
Ejemplo n.º 2
0
        private static void CopyFrom(this IPointingResource target, IPointingResource source)
        {
            var proxy = target.Unwrap();

            proxy.SetProperty(BaseUrlPropertyInfo, source.BaseUrl);
            proxy.SetProperty(TargetPropertyInfo, source.Target);
            target.Collections.CopyFrom(source.Collections);
            target.Operations.CopyFrom(source.Operations);
            target.Links.CopyFrom(source.Links);
            target.Type.CopyFrom(source.Type);
        }
Ejemplo n.º 3
0
        /// <summary>Expands an URI template with given variables.</summary>
        /// <param name="pointingResource">Pointing resource.</param>
        /// <param name="mappedVariables">Template variables with value.</param>
        /// <param name="iri">Iri of the newly created instance of <typeparamref name="T" />.</param>
        /// <returns>Expanded templated resource.</returns>
        public static T ExpandTarget(IPointingResource pointingResource, IDictionary <string, string> mappedVariables, Iri iri)
        {
            var iriTemplate = (IIriTemplate)pointingResource.Unwrap().GetProperty(JsonLdHypermediaProcessor.IriTemplatePropertyInfo);
            var targetUri   = new Uri(pointingResource.BaseUrl, new UriTemplate(iriTemplate.Template).AddParameters(mappedVariables).Resolve());
            var result      = pointingResource.Context.Create <T>(iri);
            var proxy       = result.Unwrap();

            proxy.SetProperty(TargetPropertyInfo, pointingResource.Context.Create <IResource>(targetUri));
            proxy.SetProperty(BaseUrlPropertyInfo, pointingResource.BaseUrl);
            result.Type.AddRange(pointingResource.Type.Where(_ => _ != hydra.IriTemplate));
            result.Collections.AddRange(pointingResource.Collections);
            result.Links.AddRange(pointingResource.Links);
            result.Operations.AddRange(pointingResource.Operations);
            return(result);
        }