Exemplo n.º 1
0
 private void SetContentType(StaticResource fileEntry)
 {
     if (fileEntry.Path.EndsWith(".png"))
     {
         fileEntry.ContentType = "image/png";
     }
     else if (fileEntry.Path.EndsWith(".css.br"))
     {
         fileEntry.Path        = fileEntry.Path.Substring(0, fileEntry.Path.Length - 3);
         fileEntry.ContentType = "text/css";
     }
     else if (fileEntry.Path.EndsWith(".html.br"))
     {
         fileEntry.Path        = fileEntry.Path.Substring(0, fileEntry.Path.Length - 3);
         fileEntry.ContentType = "text/html";
     }
     else if (fileEntry.Path.EndsWith(".js.br"))
     {
         fileEntry.Path        = fileEntry.Path.Substring(0, fileEntry.Path.Length - 3);
         fileEntry.ContentType = "text/js";
     }
     else if (fileEntry.Path.EndsWith(".js"))
     {
         fileEntry.ContentType = "text/js";
     }
     else if (fileEntry.Path.EndsWith(".html"))
     {
         fileEntry.ContentType = "text/html";
     }
     else if (fileEntry.Path.EndsWith(".css"))
     {
         fileEntry.ContentType = "text/css";
     }
 }
Exemplo n.º 2
0
        private void TransformIndexFile(StaticResource fileEntry)
        {
            var indexString = Encoding.UTF8.GetString(fileEntry.Content);

            indexString = _stringTokenReplacementService.ReplaceTokensInString(indexString);

            fileEntry.Content = Encoding.UTF8.GetBytes(indexString);
        }
Exemplo n.º 3
0
        private void ProcessOtherFile(ZipArchiveEntry entry)
        {
            var fileEntry = new StaticResource
            {
                Path = entry.FullName
            };

            using var fileStream   = entry.Open();
            using var memoryStream = new MemoryStream();

            fileStream.CopyTo(memoryStream);

            fileEntry.Content = memoryStream.ToArray();

            SetContentType(fileEntry);

            _fileEntries.Add(fileEntry.Path, fileEntry);
        }
Exemplo n.º 4
0
        private void ProcessContentPath(string path)
        {
            var contents = _hostEnvironment.ContentRootFileProvider.GetDirectoryContents(path);

            if (contents.Exists)
            {
                foreach (var fileInfo in contents)
                {
                    if (fileInfo.IsDirectory)
                    {
                    }
                    else
                    {
                        try
                        {
                            var fileEntry = new StaticResource
                            {
                                Path = fileInfo.Name
                            };

                            SetContentType(fileEntry);

                            if (fileEntry.ContentType.StartsWith("text/"))
                            {
                                fileEntry.IsBrCompressed = true;
                                fileEntry.Content        = ReadAndCompressFile(fileInfo);
                            }
                            else
                            {
                                fileEntry.Content = ReadFile(fileInfo);
                            }

                            _fileEntries[fileEntry.Path] = fileEntry;
                        }
                        catch (Exception e)
                        {
                            _logger.LogError(e, "Exception thrown while processing asset file {0}", fileInfo.Name);
                        }
                    }
                }
            }
        }