/// <summary> /// Handles the ItemCommand event of the TimeEntriesDataGrid control. /// </summary> /// <param name="source">The source of the event.</param> /// <param name="e">The <see cref="T:System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param> protected void TimeEntriesDataGrid_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { var id = Convert.ToInt32(e.CommandArgument); if (!IssueWorkReportManager.Delete(id)) { return; } var history = new IssueHistory { IssueId = IssueId, CreatedUserName = Security.GetUserName(), DateChanged = DateTime.Now, FieldChanged = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "TimeLogged", "Time Logged"), OldValue = string.Empty, NewValue = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Deleted", "Deleted"), TriggerLastUpdateChange = true }; IssueHistoryManager.SaveOrUpdate(history); var changes = new List <IssueHistory> { history }; IssueNotificationManager.SendIssueNotifications(IssueId, changes); BindTimeEntries(); }
/// <summary> /// Gets the name of the tab. /// </summary> /// <param name="tabName"></param> /// <param name="tabValue"></param> /// <returns></returns> private string GetTabName(string tabName, string tabValue) { switch (tabValue.ToLower()) { case "tabcomments": return(string.Format("{0} ({1})", tabName, IssueId == 0 ? 0 : IssueCommentManager.GetByIssueId(IssueId).Count)); case "tabhistory": return(string.Format("{0} ({1})", tabName, IssueId == 0 ? 0 : IssueHistoryManager.GetByIssueId(IssueId).Count)); case "tabattachments": return(string.Format("{0} ({1})", tabName, IssueId == 0 ? 0 : IssueAttachmentManager.GetByIssueId(IssueId).Count)); case "tabnotifications": return(string.Format("{0} ({1})", tabName, IssueId == 0 ? 0 : IssueNotificationManager.GetByIssueId(IssueId).Count)); case "tabrelatedissues": return(string.Format("{0} ({1})", tabName, IssueId == 0 ? 0 : RelatedIssueManager.GetRelatedIssues(IssueId).Count)); case "tabparentissues": return(string.Format("{0} ({1})", tabName, IssueId == 0 ? 0 : RelatedIssueManager.GetParentIssues(IssueId).Count)); case "tabsubissues": return(string.Format("{0} ({1})", tabName, IssueId == 0 ? 0 : RelatedIssueManager.GetChildIssues(IssueId).Count)); case "tabrevisions": return(string.Format("{0} ({1})", tabName, IssueId == 0 ? 0 : IssueRevisionManager.GetByIssueId(IssueId).Count)); case "tabtimetracking": return(string.Format("{0} ({1})", tabName, IssueId == 0 ? 0 : IssueWorkReportManager.GetByIssueId(IssueId).Count)); default: return(tabName); } }
/// <summary> /// Handles the Click event of the cmdAddBugTimeEntry control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void AddTimeEntry_Click(object sender, EventArgs e) { if (DurationTextBox.Text.Trim().Length == 0) { return; } var selectedWorkDate = TimeEntryDate.SelectedValue == null ? DateTime.MinValue : (DateTime)TimeEntryDate.SelectedValue; var workDuration = Convert.ToDecimal(DurationTextBox.Text); var workReport = new IssueWorkReport { CommentText = CommentHtmlEditor.Text.Trim(), CreatorUserName = Context.User.Identity.Name, Duration = workDuration, IssueId = IssueId, WorkDate = selectedWorkDate }; IssueWorkReportManager.SaveOrUpdate(workReport); var history = new IssueHistory { IssueId = IssueId, CreatedUserName = Security.GetUserName(), DateChanged = DateTime.Now, FieldChanged = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "TimeLogged", "Time Logged"), OldValue = string.Empty, NewValue = DurationTextBox.Text.Trim(), TriggerLastUpdateChange = true }; IssueHistoryManager.SaveOrUpdate(history); var changes = new List <IssueHistory> { history }; IssueNotificationManager.SendIssueNotifications(IssueId, changes); CommentHtmlEditor.Text = string.Empty; DurationTextBox.Text = string.Empty; BindTimeEntries(); }
/// <summary> /// Gets the name of the tab. /// </summary> /// <param name="tabName"></param> /// <param name="tabValue"></param> /// <returns></returns> private string GetTabName(string tabName, string tabValue) { int cnt; switch (tabValue.ToLower()) { case "tabcomments": cnt = IssueId == 0 ? 0 : IssueCommentManager.GetByIssueId(IssueId).Count; return(string.Format("<span class='{2}'>{0} ({1})</span>", tabName, cnt, cnt == 0 ? "normal" : "bold")); case "tabhistory": cnt = IssueId == 0 ? 0 : IssueHistoryManager.GetByIssueId(IssueId).Count; return(string.Format("<span class='{2}'>{0} ({1})</span>", tabName, cnt, cnt == 0 ? "normal" : "normal")); case "tabattachments": cnt = IssueId == 0 ? 0 : IssueAttachmentManager.GetByIssueId(IssueId).Count; return(string.Format("<span class='{2}'>{0} ({1})</span>", tabName, cnt, cnt == 0 ? "normal" : "bold")); case "tabnotifications": cnt = IssueId == 0 ? 0 : IssueNotificationManager.GetByIssueId(IssueId).Count; return(string.Format("<span class='{2}'>{0} ({1})</span>", tabName, cnt, cnt == 0 ? "normal" : "normal")); case "tabrelatedissues": cnt = IssueId == 0 ? 0 : RelatedIssueManager.GetRelatedIssues(IssueId).Count; return(string.Format("<span class='{2}'>{0} ({1})</span>", tabName, cnt, cnt == 0 ? "normal" : "bold")); case "tabparentissues": cnt = IssueId == 0 ? 0 : RelatedIssueManager.GetParentIssues(IssueId).Count; return(string.Format("<span class='{2}'>{0} ({1})</span>", tabName, cnt, cnt == 0 ? "normal" : "bold")); case "tabsubissues": cnt = IssueId == 0 ? 0 : RelatedIssueManager.GetChildIssues(IssueId).Count; return(string.Format("<span class='{2}'>{0} ({1})</span>", tabName, cnt, cnt == 0 ? "normal" : "bold")); case "tabrevisions": cnt = IssueId == 0 ? 0 : IssueRevisionManager.GetByIssueId(IssueId).Count; return(string.Format("<span class='{2}'>{0} ({1})</span>", tabName, cnt, cnt == 0 ? "normal" : "normal")); case "tabtimetracking": cnt = IssueId == 0 ? 0 : IssueWorkReportManager.GetByIssueId(IssueId).Count; return(string.Format("<span class='{2}'>{0} ({1})</span>", tabName, cnt, cnt == 0 ? "normal" : "normal")); default: return(tabName); } }
/// <summary> /// Handles the Click event of the cmdUpdate control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void CmdAddRelatedIssueClick(object sender, EventArgs e) { if (IssueIdTextBox.Text == String.Empty) { return; } if (!Page.IsValid) { return; } RelatedIssuesMessage.Visible = false; var issueId = Utilities.ParseFullIssueId(IssueIdTextBox.Text.Trim()); if (issueId <= Globals.NEW_ID) { return; } RelatedIssueManager.CreateNewRelatedIssue(IssueId, issueId); IssueIdTextBox.Text = String.Empty; var history = new IssueHistory { IssueId = IssueId, CreatedUserName = Security.GetUserName(), DateChanged = DateTime.Now, FieldChanged = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "RelatedIssue", "Related Issue"), OldValue = string.Empty, NewValue = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Added", "Added"), TriggerLastUpdateChange = true }; IssueHistoryManager.SaveOrUpdate(history); var changes = new List <IssueHistory> { history }; IssueNotificationManager.SendIssueNotifications(IssueId, changes); BindRelated(); }
/// <summary> /// Binds the history. /// </summary> private void BindHistory() { HistoryDataGrid.Columns[0].HeaderText = GetLocalResourceObject("HistoryDataGrid.DateModifiedHeader.Text").ToString(); HistoryDataGrid.Columns[1].HeaderText = GetLocalResourceObject("HistoryDataGrid.CreatorHeader.Text").ToString(); HistoryDataGrid.Columns[2].HeaderText = GetLocalResourceObject("HistoryDataGrid.FieldChangedHeader.Text").ToString(); HistoryDataGrid.Columns[3].HeaderText = GetLocalResourceObject("HistoryDataGrid.OldValueHeader.Text").ToString(); HistoryDataGrid.Columns[4].HeaderText = GetLocalResourceObject("HistoryDataGrid.NewValueHeader.Text").ToString(); List <IssueHistory> history = IssueHistoryManager.GetByIssueId(IssueId); if (history.Count == 0) { lblHistory.Text = GetLocalResourceObject("NoHistory").ToString(); lblHistory.Visible = true; } else { HistoryDataGrid.DataSource = history; HistoryDataGrid.DataBind(); } }
/// <summary> /// GRDs the bugs item command. /// </summary> /// <param name="s">The s.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param> protected void GrdBugsItemCommand(Object s, DataGridCommandEventArgs e) { var commandArgument = e.CommandArgument.ToString(); var commandName = e.CommandName.ToLower().Trim(); var currentIssueId = Globals.NEW_ID; switch (commandName) { case "delete": currentIssueId = int.Parse(commandArgument); RelatedIssueManager.DeleteParentIssue(IssueId, currentIssueId); break; } if (currentIssueId > Globals.NEW_ID) { var history = new IssueHistory { IssueId = IssueId, CreatedUserName = Security.GetUserName(), DateChanged = DateTime.Now, FieldChanged = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "ParentIssue", "Parent Issue"), OldValue = string.Empty, NewValue = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Deleted", "Deleted"), TriggerLastUpdateChange = true }; IssueHistoryManager.SaveOrUpdate(history); var changes = new List <IssueHistory> { history }; IssueNotificationManager.SendIssueNotifications(IssueId, changes); } BindRelated(); }
/// <summary> /// Handles the Click event of the cmdAddComment control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void CmdAddCommentClick(object sender, EventArgs e) { if (CommentHtmlEditor.Text.Trim().Length == 0) { return; } var comment = new IssueComment { IssueId = IssueId, Comment = CommentHtmlEditor.Text.Trim(), CreatorUserName = Security.GetUserName(), DateCreated = DateTime.Now }; var result = IssueCommentManager.SaveOrUpdate(comment); if (result) { //add history record var history = new IssueHistory { IssueId = IssueId, CreatedUserName = Security.GetUserName(), DateChanged = DateTime.Now, FieldChanged = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Comment", "Comment"), OldValue = string.Empty, NewValue = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Added", "Added"), TriggerLastUpdateChange = true }; IssueHistoryManager.SaveOrUpdate(history); } CommentHtmlEditor.Text = String.Empty; BindComments(); }
/// <summary> /// Uploads the document. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void UploadDocument(object sender, EventArgs e) { // get the current file var uploadFile = AspUploadFile.PostedFile; // if there was a file uploaded if (uploadFile != null && uploadFile.ContentLength > 0) { var inValidReason = string.Empty; var fileName = Path.GetFileName(uploadFile.FileName); var validFile = IssueAttachmentManager.IsValidFile(fileName, out inValidReason); if (validFile) { byte[] fileBytes; using (var input = uploadFile.InputStream) { fileBytes = new byte[uploadFile.ContentLength]; input.Read(fileBytes, 0, uploadFile.ContentLength); } var attachment = new IssueAttachment { Id = Globals.NEW_ID, Attachment = fileBytes, Description = AttachmentDescription.Text.Trim(), DateCreated = DateTime.Now, ContentType = uploadFile.ContentType, CreatorDisplayName = string.Empty, CreatorUserName = Security.GetUserName(), FileName = fileName, IssueId = IssueId, Size = fileBytes.Length }; if (!IssueAttachmentManager.SaveOrUpdate(attachment)) { AttachmentsMessage.ShowErrorMessage(string.Format(GetGlobalResourceObject("Exceptions", "SaveAttachmentError").ToString(), uploadFile.FileName)); if (Log.IsWarnEnabled) Log.Warn(string.Format(GetGlobalResourceObject("Exceptions", "SaveAttachmentError").ToString(), uploadFile.FileName)); return; } //add history record and send notifications var history = new IssueHistory { IssueId = IssueId, CreatedUserName = Security.GetUserName(), DateChanged = DateTime.Now, FieldChanged = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Attachment", "Attachment"), OldValue = fileName, NewValue = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Added", "Added"), TriggerLastUpdateChange = true }; IssueHistoryManager.SaveOrUpdate(history); var changes = new List<IssueHistory> { history }; IssueNotificationManager.SendIssueNotifications(IssueId, changes); BindAttachments(); } else AttachmentsMessage.ShowErrorMessage(inValidReason); } }
private bool ProcessNewComment(List <string> recipients, POP3_ClientMessage message, Mail_Message mailHeader, MailboxReaderResult result) { string messageFrom = string.Empty; if (mailHeader.From.Count > 0) { messageFrom = string.Join("; ", mailHeader.From.ToList().Select(p => p.Address).ToArray()).Trim(); } bool processed = false; foreach (var address in recipients) { Regex isReply = new Regex(@"(.*)(\+iid-)(\d+)@(.*)"); Match commentMatch = isReply.Match(address); if (commentMatch.Success && commentMatch.Groups.Count >= 4) { // we are in a reply and group 4 must contain the id of the original issue int issueId; if (int.TryParse(commentMatch.Groups[3].Value, out issueId)) { var _currentIssue = IssueManager.GetById(issueId); if (_currentIssue != null) { var project = ProjectManager.GetById(_currentIssue.ProjectId); var mailbody = Mail_Message.ParseFromByte(message.MessageToByte()); bool isHtml; List <MIME_Entity> attachments = null; string content = GetMessageContent(mailbody, project, out isHtml, ref attachments); IssueComment comment = new IssueComment { IssueId = issueId, Comment = content, DateCreated = mailHeader.Date }; // try to find if the creator is valid user in the project, otherwise take // the user defined in the mailbox config var users = UserManager.GetUsersByProjectId(project.Id); var emails = messageFrom.Split(';').Select(e => e.Trim().ToLower()); var user = users.Find(x => emails.Contains(x.Email.ToLower())); if (user != null) { comment.CreatorUserName = user.UserName; } else { // user not found continue; } var saved = IssueCommentManager.SaveOrUpdate(comment); if (saved) { //add history record var history = new IssueHistory { IssueId = issueId, CreatedUserName = comment.CreatorUserName, DateChanged = comment.DateCreated, FieldChanged = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Comment", "Comment"), OldValue = string.Empty, NewValue = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Added", "Added"), TriggerLastUpdateChange = true }; IssueHistoryManager.SaveOrUpdate(history); var projectFolderPath = Path.Combine(Config.UploadsFolderPath, project.UploadPath); // save attachments as new files int attachmentsSavedCount = 1; foreach (MIME_Entity mimeEntity in attachments) { string fileName; var contentType = mimeEntity.ContentType.Type.ToLower(); var attachment = new IssueAttachment { Id = 0, Description = "File attached by mailbox reader", DateCreated = DateTime.Now, ContentType = mimeEntity.ContentType.TypeWithSubtype, CreatorDisplayName = user.DisplayName, CreatorUserName = user.UserName, IssueId = issueId, ProjectFolderPath = projectFolderPath }; attachment.Attachment = ((MIME_b_SinglepartBase)mimeEntity.Body).Data; if (contentType.Equals("attachment")) // this is an attached email { fileName = mimeEntity.ContentDisposition.Param_FileName; } else if (contentType.Equals("message")) // message has no filename so we create one { fileName = string.Format("Attached_Message_{0}.eml", attachmentsSavedCount); } else { fileName = string.IsNullOrWhiteSpace(mimeEntity.ContentType.Param_Name) ? string.Format("untitled.{0}", mimeEntity.ContentType.SubType) : mimeEntity.ContentType.Param_Name; } attachment.FileName = fileName; var saveFile = IsAllowedFileExtension(fileName); var fileSaved = false; // can we save the file? if (saveFile) { fileSaved = IssueAttachmentManager.SaveOrUpdate(attachment); if (fileSaved) { attachmentsSavedCount++; } else { LogWarning("MailboxReader: Attachment could not be saved, please see previous logs"); } } } processed = true; // add the entry if the save did not throw any exceptions result.MailboxEntries.Add(new MailboxEntry()); } } } } } return(processed); }