Exemplo n.º 1
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 (!DocsJsonSerializerHelper.TryDeserialize <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);
            }
        }
Exemplo n.º 2
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)
            {
                var sourceDocument =
                    await source.GetDocumentAsync(project, leaf.Path, input.LanguageCode, input.Version);

                documents.Add(sourceDocument);
            }

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

                await _documentRepository.InsertAsync(document, true);
                await UpdateDocumentUpdateInfoCache(document);
            }
        }
Exemplo n.º 3
0
        public async Task PullAllAsync(PullAllDocumentInput input)
        {
            var project = await _projectRepository.GetAsync(input.ProjectId);

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

            var nav   = JsonConvert.DeserializeObject <NavigationNode>(navigationFile.Content);
            var leafs = nav.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)
            {
                var sourceDocument =
                    await source.GetDocumentAsync(project, leaf.Path, input.LanguageCode, input.Version);

                documents.Add(sourceDocument);
            }

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

                await _documentRepository.InsertAsync(document, true);
                await UpdateDocumentUpdateInfoCache(document);
            }
        }