コード例 #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        fileGuid = QueryHelper.GetGuid("fileguid", Guid.Empty);

        DebugHelper.SetContext("GetForumAttachment");

        int cacheMinutes = this.CacheMinutes;

        // Try to get data from cache
        using (CachedSection <CMSOutputForumAttachment> cs = new CachedSection <CMSOutputForumAttachment>(ref outputFile, cacheMinutes, true, null, "getforumattachment", CurrentSiteName, CacheHelper.GetBaseCacheKey(true, false), Request.QueryString))
        {
            if (cs.LoadData)
            {
                // Disable caching before check permissions
                cs.CacheMinutes = 0;

                // Process the file
                ProcessFile();

                // Keep original cache minutes if permissions are ok
                cs.CacheMinutes = cacheMinutes;

                // Ensure the cache settings
                if (cs.Cached)
                {
                    // Prepare the cache dependency
                    CacheDependency cd = null;
                    if (outputFile != null)
                    {
                        if (outputFile.ForumAttachment != null)
                        {
                            cd = CacheHelper.GetCacheDependency(outputFile.ForumAttachment.GetDependencyCacheKeys());

                            // Do not cache if too big file which would be stored in memory
                            if (!CacheHelper.CacheImageAllowed(CurrentSiteName, outputFile.ForumAttachment.AttachmentFileSize) && !ForumAttachmentInfoProvider.StoreFilesInFileSystem(CurrentSiteName))
                            {
                                cacheMinutes = largeFilesCacheMinutes;
                            }
                        }
                    }

                    if ((cd == null) && (CurrentSite != null) && (outputFile != null))
                    {
                        // Get the current forum id
                        int forumId = 0;
                        if (outputFile.ForumAttachment != null)
                        {
                            forumId = outputFile.ForumAttachment.AttachmentForumID;
                        }

                        // Set default dependency based on GUID
                        cd = CacheHelper.GetCacheDependency(new string[] { "forumattachment|" + fileGuid.ToString().ToLower() + "|" + CurrentSite.SiteID, "forumattachment|" + forumId });
                    }

                    // Cache the data
                    cs.CacheMinutes    = cacheMinutes;
                    cs.CacheDependency = cd;
                    cs.Data            = outputFile;
                }
            }
        }

        // Send the data
        SendFile(outputFile);

        DebugHelper.ReleaseContext();
    }
コード例 #2
0
    /// <summary>
    /// Ensures the physical file.
    /// </summary>
    /// <param name="file">Output file</param>
    public bool EnsurePhysicalFile(CMSOutputForumAttachment file)
    {
        if (file == null)
        {
            return(false);
        }

        // Try to link to file system
        if ((file.ForumAttachment != null) && (file.ForumAttachment.AttachmentID > 0) && ForumAttachmentInfoProvider.StoreFilesInFileSystem(CurrentSiteName))
        {
            string filePath = ForumAttachmentInfoProvider.EnsureAttachmentPhysicalFile(file.ForumAttachment, CurrentSiteName);
            if (filePath != null)
            {
                if (file.Resized)
                {
                    // If resized, ensure the thumbnail file
                    if (ForumAttachmentInfoProvider.GenerateThumbnails(CurrentSiteName))
                    {
                        filePath = ForumAttachmentInfoProvider.EnsureThumbnailFile(file.ForumAttachment, this.Width, this.Height, this.MaxSideSize);
                        if (filePath != null)
                        {
                            // Link to the physical file
                            file.PhysicalFile = filePath;
                            return(true);
                        }
                    }
                }
                else
                {
                    // Link to the physical file
                    file.PhysicalFile = filePath;
                    return(false);
                }
            }
        }


        file.PhysicalFile = "";
        return(false);
    }