コード例 #1
0
ファイル: CommentService.cs プロジェクト: Lietuva2/LT2
        public bool DeleteCommentComment(ICommentable entity, MongoObjectId commentId, MongoObjectId commentCommentId)
        {
            if (entity == null)
            {
                return(false);
            }

            var comment = entity.Comments.Where(c => c.Id == commentId).SingleOrDefault();

            if (comment == null)
            {
                return(false);
            }

            var commentComment = comment.Comments.Where(c => c.Id == commentCommentId).SingleOrDefault();

            if (commentComment == null || (commentComment.UserObjectId != CurrentUser.Id && CurrentUser.Role != UserRoles.Admin))
            {
                return(false);
            }

            comment.Comments.Remove(commentComment);
            UpdateEntity(entity);

            bus.Send(new CommentDeletedCommand()
            {
                CommentId    = commentCommentId,
                EntryType    = entity.EntryType,
                UserObjectId = CurrentUser.Id
            });

            return(true);
        }
コード例 #2
0
ファイル: ProjectService.cs プロジェクト: Lietuva2/LT2
 private Project GetProject(MongoObjectId projectId)
 {
     using (var noSqlSession = noSqlSessionFactory())
     {
         return(noSqlSession.GetById <Project>(projectId));
     }
 }
コード例 #3
0
ファイル: CommentService.cs プロジェクト: Lietuva2/LT2
        public Liking UndoLikeComment(ICommentable entity, MongoObjectId commentId, MongoObjectId parentCommentId)
        {
            Comment comment, parentComment = null;

            if (parentCommentId != null)
            {
                parentComment = GetComment(entity, parentCommentId);
                comment       = parentComment.Comments.Where(c => c.Id == commentId).SingleOrDefault();
            }
            else
            {
                comment = GetComment(entity, commentId);
            }

            if (!comment.SupportingUserIds.Contains(CurrentUser.Id))
            {
                return(null);
            }

            comment.SupportingUserIds.Remove(CurrentUser.Id);

            UpdateEntity(entity);
            var command = new CommentUnlikedCommand
            {
                ObjectId     = entity.Id,
                CommentId    = commentId,
                EntryType    = entity.EntryType,
                UserObjectId = CurrentUser.Id
            };

            bus.Send(command);

            return(GetCommentViewFromComment(entity.Id, comment, parentCommentId, entity.EntryType).Liking);
        }
コード例 #4
0
ファイル: SearchService.cs プロジェクト: Lietuva2/LT2
        private Lucene.Net.Documents.Document CreateDoc(MongoObjectId id, string text, string subject, EntryTypes type)
        {
            Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();

            doc.Add(new Lucene.Net.Documents.Field(
                        "text",
                        new System.IO.StringReader(text.StripHtml())));

            doc.Add(new Lucene.Net.Documents.Field(
                        "id",
                        id.ToString(),
                        Lucene.Net.Documents.Field.Store.YES,
                        Lucene.Net.Documents.Field.Index.UN_TOKENIZED));

            doc.Add(new Lucene.Net.Documents.Field(
                        "subject",
                        subject,
                        Lucene.Net.Documents.Field.Store.YES,
                        Lucene.Net.Documents.Field.Index.UN_TOKENIZED));

            doc.Add(new Lucene.Net.Documents.Field(
                        "type",
                        type.ToString(),
                        Lucene.Net.Documents.Field.Store.YES,
                        Lucene.Net.Documents.Field.Index.UN_TOKENIZED));

            // For the highlighter, store the raw text
            doc.Add(new Lucene.Net.Documents.Field(
                        "raw_text",
                        text.StripHtml(),
                        Lucene.Net.Documents.Field.Store.YES,
                        Lucene.Net.Documents.Field.Index.UN_TOKENIZED));

            return(doc);
        }
コード例 #5
0
        public virtual CommentView AddNewComment(MongoObjectId id, string text, EmbedModel embed, ForAgainst forAgainst = ForAgainst.Neutral, MongoObjectId versionId = null)
        {
            var entity  = GetEntity(id);
            var comment = commentService.AddNewComment(entity, forAgainst, text, embed, versionId);

            SendCommentCommand(entity, GetAddNewCommentActionType(), comment);
            return(comment);
        }
コード例 #6
0
        public CommentView AddNewCommentToComment(MongoObjectId id, MongoObjectId commentId, string text, EmbedModel embed)
        {
            var entity  = GetEntity(id);
            var comment = commentService.AddNewCommentToComment(entity, commentId, text, embed);

            SendCommentCommand(entity, ActionTypes.CommentCommented, comment);
            return(comment);
        }
コード例 #7
0
        public Liking LikeComment(MongoObjectId id, MongoObjectId commentId, MongoObjectId parentCommentId)
        {
            var entity  = GetEntity(id);
            var comment = commentService.LikeComment(entity, commentId, parentCommentId);

            SendCommentCommand(entity, string.IsNullOrEmpty(parentCommentId) ? GetLikeCommentActionType() : ActionTypes.CommentCommentLiked, comment);
            return(comment.Liking);
        }
コード例 #8
0
ファイル: ProjectService.cs プロジェクト: Lietuva2/LT2
 private Idea GetIdea(MongoObjectId ideaId, params string[] additionalFields)
 {
     string[] defaultFields = new string[] { "_id", "Subject", "State", "Deadline", "VotesCount", "RequiredVotes" };
     additionalFields = defaultFields.Union(additionalFields).ToArray();
     using (var noSqlSession = noSqlSessionFactory())
     {
         return(noSqlSession.Find <Idea>(Query.EQ("_id", ideaId)).SetFields(additionalFields).SingleOrDefault());
     }
 }
コード例 #9
0
ファイル: CommentService.cs プロジェクト: Lietuva2/LT2
        private Comment GetComment(ICommentable entity, MongoObjectId commentId, MongoObjectId parentCommentId)
        {
            if (!string.IsNullOrEmpty(parentCommentId))
            {
                var parentComment = GetComment(entity, parentCommentId);
                return(parentComment.Comments.SingleOrDefault(c => c.Id == commentId));
            }

            return(GetComment(entity, commentId));
        }
コード例 #10
0
ファイル: CommentService.cs プロジェクト: Lietuva2/LT2
        private string GetUserFullName(MongoObjectId id)
        {
            using (var session = noSqlSessionFactory())
            {
                var user = session.Find <Data.MongoDB.User>(Query.EQ("_id", id)).SetFields("FirstName", "LastName").SingleOrDefault();
                if (user != null)
                {
                    return(user.FullName);
                }

                return(string.Empty);
            }
        }
コード例 #11
0
ファイル: CommentService.cs プロジェクト: Lietuva2/LT2
        public CommentView LikeComment(ICommentable entity, MongoObjectId commentId, MongoObjectId parentCommentId)
        {
            Comment comment = GetComment(entity, commentId, parentCommentId);

            if (comment == null || comment.SupportingUserIds.Contains(CurrentUser.Id))
            {
                return(null);
            }

            comment.SupportingUserIds.Add(CurrentUser.Id);

            UpdateEntity(entity);

            return(GetCommentViewFromComment(entity.Id, comment, parentCommentId, entity.EntryType));
        }
コード例 #12
0
ファイル: CommentService.cs プロジェクト: Lietuva2/LT2
        public CommentView AddNewCommentToComment(ICommentable entity, MongoObjectId commentId, string text, EmbedModel embed)
        {
            if (CurrentUser.RequireUniqueAuthentication && !CurrentUser.IsUnique)
            {
                throw new UserNotUniqueException();
            }

            var comment = GetComment(entity, commentId);

            if (comment == null)
            {
                return(null);
            }
            comment.LastNumber++;
            var cComment = new Comment
            {
                Date         = DateTime.Now,
                Text         = text,
                UserFullName = CurrentUser.FullName,
                UserObjectId = CurrentUser.Id,
                Number       = comment.Number + comment.LastNumber
            };

            if (embed != null && !embed.IsEmpty)
            {
                cComment.Embed = new Data.MongoDB.Embed();
                cComment.Embed.InjectFrom(embed);
                cComment.Embed.Title       = cComment.Embed.Title.Sanitize();
                cComment.Embed.Description = cComment.Embed.Description.Sanitize();
            }

            comment.Comments.Add(cComment);

            UpdateEntity(entity);

            var model = GetCommentViewFromComment(entity.Id, cComment, commentId, entity.EntryType,
                                                  entity.GetRelatedVersionNumber(comment.RelatedVersionId));

            model.SubscribeMain = ActionService.Subscribe(entity.Id, CurrentUser.DbId.Value, entity.EntryType);
            model.Subscribe     = ActionService.Subscribe(comment.Id, CurrentUser.DbId.Value);

            return(model);
        }
コード例 #13
0
ファイル: SearchService.cs プロジェクト: Lietuva2/LT2
        public void DeleteIndex(MongoObjectId id)
        {
            Lucene.Net.Index.IndexModifier modifier = null;

            try
            {
                if (searcher != null)
                {
                    try
                    {
                        searcher.Close();
                    }
                    catch (Exception e)
                    {
                        logger.Error("Exception closing lucene searcher:" + e.Message, e);
                        throw;
                    }
                    searcher = null;
                }

                modifier =
                    new Lucene.Net.Index.IndexModifier(CustomAppSettings.SearchIndexFolder, analyzer, false);

                // same as build, but uses "modifier" instead of write.
                // uses additional "where" clause for bugid

                modifier.DeleteDocuments(new Lucene.Net.Index.Term("id", id.ToString()));
            }
            catch (Exception e)
            {
                logger.Error("Exception closing lucene searcher:" + e.Message, e);
            }
            finally
            {
                if (modifier != null)
                {
                    modifier.Flush();
                    modifier.Close();
                }
            }
        }
コード例 #14
0
ファイル: SiteMongoDbSession.cs プロジェクト: Lietuva2/LT2
        public FileViewModel GetFile <T>(MongoObjectId id)
        {
            var file = db.GridFS.FindOneById(id);

            if (file != null)
            {
                using (var stream = file.OpenRead())
                {
                    var bytes = new byte[stream.Length];
                    stream.Read(bytes, 0, (int)stream.Length);

                    return(new FileViewModel
                    {
                        ContentType = file.ContentType,
                        File = bytes
                    });
                }
            }

            return(null);
        }
コード例 #15
0
ファイル: ProjectService.cs プロジェクト: Lietuva2/LT2
        private string GetUserFullName(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(CommonStrings.All);
            }

            if (id == TodoAssignedTo.Unasigned)
            {
                return(CommonStrings.Unassigned);
            }

            using (var session = noSqlSessionFactory())
            {
                MongoObjectId mid  = id;
                var           user = session.Find <Data.MongoDB.User>(Query.EQ("_id", mid)).SetFields("FirstName", "LastName").SingleOrDefault();
                if (user != null)
                {
                    return(user.FullName);
                }

                return(string.Empty);
            }
        }
コード例 #16
0
ファイル: SiteMongoDbSession.cs プロジェクト: Lietuva2/LT2
 public void UpdateById <T>(MongoObjectId id, IMongoUpdate update)
 {
     db.GetCollection <T>().Update(Query.EQ("_id", id), update);
 }
コード例 #17
0
ファイル: SiteMongoDbSession.cs プロジェクト: Lietuva2/LT2
 public T FindByIdAndModify <T>(MongoObjectId id, IMongoUpdate update)
 {
     return(db.GetCollection <T>().FindAndModify(Query.EQ("_id", id), SortBy.Ascending("_id"), update, true).GetModifiedDocumentAs <T>());
 }
コード例 #18
0
        public ExpandableList <CommentView> GetCommentsByVersion(MongoObjectId id, MongoObjectId versionId, int pageNumber, ForAgainst?posOrNeg = null)
        {
            var entity = GetEntity(id);

            return(commentService.GetCommentsByVersion(entity, versionId, pageNumber, posOrNeg));
        }
コード例 #19
0
        public ExpandableList <CommentView> GetCommentsMostRecent(MongoObjectId id, int pageNumber, ForAgainst?posOrNeg = null, bool orderResultAsc = false)
        {
            var entity = GetEntity(id);

            return(commentService.GetCommentsMostRecent(entity, pageNumber, posOrNeg, orderResultAsc));
        }
コード例 #20
0
        public ExpandableList <CommentView> GetCommentsMostSupported(MongoObjectId id, int pageNumber, ForAgainst?posOrNeg = null)
        {
            var entity = GetEntity(id);

            return(commentService.GetCommentsMostSupported(entity, pageNumber, posOrNeg));
        }
コード例 #21
0
 protected virtual ICommentable GetEntity(MongoObjectId id)
 {
     throw new NotImplementedException();
 }
コード例 #22
0
ファイル: SearchService.cs プロジェクト: Lietuva2/LT2
        public void UpdateIndex(MongoObjectId id, EntryTypes type)
        {
            if (id == null)
            {
                return;
            }

            Lucene.Net.Index.IndexModifier modifier = null;
            try
            {
                if (searcher != null)
                {
                    try
                    {
                        searcher.Close();
                    }
                    catch (Exception e)
                    {
                        logger.Error("Exception closing lucene searcher:" + e.Message, e);
                        throw;
                    }
                    searcher = null;
                }

                modifier =
                    new Lucene.Net.Index.IndexModifier(CustomAppSettings.SearchIndexFolder, analyzer, false);

                // same as build, but uses "modifier" instead of write.
                // uses additional "where" clause for bugid

                modifier.DeleteDocuments(new Lucene.Net.Index.Term("id", id.ToString()));

                using (var noSqlSession = noSqlSessionFactory())
                {
                    switch (type)
                    {
                    case EntryTypes.Idea:
                        var idea = noSqlSession.GetById <Idea>(id);
                        if (idea != null)
                        {
                            modifier.AddDocument(CreateDoc(id, CreateSearchText(idea), idea.Subject, type));
                        }
                        break;

                    case EntryTypes.Issue:
                        var issue = noSqlSession.GetById <Issue>(id);
                        if (issue != null)
                        {
                            modifier.AddDocument(CreateDoc(id, CreateSearchText(issue), issue.Subject, type));
                        }
                        break;

                    case EntryTypes.User:
                        var user = noSqlSession.GetById <User>(id);
                        if (user != null)
                        {
                            modifier.AddDocument(CreateDoc(id, user.FullName, user.FullName, type));
                        }
                        break;

                    case EntryTypes.Organization:
                        var org = noSqlSession.GetById <Organization>(id);
                        if (org != null)
                        {
                            modifier.AddDocument(CreateDoc(id, org.Name, org.Name, type));
                        }
                        break;

                    case EntryTypes.Problem:
                        var prob = noSqlSession.GetById <Problem>(id);
                        if (prob != null)
                        {
                            modifier.AddDocument(CreateDoc(id, CreateSearchText(prob), prob.Text.LimitLength(100), type));
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                logger.Error("exception updating Lucene index: " + e.Message, e);
            }
            finally
            {
                try
                {
                    if (modifier != null)
                    {
                        modifier.Flush();
                        modifier.Close();
                    }
                }
                catch (Exception e)
                {
                    logger.Error("exception updating Lucene index: " + e.Message, e);
                }
            }
        }
コード例 #23
0
ファイル: CommentService.cs プロジェクト: Lietuva2/LT2
        public ExpandableList <CommentView> GetCommentsByVersion(ICommentable entity, MongoObjectId versionId, int pageNumber, ForAgainst?posOrNeg = null)
        {
            var comments = new List <CommentView>();
            var query    = entity.Comments.AsEnumerable();

            if (posOrNeg.HasValue)
            {
                query = query.Where(c => c.PositiveOrNegative == posOrNeg);
            }

            foreach (var comment in query.Where(c => c.RelatedVersionId == versionId).OrderByDescending(c => c.SupportingUserIds.Count).ThenByDescending(c => c.Date).GetExpandablePage(pageNumber, CustomAppSettings.PageSizeComment))
            {
                comments.Add(GetCommentViewWithComments(entity, comment));
            }

            return(new ExpandableList <CommentView>(comments, CustomAppSettings.PageSizeComment));
        }
コード例 #24
0
ファイル: CommentService.cs プロジェクト: Lietuva2/LT2
        public virtual CommentView AddNewComment(ICommentable entity, ForAgainst forAgainst, string text, EmbedModel embed, MongoObjectId versionId = null)
        {
            if (CurrentUser.RequireUniqueAuthentication && !CurrentUser.IsUnique)
            {
                throw new UserNotUniqueException();
            }

            if (entity.Id == CurrentUser.Id)
            {
                forAgainst = ForAgainst.Neutral;
            }

            entity.LastNumber++;
            var comment = new Comment
            {
                Date               = DateTime.Now,
                Text               = text,
                UserFullName       = CurrentUser.FullName,
                UserObjectId       = CurrentUser.Id,
                RelatedVersionId   = versionId,
                PositiveOrNegative = forAgainst,
                Number             = entity.LastNumber.ToString() + "."
            };

            if (embed != null && !embed.IsEmpty)
            {
                comment.Embed = new Data.MongoDB.Embed();
                comment.Embed.InjectFrom(embed);

                comment.Embed.Title       = comment.Embed.Title.Sanitize();
                comment.Embed.Description = comment.Embed.Description.Sanitize();
            }
            entity.Comments.Add(comment);
            UpdateEntity(entity);

            var model = GetCommentViewFromComment(entity.Id, comment, null, entity.EntryType,
                                                  entity.GetRelatedVersionNumber(comment.RelatedVersionId));


            model.SubscribeMain = ActionService.Subscribe(entity.Id, CurrentUser.DbId.Value, entity.EntryType);
            model.Subscribe     = ActionService.Subscribe(comment.Id, CurrentUser.DbId.Value);

            return(model);
        }
コード例 #25
0
ファイル: ProjectService.cs プロジェクト: Lietuva2/LT2
 private Idea GetIdea(MongoObjectId ideaId)
 {
     return(GetIdea(ideaId, new string[] {}));
 }
コード例 #26
0
ファイル: CommentService.cs プロジェクト: Lietuva2/LT2
        public CommentView GetCommentViewFromComment(string objectId, Data.MongoDB.Comment comment, MongoObjectId parentId, EntryTypes type, string relatedVersion = null)
        {
            var hiddenText = Globalization.Resources.Comments.Resource.CommentHidden;
            var model      = new CommentView
            {
                CommentText           = comment.IsHidden ? hiddenText : comment.Text.NewLineToHtml().ActivateLinks() ?? string.Empty,
                CommentDate           = comment.Date,
                AuthorFullName        = comment.UserFullName,
                AuthorObjectId        = comment.UserObjectId,
                ForAgainst            = comment.PositiveOrNegative,
                ProfilePictureThumbId = UserService.GetProfilePictureThumbId(comment.UserObjectId),
                Liking = new Liking()
                {
                    EntryId         = objectId,
                    ParentId        = parentId,
                    CommentId       = comment.Id,
                    Type            = type,
                    LikesCount      = GetLikesCountString(comment.SupportingUserIds.Count),
                    IsLikeVisible   = !comment.IsHidden && CurrentUser.IsAuthenticated && !comment.SupportingUserIds.Contains(CurrentUser.Id) && comment.UserObjectId != CurrentUser.Id,
                    IsUnlikeVisible = !comment.IsHidden && CurrentUser.IsAuthenticated && comment.SupportingUserIds.Contains(CurrentUser.Id) && comment.UserObjectId != CurrentUser.Id
                },
                Id = comment.Id,
                IsCreatedByCurrentUser = CurrentUser.IsAuthenticated && (comment.UserObjectId == CurrentUser.Id || CurrentUser.Role == UserRoles.Admin),
                IsCommentable          = type != EntryTypes.Problem && CurrentUser.IsAuthenticated,
                ParentId       = parentId,
                EntryId        = objectId,
                VersionId      = comment.RelatedVersionId,
                RelatedVersion = relatedVersion,
                EntryType      = type,
                IsHidden       = comment.IsHidden,
                Number         = comment.Number,
                Embed          = comment.Embed != null ? new EmbedModel()
                {
                    Url           = comment.Embed.Url,
                    Author_Name   = comment.Embed.Author_Name,
                    Author_Url    = comment.Embed.Author_Url,
                    Cache_Age     = comment.Embed.Cache_Age,
                    Description   = comment.Embed.Description,
                    Height        = comment.Embed.Height,
                    Html          = comment.Embed.Type != "link" ? comment.Embed.Html : string.Empty,
                    Provider_Name = comment.Embed.Provider_Name,
                    Provider_Url  = comment.Embed.Provider_Url,
                    Thumbnail_Url = comment.Embed.Thumbnail_Url,
                    Title         = comment.Embed.Title,
                    Type          = comment.Embed.Type,
                    Version       = comment.Embed.Version,
                    Width         = comment.Embed.Width
                } : null
            };

            if (CurrentUser.IsAuthenticated && parentId == null)
            {
                model.Subscribe = ActionService.IsSubscribed(comment.Id, CurrentUser.DbId.Value);
            }
            //model.Liking.IsCreatedByCurrentUser = CurrentUser.IsAuthenticated && comment.UserObjectId == CurrentUser.Id;

            return(model);
        }
コード例 #27
0
        public Liking UndoLikeComment(MongoObjectId id, MongoObjectId commentId, MongoObjectId parentCommentId)
        {
            var entity = GetEntity(id);

            return(commentService.UndoLikeComment(entity, commentId, parentCommentId));
        }
コード例 #28
0
        public bool DeleteComment(MongoObjectId id, MongoObjectId commentId)
        {
            var entity = GetEntity(id);

            return(commentService.DeleteComment(entity, commentId));
        }
コード例 #29
0
ファイル: CommentService.cs プロジェクト: Lietuva2/LT2
 private Comment GetComment(ICommentable entity, MongoObjectId commentId)
 {
     return(entity.Comments.Where(c => c.Id == commentId).SingleOrDefault());
 }