コード例 #1
0
ファイル: SiteGenerator.cs プロジェクト: Nerven/Self
        private async Task _GenerateProjectLogosAsync(ProjectInfo project, IHtmlSite site)
        {
            var _logo        = _LogoBuilder.GetLogo(project);
            var _svgDocument = await _logo.GetSvgDocumentAsync().ConfigureAwait(false);

            var _svgResource = HtmlStreamResourceProperties.CreateStreamResource(null, () =>
            {
                var _stream = new MemoryStream();
                _svgDocument.Save(_stream);
                _stream.Position = 0;
                return(_stream);
            });

            _svgResource.Name = new[] { "external-assets", "logo", "svg", _logo.Key + ".svg" };
            site.Resources.Add(_svgResource);

            foreach (var _pixelSize in new[] { 16, 32, 48, 256, 512, 4096 })
            {
                var _sizeString = _pixelSize.ToString(CultureInfo.InvariantCulture);

                var _pngResource = HtmlStreamResourceProperties.CreateStreamResource("image/png", await _logo.GetPngDataAsync(_pixelSize).ConfigureAwait(false));
                _pngResource.Name = new[] { "external-assets", "logo", _sizeString + "x" + _sizeString + "_png", _logo.Key + ".png" };
                site.Resources.Add(_pngResource);
            }
        }
コード例 #2
0
ファイル: SiteGenerator.cs プロジェクト: Nerven/Self
        private static void _AddFileResourcesToSite(IHtmlSite site, string resourcesDirectoryPath)
        {
            var _cleanResourcesDirectoryPath = resourcesDirectoryPath.EndsWith("\\", StringComparison.Ordinal)
                ? resourcesDirectoryPath.Substring(0, resourcesDirectoryPath.Length - 1)
                : resourcesDirectoryPath;

            foreach (var _resourceFilePath in Directory.GetFiles(_cleanResourcesDirectoryPath, "*", SearchOption.AllDirectories))
            {
                Must.Assertion
                .Assert(_resourceFilePath.StartsWith(_cleanResourcesDirectoryPath, StringComparison.Ordinal));

                var _nameParts = _resourceFilePath.Substring(_cleanResourcesDirectoryPath.Length + 1).Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
                var _resource  = HtmlStreamResourceProperties.CreateStreamResource(null, _ => new FileStream(_resourceFilePath, FileMode.Open, FileAccess.Read));
                _resource.Name = new[] { "assets" }.Concat(_nameParts).ToArray();

                site.Resources.Add(_resource);
            }
        }