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); }
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); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { string retVal = "<unknown>"; ICommentable commentable = value as ICommentable; if (commentable != null) { if (commentable.Comment != null) { retVal = commentable.Comment.Trim(); int index = retVal.IndexOf("\n"); if (index > 0) { retVal = retVal.Substring(0, index) + "..."; } } else { retVal = ""; } } return(retVal); }
public SimpleListContainerModel GetCommentSupporters(int pageNumber, ICommentable entity, string commentId, string parentId) { Comment comment; if (!string.IsNullOrEmpty(parentId)) { var parent = GetComment(entity, parentId); comment = parent.Comments.Where(c => c.Id == commentId).SingleOrDefault(); } else { comment = GetComment(entity, commentId); } if (comment == null) { return(new SimpleListContainerModel()); } var result = comment.SupportingUserIds.Select( i => new SimpleListModel { Id = i, Subject = GetUserFullName(i) }).OrderByDescending(i => i.Subject) .GetExpandablePage(pageNumber, CustomAppSettings.PageSizeList).ToList(); result.ForEach(r => r.Type = EntryTypes.User); var simpleList = new SimpleListContainerModel(); simpleList.List = new ExpandableList <SimpleListModel>(result, CustomAppSettings.PageSizeList); return(simpleList); }
/// <summary> /// Sets the default control size, according to its contents /// </summary> /// <param name="control"></param> /// <param name="location"></param> /// <returns>return>The location where filling should be continued</returns> private Point SetSizeAndLocation(ModelControl control, Point location) { // Set the control location control.ComputedPositionAndSize = true; control.Location = location; Point retVal = control.Location; // Increase control size according to title retVal = SetText( control, control.ModelName, control.Bold, Color.Black, retVal); // Increase control size according to comment ICommentable commentable = control.TypedModel as ICommentable; if (commentable != null) { retVal = SetText( control, commentable.Comment, control.Italic, Color.Green, retVal); } // Registers the control to update the panel size RegisterControl(control); return(retVal); }
private static void SaveComments(ICommentable commentable, CodeWriter writer) { foreach (String comment in commentable.Comments) { writer.WriteLine("/// {0}", comment); } }
/// <summary> /// Provides the description of a variable /// </summary> /// <param name="variable">The variable to describe</param> /// <returns></returns> private void CreateVariableHeader(IVariable variable) { AddTable(new string[] { variable.Name }, new int[] { 40, 80 }); ICommentable commentable = variable as ICommentable; if (commentable != null && !string.IsNullOrEmpty(commentable.Comment)) { AddRow(commentable.Comment); } if (!string.IsNullOrEmpty(variable.TypeName)) { AddTableHeader("Type"); AddRow(variable.TypeName); } ReqRelated reqRelated = variable as ReqRelated; if (reqRelated != null) { AddTableHeader("Related requirements"); AddRow(GetRequirementsAsString(reqRelated.Requirements)); } }
public CommentView ShowComment(ICommentable entity, string commentId, string parentId) { Comment comment = GetComment(entity, commentId, parentId); comment.IsHidden = false; UpdateEntity(entity); return(GetCommentViewWithComments(entity, comment, parentId)); }
public void UpdateEntity(ICommentable entity) { using (var noSqlSession = noSqlSessionFactory()) { entity.ModificationDate = DateTime.Now; noSqlSession.Update(entity); } }
public void Link() { ICommentable o = GetTarget(); if (o != null) { o.Comment = this; } }
/// <summary> /// Comments an Icommentable /// </summary> /// <param name="element"></param> public void Comment(ModelElement element) { ICommentable commentable = element as ICommentable; if (commentable != null && !string.IsNullOrEmpty(commentable.Comment)) { Comment(commentable.Comment); } }
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)); }
/// <summary> /// The way text is retrieved from the instance /// </summary> /// <returns></returns> public override string GetText() { string retVal = ""; ICommentable commentable = Instance as ICommentable; if (commentable != null) { retVal = commentable.Comment; } return(retVal); }
private CommentView GetCommentViewWithComments(ICommentable entity, Comment comment, string parentId = null) { var commentView = GetCommentViewFromComment(entity.Id, comment, parentId, entity.EntryType, entity.GetRelatedVersionNumber(comment.RelatedVersionId)); foreach (var cComment in comment.Comments.OrderBy(c => c.Date)) { var cCommentView = GetCommentViewFromComment(entity.Id, cComment, comment.Id, entity.EntryType); commentView.Comments.Add(cCommentView); } return(commentView); }
public static void WriteComment(User user, ICommentable content, string text) { var comment = new Comment { Text = text }; comment.User.Add(user); comment.Save(); content.Comments.Add(comment); Repository.SaveChanges(); }
/// <summary> /// Ensure that empty comments are not stored in the XML file /// </summary> /// <param name="obj"></param> /// <param name="visitSubNodes"></param> public override void visit(BaseModelElement obj, bool visitSubNodes) { ICommentable commentable = obj as ICommentable; if (commentable != null) { if (commentable.Comment == "") { commentable.Comment = null; } } base.visit(obj, visitSubNodes); }
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)); }
/// <summary> /// Allows to refresh the view, when the selected model changed /// </summary> /// <param name="context"></param> /// <returns>true if refresh should be performed</returns> public override bool HandleSelectionChange(Context.SelectionContext context) { bool retVal = base.HandleSelectionChange(context); DisplayedModel = context.Element; ICommentable commentable = DisplayedModel as ICommentable; if (commentable != null) { SyntaxHighlight = false; AutoComplete = false; setChangeHandler(new CommentableTextChangeHandler((ModelElement)commentable)); } return(retVal); }
public override void OnValueChanged(SourceGrid.CellContext sender, EventArgs e) { base.OnValueChanged(sender, e); Grid grid = (Grid)sender.Grid; var row = grid.Rows[sender.Position.Row]; if (row.Tag == null) { return; } ICommentable entry = (ICommentable)row.Tag; entry.Comment = (string)sender.Value; }
/// <summary> /// Adds a Comment to a Post. /// </summary> /// <param name="comment">The Comment to add.</param> /// <param name="commented">The commented entity.</param> public virtual void AddComment(ICommentable comment, ICommentable commented) { // Initialize the collection if needed if (Comments == null) { Comments = new List<ICommentable>(); } // See if the commented entity is this if (commented == null) { commented = this; } commented.Comments.Add(comment); }
/// <summary> /// The way text is set back in the instance /// </summary> /// <returns></returns> public override void SetText(string text) { text = RemoveUselessCharacters(text); ICommentable commentable = Instance as ICommentable; if (commentable != null) { // We don't care about changes in only \r string originalText = RemoveUselessCharacters(commentable.Comment); if (originalText != text) { commentable.Comment = text; } } }
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)); }
protected virtual void WriteAfterComments(IndentedTextWriter writer, ICommentable commentable) { var isInlined = commentable is Expression; CommentType type = default; var first = true; foreach (var c in commentable.CommentsAfter) { if ((isInlined && first) || (type == CommentType.InlineComment && c.Type == CommentType.InlineComment)) { writer.Write(' '); } type = Write(writer, c); first = false; } }
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); }
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); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (provider != null) { IWindowsFormsEditorService svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService; if (svc != null) { ICommentable commentable = value as ICommentable; if (commentable != null) { Window form = new Window { DockAreas = DockAreas.Float, AutoComplete = false }; CommentableTextChangeHandler handler = new CommentableTextChangeHandler(commentable as ModelElement); form.setChangeHandler(handler); GuiUtils.MdiWindow.AddChildWindow(form, DockAreas.Float); } } } return(value); }
/// <summary> /// Provides the description of a procedure or a function /// </summary> /// <param name="callable">The callable to describe</param> /// <returns></returns> private void CreateProcedureOrFunctionHeader(ICallable callable) { AddTable(new[] { callable.Name }, new[] { 40, 80 }); ICommentable commentable = callable as ICommentable; if (commentable != null && !string.IsNullOrEmpty(commentable.Comment)) { AddRow(commentable.Comment); } if (callable.FormalParameters.Count > 0) { AddTableHeader("Parameters"); AddTableHeader("Name", "Type"); foreach (Parameter parameter in callable.FormalParameters) { AddRow(parameter.Name, parameter.getTypeName()); } } ITypedElement typedElement = callable as ITypedElement; if (typedElement != null && !string.IsNullOrEmpty(typedElement.TypeName)) { AddTableHeader("Return value"); AddRow(typedElement.TypeName); } ReqRelated reqRelated = callable as ReqRelated; if (reqRelated != null) { AddTableHeader("Related requirements"); AddRow(GetRequirementsAsString(reqRelated.Requirements)); } }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { object retVal = null; BaseTreeNode.BaseEditor editor = context.Instance as BaseTreeNode.BaseEditor; string text = value as string; if (editor != null && text != null) { ICommentable commentable = editor.Model as ICommentable; if (commentable != null) { commentable.Comment = text; retVal = commentable; } } if (retVal == null) { retVal = base.ConvertFrom(context, culture, value); } return(retVal); }
public ExpandableList <CommentView> GetCommentsMostRecent(ICommentable entity, int pageNumber, ForAgainst?posOrNeg = null, bool orderResultAsc = false) { 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.OrderByDescending(c => c.Date).GetExpandablePage(pageNumber, CustomAppSettings.PageSizeComment)) { comments.Add(GetCommentViewWithComments(entity, comment)); } var result = new ExpandableList <CommentView>(comments, CustomAppSettings.PageSizeComment); if (orderResultAsc) { result.List = result.List.OrderBy(m => m.CommentDate).ToList(); } return(result); }
protected virtual void WriteBeforeComments(IndentedTextWriter writer, ICommentable commentable) { CommentType type = default; var first = true; foreach (var c in commentable.CommentsBefore) { if (!first) { if (type == CommentType.InlineComment) { writer.Write(' '); } } type = Write(writer, c); first = false; } if (!first && type == CommentType.InlineComment) { writer.Write(' '); } }
public virtual void FillComments(ICommentable entity) { var comments = GetMany(entity.Id); entity.Comments = comments; }
/// <summary> /// Checks that a comment is attached to this ICommentable /// </summary> /// <param name="commentable"></param> private static void checkComment(ICommentable commentable) { if (commentable != null && string.IsNullOrEmpty(commentable.Comment)) { NameSpace nameSpace = EnclosingNameSpaceFinder.find((ModelElement) commentable); bool requiresComment = nameSpace != null; Types.StateMachine stateMachine = commentable as Types.StateMachine; if (stateMachine != null) { requiresComment = stateMachine.EnclosingStateMachine == null; } Rules.RuleCondition ruleCondition = commentable as Rules.RuleCondition; if (ruleCondition != null) { requiresComment = ruleCondition.EnclosingRule.RuleConditions.Count > 1; } if (commentable is NameSpace || commentable is Functions.Case || commentable is Rules.PreCondition || commentable is Rules.Action) { requiresComment = false; } Rule rule = commentable as Rule; if (rule != null && rule.EnclosingProcedure != null) { requiresComment = rule.EnclosingProcedure.Rules.Count > 1; } ITypedElement typedElement = commentable as ITypedElement; if (typedElement != null) { if (typedElement.Type != null) { requiresComment = requiresComment && string.IsNullOrEmpty(typedElement.Type.Comment); } } IVariable variable = commentable as IVariable; if (variable != null) { requiresComment = false; } if (requiresComment) { ((ModelElement) commentable).AddInfo("This element should be documented"); } } }