Example #1
0
        public ActionResult Index(VMArchive archive)
        {
            if (!ModelState.IsValid)
            {
                return RedirectToAction("NotFound", "Error");
            }

            VMArchive model = null;
            if (archive.Month == null)
            {
                return RedirectToAction("NotFound", "Error");
            }

            HNKBlogConfigManager cfgMgr = null;
            try
            {
                cfgMgr = new HNKBlogConfigManager(AppSettings.GetDbConnectionString());
            }
            catch (Exception e)
            {
                AzureLog.WriteToTable(e);
                return new HttpStatusCodeResult(500);
            }

            // 初期化時にブログ記事をデータベースから取得します
            model = new VMArchive((int)archive.Year, (int)archive.Month, archive.P);
            model.SetPageTitle(string.Format("{0}年{1}月の記事", (int)model.Year, (int)model.Month), cfgMgr.BlogTitle.Value);
            return View(model);
        }
Example #2
0
        public ActionResult Index(VMArticle article)
        {
            if (!ModelState.IsValid)
            {
                return RedirectToAction("NotFound", "Error");
            }

            HNKBlogConfigManager cfgMgr = null;
            try
            {
                cfgMgr = new HNKBlogConfigManager(AppSettings.GetDbConnectionString());
            }
            catch (Exception e)
            {
                AzureLog.WriteToTable(e);
                return new HttpStatusCodeResult(500);
            }

            // 初期化時に記事をデータベースから取得します
            VMArticle model = new VMArticle((int)article.Id);
            if (model.PublicArticle.Id < 1)
            {
                return RedirectToAction("NotFound", "Error");
            }
            model.SetPageTitle(model.PublicArticle.Title, cfgMgr.BlogTitle.Value);

            model.IsEnabledComment = cfgMgr.IsEnabledComment();
            model.IsEnabledDisqus = cfgMgr.IsEnabledDisqus();
            return View(model);
        }
Example #3
0
        public ActionResult Category(VMArchiveCategory args)
        {
            if (!ModelState.IsValid)
            {
                return RedirectToAction("NotFound", "Error");
            }

            HNKBlogConfigManager cfgMgr = null;
            try
            {
                cfgMgr = new HNKBlogConfigManager(AppSettings.GetDbConnectionString());
            }
            catch (Exception e)
            {
                AzureLog.WriteToTable(e);
                return new HttpStatusCodeResult(500);
            }

            Category category = VMArchiveCategory.GetPublicCategory(args.Id);
            args.Category = category;

            List<Article> articles = args.GetPublicArticles(args.Id, args.P);
            args.PublicArticles = articles;
            args.SetPageTitle(string.Format("{0}カテゴリ", args.Category.Name), cfgMgr.BlogTitle.Value);
            return View("Category", args);
        }
Example #4
0
        public ActionResult NotFound()
        {
            HNKBlogConfigManager cfgMgr = null;
            try
            {
                cfgMgr = new HNKBlogConfigManager(AppSettings.GetDbConnectionString());
            }
            catch (Exception e)
            {
                AzureLog.WriteToTable(e);
                return new HttpStatusCodeResult(500);
            }

            VMError model = new VMError("NotFound");
            model.SetPageTitle("お探しのページは見つかりませんでした", cfgMgr.BlogTitle.Value);
            return View(model);
        }
Example #5
0
        public ActionResult Index()
        {
            HNKBlogConfigManager cfgMgr = null;
            try
            {
                cfgMgr = new HNKBlogConfigManager(AppSettings.GetDbConnectionString());
            }
            catch (Exception e)
            {
                AzureLog.WriteToTable(e);
                return new HttpStatusCodeResult(500);
            }

            VMError model = new VMError("Internal Server Error");
            model.SetPageTitle("エラーが発生しました", cfgMgr.BlogTitle.Value);
            return View(model);
        }
Example #6
0
        public JavaScriptResult GoogleAnalytics()
        {
            HNKBlogConfigManager cfgMgr = null;
            try
            {
                cfgMgr = new HNKBlogConfigManager(AppSettings.GetDbConnectionString());
            }
            catch (Exception e)
            {
                AzureLog.WriteToTable(e);
                return new JavaScriptResult();
            }

            JavaScriptResult jsResult = new JavaScriptResult();
            jsResult.Script = cfgMgr.GoogleAnalytics.Value;
            return jsResult;
        }
Example #7
0
        public ActionResult AccessAnalytics()
        {
            HNKBlogConfigManager cfgMgr = null;
            try
            {
                cfgMgr = new HNKBlogConfigManager(AppSettings.GetDbConnectionString());
            }
            catch (Exception e)
            {
                AzureLog.WriteToTable(e);
                return new HttpStatusCodeResult(500);
            }

            VMConfigAccessAnalytics model = new VMConfigAccessAnalytics();
            model.LoadUIElements();
            model.GoogleAnalytics = cfgMgr.GoogleAnalytics.Value;
            return View(model);
        }
Example #8
0
        public ActionResult Rss()
        {
            HNKBlogConfigManager cfgMgr = null;
            try
            {
                cfgMgr = new HNKBlogConfigManager(AppSettings.GetDbConnectionString());
            }
            catch (Exception e)
            {
                AzureLog.WriteToTable(e);
                return new HttpStatusCodeResult(500);
            }

            // ブログの設定でRSS配信が禁止されている場合
            if (!cfgMgr.IsEnabledOutputRssFeed())
            {
                return new HttpNotFoundResult();
            }

            List<Article> articles = new List<Article> { };
            try
            {
                int hitCount = 0;
                articles = ArticleFetcher.GetArticles(AppSettings.GetDbConnectionString(), 10, 1, out hitCount);
            }
            catch (Exception e)
            {
                AzureLog.WriteToTable(e);
                return new HttpStatusCodeResult(500);
            }

            Uri blogUrl = null;
            try
            {
                blogUrl = new Uri(AppSettings.GetBlogUrl());
            }
            catch (Exception e)
            {
                AzureLog.WriteToTable(e);
                return new HttpStatusCodeResult(500);
            }

            return new RssFeedResult(blogUrl, cfgMgr.BlogTitle.Value, cfgMgr.BlogDescription.Value, articles);
        }
Example #9
0
        /// <summary>
        /// トップページを表示します
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public ActionResult Index(VMHome args)
        {
            HNKBlogConfigManager cfgMgr = null;
            try
            {
                cfgMgr = new HNKBlogConfigManager(AppSettings.GetDbConnectionString());
            }
            catch (Exception e)
            {
                AzureLog.WriteToTable(e);
                return new HttpStatusCodeResult(500);
            }
            args.BlogDescription = cfgMgr.BlogDescription.Value;

            try
            {
                int hitCount = 0;
                args.PublicArticles = ArticleFetcher.GetArticles(AppSettings.GetDbConnectionString(), args.L, args.P, out hitCount);
                args.TotalArticleCount = hitCount;
                args.SetPageTitle(string.Empty, cfgMgr.BlogTitle.Value);
            }
            catch (Exception e)
            {
                AzureLog.WriteToTable(e);
                return new HttpStatusCodeResult(500);
            }

            foreach (Article article in args.PublicArticles) {
                string[] delimiter = { "," };
                string[] tagIdsStr = article.TagIds.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
                if (tagIdsStr.Length > 0)
                {
                    List<int> tagIdsInt = new List<int> { };
                    foreach (string tagIdStr in tagIdsStr)
                    {
                        int tagIdInt = 0;
                        bool ret = int.TryParse(tagIdStr, out tagIdInt);
                        if (ret)
                        {
                            tagIdsInt.Add(tagIdInt);
                        }
                    }

                    try
                    {
                        using (HNKTagResource resource = new HNKTagResource(AppSettings.GetDbConnectionString()))
                        {
                            List<HNKTag> tags = resource.GetTags(tagIdsInt);
                            if (tags != null && tags.Count > 0)
                            {
                                article.Tags = tags;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        AzureLog.WriteToTable(e);
                    }
                }

            }

            return View(args);
        }