public DetailsCommentPartialViewModel(Db db, Comment comment, ViewDataDictionary viewData)
        {
            var creatorUser = Utils.GetAllUsers(db, viewData).FirstOrDefault(x => x.Username.Is(comment.Creator));
            Creator = creatorUser == null ? comment.Creator : creatorUser.Name;
            DateOfCreation = comment.DateOfCreation.ToCentralEuropeanTime();
            Text = comment.Text;

            StatusText = "";
            if (comment.DuplicateIssueId.HasValue)
                StatusText += "Added a <a href=\"" + comment.DuplicateIssueId.Value + "\">duplicate</a>. ";

            if (comment.NewStatus.HasValue() && comment.OldStatus.HasValue())
                StatusText += "Changed status from <code>" + comment.OldStatus + "</code> to <code>" + comment.NewStatus + "</code>. ";
            else if (comment.NewStatus.HasValue())
                StatusText += "Changed status to <code>" + comment.NewStatus + "</code> .";
            else if (comment.OldStatus.HasValue())
                StatusText += "Removed status <code>" + comment.OldStatus + "</code>. ";

            var oldUser = Utils.GetAllUsers(db, viewData).FirstOrDefault(x => x.Username.Is(comment.OldAssignedTo));
            var newUser = Utils.GetAllUsers(db, viewData).FirstOrDefault(x => x.Username.Is(comment.NewAssignedTo));

            if (comment.NewAssignedTo.HasValue() && comment.OldAssignedTo.HasValue())
                StatusText += "Assigned from <code>" + (oldUser != null ? oldUser.Name : comment.OldAssignedTo) + "</code> to <code>" + (newUser != null ? newUser.Name : comment.NewAssignedTo) + "</code>. ";
            else if (comment.NewAssignedTo.HasValue())
                StatusText += "Assigned to <code>" + (newUser != null ? newUser.Name : comment.NewAssignedTo) + "</code>. ";
            else if (comment.OldAssignedTo.HasValue())
                StatusText += "Removed assignment from <code>" + (oldUser != null ? oldUser.Name : comment.OldAssignedTo) + "</code>. ";

            if (comment.Email.HasValue())
                StatusText += "Sent an e-mail to <code>" + comment.Email + "</code>. ";

            if (comment.AttachmentFileName.HasValue())
                StatusText += "Added the attachment <a href=\"../Attachment/" + comment.Id + "\">" + comment.AttachmentNiceName + "</a>. ";
        }
예제 #2
0
        public void Update(IPrincipal user, int issueId, string newUser, string newStatus, string text)
        {
            var issue = _db.Issues.SingleOrDefault(x => x.Id == issueId);
            if (issue != null)
            {
                var hasChanged = false;

                var comment = new Comment
                {
                    IssueId = issue.Id,
                    DateOfCreation = DateTime.Now.ToUniversalTime(),
                    Creator = Utils.GetCurrentUser(_db, _viewData, user).Username
                };

                if (newStatus.HasValue() && Utils.GetAllStati(_db, _viewData).Any(x => x.Name.Is(newStatus)))
                    if (!issue.Status.Is(newStatus))
                    {
                        comment.OldStatus = issue.Status;
                        comment.NewStatus = newStatus;
                        issue.Status = newStatus;
                        hasChanged = true;
                    }

                if (newUser.HasValue() && Utils.GetAllUsers(_db, _viewData).Any(x => x.Name.Is(newUser)))
                {
                    if (!issue.AssignedTo.Is(newUser))
                    {
                        comment.OldAssignedTo = issue.AssignedTo;
                        comment.NewAssignedTo = newUser;
                        issue.AssignedTo = newUser;
                        hasChanged = true;
                    }
                }
                else if (newUser.Is("-"))
                {
                    comment.OldAssignedTo = issue.AssignedTo;
                    comment.NewAssignedTo = "-";
                    issue.AssignedTo = null;
                    hasChanged = true;
                }

                if (text.HasValue())
                {
                    comment.Text = text;
                    hasChanged = true;
                }

                if (hasChanged)
                    _db.Comments.Add(comment);

                _db.SaveChanges();
            }
        }
예제 #3
0
파일: Issue.cs 프로젝트: saxx/IssueTracker
        public void AddComment(string creator, string text)
        {
            if (string.IsNullOrEmpty(text))
                return; //we don't accept empty comments

            using (var context = new Db())
            {
                var comment = new Comment
                {
                    Creator = creator,
                    DateOfCreation = DateTime.Now.ToUniversalTime(),
                    Text = text,
                    IssueId = Id
                };

                context.Comments.Add(comment);
                context.SaveChanges();
            }
        }
예제 #4
0
파일: Issue.cs 프로젝트: saxx/IssueTracker
        public void AddAttachment(string creator, string niceName, string base64, HttpServerUtility server)
        {
            var extension = Path.GetExtension(niceName);
            var path = Path.Combine(server.MapPath(IssueTrackerSettings.AttachmentsPath), Guid.NewGuid().ToString() + extension);

            var bytes = Convert.FromBase64String(base64);
            File.WriteAllBytes(path, bytes);

            using (var context = new Db())
            {
                var comment = new Comment
                {
                    Creator = creator,
                    DateOfCreation = DateTime.Now.ToUniversalTime(),
                    IssueId = Id,
                    Text = "",
                    AttachmentFileName = Path.GetFileName(path),
                    AttachmentNiceName = niceName
                };
                context.Comments.Add(comment);
                context.SaveChanges();
            }
        }
예제 #5
0
        public Issue Create(
            [CanBeNull] string creator, 
            [CanBeNull] string text,
            [CanBeNull] string stackTrace, 
            [CanBeNull] string serverVariables, 
            [CanBeNull] string version,
            bool logOwnExceptions = true)
        {
            try
            {
                // sometimes we get some escaped characters
                text = (text ?? "").Replace("---&gt;", "--->");
                stackTrace = (stackTrace ?? "").Replace("---&gt;", "--->");

                // get a nicer error message from the stacktrace for generic asp.net errors (if the text only contains useless info)
                var uglyTexts = new[]
                {
                    "Exception of type 'System.Web.HttpUnhandledException' was thrown.",
                    "Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerWrapper'."
                };
                if (text.IsNoW() || uglyTexts.Any(x => x.Is(text)))
                {
                    if (stackTrace.HasValue())
                    {
                        text = stackTrace.Split('\n')[0].Trim();

                        if (text.Contains("---> "))
                            text = text.Substring(text.LastIndexOf("---> ", StringComparison.InvariantCultureIgnoreCase) + 5);
                    }
                }

                // remove some useless info from the text to make it easier to read
                if (text.HasValue())
                {
                    text = text.Replace("System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> ", "");
                }

                // find an identical issue
                var parentIssue = _db.Issues
                    .Where(x => x.Text == text || (text == "" && x.Text == null))
                    .Where(x => x.StackTrace == stackTrace || (stackTrace == "" && x.StackTrace == null))
                    .OrderByDescending(x => x.DateOfCreation)
                    .FirstOrDefault();

                // only log the issue if there's not an parent issue that was just posted (prevent overposting)
                if (parentIssue != null && parentIssue.DateOfCreation >= DateTime.Now.ToUniversalTime().AddHours(-1))
                {
                    return null;
                }

                string remoteHost = null;
                const string serverVariablesHostKey = "REMOTE_HOST";
                if (HttpContext.Current != null && HttpContext.Current.Request.ServerVariables[serverVariablesHostKey] != null)
                    remoteHost = HttpContext.Current.Request.ServerVariables[serverVariablesHostKey];

                var newIssue = new Issue
                {
                    DateOfCreation = DateTime.Now.ToUniversalTime(),
                    Creator = creator.GetStringOrNull(),
                    Text = text.GetStringOrNull(),
                    StackTrace = stackTrace.GetStringOrNull(),
                    ServerVariables = serverVariables.GetStringOrNull(),
                    Status = IssueTrackerSettings.StatusForNewIssues,
                    Version = version.GetStringOrNull(),
                    RemoteHost = remoteHost.GetStringOrNull(),
                    AssignedTo = null
                };
                _db.Issues.Add(newIssue);
                _db.SaveChanges();

                if (parentIssue != null)
                {
                    parentIssue = parentIssue.ParentIssueId.HasValue ? _db.Issues.Single(x => x.Id == parentIssue.ParentIssueId.Value) : parentIssue;
                    newIssue.ParentIssueId = parentIssue.Id;

                    var comment = new Comment
                    {
                        Creator = creator,
                        DateOfCreation = DateTime.Now.ToUniversalTime(),
                        DuplicateIssueId = newIssue.Id,
                        IssueId = parentIssue.Id,
                        Text = ""
                    };
                    _db.Comments.Add(comment);

                    var status = _db.Status.FirstOrDefault(x => x.Name.ToLower() == parentIssue.Status);
                    if (status != null && status.Reactivate)
                        parentIssue.Status = IssueTrackerSettings.StatusForNewIssues;
                    else
                        newIssue.Status = parentIssue.Status;
                }
                _db.SaveChanges();

                new AddTagsService(_db).AddTags(newIssue);
                return newIssue;
            }
            catch (Exception ex)
            {
                if (logOwnExceptions)
                {
                    // make sure we don't log own exceptions if we're logging an own exception already - because this would create a logging loop
                    Create("IssueTracker", ex.Message, ex.ToString(), null, GetType().Assembly.GetName().Version.ToString(), false);
                }
            }
            return null;
        }