Beispiel #1
0
        public async Task <DocumentResourceDto> GetResourceAsync(GetDocumentResourceInput input)
        {
            var project = await _projectRepository.GetAsync(input.ProjectId);

            var cacheKey = $"Resource@{project.ShortName}#{input.LanguageCode}#{input.Name}#{input.Version}";

            async Task <DocumentResourceDto> GetResourceAsync()
            {
                var store            = _documentStoreFactory.Create(project.DocumentStoreType);
                var documentResource = await store.GetResource(project, input.Name, input.LanguageCode, input.Version);

                return(ObjectMapper.Map <DocumentResource, DocumentResourceDto>(documentResource));
            }

            if (Debugger.IsAttached)
            {
                return(await GetResourceAsync());
            }

            return(await ResourceCache.GetOrAddAsync(
                       cacheKey,
                       GetResourceAsync,
                       () => new DistributedCacheEntryOptions
            {
                //TODO: Configurable?
                AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(6),
                SlidingExpiration = TimeSpan.FromMinutes(30)
            }
                       ));
        }
Beispiel #2
0
        public async Task <DocumentResourceDto> GetResourceAsync(GetDocumentResourceInput input)
        {
            var project = await _projectRepository.GetAsync(input.ProjectId);

            input.Version = string.IsNullOrWhiteSpace(input.Version) ? project.LatestVersionBranchName : input.Version;
            input.Version = GetProjectVersionPrefixIfExist(project) + input.Version;

            var cacheKey = CacheKeyGenerator.GenerateDocumentResourceCacheKey(project, input.Name, input.LanguageCode, input.Version);

            async Task <DocumentResource> GetResourceAsync()
            {
                var source = _documentStoreFactory.Create(project.DocumentStoreType);

                return(await source.GetResource(project, input.Name, input.LanguageCode, input.Version));
            }

            if (HostEnvironment.IsDevelopment())
            {
                return(ObjectMapper.Map <DocumentResource, DocumentResourceDto>(await GetResourceAsync()));
            }

            return(ObjectMapper.Map <DocumentResource, DocumentResourceDto>(
                       await ResourceCache.GetOrAddAsync(
                           cacheKey,
                           GetResourceAsync,
                           () => new DistributedCacheEntryOptions
            {
                AbsoluteExpirationRelativeToNow = _documentResourceAbsoluteExpiration,
                SlidingExpiration = _documentResourceSlidingExpiration
            }
                           )
                       ));
        }
Beispiel #3
0
        public async Task <DocumentResourceDto> GetResourceAsync(GetDocumentResourceInput input)
        {
            var project = await _projectRepository.GetAsync(input.ProjectId);

            var store = _documentStoreFactory.Create(project.DocumentStoreType);

            var documentResource = await store.GetResource(project, input.Name, input.Version);

            return(ObjectMapper.Map <DocumentResource, DocumentResourceDto>(documentResource));
        }
Beispiel #4
0
 public Task <DocumentResourceDto> GetResourceAsync(GetDocumentResourceInput input)
 {
     return(DocumentAppService.GetResourceAsync(input));
 }