示例#1
0
        public DateTime?GetLastModificationDate(CacheFileDescription cacheFileDescription)
        {
            string fullPath = GetFilePath(cacheFileDescription);
            var    entity   = _fileManager.GetFile(fullPath);

            return(entity.LastModified);
        }
示例#2
0
        public string GetFilePath(CacheFileDescription cacheFileDescription)
        {
            string path;

            switch (cacheFileDescription.CacheFileType)
            {
            case CacheFileType.Page:
                path = GetPageFilePath(cacheFileDescription);
                break;

            case CacheFileType.PageResource:
                path = GetResourceFilePath(cacheFileDescription);
                break;

            case CacheFileType.Attachment:
                path = GetAttachmentFilePath(cacheFileDescription);
                break;

            case CacheFileType.Document:
                path = GetDocumentFilePath(cacheFileDescription);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(NormalizePath(path));
        }
示例#3
0
        private string GetResourceFilePath(CacheFileDescription cacheFileDescription)
        {
            CachedPageResourceDescription resourceDescription = cacheFileDescription as CachedPageResourceDescription;

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

            string resourcesPath = GetHtmlPageResourcesFolder(resourceDescription.CachedPageDescription);

            return(Path.Combine(resourcesPath, resourceDescription.ResourceName));
        }
示例#4
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));
        }
示例#5
0
        private string GetCachePath(string path, CacheFileDescription cacheFileDescription)
        {
            if (cacheFileDescription.SaveOptions == null)
            {
                throw new System.Exception("CacheFileDescription.Options is not set");
            }
            string filePath;
            string fileName;

            var options = cacheFileDescription.SaveOptions as ImageSaveOptions;

            if (options != null)
            {
                if (!string.IsNullOrEmpty(options.CustomName))
                {
                    if (options.UseWidthForCustomName)
                    {
                        fileName = string.Format("{0}_{1}.{2}", options.CustomName,
                                                 options.Width,
                                                 options.ConvertFileType.ToString().ToLower());
                    }
                    else
                    {
                        fileName = string.Format("{0}.{1}", options.CustomName,
                                                 options.ConvertFileType.ToString().ToLower());
                    }
                }
                else
                {
                    fileName = string.Format("{0}.{1}", cacheFileDescription.BaseName,
                                             options.ConvertFileType.ToString().ToLower());
                }
                filePath = string.Format(@"{0}\{1}\{2}\{3}", path, cacheFileDescription.Guid,
                                         options.PageNumber, fileName);
            }
            else
            {
                fileName = !string.IsNullOrEmpty(cacheFileDescription.SaveOptions.CustomName)
                ? string.Format("{0}.{1}", cacheFileDescription.SaveOptions.CustomName, cacheFileDescription.SaveOptions.ConvertFileType.ToString().ToLower())
                : string.Format("{0}.{1}", cacheFileDescription.BaseName, cacheFileDescription.SaveOptions.ConvertFileType.ToString().ToLower());

                filePath = string.Format(@"{0}\{1}\{2}", path, cacheFileDescription.Guid, fileName);
            }
            return(filePath);
        }
示例#6
0
        private string GetDocumentFilePath(CacheFileDescription cacheFileDescription)
        {
            CachedDocumentDescription document = cacheFileDescription as CachedDocumentDescription;

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

            string documentName = document.Name.Equals("document") && (document.OutputExtension.Equals("pdf") || document.OutputExtension.Equals(".pdf"))
                ? PdfFileName
                : Path.ChangeExtension(document.Name, document.OutputExtension);

            string documentFolder = BuildCachedDocumentFolderPath(document);

            return(Path.Combine(documentFolder, documentName));
        }
示例#7
0
        public Stream GetInputStream(CacheFileDescription cacheFileDescription)
        {
            if (cacheFileDescription == null || String.IsNullOrEmpty(cacheFileDescription.Guid) ||
                cacheFileDescription.LastModified == 0)
            {
                throw new System.Exception("CacheFileDescription is not set");
            }

            var key      = GetCachePath(_conversionConfig.CachePath, cacheFileDescription);
            var fileInfo = new S3FileInfo(_client, bucketName, key);

            if (!fileInfo.Exists)
            {
                throw new System.Exception("File not found");
            }

            return(fileInfo.OpenRead());
        }
示例#8
0
        private string GetAttachmentFilePath(CacheFileDescription cacheFileDescription)
        {
            CachedAttachmentDescription attachmentDescription =
                cacheFileDescription as CachedAttachmentDescription;

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

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

            return(Path.Combine(
                       CacheFolderName,
                       ToRelativeDirectoryName(path),
                       AttachmentDirectory,
                       attachmentDescription.AttachmentName));
        }
示例#9
0
        public bool Exists(CacheFileDescription cacheFileDescription)
        {
            if (!_conversionConfig.IsUseCache())
            {
                return(false);
            }

            if (cacheFileDescription == null)
            {
                throw new System.Exception("CacheFileDescription is not set");
            }

            if (cacheFileDescription.LastModified == 0)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(cacheFileDescription.Guid))
            {
                throw new System.Exception("CacheFileDescription is not set");
            }


            if (string.IsNullOrEmpty(_conversionConfig.StoragePath))
            {
                throw new System.Exception("Storage path is not set");
            }


            var        key      = GetCachePath(_conversionConfig.CachePath, cacheFileDescription);
            S3FileInfo fileInfo = new S3FileInfo(_client, bucketName, key);

            if (!fileInfo.Exists)
            {
                return(false);
            }
            return(fileInfo.LastWriteTimeUtc >= DateTime.UtcNow.AddMinutes(-5));
        }
示例#10
0
        public Stream GetOutputSaveStream(CacheFileDescription cacheFileDescription)
        {
            try
            {
                if (!_conversionConfig.IsUseCache())
                {
                    return(new MemoryStream());
                }

                if (cacheFileDescription == null || String.IsNullOrEmpty(cacheFileDescription.Guid))
                {
                    throw new System.Exception("CacheFileDescription is not set");
                }

                string     key      = GetCachePath(_conversionConfig.CachePath, cacheFileDescription);
                S3FileInfo fileInfo = new S3FileInfo(_client, bucketName, key);
                return(fileInfo.Create());
            }
            catch (System.Exception e)
            {
                throw new System.Exception(e.Message);
            }
        }
示例#11
0
        public bool Exists(CacheFileDescription cacheFileDescription)
        {
            string path = GetFilePath(cacheFileDescription);

            return(_fileManager.FileExist(path));
        }
示例#12
0
        public Stream GetOutputSaveStream(CacheFileDescription cacheFileDescription)
        {
            string path = GetFilePath(cacheFileDescription);

            return(new OutputStream(stream => _fileManager.Upload(stream, path)));
        }
示例#13
0
        public Stream GetInputStream(CacheFileDescription cacheFileDescription)
        {
            string path = GetFilePath(cacheFileDescription);

            return(_fileManager.Download(path));
        }
示例#14
0
 public string GetCacheUri(CacheFileDescription cacheFileDescription)
 {
     return(GetCachePath(_conversionConfig.CachePath, cacheFileDescription));
 }