Exemple #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)
            }
                       ));
        }
Exemple #2
0
        protected virtual async Task <List <VersionInfo> > GetVersionsAsync(Project project)
        {
            var store    = _documentStoreFactory.Create(project.DocumentStoreType);
            var versions = await store.GetVersionsAsync(project);

            if (!versions.Any())
            {
                return(versions);
            }

            if (!project.MinimumVersion.IsNullOrEmpty())
            {
                var minVersionIndex = versions.FindIndex(v => v.Name == project.MinimumVersion);
                if (minVersionIndex > -1)
                {
                    versions = versions.GetRange(0, minVersionIndex + 1);
                }
            }

            if (versions.Any() && !string.IsNullOrEmpty(project.LatestVersionBranchName))
            {
                versions.First().Name = project.LatestVersionBranchName;
            }

            return(versions);
        }
Exemple #3
0
        public async Task <string> GetDefaultLanguageCode(string shortName)
        {
            var project = await _projectRepository.GetByShortNameAsync(shortName);

            var store        = _documentStoreFactory.Create(project.DocumentStoreType);
            var languageList = await store.GetLanguageListAsync(project, project.LatestVersionBranchName);

            return(languageList.Languages.Single(l => l.IsDefault).Code);
        }
Exemple #4
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));
        }
Exemple #5
0
        protected virtual async Task <DocumentWithDetailsDto> GetDocumentWithDetailsDto(
            Project project,
            string documentName,
            string version,
            bool normalize)
        {
            var documentStore = _documentStoreFactory.Create(project.DocumentStoreType);
            var document      = await documentStore.Find(project, documentName, version);

            var dto = ObjectMapper.Map <Document, DocumentWithDetailsDto>(document);

            dto.Project = ObjectMapper.Map <Project, ProjectDto>(project);

            return(dto);
        }
        public async Task GetDocumentAsync()
        {
            var store = _documentStoreFactory.Create(GithubDocumentStore.Type);

            var project = await _projectRepository.FindAsync(_testData.PorjectId);

            project.ShouldNotBeNull();

            var document = await store.GetDocumentAsync(project, "index2", "0.123.0");

            document.ShouldNotBeNull();

            document.Title.ShouldBe("index2");
            document.FileName.ShouldBe("index2");
            document.Version.ShouldBe("0.123.0");
            document.Content.ShouldBe("stringContent");
        }
Exemple #7
0
 protected void Initialize(IDocumentStoreFactory subscriptionStoreFactory, IRouteManager routeManager, QueueName inputQueueName)
 {
     Condition.Requires(subscriptionStoreFactory, "subscriptionStoreFactory").IsNotNull();
     Condition.Requires(inputQueueName, "inputQueueName").IsNotNull();
     Condition.Requires(routeManager, "routeManager").IsNotNull();
     RouteManager   = routeManager;
     Subscriptions  = subscriptionStoreFactory.Create <Type, SubscriptionRegistration>();
     InputQueueName = inputQueueName;
 }
        private async Task <DocumentWithDetailsDto> GetDocument(Project project, string documentName, string version, bool normalize)
        {
            if (project == null)
            {
                throw new EntityNotFoundException("Project Not Found!");
            }

            if (string.IsNullOrWhiteSpace(documentName))
            {
                documentName = project.DefaultDocumentName;
            }

            IDocumentStore documentStore = _documentStoreFactory.Create(project);
            Document       document      = await documentStore.FindDocumentByNameAsync(project, documentName, version);

            var dto = ObjectMapper.Map <Document, DocumentWithDetailsDto>(document);

            dto.Project = ObjectMapper.Map <Project, ProjectDto>(project);

            return(dto);
        }
Exemple #9
0
        public async Task <DocumentWithDetailsDto> GetDocument(ProjectDto project, string documentName, string version, bool normalize)
        {
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            if (string.IsNullOrWhiteSpace(documentName))
            {
                documentName = project.DefaultDocumentName;
            }

            IDocumentStore documentStore = _documentStoreFactory.Create(project.DocumentStoreType);

            Document document = await documentStore.FindDocumentByNameAsync(project.ExtraProperties, project.Format, documentName, version);

            var dto = ObjectMapper.Map <Document, DocumentWithDetailsDto>(document);

            dto.Project = project;

            return(dto);
        }
Exemple #10
0
        protected virtual async Task <DocumentWithDetailsDto> GetDocumentWithDetailsDto(
            Project project,
            string documentName,
            string version)
        {
            var cacheKey = $"Document@{project.ShortName}#{documentName}#{version}";


            Document document;

            async Task <Document> GetDocumentAsync()
            {
                Logger.Info($"在缓存中找不到。仓储请求请求 {documentName}...");
                var store = _documentStoreFactory.Create(project.DocumentStoreType);

                //判断为Github,或者Filesystem,调用不同的实现
                document = await store.GetDocumentAsync(project, documentName, version);

                Logger.Info($"文档检索: {documentName}");
                return(document);
            }

            //如果是Debug模式,不进入缓存
            if (Debugger.IsAttached)
            {
                //需要检查
                document = await GetDocumentAsync();
            }
            var documentCache = _cacheManager.GetCache(cacheKey).AsTyped <string, Document>();

            document = await documentCache.GetOrDefaultAsync(cacheKey);

            if (document == null)
            {
                var cacheDocument = await GetDocumentAsync();

                _cacheManager.GetCache(cacheKey).Set(cacheKey, cacheDocument, null, TimeSpan.FromHours(30));
            }

            //实际进行的是类型转换

            var documentDto = new DocumentWithDetailsDto();

            ObjectMapper.Map(document, documentDto);



            return(documentDto);
        }
 public void Create()
 {
     _documentStoreFactory.Create(GithubDocumentStore.Type).GetType().ShouldBe(typeof(GithubDocumentStore));
     _documentStoreFactory.Create(FileSystemDocumentStore.Type).GetType().ShouldBe(typeof(FileSystemDocumentStore));
 }
 protected void Initialize(IDocumentStoreFactory subscriptionStoreFactory, IRouteManager routeManager, QueueName inputQueueName)
 {
     Condition.Requires(subscriptionStoreFactory, "subscriptionStoreFactory").IsNotNull();
       Condition.Requires(inputQueueName, "inputQueueName").IsNotNull();
       Condition.Requires(routeManager, "routeManager").IsNotNull();
       RouteManager = routeManager;
       Subscriptions = subscriptionStoreFactory.Create<Type, SubscriptionRegistration>();
       InputQueueName = inputQueueName;
 }