/// <summary>Obtains a type of the link of the given <paramref name="entity" />.</summary> /// <param name="entity">Entity for which to obtain a link type.</param> /// <param name="linksPolicy">Links policy etermining how far a relation should be considered a link.</param> /// <param name="root">Root Iri to be used when resolving some of the policies.</param> /// <returns>Determined link type Iri.</returns> public static Iri GetLinkType(this IEntity entity, LinksPolicy linksPolicy, Iri root) { Iri result = null; if (entity != null) { result = entity.GetTypes().Any(_ => _ == hydra.IriTemplate) ? hydra.TemplatedLink : null; if (result == null && !entity.Iri.IsBlank) { if (linksPolicy >= LinksPolicy.SameRoot && root != null && entity.Iri != root && entity.Iri.ToRoot() == root) { result = hydra.Link; } if (result == null && linksPolicy >= LinksPolicy.AllHttp && entity.Iri.IsHttp()) { result = hydra.Link; } if (result == null && linksPolicy >= LinksPolicy.All) { result = hydra.Link; } } } return(result); }
private HydraClientFactory( ICollection <HypermediaProcessorFactory> hypermediaProcessorFactories = null, IIriTemplateExpansionStrategy iriTemplateExpansionStrategy = null, LinksPolicy?linksPolicy = null, HttpCallFacility httpCall = null) { _hypermediaProcessorInstances = new Dictionary <HypermediaProcessorFactory, IHypermediaProcessor>(); _hypermediaProcessorFactories = hypermediaProcessorFactories ?? new List <HypermediaProcessorFactory>(); _iriTemplateExpansionStrategy = iriTemplateExpansionStrategy; _linksPolicy = linksPolicy ?? LinksPolicy.Strict; _httpCall = httpCall; }
internal ProcessingState( IEntityContext context, IOntologyProvider ontologyProvider, Iri rootResource, LinksPolicy linksPolicy, string originatingMediaType) { _ontologyProvider = ontologyProvider; _statements = new Dictionary <Iri, ISet <Statement> >(); _statementsStatistics = new Dictionary <Iri, int>(); Context = context; ForbiddenHypermeda = new HashSet <Iri>(); AllHypermedia = new HashSet <Iri>(); BaseUrl = rootResource; Root = rootResource.ToRoot(); LinksPolicy = linksPolicy; OriginatingMediaType = originatingMediaType; }
/// <summary>Initializes a new instance of the <see cref="HydraClient" /> class.</summary> /// <param name="hypermediaProcessors"> /// Hypermedia processors used for response hypermedia controls extraction. /// </param> /// <param name="iriTemplateExpansionStrategy">IRI template variable expansion strategy.</param> /// <param name="linksPolicy">Policy defining what is a considered a link.</param> /// <param name="httpCall">HTTP facility used to call remote server.</param> public HydraClient( IEnumerable <IHypermediaProcessor> hypermediaProcessors, IIriTemplateExpansionStrategy iriTemplateExpansionStrategy, LinksPolicy linksPolicy, HttpCallFacility httpCall) { _hypermediaProcessors = hypermediaProcessors ?? throw new ArgumentNullException(nameof(hypermediaProcessors)); if (!_hypermediaProcessors.Any()) { throw new ArgumentOutOfRangeException(NoHypermediaProcessors); } _iriTemplateExpansionStrategy = iriTemplateExpansionStrategy ?? throw new ArgumentNullException(nameof(iriTemplateExpansionStrategy), NoIriTemplateExpansionStrategy); _httpCall = httpCall ?? throw new ArgumentNullException(nameof(httpCall), NoHttpFacility); LinksPolicy = linksPolicy; }
/// <summary>Configures a factory to create a client with all resources considered links.</summary> /// <returns>This instance of the <see cref="HydraClientFactory" />.</returns> public HydraClientFactory WithAllLinks() { _linksPolicy = LinksPolicy.All; return(this); }
/// <summary>Configures a factory to create a client with links of resources from the same host and port.</summary> /// <returns>This instance of the <see cref="HydraClientFactory" />.</returns> public HydraClientFactory WithSameRootLinks() { _linksPolicy = LinksPolicy.SameRoot; return(this); }
/// <summary>Configures a factory to create a client with explicitly defined links.</summary> /// <returns>This instance of the <see cref="HydraClientFactory" />.</returns> public HydraClientFactory WithStrictLinks() { _linksPolicy = LinksPolicy.Strict; return(this); }
/// <summary>Initializes a new instance of the <see cref="HypermediaProcessingOptions" /> class.</summary> /// <param name="originalUrl">Original Url.</param> /// <param name="linksPolicy">Links policy.</param> public HypermediaProcessingOptions( Uri originalUrl = null, LinksPolicy linksPolicy = LinksPolicy.Strict) : this(null, null, originalUrl, linksPolicy) { }