Пример #1
0
    public override void OnPageLoaded()
    {
        int     nid     = int.Parse(GlobalSettings.Decrypt(Request.QueryString["ID"]));
        Article article = ArticleManager.GetArticle(nid);

        //构建资讯的关键字标签
        StringBuilder sb = new StringBuilder();

        //添加资讯关键字
        sb.Append(article.Keywords.Replace(';', ','));
        sb.Append(",");
        //添加资讯副标题
        if (!string.IsNullOrEmpty(article.SubTitle))
        {
            sb.AppendFormat("{0},", article.SubTitle);
        }
        //添加资讯所属分类的关键字
        sb.Append(null == article.CategoryObject ? string.Empty : article.CategoryObject.Name);

        //设置页面关键字标签
        this.AddKeywords(sb.ToString());

        //设置资讯页面描述信息为资讯简述/名称+关键字列表
        this.AddDescription((string.IsNullOrEmpty(article.Abstract) ? article.Title : article.Abstract) + " 关键字: " + sb.ToString());

        //设置资讯页面标题为名称+" - "+关键字组合标题名
        this.ShortTitle = article.Title + " - " + sb.ToString();
        SetTitle();

        AddJavaScriptInclude("Scripts/Pages/newsDetail.aspx.js", false, false);
    }
Пример #2
0
        internal static void Delete(IDataStore dataStore, Article article)
        {
            ArticleManager manager = new ArticleManager(dataStore);

            BusinessObjectActionReport <DataRepositoryActionStatus> report = manager.Delete(article);

            Assert.AreEqual(DataRepositoryActionStatus.Success, report.Status);
            Assert.IsNull(manager.GetArticle(article.ArticleId));

            Trace.WriteLine("Successfully deleted article " + article.Subject);
        }
Пример #3
0
        public void Test_Delete_ArticleGroup()
        {
            IUserBasic   userBasic    = Test_WorkmateMembershipProvider.CreateUser(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.DummyDataManager);
            MessageBoard messageBoard = Test_MessageBoards.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.Random);

            ArticleGroup       articleGroup       = Test_ArticleGroups.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.Random);
            ArticleGroupThread articleGroupThread = Test_ArticleGroupThreads.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, articleGroup, this.Random);
            Article            article            = Test_Articles.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, userBasic
                                                                         , articleGroupThread, messageBoard, this.Random);

            Test_ArticleGroups.Delete(this.DataStore, articleGroup);

            ArticleGroupThreadManager articleGroupThreadManager = new ArticleGroupThreadManager(this.DataStore);
            ArticleManager            articleManager            = new ArticleManager(this.DataStore);

            Assert.IsNull(articleGroupThreadManager.GetArticleGroupThread(articleGroupThread.ArticleGroupThreadId));
            Assert.IsNull(articleManager.GetArticle(article.ArticleId));
        }
Пример #4
0
        internal static Article Create(IDataStore dataStore, IApplicationSettings applicationSettings, IApplication application
                                       , IUserBasic author, ArticleGroupThread articleGroupThread
                                       , MessageBoard messageBoard
                                       , Random random)
        {
            ArticleManager manager = new ArticleManager(dataStore);

            Article article = new Article(
                author
                , articleGroupThread
                , DebugUtility.GetRandomEnum <ArticleStatus>(random)
                , DebugUtility.GetRandomEnum <ArticleType>(random)
                , "Article Subject" + random.Next(1000000, 10000000)
                , "Article Body" + random.Next(1000000, 10000000)
                , "URLName" + random.Next(1000000, 10000000)
                , DebugUtility.FlipCoin(random));

            int count = random.Next(0, 10);

            for (int i = 0; i < count; i++)
            {
                article.ContentLevelNodeNames.Add("Category " + i + (DebugUtility.FlipRiggedCoin(random, .2) ? " " + random.Next(10000, 100000) : string.Empty));
            }

            BusinessObjectActionReport <DataRepositoryActionStatus> report = manager.Create(article, messageBoard.MessageBoardId, DebugUtility.FlipCoin(random));

            Assert.AreEqual(DataRepositoryActionStatus.Success, report.Status);
            Assert.Greater(article.ArticleId, 0);

            Article dsArticle = manager.GetArticle(article.ArticleId);

            Assert.IsNotNull(dsArticle);

            IArticleModel articelModel = manager.GetArticleModel(dsArticle.ArticleId);

            Assert.AreEqual(article.ContentLevelNodeNames.Count, articelModel.ContentLevelNodes.Count);
            for (int i = 0; i < article.ContentLevelNodeNames.Count; i++)
            {
                Assert.AreEqual(article.ContentLevelNodeNames[i], articelModel.ContentLevelNodes[i]);
            }

            return(dsArticle);
        }
Пример #5
0
    void BindArticle(int id)
    {
        Article article = ArticleManager.GetArticle(id);

        BindParentCategory(article.Category);
        txtTitle.Text    = article.Title;
        txtSubTitle.Text = article.SubTitle;
        txtAbstract.Text = article.Abstract;
        txtContent.Text  = article.Content;
        ddlArticleImages.SelectedValue = article.Image.ToString();

        if (article.Date.HasValue)
        {
            txtDate.Text = article.Date.Value.ToString("yyyy年MM月dd日");
        }

        txtCopyFrom.Text        = article.CopyFrom;
        txtAuthor.Text          = article.Author;
        txtKeywords.Text        = article.Keywords;
        txtDisplayOrder.Text    = article.DisplayOrder.ToString();
        txtMemo.Text            = article.ArticleMemo;
        csArticle.SelectedValue = article.Status;
    }
 /// <summary>
 /// Fetches and returns a Doctrine Ships article.
 /// </summary>
 /// <param name="articleId">The id of the article for which an article object should be returned.</param>
 /// <returns>An individual article.</returns>
 public Article GetArticle(int articleId)
 {
     return(ArticleManager.GetArticle(articleId));
 }
Пример #7
0
    private void BindData()
    {
        string articleIDStr = Request.QueryString["id"];

        if (!string.IsNullOrEmpty(articleIDStr))
        {
            int articleID;
            if (int.TryParse(HHOnline.Framework.GlobalSettings.Decrypt(articleIDStr), out articleID))
            {
                // 增加点击率
                //ArticleManager.IncreaseHitTimes(articleID);
                BaseViews views = ViewsFactory.GetViews(typeof(ArticleViews));
                views.AddViewCount(articleID);

                Article article = ArticleManager.GetArticle(articleID);
                if (article != null)
                {
                    lblAbstract.InnerHtml = article.Abstract;
                    lblAuthor.Text        = string.IsNullOrEmpty(article.Author) ? "匿名" : article.Author;
                    lblDate.Text          = article.Date.HasValue ? article.Date.Value.ToString() : DateTime.Now.ToString();
                    lblHitTimes.Text      = article.HitTimes.ToString();
                    lblTitle.Text         = article.Title;
                    lblSubTitle.Text      = article.SubTitle;
                    lblKeywords.Text      = string.IsNullOrEmpty(article.Keywords) ? "无" : article.Keywords;

                    // 获取所有产品
                    ProductQuery pq = new ProductQuery();
                    pq.HasPublished = true;
                    List <Product>         products = Products.GetProductList(pq);
                    List <ReplaceKeyValue> rkvs     = new List <ReplaceKeyValue>();

                    foreach (Product item in products)
                    {
                        ReplaceKeyValue rkv = new ReplaceKeyValue();
                        rkv.Key   = item.ProductName;
                        rkv.Value = "<a style='color: blue; text-decoration:underline;' href=\"view.aspx?product-product&ID=" + HHOnline.Framework.GlobalSettings.Encrypt(item.ProductID.ToString()) + "\">" + item.ProductName + "</a>";
                        rkvs.Add(rkv);
                    }

                    FastReplace fr = new FastReplace(rkvs.ToArray());
                    lblContent.InnerHtml = fr.ReplaceAll(article.Content);

                    // 查找分类
                    ArticleCategory ac = ArticleManager.GetArticleCategory(article.Category);
                    if (ac != null)
                    {
                        btnCategory.Text          = ac.Name;
                        btnCategory.OnClientClick = "window.location.href='view.aspx?news-newslist&cate=" + HHOnline.Framework.GlobalSettings.Encrypt(ac.ID.ToString()) + "';return false;";
                    }

                    if (!string.IsNullOrEmpty(article.CopyFrom))
                    {
                        lblCopyForm.Text    = "文章来源: " + article.CopyFrom;
                        lblCopyForm.Visible = true;
                    }
                    else
                    {
                        lblCopyForm.Visible = false;
                    }

                    // 获取附件
                    ArticleAttachment attachment = ArticleAttachments.GetAttachment(article.Image);
                    if (attachment != null)
                    {
                        if (attachment.IsRemote)
                        {
                            imgAttachment.ImageUrl = attachment.FileName;
                        }
                        else
                        {
                            imgAttachment.ImageUrl = attachment.GetDefaultImageUrl(100, 100);
                        }
                        imgAttachment.Visible = true;
                    }
                    else
                    {
                        imgAttachment.Visible = false;
                    }

                    this.ShortTitle = article.Title;
                }
                else
                {
                    imgAttachment.Visible = false;
                }
            }
            this.SetTitle();
        }
    }
Пример #8
0
    protected void btnPost_Click(object sender, EventArgs e)
    {
        if (isEdit)
        {
            int     id      = int.Parse(Request.QueryString["ID"]);
            Article article = ArticleManager.GetArticle(id);

            article.Title        = txtTitle.Text.Trim();
            article.SubTitle     = txtSubTitle.Text.Trim();
            article.Abstract     = txtAbstract.Text;
            article.Content      = txtContent.Text;
            article.CopyFrom     = txtCopyFrom.Text.Trim();
            article.Author       = txtAuthor.Text.Trim();
            article.Keywords     = GlobalSettings.FormatKeywords(txtKeywords.Text);
            article.DisplayOrder = int.Parse(txtDisplayOrder.Text);
            article.ArticleMemo  = txtMemo.Text;
            article.Status       = csArticle.SelectedValue;
            if (!string.IsNullOrEmpty(ddlArticleImages.SelectedValue))
            {
                article.Image = int.Parse(ddlArticleImages.SelectedValue);
            }
            if (string.IsNullOrEmpty(txtDate.Text.Trim()))
            {
                article.Date = DateTime.Now;
            }
            else
            {
                article.Date = DateTime.Parse(txtDate.Text.Trim());
            }
            article.UpdateTime = DateTime.Now;
            article.UpdateUser = Profile.AccountInfo.UserID;

            DataActionStatus status = ArticleManager.UpdateArticle(article);

            if (status == DataActionStatus.DuplicateName)
            {
                //mbMsg.ShowMsg("新增资讯失败,存在同名资讯!");
            }
            else if (status == DataActionStatus.UnknownFailure)
            {
                throw new HHException(ExceptionType.Failed, "更新资讯信息失败,请联系管理员!");
            }
            else if (status == DataActionStatus.Success)
            {
                throw new HHException(ExceptionType.Success, "操作成功,已成功更新资讯!");
            }
        }
        else
        {
            Article article = new Article();
            //int parentID = int.Parse(Request.QueryString["catid"]);
            int parentID = ascCategory.SelectedCategoryID;

            article.Category     = parentID;
            article.Title        = txtTitle.Text.Trim();
            article.SubTitle     = txtSubTitle.Text.Trim();
            article.Abstract     = txtAbstract.Text;
            article.Content      = txtContent.Text;
            article.CopyFrom     = txtCopyFrom.Text.Trim();
            article.Author       = txtAuthor.Text.Trim();
            article.Keywords     = GlobalSettings.FormatKeywords(txtKeywords.Text);
            article.DisplayOrder = int.Parse(txtDisplayOrder.Text);
            article.ArticleMemo  = txtMemo.Text;
            article.Status       = csArticle.SelectedValue;
            if (!string.IsNullOrEmpty(ddlArticleImages.SelectedValue))
            {
                article.Image = int.Parse(ddlArticleImages.SelectedValue);
            }
            if (string.IsNullOrEmpty(txtDate.Text.Trim()))
            {
                article.Date = DateTime.Now;
            }
            else
            {
                article.Date = DateTime.Parse(txtDate.Text.Trim());
            }
            article.CreateTime = DateTime.Now;
            article.CreateUser = Profile.AccountInfo.UserID;
            article.UpdateTime = DateTime.Now;
            article.UpdateUser = Profile.AccountInfo.UserID;

            DataActionStatus status;
            ArticleManager.AddArticle(article, out status);

            if (status == DataActionStatus.DuplicateName)
            {
                throw new HHException(ExceptionType.Failed, "新增资讯失败,存在同名资讯!");
            }
            else if (status == DataActionStatus.UnknownFailure)
            {
                throw new HHException(ExceptionType.Failed, "新增资讯失败,请联系管理员!");
            }
            else if (status == DataActionStatus.Success)
            {
                throw new HHException(ExceptionType.Success, "操作成功,已成功增加一个新的资讯!");
            }
        }
    }
Пример #9
0
        public void Test_CreateUpdateDeleteArticle()
        {
            IUserBasic         userBasic          = Test_WorkmateMembershipProvider.CreateUser(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.DummyDataManager);
            MessageBoard       messageBoard       = Test_MessageBoards.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.Random);
            ArticleGroup       articleGroup       = Test_ArticleGroups.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.Random);
            ArticleGroupThread articleGroupThread = Test_ArticleGroupThreads.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, articleGroup, this.Random);

            ArticleManager manager = new ArticleManager(this.DataStore);
            Article        record  = Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, userBasic
                                            , articleGroupThread, messageBoard, this.Random);

            MessageBoardThreadManager messageBoardThreadManager = new MessageBoardThreadManager(this.DataStore);

            Article recordToCompare;

            for (int i = 0; i < this.DefaultUpdateTestIterations; i++)
            {
                PopulateWithRandomValues(record, this.DummyDataManager, this.Random);
                recordToCompare = record;

                manager.Update(record);
                record = manager.GetArticle(record.ArticleId);

                string errors = string.Empty;
                // TODO (Roman): relax datetime comparisons
                Assert.IsTrue(DebugUtility.ArePropertyValuesEqual(record, recordToCompare, out errors), errors);
                Trace.WriteLine("Update test successfull.");
            }

            IArticleModel articleModel = manager.GetArticleModel(record.ArticleId);

            Assert.AreEqual(0, articleModel.TotalComments);

            #region messageboards
            MessageBoardThread messageBoardThread = messageBoardThreadManager.GetMessageBoardThread(articleModel.MessageBoardThreadId);
            Assert.IsNotNull(messageBoardThread);

            MessageManager messageManager = new MessageManager(this.DataStore);

            messageManager.Create(new Message(userBasic, messageBoardThread, "Test Message Subject 1", "Body1"));
            messageManager.Create(new Message(userBasic, messageBoardThread, "Test Message Subject 2", "Body2"));

            Message message = new Message(userBasic, messageBoardThread, "Test Message Subject 3", "Body3");
            messageManager.Create(message);

            articleModel = manager.GetArticleModel(record.ArticleId);
            Assert.AreEqual(3, articleModel.TotalComments);

            Assert.AreEqual(DataRepositoryActionStatus.Success, messageManager.Delete(message).Status);
            articleModel = manager.GetArticleModel(record.ArticleId);
            Assert.AreEqual(2, articleModel.TotalComments);
            #endregion

            #region attachments
            IArticleAttachmentModel articleAttachmentModel = AddAttachment(this.DataStore, this.Application.ApplicationId, articleModel, userBasic, this.Random);
            AddAttachment(this.DataStore, this.Application.ApplicationId, articleModel, userBasic, this.Random);

            DeleteAttachment(this.DataStore, articleModel, articleAttachmentModel.AttachmentId, this.Random);

            AddAttachment(this.DataStore, this.Application.ApplicationId, articleModel, userBasic, this.Random);
            AddAttachment(this.DataStore, this.Application.ApplicationId, articleModel, userBasic, this.Random);

            articleAttachmentModel = AddAttachment(this.DataStore, this.Application.ApplicationId, articleModel, userBasic, this.Random);
            DeleteAttachment(this.DataStore, articleModel, articleAttachmentModel.AttachmentId, this.Random);

            AddAttachment(this.DataStore, this.Application.ApplicationId, articleModel, userBasic, this.Random);
            #endregion

            #region contentnodelevels
            if (articleModel.ContentLevelNodeId.HasValue)
            {
                string newName = "Some Name" + this.Random.Next(10000, 100000);
                CMSContentLevelNodeManager contentLevelNodeManager = new CMSContentLevelNodeManager(this.DataStore);
                contentLevelNodeManager.RenameContentLevelNode(articleModel.ContentLevelNodeId.Value, newName);

                articleModel = manager.GetArticleModel(record.ArticleId);
                Assert.AreEqual(articleModel.ContentLevelNodes[articleModel.ContentLevelNodes.Count - 1], newName);
            }
            #endregion

            Delete(this.DataStore, record);
            Test_ArticleGroups.Delete(this.DataStore, articleGroup);

            Assert.IsNull(messageBoardThreadManager.GetMessageBoardThread(articleModel.MessageBoardThreadId));

            ArticleAttachmentManager articleAttachmentManager = new ArticleAttachmentManager(this.DataStore);
            Assert.IsEmpty(articleAttachmentManager.GetArticleAttachments(articleModel.ArticleId));
        }