Пример #1
0
        private async Task SetVersionAsync(ProjectDto project)
        {
            var versionInfoDtos = await _documentAppService.GetVersions(project.ShortName);

            Versions = versionInfoDtos.Select(v => new VersionInfo(v.DisplayName, v.Name)).ToList();

            LatestVersionInfo = GetLatestVersion();

            if (string.Equals(Version, DocsAppConsts.Latest, StringComparison.OrdinalIgnoreCase))
            {
                LatestVersionInfo.IsSelected = true;
                Version = LatestVersionInfo.Version;
            }
            else
            {
                var versionFromUrl = Versions.FirstOrDefault(v => v.Version == Version);
                if (versionFromUrl != null)
                {
                    versionFromUrl.IsSelected = true;
                    Version = versionFromUrl.Version;
                }
                else
                {
                    Versions.First().IsSelected = true;
                    Version = Versions.First().Version;
                }
            }

            VersionSelectItems = Versions.Select(v => new SelectListItem
            {
                Text     = v.DisplayText,
                Value    = CreateLink(LatestVersionInfo, v.Version, DocumentName),
                Selected = v.IsSelected
            }).ToList();
        }
Пример #2
0
        public async Task OnGet()
        {
            var projectDto = await _projectAppService.FindByShortNameAsync(ProjectName);

            ProjectFormat = projectDto.Format;

            DocumentNameWithExtension = DocumentName + "." + projectDto.Format;

            var versions = await _documentAppService.GetVersions(projectDto.ShortName, projectDto.DefaultDocumentName,
                                                                 projectDto.ExtraProperties, projectDto.DocumentStoreType, DocumentNameWithExtension);

            Versions = versions.Select(v => new VersionInfo(v, v)).ToList();

            AddDefaultVersionIfNotContains();

            var latestVersion = Versions.Count == 1 ? Versions[0] : Versions[1];

            latestVersion.DisplayText = $"{latestVersion.Version} - latest";
            latestVersion.Version     = latestVersion.Version;


            var versionFromUrl = Versions.FirstOrDefault(v => v.Version == Version);

            if (versionFromUrl != null)
            {
                versionFromUrl.IsSelected = true;
            }
            else if (string.Equals(Version, "latest", StringComparison.InvariantCultureIgnoreCase))
            {
                latestVersion.IsSelected = true;
            }
            else
            {
                Versions.First().IsSelected = true;
            }

            if (Version == null)
            {
                Version = Versions.Single(x => x.IsSelected).Version;
            }

            Document = await _documentAppService.GetByNameAsync(ProjectName, DocumentNameWithExtension, Version, true);

            var converter = _documentConverterFactory.Create(Document.Format ?? projectDto.Format);
            var content   = converter.NormalizeLinks(Document.Content, Document.Project.ShortName, Document.Version, Document.LocalDirectory);

            content = converter.Convert(content);

            content          = HtmlNormalizer.ReplaceImageSources(content, Document.RawRootUrl, Document.LocalDirectory);
            content          = HtmlNormalizer.ReplaceCodeBlocksLanguage(content, "language-C#", "language-csharp"); //todo find a way to make it on client in prismJS configuration (eg: map C# => csharp)
            Document.Content = content;

            Navigation = await _documentAppService.GetNavigationDocumentAsync(ProjectName, Version, false);

            Navigation.ConvertItems();
        }
Пример #3
0
        private async Task SetVersionAsync(ProjectDto project)
        {
            Versions = (await _documentAppService
                        .GetVersions(project.ShortName, project.DefaultDocumentName, project.ExtraProperties,
                                     project.DocumentStoreType, DocumentNameWithExtension))
                       .Select(v => new VersionInfo(v, v)).ToList();

            Versions.Insert(0, new VersionInfo("master", "master"));

            LatestVersionInfo = GetLatestVersion();

            if (string.Equals(Version, DocsAppConsts.LatestVersion, StringComparison.OrdinalIgnoreCase))
            {
                LatestVersionInfo.IsSelected = true;
                Version = LatestVersionInfo.Version;
            }
            else
            {
                var versionFromUrl = Versions.FirstOrDefault(v => v.Version == Version);
                if (versionFromUrl != null)
                {
                    versionFromUrl.IsSelected = true;
                    Version = versionFromUrl.Version;
                }
                else
                {
                    Versions.First().IsSelected = true;
                    Version = Versions.First().Version;
                }
            }

            VersionSelectItems = Versions.Select(v => new SelectListItem
            {
                Text     = v.DisplayText,
                Value    = CreateLink(v.Version, DocumentName),
                Selected = v.IsSelected
            }).ToList();
        }