Exemplo n.º 1
0
        public List <CachedPageResourceDescription> GetHtmlPageResources(CachedPageDescription cachedPageDescription)
        {
            List <CachedPageResourceDescription> result = new List <CachedPageResourceDescription>();
            string resourcesFolder = GetHtmlPageResourcesFolder(cachedPageDescription);

            var pathDelimiter = _fileManager.PathDelimiter.ToString();

            if (!resourcesFolder.EndsWith(pathDelimiter))
            {
                resourcesFolder += pathDelimiter;
            }

            var files = _fileManager.GetFiles(resourcesFolder);

            foreach (var file in files)
            {
                if (!file.IsDirectory)
                {
                    CachedPageResourceDescription resource =
                        new CachedPageResourceDescription(cachedPageDescription, Path.GetFileName(file.Path));
                    result.Add(resource);
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        public void TestExistsFileNotExist()
        {
            var path       = "dir/file.ext";
            var cachedPage = new CachedPageDescription(path);

            var exists = _viewerDataHandler.Exists(cachedPage);

            Assert.IsFalse(exists);
        }
Exemplo n.º 3
0
        public void TestGetHtmlPageResourcesFolder()
        {
            var cachedPage = new CachedPageDescription("document.doc")
            {
                PageNumber      = 1,
                OutputExtension = "html"
            };

            var folder = _viewerDataHandler.GetHtmlPageResourcesFolder(cachedPage);

            Assert.AreEqual("cache/document_doc/r/p1", folder);
        }
Exemplo n.º 4
0
        private string BuildCachedPageFolderPath(CachedPageDescription cachedPageDescription)
        {
            string path = cachedPageDescription.Guid.Contains(CacheFolderName)
               ? cachedPageDescription.Guid.Replace(CacheFolderName, string.Empty)
               : cachedPageDescription.Guid;

            string relativeDirectoryName = ToRelativeDirectoryName(path);
            string dimmensionsSubFolder  = GetDimmensionsSubFolder(cachedPageDescription);

            return(!string.IsNullOrEmpty(dimmensionsSubFolder)
                ? Path.Combine(CacheFolderName, relativeDirectoryName, dimmensionsSubFolder)
                : Path.Combine(CacheFolderName, relativeDirectoryName));
        }
Exemplo n.º 5
0
        public string GetHtmlPageResourcesFolder(CachedPageDescription cachedPageDescription)
        {
            string resourcesForPageFolderName = string.Format("{0}{1}", PageNamePrefix, cachedPageDescription.PageNumber);

            string path = cachedPageDescription.Guid.Contains(CacheFolderName)
                ? cachedPageDescription.Guid.Replace(CacheFolderName, string.Empty)
                : cachedPageDescription.Guid;

            string documentFolder = ToRelativeDirectoryName(path);
            string result         = Path.Combine(CacheFolderName, documentFolder, ResourcesDirectory, resourcesForPageFolderName);

            return(NormalizePath(result));
        }
Exemplo n.º 6
0
        public void TestGetFilePath()
        {
            var path       = "document.doc";
            var cachedPage = new CachedPageDescription(path)
            {
                PageNumber      = 1,
                OutputExtension = "html"
            };

            var filePath = _viewerDataHandler.GetFilePath(cachedPage);

            Assert.AreEqual("cache/document_doc/p1.html", filePath);
        }
Exemplo n.º 7
0
        public void TestGetLastModificationDate1()
        {
            var path       = "cache/p1.html";
            var cachedPage = new CachedPageDescription(path)
            {
                PageNumber      = 1,
                OutputExtension = "html"
            };

            var date = _viewerDataHandler.GetLastModificationDate(cachedPage);

            Assert.IsTrue(date.HasValue);
            Assert.AreEqual(DateTime.Now.Year, date.Value.Year);
        }
Exemplo n.º 8
0
        private string GetDimmensionsSubFolder(CachedPageDescription cachedPageDescription)
        {
            //based on GroupDocs.Viewer.Converter.Options.ConvertImageFileType
            string outputExtension = !string.IsNullOrEmpty(cachedPageDescription.OutputExtension) && cachedPageDescription.OutputExtension.Contains(".")
                ? cachedPageDescription.OutputExtension
                : string.Format(".{0}", cachedPageDescription.OutputExtension);

            string[] possibleImageExtensions = new[] { ".jpg", ".png", ".bmp" };
            if (!possibleImageExtensions.Contains(outputExtension))
            {
                return(string.Empty);
            }

            return(string.Format(ImageFolderNameFormat, cachedPageDescription.Width, cachedPageDescription.Height));
        }
Exemplo n.º 9
0
        private string BuildPageFileName(CachedPageDescription cachedPageDescription)
        {
            var extension = cachedPageDescription.OutputExtension;

            if (string.IsNullOrEmpty(extension))
            {
                extension = ".html";
            }
            else if (!extension.Contains("."))
            {
                extension = string.Format(".{0}", extension);
            }

            return(string.Format("{0}{1}{2}", PageNamePrefix, cachedPageDescription.PageNumber, extension));
        }
Exemplo n.º 10
0
        private string GetPageFilePath(CacheFileDescription cacheFileDescription)
        {
            CachedPageDescription pageDescription = cacheFileDescription as CachedPageDescription;

            if (pageDescription == null)
            {
                throw new InvalidOperationException(
                          "cacheFileDescription object should be an instance of CachedPageDescription class");
            }

            string fileName = BuildPageFileName(pageDescription);
            string folder   = BuildCachedPageFolderPath(pageDescription);

            return(Path.Combine(folder, fileName));
        }
Exemplo n.º 11
0
        public void TestExistsFileExist()
        {
            var path   = "cache/document_doc/p1.html";
            var stream = GetTestFileStream();

            _fileManager.Files.Add(path, stream);

            var cachedPage = new CachedPageDescription("document.doc")
            {
                PageNumber      = 1,
                OutputExtension = "html"
            };

            var exists = _viewerDataHandler.Exists(cachedPage);

            Assert.IsTrue(exists);
        }
Exemplo n.º 12
0
        public void TestGetHtmlPageResources()
        {
            var cachedPage = new CachedPageDescription("document.doc")
            {
                PageNumber      = 1,
                OutputExtension = "html"
            };

            //resources
            _fileManager.Files.Add("cache/document_doc/r/p1/styles.css", Stream.Null);
            _fileManager.Files.Add("cache/document_doc/r/p1/fonts.css", Stream.Null);

            var resources = _viewerDataHandler.GetHtmlPageResources(cachedPage);

            Assert.IsTrue(resources.Any(_ => _.ResourceName.Equals("styles.css")));
            Assert.IsTrue(resources.Any(_ => _.ResourceName.Equals("fonts.css")));
        }
Exemplo n.º 13
0
        public void TestGetInputStream()
        {
            var path   = "cache/document_doc/p1.html";
            var stream = GetTestFileStream();

            _fileManager.Files.Add(path, stream);

            var cachedPage = new CachedPageDescription("document.doc")
            {
                PageNumber      = 1,
                OutputExtension = "html"
            };

            var inputStream = _viewerDataHandler.GetInputStream(cachedPage);

            Assert.AreEqual(3, inputStream.Length);
        }
Exemplo n.º 14
0
        public void TestGetOutputSaveStream()
        {
            var path   = "cache/document_doc/p1.html";
            var stream = GetTestFileStream();

            var cachedPage = new CachedPageDescription("document.doc")
            {
                PageNumber      = 1,
                OutputExtension = "html"
            };

            var outputStream = _viewerDataHandler.GetOutputSaveStream(cachedPage);

            stream.CopyTo(outputStream);
            outputStream.Close();
            outputStream.Dispose();

            Assert.AreEqual(3, _fileManager.Files[path].Length);
        }