private static Task <IResource> ClientInitializer(
     ITypedEntity resource,
     IHydraClient client,
     ProcessingState processingState,
     CancellationToken cancellationToken)
 {
     resource.Unwrap().SetProperty(ClientPropertyInfo, client);
     return(ResourceInitializer(
                resource.Is(hydra.ApiDocumentation) ? (ITypedEntity)resource.ActLike <IApiDocumentation>() : resource.ActLike <ICollection>(),
                client,
                processingState,
                cancellationToken));
 }
示例#2
0
        private static async Task <IResource> ResourceInitializer(
            ITypedEntity resource,
            IHydraClient client,
            ProcessingState processingState,
            CancellationToken cancellationToken)
        {
            IHydraResource hydraResource = resource as IHydraResource
                                           ?? (resource.Is(hydra.Resource) ? resource.ActLike <IHydraResource>() : null);

            bool hasView = false;

            foreach (var statement in processingState.StatementsOf(resource.Iri))
            {
                hydraResource = await GatherLinks(resource, statement, processingState, hydraResource, cancellationToken);

                if (statement.Predicate == hydra.view)
                {
                    hasView = true;
                }
            }

            if (hydraResource != null && processingState.NumberOfStatementsOf(resource.Iri) > 0)
            {
                GatherOperationTargets(hydraResource, processingState);
                if (hasView)
                {
                    hydraResource = hydraResource.ActLike <IResourceView>();
                }

                var addToHypermedia = !processingState.ForbiddenHypermeda.Contains(hydraResource.Iri) &&
                                      (!hydraResource.Iri.IsBlank || IsHydraDependent(hydraResource));
                if (addToHypermedia)
                {
                    processingState.AllHypermedia.Add(hydraResource.Iri);
                }
            }

            return(hydraResource);
        }