コード例 #1
0
ファイル: Wiki.aspx.cs プロジェクト: kohku/codefactory
    private void BindWikiContent()
    {
        if (string.IsNullOrEmpty(Request.QueryString["id"]))
            throw new InvalidOperationException("A valid identifier is requested.");

        wiki = Wiki.Load(new Guid(Request.QueryString["id"]));

        if (wiki == null)
            return;

        // Tracing on first request.
        if (!Page.IsPostBack)
            TraceWiki(wiki);

        Page.Title = string.Format("Wiki - {0}", wiki.Title);
        TitleLabel.Text = wiki.Title;
        EditorLabel.Text = string.Format("Autor: {0}{1}", !string.IsNullOrEmpty(wiki.Editor) ? wiki.Editor : "ND",
            !string.IsNullOrEmpty(wiki.DepartmentArea) ? string.Format(" - {0}", wiki.DepartmentArea) : string.Empty);
        ContentLabel.Text = wiki.Content;
        EditButton.Visible = wiki.Editable || User.IsInRole("Administrator");

        relatedWiki = Wiki.GetRelatedWiki(wiki);

        if (relatedWiki != null)
        {
            int max = 3;

            while (max-- > 0 && (relatedWiki == null || relatedWiki.Equals(wiki)))
            relatedWiki = Wiki.GetRandomWiki();

            TitleRelatedLabel.Text = relatedWiki.Title;
            ContentRelatedLabel.Text = relatedWiki.Description;
            RelatedWikiLink.NavigateUrl = TitleRelatedLabel.NavigateUrl = relatedWiki.RelativeLink;
        }
    }
コード例 #2
0
ファイル: Default_Old.aspx.cs プロジェクト: kohku/codefactory
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (HttpContext.Current.Cache["contentOfDay"] == null &&
                HttpContext.Current.Cache["Article1Cover"] == null &&
                HttpContext.Current.Cache["Article2Cover"] == null)
            {
                content1 = Wiki.GetRandomWiki();

                if (content1 == null)
                {
                    UpdateView();
                    return;
                }

                contentOfDay = content1.Title;

                content2 = Wiki.GetRandomWiki();

                /// Mmm... aki puede haber problemas, cuando Wiki.GetRandomWiki() regrese siempre el mismo
                /// (solo haya un wiki) y también cuando regresa null.
                int max = 20;

                while (max-- > 0 && content1.Equals(content2))
                    content2 = Wiki.GetRandomWiki();

                DateTime absoluteExpiration = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                absoluteExpiration = absoluteExpiration.AddDays(1);

                HttpContext.Current.Cache.Add("contentOfDay", contentOfDay, null, absoluteExpiration,
                    Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
                HttpContext.Current.Cache.Add("Article1Cover", content1.ID, null, absoluteExpiration,
                    Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
                HttpContext.Current.Cache.Add("Article2Cover", content2.ID, null, absoluteExpiration,
                    Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
            }
            else
            {
                contentOfDay = (string)HttpContext.Current.Cache["contentOfDay"];
                content1 = Wiki.Load((Guid)HttpContext.Current.Cache["Article1Cover"]);
                content2 = Wiki.Load((Guid)HttpContext.Current.Cache["Article2Cover"]);
            }

            UpdateView();
        }
    }