예제 #1
0
        public async Task <Article> Create(Article article, string role, string userId)
        {
            if (Convert.ToInt32(role) == (int)RoleType.Writer)
            {
                article.ReviewerDone = false;
                article.PublishDone  = false;
                article.Active       = true;
                article.WriteDone    = true;
                if (article.IsDraft)
                {
                    article.WriteDone = false;
                }
                article.CreatedDate   = DateTime.UtcNow;
                article.UpdateDate    = DateTime.UtcNow;
                article.PublishedDate = null;

                article.Id = await _repository.Create(article, role);

                await _repository.CreateArticleUser(role, userId, article.Id);

                if (!article.IsDraft)
                {
                    var message = new ArticleMessage {
                        Id = article.Id, Title = article.Title, MessageType = MessageType.WriterDone
                    };
                    this.CreateArticleNotification(message);
                }
            }
            else
            {
                article = null;
            }

            return(article);
        }
예제 #2
0
파일: CnBlogsFeed.cs 프로젝트: MM1314/QG
        private void GetTopCnblogsFeed(int m_topNum)
        {
            try
            {
                var html   = GetRemoteUri(s_cnblogsIndexUri, Encoding.UTF8);
                var matchs = s_cnblogsIndexRegex.Matches(html);
                var i      = 0;
                s_articles = new List <ArticleMessage>();
                foreach (Match match in matchs)
                {
                    if (i >= m_topNum)
                    {
                        break;
                    }
                    var article = new ArticleMessage
                    {
                        Title       = match.Groups[2].Value,
                        Url         = match.Groups[1].Value,
                        Description = match.Groups[3].Value
                    };

                    if (i == 0)
                    {
                        article.PicUrl = s_defaultBigPicUri;
                    }
                    else
                    {
                        var matchPic = s_picUrlRegex.Match(article.Description);
                        if (matchPic.Success)
                        {
                            article.PicUrl = matchPic.Groups[1].Value;
                        }
                        else
                        {
                            article.PicUrl = s_defaultSmallPicUri;
                        }
                    }

                    s_articles.Add(article);

                    i += 1;
                }

                s_outDate = DateTime.Now.AddMilliseconds(s_timeout);
            }
            catch (Exception ex)
            {
                s_articles = null;
                s_outDate  = DateTime.Now;
#if DEBUG
                throw ex;
#endif
            }

            //return s_articles;
        }
예제 #3
0
        public bool CreateArticleNotification(ArticleMessage message)
        {
            try
            {
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
                CloudQueueClient    queueClient    = storageAccount.CreateCloudQueueClient();
                CloudQueue          queue          = queueClient.GetQueueReference("mail-notification");
                queue.CreateIfNotExistsAsync();
                string messsage = JsonSerializer.Serialize(message);
                queue.AddMessageAsync(new CloudQueueMessage(messsage));

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #4
0
        public void Handle(CreateArticleMessageCommand command)
        {
            var article = ArticleRepository.Load(command.ArticleId);

            Guard.IsNotNull(article, "article");
            // 用户评论
            if (command.UserId != null)
            {
                // 文章留言
                var user = UserRepository.Get((int)command.UserId);
                Guard.IsNotNull(user, "user");

                // 用户留言
                var userReply = new ArticleMessage()
                {
                    Content      = HttpUtility.HtmlEncode(command.Content),
                    Article      = article,
                    CreateDate   = DateTime.Now,
                    IsShow       = command.IsShow,
                    User         = user,
                    LastDateTime = DateTime.Now
                };
                ArticleMessageRepository.Save(userReply);
            }
            else
            {
                // 匿名用户留言
                var reply = new ArticleMessage()
                {
                    Content      = HttpUtility.HtmlEncode(command.Content),
                    Email        = command.Email,
                    Article      = article,
                    NickName     = command.NickName,
                    WebSiteUrl   = command.WebSiteUrl,
                    CreateDate   = DateTime.Now,
                    IsShow       = command.IsShow,
                    LastDateTime = DateTime.Now
                };
                ArticleMessageRepository.Save(reply);
            }
        }
예제 #5
0
        public async Task <Article> Update(int id, Article article, string role, string userId)
        {
            var model = await _repository.GetById(id, role);

            if (Convert.ToInt32(role) == (int)RoleType.Writer)
            {
                if (model.WriteDone)
                {
                    //Article Write completed already
                    throw new InvalidOperationException("Article Write completed already!!");
                }

                model.Title       = article.Title;
                model.Description = article.Description;
                model.Topics      = article.Topics;
                model.Tags        = article.Tags;
                model.UpdateDate  = DateTime.UtcNow;
                model.WriteDone   = false;

                await _repository.CreateArticleUser(role, userId, article.Id);

                await _repository.Update(id, model, role, userId);

                if (!article.IsDraft)
                {
                    model.WriteDone = true;
                    //Article message Queue
                    var message = new ArticleMessage {
                        Id = model.Id, Title = model.Title, MessageType = MessageType.WriterDone
                    };
                    this.CreateArticleNotification(message);
                }
            }
            else if (Convert.ToInt32(role) == (int)RoleType.Reviewer)
            {
                if (model.ReviewerDone)
                {
                    throw new InvalidOperationException("Article Reviewe completed already.!!");
                }

                model.ReviewerDone     = true;
                model.UpdateDate       = DateTime.UtcNow;
                model.ReviewerComments = article.ReviewerComments;

                await _repository.CreateArticleUser(role, userId, article.Id);

                await _repository.Update(id, model, role, userId);

                //Article message Queue
                var message = new ArticleMessage {
                    Id = article.Id, Title = article.Title, MessageType = MessageType.ReviewerDone
                };
                this.CreateArticleNotification(message);
            }
            else if (Convert.ToInt32(role) == (int)RoleType.Editor)
            {
                if (model.EditorDone)
                {
                    throw new InvalidOperationException("Article Editor completed already.!!");
                }

                model.EditorDone     = true;
                model.UpdateDate     = DateTime.UtcNow;
                model.EditorComments = article.EditorComments;
                await _repository.CreateArticleUser(role, userId, article.Id);

                await _repository.Update(id, model, role, userId);

                //Article message Queue
                var message = new ArticleMessage {
                    Id = article.Id, Title = article.Title, MessageType = MessageType.EditorDone
                };
                this.CreateArticleNotification(message);
            }
            else if (Convert.ToInt32(role) == (int)RoleType.Publisher)
            {
                if (model.PublishDone)
                {
                    throw new InvalidOperationException("Article Publish completed already.!!");
                }

                model.PublishDone   = true;
                model.UpdateDate    = DateTime.UtcNow;
                model.PublishedDate = DateTime.UtcNow;
                model.Tags          = article.Tags;

                await _repository.CreateArticleUser(role, userId, article.Id);

                await _repository.Update(id, model, role, userId);

                //Article message Queue
                var message = new ArticleMessage {
                    Id = article.Id, Title = article.Title, MessageType = MessageType.PublisherDone
                };
                this.CreateArticleNotification(message);
            }

            return(model);
        }
        public void Handle(CreateArticleMessageReplyCommand command)
        {
            var articleMessage = ArticleMessageRepository.Get(command.ArticleMessageId);

            Guard.IsNotNull(articleMessage, "articleMessage");

            if (command.UserId != null)
            {
                // 用户留言回复
                var user = UserRepository.Get((int)command.UserId);
                Guard.IsNotNull(user, "user");
                //// 用户留言
                //var reply = new ArticleReplyMessage()
                //{
                //    Content = HttpUtility.HtmlEncode(command.Content),
                //    CreateDate = DateTime.Now,
                //    IsShow = command.IsShow,
                //    User = user
                //    //ArticleMessage = articleMessage
                //};
                // 用户留言
                var reply = new ArticleMessage()
                {
                    Content            = HttpUtility.HtmlEncode(command.Content),
                    CreateDate         = DateTime.Now,
                    IsShow             = command.IsShow,
                    User               = user,
                    Article            = articleMessage.Article,
                    BaseArticleMessage = articleMessage,
                    LastDateTime       = DateTime.Now
                };
                // articleMessage.AddArticleMessage(reply);


                //if(command.BaseArticleReplyMessageId!=null)
                //{
                //    var baseArticleReplyMessage =
                //        ArticleReplyMessageRepository.Get(int.Parse(command.BaseArticleReplyMessageId.ToString()));
                //    Guard.IsNotNull(baseArticleReplyMessage, "baseArticleReplyMessage");
                //    reply.BaseArticleReplyMessage = baseArticleReplyMessage;
                //}
                //  articleMessage.ArticleReplyMessages.Add(reply);
                ArticleMessageRepository.Save(reply);
            }
            else
            {
                var reply = new ArticleMessage()
                {
                    NickName           = command.NickName,
                    Email              = command.Email,
                    WebSiteUrl         = command.WebSiteUrl,
                    Content            = HttpUtility.HtmlEncode(command.Content),
                    CreateDate         = DateTime.Now,
                    IsShow             = command.IsShow,
                    BaseArticleMessage = articleMessage,
                    Article            = articleMessage.Article,
                    LastDateTime       = DateTime.Now
                };
                // articleMessage.AddArticleReplyMessage(reply);
                ArticleMessageRepository.Save(reply);
            }
        }
예제 #7
0
        private ArticleMessageDto CreateArticleMessageDto(
            Article a,
            ArticleMessage am,
            User u)
        {
            //var doto = new ArticleMessageDto()
            //          {
            //              Id = am.Id,
            //              Content = HttpUtility.HtmlDecode(am.Content),
            //              CreateDate = am.CreateDate,
            //              UserImg = DefaultUserHeadImg
            //          };

            //if (u != null)
            //{
            //    doto.UserId = u.Id;
            //    doto.NickName = u.RealName;
            //    doto.UserImg = u.SmallImgHead;
            //    doto.UserDomain = u.Domain;
            //}
            //else
            //{
            //    doto.NickName = am.NickName;
            //}



            //var articleReplyMessagesList = (from ar in ArticleMessageDbProxyRepository.FindAll()
            //                                from  arm in ar.ArticleMessages
            //                                let ra =ar.RootArticleMessage
            //                                let ba = ar.BaseArticleMessage
            //                                let aru = ar.User
            //                                let bau = ba.User
            //                                where ra.Id == am.Id
            //                                select CreateArticleReplyMessageDto(ar,arm,aru,bau)).ToList();


            ////var articleReplyMessageList = (from qam in am.ArticleMessages
            ////                               let qu = qam.User
            ////                               let bm = qam.BaseArticleMessage
            ////                               let tu = bm.User
            ////                               select CreateArticleReplyMessageDto(am,bm, qu, tu)).ToList();



            //doto.ArticleReplyMessages = articleReplyMessagesList;

            //// 加载留言的所有回复
            //var articleReplyMessageList = (from ar in ArticleReplyMessageDbProxyRepository.FindAll()
            //                               let aru = ar.User
            //                               let bam = ar.BaseArticleMessage
            //                               where bam.Id == am.Id
            //                               select ar).ToList();

            //// 加载留言一级回复
            //var articleReplyMessageOneList = articleReplyMessageList.Where(x => x.BaseArticleReplyMessage == null).ToList();
            //// 加载留言第二级回复
            //var articleReplyMessageTwoList = articleReplyMessageList.Where(x => x.BaseArticleReplyMessage != null).ToList();

            //// 加载留言回复数据
            //articleReplyMessageOneList.ForEach(x => doto.ArticleReplyMessages.Add(
            //    CreateArticleReplyMessageDto(x, x.User, articleReplyMessageTwoList)));


            //articleReplyMessageList.ForEach(x=>
            //                                    {

            //                                        doto.ArticleReplyMessages=
            //                                    });

            //if (amr != null)
            //{

            //    amr.ForEach(x =>
            //                    {
            //                       x.ArticleReplyMessage.Add(new ArticleReplyMessageDto()
            //                                                     {
            //                                                         Content = HttpUtility.HtmlDecode(x.Content),
            //                                                     });

            //                    });



            //    doto.ArticleReplyMessages

            //        .. = new BaseArticleMessageDto();
            //    if (bam.User != null)
            //    {
            //        doto.BaseArticleMessage.UserId = bam.User.Id;
            //        doto.BaseArticleMessage.NickName = bam.User.RealName;
            //        doto.BaseArticleMessage.Domain = bam.User.Domain;
            //    }
            //    else
            //    {
            //        doto.BaseArticleMessage.NickName = bam.NickName;
            //    }
            //}
            var dto = new ArticleMessageDto()
            {
                Content    = HttpUtility.HtmlDecode(am.Content),
                CreateDate = am.CreateDate,
                Id         = am.Id,
                ArticleId  = a.Id
            };

            // 评论用户信息
            if (u != null)
            {
                dto.UserArticleMessageDto = new UserArticleMessageDto()
                {
                    NickName   = u.RealName,
                    UserId     = u.Id,
                    UserImg    = u.SmallImgHead,
                    UserDomain = u.Domain
                };
            }
            else
            {
                dto.UserArticleMessageDto = new UserArticleMessageDto()
                {
                    NickName = am.NickName
                };
            }

            // 评论对象用户信息
            if (am.BaseArticleMessage != null)
            {
                dto.BaseArticleMessageId = am.BaseArticleMessage.Id;
                var user = am.BaseArticleMessage.User;
                if (user != null)
                {
                    dto.TagerUserArticleMessageDto = new TagerUserArticleMessageDto()
                    {
                        NickName   = user.RealName,
                        UserId     = user.Id,
                        UserImg    = user.SmallImgHead,
                        UserDomain = user.Domain
                    };
                }
                else
                {
                    dto.TagerUserArticleMessageDto = new TagerUserArticleMessageDto()
                    {
                        NickName = am.BaseArticleMessage.NickName
                    };
                }
            }
            return(dto);
        }