Пример #1
0
        private object TransformColectionWithLock(
            ILocallyControlledNamedGraphSelector locallyControlledNamedGraphSelector,
            object result,
            RequestInfo request,
            int totalItems,
            int skip,
            int take)
        {
            lock (locallyControlledNamedGraphSelector)
            {
                var requestId    = Guid.NewGuid().ToString();
                var graphUri     = (Uri)request.Url.WithFragment(requestId);
                var collectionId = new EntityId((Uri)request.Url);
                var viewId       = new EntityId((Uri)request.Url.WithFragment("view-" + requestId));
                locallyControlledNamedGraphSelector.MapEntityGraphForRequest(request, collectionId, graphUri);
                locallyControlledNamedGraphSelector.MapEntityGraphForRequest(request, viewId, graphUri);
                result = TransformCollection(result, request.Url, totalItems, skip, take);
                _entityContextProvider.EntityContext.Disposed += () =>
                {
                    _entityContextProvider.TripleStore.Remove(graphUri);
                    locallyControlledNamedGraphSelector.UnmapEntityGraphForRequest(request, collectionId);
                    locallyControlledNamedGraphSelector.UnmapEntityGraphForRequest(request, viewId);
                };
            }

            return(result);
        }
Пример #2
0
        private IApiDocumentation GetApiEntryPointDescription(string fileExtension)
        {
            var namedGraphSelector = _namedGraphSelectorFactory.NamedGraphSelector;
            ILocallyControlledNamedGraphSelector locallyControlledNamedGraphSelector = namedGraphSelector as ILocallyControlledNamedGraphSelector;

            return(locallyControlledNamedGraphSelector != null?
                   GetApiEntryPointDescriptionWithLock(fileExtension, locallyControlledNamedGraphSelector) :
                       BuildApiDocumentation(fileExtension, (Uri)((HttpUrl)Response.Request.Url).WithFragment(String.Empty)));
        }
Пример #3
0
        /// <inheritdoc />
        public Task <object> Transform(IRequestMapping requestMapping, IRequestInfo request, object result, object[] arguments)
        {
            RequestInfo requestInfo;
            MethodInfo  underlyingMethod;

            if (!CanOutputHypermedia((underlyingMethod = requestMapping.Operation.UnderlyingMethod).ReturnType, requestInfo = request as RequestInfo))
            {
                return(Task.FromResult(result));
            }

            int  totalItems          = ((IEnumerable)result).Cast <object>().Count();
            int  skip                = 0;
            int  take                = 0;
            bool canOutputHypermedia = false;
            KeyValuePair <Verb, MethodInfo> method;

            if ((requestMapping.Target.GetType().GetImplementationOfAny(typeof(IController <>), typeof(IAsyncController <>)) != null) &&
                (!Equals(method = requestMapping.Target.GetType().DiscoverCrudMethods().FirstOrDefault(entry => entry.Value == underlyingMethod), default(KeyValuePair <Verb, MethodInfo>))))
            {
                switch (method.Key.ToString())
                {
                case "":
                    var parameters      = underlyingMethod.GetParameters();
                    var resultingValues = arguments.Where((item, index) => parameters[index].IsOut).ToList();
                    totalItems = (resultingValues.Count > 0 ? (int)resultingValues[0] : -1);
                    if ((arguments[1] != null) && (arguments[2] != null))
                    {
                        skip = (int)arguments[1];
                        take = ((take = (int)arguments[2]) == 0 ? 0 : Math.Min(take, totalItems));
                        canOutputHypermedia = (requestMapping.ArgumentSources[1] == ArgumentValueSources.Bound) && (requestMapping.ArgumentSources[2] == ArgumentValueSources.Bound);
                    }

                    break;
                }
            }

            if (!canOutputHypermedia)
            {
                return(Task.FromResult(result));
            }

            var namedGraphSelector = _namedGraphSelectorFactory.NamedGraphSelector;
            ILocallyControlledNamedGraphSelector locallyControlledNamedGraphSelector = namedGraphSelector as ILocallyControlledNamedGraphSelector;

            result = (locallyControlledNamedGraphSelector == null ? TransformCollection(result, requestInfo.Url, totalItems, skip, take) :
                      TransformColectionWithLock(locallyControlledNamedGraphSelector, result, requestInfo, totalItems, skip, take));
            return(Task.FromResult(result));
        }
Пример #4
0
        private IApiDocumentation GetApiEntryPointDescriptionWithLock(string fileExtension, ILocallyControlledNamedGraphSelector locallyControlledNamedGraphSelector)
        {
            IApiDocumentation result;

            lock (locallyControlledNamedGraphSelector)
            {
                Uri     graphUri;
                HttpUrl url = Response.Request.Url as HttpUrl;
                if (url != null)
                {
                    if (url.HasParameters)
                    {
                        url = (HttpUrl)url.WithoutParameters();
                    }

                    graphUri = (Uri)url.WithFragment(String.Empty);
                }
                else
                {
                    graphUri = (Uri)Response.Request.Url;
                }

                result = BuildApiDocumentation(fileExtension, locallyControlledNamedGraphSelector.NamedGraph = graphUri);
                _entityContextProvider.EntityContext.Disposed += () => _entityContextProvider.TripleStore.Remove(graphUri);
                locallyControlledNamedGraphSelector.NamedGraph = null;
            }

            return(result);
        }
Пример #5
0
        private object TransformColectionWithLock(
            ILocallyControlledNamedGraphSelector locallyControlledNamedGraphSelector,
            object result,
            RequestInfo request,
            int totalItems,
            int skip,
            int take)
        {
            lock (locallyControlledNamedGraphSelector)
            {
                var requestId = Guid.NewGuid().ToString();
                var graphUri = (Uri)request.Url.WithFragment(requestId);
                var collectionId = new EntityId((Uri)request.Url);
                var viewId = new EntityId((Uri)request.Url.WithFragment("view-" + requestId));
                locallyControlledNamedGraphSelector.MapEntityGraphForRequest(request, collectionId, graphUri);
                locallyControlledNamedGraphSelector.MapEntityGraphForRequest(request, viewId, graphUri);
                result = TransformCollection(result, request.Url, totalItems, skip, take);
                _entityContextProvider.EntityContext.Disposed += () =>
                    {
                        _entityContextProvider.TripleStore.Remove(graphUri);
                        locallyControlledNamedGraphSelector.UnmapEntityGraphForRequest(request, collectionId);
                        locallyControlledNamedGraphSelector.UnmapEntityGraphForRequest(request, viewId);
                    };
            }

            return result;
        }