Пример #1
0
        public async Task <DocumentParametersDto> GetParametersAsync(GetParametersDocumentInput input)
        {
            var project = await _projectRepository.GetAsync(input.ProjectId);

            try
            {
                if (string.IsNullOrWhiteSpace(project.ParametersDocumentName))
                {
                    return(await Task.FromResult <DocumentParametersDto>(null));
                }

                var document = await GetDocumentWithDetailsDtoAsync(
                    project,
                    project.ParametersDocumentName,
                    input.LanguageCode,
                    input.Version
                    );

                if (!JsonConvertExtensions.TryDeserializeObject <DocumentParametersDto>(document.Content,
                                                                                        out var documentParameters))
                {
                    throw new UserFriendlyException(
                              $"Cannot validate document parameters file '{project.ParametersDocumentName}' for the project {project.Name}.");
                }

                return(documentParameters);
            }
            catch (DocumentNotFoundException)
            {
                Logger.LogWarning($"Parameter file ({project.ParametersDocumentName}) not found!");
                return(new DocumentParametersDto());
            }
        }
Пример #2
0
        public virtual async Task <NavigationNode> GetNavigationAsync(GetNavigationDocumentInput input)
        {
            var project = await _projectRepository.GetAsync(input.ProjectId);

            var navigationDocument = await GetDocumentWithDetailsDtoAsync(
                project,
                project.NavigationDocumentName,
                input.LanguageCode,
                input.Version
                );

            if (!JsonConvertExtensions.TryDeserializeObject <NavigationNode>(navigationDocument.Content, out var navigationNode))
            {
                throw new UserFriendlyException($"Cannot validate navigation file '{project.NavigationDocumentName}' for the project {project.Name}.");
            }

            var leafs = navigationNode.Items.GetAllNodes(x => x.Items)
                        .Where(x => !x.Path.IsNullOrWhiteSpace())
                        .ToList();

            foreach (var leaf in leafs)
            {
                var cacheKey           = CacheKeyGenerator.GenerateDocumentUpdateInfoCacheKey(project, leaf.Path, input.LanguageCode, input.Version);
                var documentUpdateInfo = await DocumentUpdateCache.GetAsync(cacheKey);

                if (documentUpdateInfo != null)
                {
                    leaf.CreationTime              = documentUpdateInfo.CreationTime;
                    leaf.LastUpdatedTime           = documentUpdateInfo.LastUpdatedTime;
                    leaf.LastSignificantUpdateTime = documentUpdateInfo.LastSignificantUpdateTime;
                }
            }

            return(navigationNode);
        }
Пример #3
0
        public async Task <Dictionary <string, List <string> > > GetAvailableParametersAsync(string document)
        {
            try
            {
                if (!document.Contains(JsonOpener) || !document.Contains(DocsParam))
                {
                    return(new Dictionary <string, List <string> >());
                }

                var(jsonBeginningIndex, jsonEndingIndex, insideJsonSection) = GetJsonBeginEndIndexesAndPureJson(document);

                if (jsonBeginningIndex < 0 || jsonEndingIndex <= 0 || string.IsNullOrWhiteSpace(insideJsonSection))
                {
                    return(new Dictionary <string, List <string> >());
                }

                var pureJson = insideJsonSection.Replace(DocsParam, "").Trim();

                if (!JsonConvertExtensions.TryDeserializeObject <Dictionary <string, List <string> > >(pureJson, out var availableParameters))
                {
                    throw new UserFriendlyException("ERROR-20200327: Cannot validate JSON content for `AvailableParameters`!");
                }

                return(await Task.FromResult(availableParameters));
            }
            catch (Exception)
            {
                Logger.LogWarning("Unable to parse parameters of document.");
                return(new Dictionary <string, List <string> >());
            }
        }
Пример #4
0
        public async Task PullAllAsync(PullAllDocumentInput input)
        {
            var project = await _projectRepository.GetAsync(input.ProjectId);

            var navigationDocument = await GetDocumentAsync(
                project,
                project.NavigationDocumentName,
                input.LanguageCode,
                input.Version
                );

            if (!JsonConvertExtensions.TryDeserializeObject <NavigationNode>(navigationDocument.Content, out var navigation))
            {
                throw new UserFriendlyException($"Cannot validate navigation file '{project.NavigationDocumentName}' for the project {project.Name}.");
            }

            var leafs = navigation.Items.GetAllNodes(x => x.Items)
                        .Where(x => x.IsLeaf && !x.Path.IsNullOrWhiteSpace())
                        .ToList();

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

            var documents = new List <Document>();

            foreach (var leaf in leafs)
            {
                if (leaf.Path.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ||
                    leaf.Path.StartsWith("https://", StringComparison.OrdinalIgnoreCase) ||
                    (leaf.Path.StartsWith("{{") && leaf.Path.EndsWith("}}")))
                {
                    continue;
                }

                try
                {
                    var sourceDocument = await source.GetDocumentAsync(project, leaf.Path, input.LanguageCode, input.Version);

                    documents.Add(sourceDocument);
                }
                catch (Exception e)
                {
                    Logger.LogException(e);
                }
            }

            foreach (var document in documents)
            {
                await _documentRepository.DeleteAsync(document.ProjectId, document.Name,
                                                      document.LanguageCode,
                                                      document.Version);

                await _documentRepository.InsertAsync(document, true);
                await UpdateDocumentUpdateInfoCache(document);
            }
        }
Пример #5
0
        public async Task <LanguageConfig> GetLanguageListAsync(Project project, string version)
        {
            var path = Path.Combine(project.GetFileSystemPath(), DocsDomainConsts.LanguageConfigFileName);
            var configJsonContent = await FileHelper.ReadAllTextAsync(path);

            if (!JsonConvertExtensions.TryDeserializeObject <LanguageConfig>(configJsonContent, out var languageConfig))
            {
                throw new UserFriendlyException($"Cannot validate language config file '{DocsDomainConsts.LanguageConfigFileName}' for the project {project.Name}.");
            }

            return(languageConfig);
        }
Пример #6
0
        public async Task <LanguageConfig> GetLanguageListAsync(Project project, string version)
        {
            var token     = project.GetGitHubAccessTokenOrNull();
            var rootUrl   = project.GetGitHubUrl(version);
            var userAgent = project.GetGithubUserAgentOrNull();

            var url = CalculateRawRootUrl(rootUrl) + DocsDomainConsts.LanguageConfigFileName;

            var configAsJson = await DownloadWebContentAsStringAsync(url, token, userAgent);

            if (!JsonConvertExtensions.TryDeserializeObject <LanguageConfig>(configAsJson, out var languageConfig))
            {
                throw new UserFriendlyException($"Cannot validate language config file '{DocsDomainConsts.LanguageConfigFileName}' for the project {project.Name} - v{version}.");
            }

            return(languageConfig);
        }