示例#1
0
    /// <summary>
    /// Returns the cache dependency for the given document node.
    /// </summary>
    /// <param name="node">Document node</param>
    protected CacheDependency GetNodeDependency(TreeNode node)
    {
        string siteName = CurrentSiteName.ToLower();

        return(CacheHelper.GetCacheDependency(new string[] {
            CacheHelper.FILENODE_KEY,
            CacheHelper.FILENODE_KEY + "|" + siteName,
            "node|" + siteName + "|" + node.NodeAliasPath.ToLower()
        }));
    }
    /// <summary>
    /// Gets the default cache dependencies.
    /// </summary>
    public override string GetDefaultCacheDependendencies()
    {
        // Get default dependencies
        string result = base.GetDefaultCacheDependendencies();

        if (result != null)
        {
            result += "\n";
        }

        result += "cms.culturesite|all";
        result += "\ncms.culture|all";
        // Current page info
        PageInfo currentPageInfo = CMSContext.CurrentPageInfo;

        if (currentPageInfo != null)
        {
            result += "\nnode|" + CurrentSiteName.ToLower() + "|" + currentPageInfo.NodeAliasPath.ToLower();
        }

        return(result);
    }
示例#3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        DebugHelper.SetContext("GetFile");

        // Load the site name
        LoadSiteName();

        // Check the site
        if (CurrentSiteName == "")
        {
            throw new Exception("[GetFile.aspx]: Site not running.");
        }

        // Validate the culture
        PreferredCultureOnDemand culture = new PreferredCultureOnDemand();

        URLRewriter.ValidateCulture(CurrentSiteName, culture, null);

        // Set campaign
        if (IsLiveSite)
        {
            // Store campaign name if present
            string campaign = AnalyticsHelper.CurrentCampaign(CurrentSiteName);
            if (!String.IsNullOrEmpty(campaign))
            {
                PageInfo pi = CMSContext.CurrentPageInfo;

                // Log campaign
                if ((pi != null) && AnalyticsHelper.IsLoggingEnabled(CurrentSiteName, pi.NodeAliasPath) && AnalyticsHelper.SetCampaign(campaign, CurrentSiteName, pi.NodeAliasPath))
                {
                    CMSContext.Campaign = campaign;
                }
            }
        }

        int cacheMinutes = CacheMinutes;

        // Try to get data from cache
        using (CachedSection <CMSOutputFile> cs = new CachedSection <CMSOutputFile>(ref outputFile, cacheMinutes, true, null, "getfile", CurrentSiteName, CacheHelper.BaseCacheKey, Request.QueryString))
        {
            if (cs.LoadData)
            {
                // Store current value and temporarly disable caching
                bool cached = cs.Cached;
                cs.Cached = false;

                // Process the file
                ProcessAttachment();

                // Restore cache settings - data were loaded
                cs.Cached = cached;

                if (cs.Cached)
                {
                    // Do not cache if too big file which would be stored in memory
                    if ((outputFile != null) &&
                        (outputFile.Attachment != null) &&
                        !CacheHelper.CacheImageAllowed(CurrentSiteName, outputFile.Attachment.AttachmentSize) &&
                        !AttachmentManager.StoreFilesInFileSystem(CurrentSiteName))
                    {
                        cacheMinutes = largeFilesCacheMinutes;
                    }

                    if (cacheMinutes > 0)
                    {
                        // Prepare the cache dependency
                        CacheDependency cd = null;
                        if (outputFile != null)
                        {
                            string[] dependencies = new string[] {
                                "node|" + CurrentSiteName.ToLower() + "|" + outputFile.AliasPath.ToLower(),
                                ""
                            };

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

                                dependencies[1] = "attachment|" + outputFile.Attachment.AttachmentGUID.ToString().ToLower();
                            }

                            cd = CacheHelper.GetCacheDependency(dependencies);
                        }

                        if (cd == null)
                        {
                            // Set default dependency
                            if (guid != Guid.Empty)
                            {
                                // By attachment GUID
                                cd = CacheHelper.GetCacheDependency(new string[] { "attachment|" + guid.ToString().ToLower() });
                            }
                            else if (nodeGuid != Guid.Empty)
                            {
                                // By node GUID
                                cd = CacheHelper.GetCacheDependency(new string[] { "nodeguid|" + CurrentSiteName.ToLower() + "|" + nodeGuid.ToString().ToLower() });
                            }
                            else if (aliasPath != null)
                            {
                                // By node alias path
                                cd = CacheHelper.GetCacheDependency(new string[] { "node|" + CurrentSiteName.ToLower() + "|" + aliasPath.ToLower() });
                            }
                        }

                        cs.CacheDependency = cd;
                    }

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

        // Do not cache images in the browser if cache is not allowed
        if (LatestVersion)
        {
            useClientCache = false;
        }

        // Send the data
        SendFile(outputFile);

        DebugHelper.ReleaseContext();
    }
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
            // Do not process
        }
        else
        {
            string culture = CMSContext.PreferredCultureCode;

            mSeparator = DisplayLayout.ToLower() == "vertical" ? "<br />" : " ";

            DataSet ds = null;

            // Try to get data from cache
            using (CachedSection <DataSet> cs = new CachedSection <DataSet>(ref ds, this.CacheMinutes, true, this.CacheItemName, "languageselection", CMSContext.CurrentSiteName))
            {
                if (cs.LoadData)
                {
                    // Get the data
                    ds = CultureInfoProvider.GetSiteCultures(CMSContext.CurrentSiteName);

                    // Add to the cache
                    if (cs.Cached)
                    {
                        cs.CacheDependency = this.GetCacheDependency();
                        cs.Data            = ds;
                    }
                }
            }

            if (!DataHelper.DataSourceIsEmpty(ds) && (ds.Tables[0].Rows.Count > 1))
            {
                // Collection of available documents in culture
                Dictionary <string, string> documentCultures = null;
                // Check whether hiding is required or URLs should be generated with lang prefix
                if (this.HideUnavailableCultures || this.UseURLsWithLangPrefix)
                {
                    string cacheItemName = this.CacheItemName;
                    if (!String.IsNullOrEmpty(cacheItemName))
                    {
                        cacheItemName += "prefix";
                    }

                    // Current page info
                    PageInfo currentPageInfo = CMSContext.CurrentPageInfo;

                    // Try to get data from cache
                    using (CachedSection <Dictionary <string, string> > cs = new CachedSection <Dictionary <string, string> >(ref documentCultures, this.CacheMinutes, true, cacheItemName, "languageselectionprefix", CMSContext.CurrentSiteName, currentPageInfo.NodeAliasPath.ToLower()))
                    {
                        if (cs.LoadData)
                        {
                            // Initialize tree provider object
                            TreeProvider tp = new TreeProvider(CMSContext.CurrentUser);
                            tp.FilterOutDuplicates       = false;
                            tp.CombineWithDefaultCulture = false;

                            // Get all language versions
                            DataSet culturesDs = tp.SelectNodes(CMSContext.CurrentSiteName, "/%", TreeProvider.ALL_CULTURES, false, null, "NodeID = " + currentPageInfo.NodeId, null, -1, true, 0, "DocumentCulture, DocumentUrlPath");

                            // Create culture/UrlPath collection
                            if (!DataHelper.DataSourceIsEmpty(culturesDs))
                            {
                                documentCultures = new Dictionary <string, string>();
                                foreach (DataRow dr in culturesDs.Tables[0].Rows)
                                {
                                    string docCulture = ValidationHelper.GetString(dr["DocumentCulture"], String.Empty).ToLower();
                                    string urlPath    = ValidationHelper.GetString(dr["DocumentUrlPath"], String.Empty);
                                    documentCultures.Add(docCulture, urlPath);
                                }
                            }

                            // Add to the cache
                            if (cs.Cached)
                            {
                                cs.CacheDependency = CacheHelper.GetCacheDependency(new string[] { "cms.culturesite|all", "cms.culture|all", "node|" + CurrentSiteName.ToLower() + "|" + currentPageInfo.NodeAliasPath.ToLower() });
                                cs.Data            = documentCultures;
                            }
                        }
                    }
                }

                // Render the cultures
                ltlHyperlinks.Text = "";
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    string cultureCode      = Convert.ToString(dr["CultureCode"]);
                    string cultureAlias     = Convert.ToString(dr["CultureAlias"]);
                    string cultureShortName = Convert.ToString(dr["CultureShortName"]);
                    // Indicates whether exists document in specific culture
                    bool documentCultureExists = true;

                    // Check whether exists document in specified culture
                    if ((documentCultures != null) && (this.HideUnavailableCultures))
                    {
                        documentCultureExists = documentCultures.ContainsKey(cultureCode.ToLower());
                    }

                    if (documentCultureExists)
                    {
                        if (!(HideCurrentCulture && (String.Compare(CMSContext.CurrentDocument.DocumentCulture, cultureCode, true) == 0)))
                        {
                            if (String.Compare(culture, cultureCode, StringComparison.InvariantCultureIgnoreCase) != 0)
                            {
                                string url  = null;
                                string lang = cultureCode;
                                // Check whether culture alias is defined and if so use it
                                if (!String.IsNullOrEmpty(cultureAlias))
                                {
                                    lang = cultureAlias;
                                }

                                // Get specific url with language prefix
                                if (this.UseURLsWithLangPrefix && documentCultures != null)
                                {
                                    string urlPath = String.Empty;
                                    if (documentCultures.ContainsKey(cultureCode.ToLower()))
                                    {
                                        urlPath = documentCultures[cultureCode.ToLower()];
                                    }
                                    url  = TreePathUtils.GetUrl(CMSContext.CurrentAliasPath, urlPath, CMSContext.CurrentSiteName, lang);
                                    url += URLHelper.GetQuery(URLHelper.CurrentURL);
                                    url  = URLHelper.RemoveParameterFromUrl(url, URLHelper.LanguageParameterName);
                                    url  = URLHelper.RemoveParameterFromUrl(url, URLHelper.AliasPathParameterName);
                                }
                                // Get URL with lang parameter
                                else
                                {
                                    // Build current URL
                                    url = URLHelper.CurrentURL;
                                    url = URLHelper.RemoveParameterFromUrl(url, URLHelper.LanguageParameterName);
                                    url = URLHelper.RemoveParameterFromUrl(url, URLHelper.AliasPathParameterName);
                                    url = URLHelper.AddParameterToUrl(url, URLHelper.LanguageParameterName, lang);
                                }



                                ltlHyperlinks.Text += "<a href=\"" + url + "\">" + HTMLHelper.HTMLEncode(cultureShortName) + "</a>";
                            }
                            else
                            {
                                ltlHyperlinks.Text += cultureShortName;
                            }
                            ltlHyperlinks.Text += mSeparator;
                        }
                    }
                }
            }
            else
            {
                Visible = false;
            }
        }
    }