/// <summary> /// Create a new case with all available details about the error /// </summary> private void SubmitNew(FBApi api, Mapping target) { LogMessageFormatter formatter = new LogMessageFormatter(FirstMessage); Dictionary <string, string> args = new Dictionary <string, string> { { "sScoutDescription", Error.Fingerprint }, { "sProject", target.Project }, { "sArea", target.Area }, { "ixPriority", target.Priority.ToString() }, { "sTitle", formatter.GetTitle() }, { "sVersion", Session.Summary.ApplicationVersion.ToString() }, { "sEvent", formatter.GetNewEvent(Error) }, { "sTags", formatter.GetTags() }, }; string results = api.Cmd("new", args); // TODO: Should check for errors here Log.Information(LogCategory, "Completed new issue submission", "Scout Description: {0}\r\nProject: {1}\r\nArea: {2}\r\nRaw result: {3}", Error.Fingerprint, target.Project, target.Area, results); }
private void ThreadSafeDisplayDefect(string caseId, string projectName, string areaName) { if (InvokeRequired) { ThreadSafeDisplayDefectInvoker invoker = ThreadSafeDisplayDefect; Invoke(invoker, new object[] { caseId, projectName, areaName }); } else { try { //now add these items to the project selection area. ProjectSelection.Items.Clear(); ProjectSelection.DataSource = new List <string>(m_ProjectsAndAreas.Keys); //data source requires a list int lastMessageIndex = m_LogMessages.Count - 1; StringBuilder builder = new StringBuilder(); // Use compact formatting of all but the last message for (int i = 0; i < lastMessageIndex; i++) { LogMessageFormatter preludeFormatter = new LogMessageFormatter(m_LogMessages[i]); builder.Append(preludeFormatter.GetLogMessageSummary()); } // Skip a line between last "prelude" message and the primary message if (lastMessageIndex > 0) { builder.AppendLine(); } // The primary message is the last of the selected messages LogMessageFormatter formatter = new LogMessageFormatter(m_PrimaryMessage); builder.Append(formatter.GetLogMessageDetails()); // Add session details after the primary message builder.AppendLine(); builder.AppendFormat("Session Details:\r\n"); LogMessageFormatter.AppendDivider(builder); builder.Append(formatter.GetSessionDetails()); // This will be applied later, after user editing is done m_SessionIdMessage = formatter.GetSessionIdMessage(); // Check the fingerprint of the primary message to determine if // a case for this error already exists in FogBugz if (string.IsNullOrEmpty(caseId)) { // If there is no existing case, check if this session has an // affinity for a particular project (i.e. is there a // MappingTarget associated with this MappingSource in the config?) // If so, default the project selection accordingly. Mapping target = m_Controller.FindTarget(m_PrimaryMessage.Session); m_Context.Log.Verbose(LogCategory, "No existing case found, user will be able to select project", "The current mapping information for the message is:\r\n{0}", (target == null) ? "(No mapping found)" : target.Project); ProjectSelection.SelectedItem = target == null ? null : target.Project; ProjectSelection.Enabled = true; AreaSelection.Enabled = true; CaseLabel.Tag = null; CaseLabel.Text = "(New Case)"; Text = "Create New Case"; } else { // If a case already exists, get info about it from FogBugz ProjectSelection.SelectedItem = projectName; ProjectSelection.Enabled = false; AreaSelection.SelectedItem = areaName; AreaSelection.Enabled = false; m_Context.Log.Verbose(LogCategory, "Existing case fond, user will not be able to change project / area", "The current case is in:\r\n {0} {1}", projectName, areaName); CaseLabel.Tag = caseId; CaseLabel.Text = caseId; Text = "Edit Case " + caseId; } TitleTextBox.Text = formatter.GetTitle(); TitleTextBox.SelectionStart = 0; TitleTextBox.SelectionLength = 0; TitleTextBox.Enabled = true; DescriptionTextBox.Text = builder.ToString(); DescriptionTextBox.SelectionStart = 0; DescriptionTextBox.SelectionLength = 0; DescriptionTextBox.Enabled = true; DescriptionTextBox.Select(); DescriptionTextBox.Focus(); //this is what they should edit. ValidateData(); } finally { //one way or the other, we're done so the user shouldn't be given the impression we're waiting around. UseWaitCursor = false; } } }
/// <summary> /// Update an existing case /// </summary> private void SubmitUpdate(FBApi api, string caseId) { Dictionary <string, string> queryArgs = new Dictionary <string, string> { { "q", caseId }, { "cols", "sVersion,tags,events" } }; string queryResults = api.Cmd("search", queryArgs); Log.Verbose(LogCategory, "Retrieved existing issue information from server", "Query Results:\r\n{0}", queryResults); XmlDocument xml = new XmlDocument(); xml.LoadXml(queryResults); XmlNodeList eventList = xml.GetElementsByTagName("s"); string sessionIdMessage = new LogMessageFormatter(FirstMessage).GetSessionIdMessage(); // If this case already references this session, we're done foreach (XmlNode node in eventList) { if (node.InnerText.Contains(sessionIdMessage)) { return; } } LogMessageFormatter formatter = new LogMessageFormatter(FirstMessage); Dictionary <string, string> updateArgs = new Dictionary <string, string> { { "sScoutDescription", Error.Fingerprint }, }; // Compare the version of the current session with the session associated with the case. // The version in FogBugz is the high watermark (highest version seen to-date). // If this session if for a XmlNode versionNode = xml.SelectSingleNode("//sVersion"); Version previousVersion = new Version(versionNode.InnerText); if (Session.Summary.ApplicationVersion > previousVersion) { // If this is a new version, update the high watermark and write // a detailed description. updateArgs.Add("sVersion", Session.Summary.ApplicationVersion.ToString()); updateArgs.Add("sEvent", formatter.GetRecurrenceLaterVersionEvent(Error)); Log.Verbose(LogCategory, "Updating latest version information on existing issue", "This new instance has a higher version number than any previous occurrence so we'll update the high water mark on the server.\r\nPrevious Version: {0}\r\nThis Version: {1}", previousVersion, Session.Summary.ApplicationVersion); } else if (Session.Summary.ApplicationVersion == previousVersion) { // If this is another instance of the same version, write a short update updateArgs.Add("sEvent", formatter.GetRecurrenceSameVersionEvent(Error)); } else { // If the version of this session is earlier, ignore this session. Log.Information(LogCategory, "Skipping reporting new occurrence of issue because its from an old version", "This new instance has a lower version number than one or more previous occurrences, so we wont report it.\r\nPrevious Version: {0}\r\nThis Version: {1}", previousVersion, Session.Summary.ApplicationVersion); return; } // We use the "new" command rather than "edit" because FogBugz has the // smarts to reactivate closed cases with scout descriptions. string results = api.Cmd("new", updateArgs); // TODO: Should check for errors here Log.Information(LogCategory, "Completed issue update submission", "Scout Description: {0}\r\nRaw result: {1}", Error.Fingerprint, results); }