Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string condition = Request.QueryString["Condition"];

            if (String.IsNullOrWhiteSpace(condition))
                Master.ReturnIndex();

            try
            {
                IList<Blog> blogList = new List<Blog>();

                if (condition == "Time")
                {
                    int year = Convert.ToInt32(Request.QueryString["Year"]);
                    int month = Convert.ToInt32(Request.QueryString["Month"] == null ? "0" : Request.QueryString["Month"]);
                    int day = Convert.ToInt32(Request.QueryString["Day"] == null ? "0" : Request.QueryString["Day"]);

                    blogList = Blog.LoadByPostDate(year, month, day);

                    String archivePeriod = String.Empty;
                    if (month == 0)
                        archivePeriod = CultureInfo.CurrentUICulture.IetfLanguageTag == "zh-CN" ? year + "年" : year.ToString();
                    else if (day == 0)
                        archivePeriod = (new DateTime(year, month, 1)).ToString("y", CultureInfo.CurrentUICulture);
                    else
                        archivePeriod = (new DateTime(year, month, day)).ToString("D", CultureInfo.CurrentUICulture);

                    Master.SubTitle = archivePeriod + Resources.BlogRenderer.ArchivePostedBlogsText;
                    Master.MetaKeywords.Content = "Blog Archives, " + archivePeriod + ", Wayne Ye";
                    Master.MetaDescription.Content = "List of blogs archives within " + archivePeriod;
                    lblInfo.Text = String.Format("<br /><span class=\"HighlightWords\" style=\"font-weight:bold;\">"
                        + Resources.BlogRenderer.ShowArchiveBlogsText + "</span><p>&nbsp;</p>", archivePeriod, blogList.Count);

                    br.WordsForNoRecords = Resources.BlogRenderer.SearchBlogNoRecord;
                    br.DataSource = blogList;
                    br.AdminMode = Master.IsAdminMode();
                    br.DataBind();
                }
                else if (condition == "Category")
                {
                    IRepositoryController repositoryController = new RepositoryController();
                    String catPermalink = Request.QueryString["Cat"];

                    if (String.IsNullOrWhiteSpace(catPermalink))
                    {
                        Master.ReturnIndex();
                        return;
                    }

                    if (catPermalink.EndsWith("/"))  // Indicates request URI is end with a slash
                        catPermalink = catPermalink.Remove(catPermalink.Length - 1);

                    int catId = repositoryController.LoadCatIdByPermalink(catPermalink);

                    // Cannot find the specified category, throw exception for logging
                    if (catId == 0)
                        Master.Return404();

                    Master.SubTitle = String.Format(Resources.BlogRenderer.CategoryPageTitle, catPermalink.Replace("/", "»"));
                    Master.MetaKeywords.Content = "Blog Category, " + catPermalink.Replace("/", ", ");
                    Master.MetaDescription.Content = "List of blogs under category: " + catPermalink.Replace("/", "->");

                    int totalCount = 0;
                    repositoryController.LoadCategoryBlogs(1, catId, out totalCount);
                    String catBreadcrumbs = repositoryController.LoadCatBreadCrumbsById(catId);

                    lblInfo.Text =
                        String.Format("<br /><span style=\"font-weight:bold;\">" + Resources.BlogRenderer.ShowCategorizedBlogsText
                        + "</span><p>&nbsp;</p>", catBreadcrumbs, totalCount);

                    br.CatId = catId;
                    br.CatPermalink = catPermalink;
                    br.AdminMode = Master.IsAdminMode();
                    br.LoadCategoryBlogs();
                }
            }
            catch (CategoryNotFoundException cne)
            {
                WayneLogger.WriteLog(cne.Message, "CategoryNotFound.log");
                Master.Return404();
            }
            //catch(NullReferenceException nre)
            //{
            //    WayneLogger.WriteLog("Null reference!" + nre.Message + ", categoryNames: " + categoryNames.VisuallyPrint()
            //        , "NullRefBug.log");
            //}
            catch (Exception ex)
            {
                WayneLogger.WriteLog(ex);
                Master.ReturnIndex();
            }
        }