private void FillSubGrid(bool isRefreshNeeded = false) { SetCustomerInfo(); if (isRefreshNeeded) { if (_viewMode.In(FormBugSubmissionMode.ViewOnly, FormBugSubmissionMode.ValidationMode)) { _listAllSubs = ListViewedSubs; } else { _listAllSubs = BugSubmissions.GetAllInRange(dateRangePicker.GetDateTimeFrom(), dateRangePicker.GetDateTimeTo()); } try { _dictPatients = RegistrationKeys.GetPatientsByKeys(_listAllSubs.Select(x => x.RegKey).ToList()); } catch (Exception e) { e.DoNothing(); _dictPatients = new Dictionary <string, Patient>(); } } gridSubs.BeginUpdate(); gridSubs.Columns.Clear(); gridSubs.Columns.Add(new ODGridColumn("Reg Key", 140)); gridSubs.Columns.Add(new ODGridColumn("Vers.", 55, GridSortingStrategy.VersionNumber)); if (comboGrouping.SelectedIndex == 0) //None { gridSubs.Columns.Add(new ODGridColumn("DateTime", 75, GridSortingStrategy.DateParse)); } else { gridSubs.Columns.Add(new ODGridColumn("Count", 75, GridSortingStrategy.AmountParse)); } gridSubs.Columns.Add(new ODGridColumn("HasBug", 50, HorizontalAlignment.Center)); gridSubs.Columns.Add(new ODGridColumn("Msg Text", 300)); gridSubs.AllowSortingByColumn = true; List <string> listSelectedVersions = comboVersions.ListSelectedItems.Select(x => (string)x).ToList(); if (listSelectedVersions.Contains("All")) { listSelectedVersions.Clear(); } List <string> listSelectedRegKeys = comboRegKeys.ListSelectedItems.Select(x => (string)x).ToList(); if (listSelectedRegKeys.Contains("All")) { listSelectedRegKeys.Clear(); } List <string> listStackFilters = textStackFilter.Text.Split(',') .Where(x => !string.IsNullOrWhiteSpace(x)) .Select(x => x.ToLower()).ToList(); List <string> listPatNumFilters = textPatNums.Text.Split(',') .Where(x => !string.IsNullOrWhiteSpace(x)) .Select(x => x.ToLower()).ToList(); gridSubs.Rows.Clear(); _listAllSubs.ForEach(x => x.TagOD = null); List <BugSubmission> listFilteredSubs = _listAllSubs.Where(x => PassesFilterValidation(x, listSelectedRegKeys, listStackFilters, listPatNumFilters, listSelectedVersions) ).ToList(); foreach (BugSubmission sub in listFilteredSubs) { ODGridRow row = new ODGridRow(); row.Cells.Add(sub.RegKey); row.Cells.Add(sub.Info.DictPrefValues[PrefName.ProgramVersion]); List <BugSubmission> listPreviousRows; List <BugSubmission> listGroupedSubs; List <string> listProgVersions; switch (comboGrouping.SelectedIndex) { case 0: #region None row.Cells.Add(sub.SubmissionDateTime.ToString().Replace('\r', ' ')); row.Tag = new List <BugSubmission>() { sub }; //Tag is a specific bugSubmission #endregion break; case 1: #region Customer //Take previously proccessed rows and see if we have already handled the grouping. listPreviousRows = listFilteredSubs.Take(listFilteredSubs.IndexOf(sub)).ToList(); if (listPreviousRows.Any(x => x.RegKey == sub.RegKey && x.Info.DictPrefValues[PrefName.ProgramVersion] == sub.Info.DictPrefValues[PrefName.ProgramVersion] && x.ExceptionStackTrace == sub.ExceptionStackTrace && x.BugId == sub.BugId)) { //Skip adding rows that have already been added when grouping continue; } listGroupedSubs = listFilteredSubs.FindAll(x => x.RegKey == sub.RegKey && x.Info.DictPrefValues[PrefName.ProgramVersion] == sub.Info.DictPrefValues[PrefName.ProgramVersion] && x.ExceptionStackTrace == sub.ExceptionStackTrace && x.BugId == sub.BugId); row.Cells.Add(listGroupedSubs.Count.ToString()); //row.Cells[1].Text=string.Join(",",listGroupedSubs.Select(x => x.Info.DictPrefValues[PrefName.ProgramVersion]).ToList()); listProgVersions = listGroupedSubs.Select(x => x.Info.DictPrefValues[PrefName.ProgramVersion]).Distinct().ToList(); if (listProgVersions.Count > 1) { row.Cells[1].Text = listProgVersions.Select(x => new Version(x)).Max().ToString(); } else { row.Cells[1].Text = listProgVersions.First(); } row.Tag = listGroupedSubs; //Tag is a list of bugSubmissions #endregion break; case 2: #region StackTrace //Take previously proccessed rows and see if we have already handled the grouping. listPreviousRows = listFilteredSubs.Take(listFilteredSubs.IndexOf(sub)).ToList(); if (listPreviousRows.Any(x => x.ExceptionStackTrace == sub.ExceptionStackTrace && x.BugId == sub.BugId)) { //Skip adding rows that have already been added when grouping continue; } listGroupedSubs = listFilteredSubs.FindAll(x => x.ExceptionStackTrace == sub.ExceptionStackTrace && x.BugId == sub.BugId); row.Cells.Add(listGroupedSubs.Count.ToString()); listProgVersions = listGroupedSubs.Select(x => x.Info.DictPrefValues[PrefName.ProgramVersion]).Distinct().ToList(); if (listProgVersions.Count > 1) { row.Cells[1].Text = listProgVersions.Select(x => new Version(x)).Max().ToString(); } else { row.Cells[1].Text = listProgVersions.First(); } row.Tag = listGroupedSubs; //Tag is a list of bugSubmissions #endregion break; case 3: #region 95% //if(sub.TagOD!=null) { // continue; //} //listGroupedSubs=listFilteredSubs.FindAll(x => x.BugId==sub.BugId // &&x.TagOD==null // &&CalculateSimilarity(x.ExceptionMessageText,sub.ExceptionMessageText)>95 // &&(x==sub||CalculateSimilarity(x.ExceptionStackTrace,sub.ExceptionStackTrace)>95)); //listGroupedSubs.ForEach(x => x.TagOD=true); //row.Cells.Add(listGroupedSubs.Count.ToString()); //listProgVersions=listGroupedSubs.Select(x => x.Info.DictPrefValues[PrefName.ProgramVersion]).Distinct().ToList(); //if(listProgVersions.Count>1) { // row.Cells[1].Text=listProgVersions.Select(x => new Version(x)).Max().ToString(); //} //else { // row.Cells[1].Text=listProgVersions.First(); //} //row.Tag=listGroupedSubs;//Tag is a list of bugSubmissions #endregion break; } row.Cells.Add(sub.BugId == 0 ? "" : "X"); row.Cells.Add(sub.ExceptionMessageText); gridSubs.Rows.Add(row); } gridSubs.EndUpdate(); gridSubs.SortForced(1, false); //Sort by Version column if (isRefreshNeeded) { FillVersionsFilter(); FillRegKeyFilter(); } }
private void FillSubGrid(bool isRefreshNeeded = false, string grouping95 = "") { List <string> listSelectedVersions = listVersionsFilter.SelectedItems.OfType <string>().ToList(); if (listSelectedVersions.Contains("All")) { listSelectedVersions.Clear(); } if (isRefreshNeeded && listSelectedVersions.IsNullOrEmpty()) { if (!MsgBox.Show(MsgBoxButtons.YesNo, "All bug submissions are going to be downloaded...\r\nAre you sure about this?")) { return; } } Action loadingProgress = null; Cursor = Cursors.WaitCursor; #region gridSubs columns gridSubs.BeginUpdate(); gridSubs.ListGridColumns.Clear(); gridSubs.ListGridColumns.Add(new GridColumn("Submitter", 140)); gridSubs.ListGridColumns.Add(new GridColumn("Vers.", 55, GridSortingStrategy.VersionNumber)); if (comboGrouping.SelectedIndex == 0) //Group by 'None' { gridSubs.ListGridColumns.Add(new GridColumn("DateTime", 75, GridSortingStrategy.DateParse)); } else { gridSubs.ListGridColumns.Add(new GridColumn("#", 30, HorizontalAlignment.Right, GridSortingStrategy.AmountParse)); } gridSubs.ListGridColumns.Add(new GridColumn("Flag", 50, HorizontalAlignment.Center)); gridSubs.ListGridColumns.Add(new GridColumn("Msg Text", 0)); gridSubs.AllowSortingByColumn = true; gridSubs.ListGridRows.Clear(); #endregion bugSubmissionControl.ClearCustomerInfo(); bugSubmissionControl.SetTextDevNoteEnabled(false); if (isRefreshNeeded) { loadingProgress = ODProgress.Show(ODEventType.BugSubmission, typeof(BugSubmissionEvent), Lan.g(this, "Refreshing Data") + "..."); #region Refresh Logic if (_viewMode.In(FormBugSubmissionMode.ViewOnly, FormBugSubmissionMode.ValidationMode)) { _listAllSubs = ListViewedSubs; } else { BugSubmissionEvent.Fire(ODEventType.BugSubmission, Lan.g(this, "Refreshing Data: Bugs")); _listAllSubs = BugSubmissions.GetAllInRange(dateRangePicker.GetDateTimeFrom(), dateRangePicker.GetDateTimeTo(), listSelectedVersions); } try { BugSubmissionEvent.Fire(ODEventType.BugSubmission, Lan.g(this, "Refreshing Data: Patients")); _dictPatients = RegistrationKeys.GetPatientsByKeys(_listAllSubs.Select(x => x.RegKey).ToList()); } catch (Exception e) { e.DoNothing(); _dictPatients = new Dictionary <string, Patient>(); } BugSubmissionEvent.Fire(ODEventType.BugSubmission, Lan.g(this, "Refreshing Data: JobLinks")); _listJobLinks = JobLinks.GetManyForType(JobLinkType.Bug, _listAllSubs.Select(x => x.BugId).Where(x => x != 0).Distinct().ToList()); #endregion } #region Filter Logic BugSubmissionEvent.Fire(ODEventType.BugSubmission, "Filtering Data"); List <BugSubmission> listFilteredSubs = null; List <string> listSelectedRegKeys = comboRegKeys.ListSelectedItems.Select(x => (string)x).ToList(); if (listSelectedRegKeys.Contains("All")) { listSelectedRegKeys.Clear(); } List <string> listStackFilters = textStackFilter.Text.Split(',') .Where(x => !string.IsNullOrWhiteSpace(x)) .Select(x => x.ToLower()).ToList(); List <string> listPatNumFilters = textPatNums.Text.Split(',') .Where(x => !string.IsNullOrWhiteSpace(x)) .Select(x => x.ToLower()).ToList(); _listAllSubs.ForEach(x => x.TagCustom = null); List <string> listCategoryFilters = textCategoryFilters.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); string msgText = textMsgText.Text; string devNoteFilter = textDevNoteFilter.Text; DateTime dateTimeFrom = dateRangePicker.GetDateTimeFrom(); DateTime dateTimeTo = dateRangePicker.GetDateTimeTo(); //Filter the list of all bug submissions and then order it by program version and submission date time so that the grouping is predictable. listFilteredSubs = _listAllSubs.Where(x => PassesFilterValidation(x, listCategoryFilters, listSelectedRegKeys, listStackFilters, listPatNumFilters, listSelectedVersions, grouping95, msgText, devNoteFilter, dateTimeFrom, dateTimeTo) ) .OrderByDescending(x => new Version(x.ProgramVersion)) .ThenByDescending(x => x.SubmissionDateTime) .ToList(); if (isRefreshNeeded) { FillPatNameFilter(_listAllSubs); } #endregion #region Grouping Logic List <BugSubmission> listGridSubmissions = new List <BugSubmission>(); BugSubmissionEvent.Fire(ODEventType.BugSubmission, "Grouping Data"); switch (comboGrouping.SelectedIndex) { case 0: #region None foreach (BugSubmission bugSubmission in listFilteredSubs) { AddGroupedSubsToGridSubs(listGridSubmissions, new List <BugSubmission>() { bugSubmission }); } listShowHideOptions.SetSelected(3, false); //Deselect 'None' _minGroupingCount = -1; butAddJob.Enabled = true; #endregion break; case 1: #region RegKey/Ver/Stack listFilteredSubs.GroupBy(x => new { x.BugId, x.RegKey, x.ProgramVersion, x.ExceptionMessageText, x.ExceptionStackTrace }) .ToDictionary(x => x.Key, x => x.ToList()) .ForEach(x => AddGroupedSubsToGridSubs(listGridSubmissions, x.Value)); butAddJob.Enabled = true; #endregion break; case 2: #region StackTrace listFilteredSubs.GroupBy(x => new { x.BugId, x.ExceptionMessageText, x.ExceptionStackTrace }) .ToDictionary(x => x.Key, x => x.ToList()) .ForEach(x => AddGroupedSubsToGridSubs(listGridSubmissions, x.Value)); butAddJob.Enabled = true; #endregion break; case 3: #region 95% //At this point all bugSubmissions in listFilteredSubs is at least a 95% match. Group them all together in a single row. AddGroupedSubsToGridSubs(listGridSubmissions, listFilteredSubs); butAddJob.Enabled = true; #endregion break; case 4: #region StackSig listFilteredSubs.GroupBy(x => new { x.BugId, x.ExceptionMessageText, x.OdStackSignature }) .ToDictionary(x => x.Key, x => x.ToList()) .ForEach(x => AddGroupedSubsToGridSubs(listGridSubmissions, x.Value)); butAddJob.Enabled = false; //Can not add jobs in this mode. #endregion break; case 5: #region StackSimple listFilteredSubs.GroupBy(x => new { x.BugId, x.ExceptionMessageText, x.SimplifiedStackTrace }) .ToDictionary(x => x.Key, x => x.ToList()) .ForEach(x => AddGroupedSubsToGridSubs(listGridSubmissions, x.Value)); butAddJob.Enabled = false; //Can not add jobs in this mode. #endregion break; case 6: #region Hash listFilteredSubs.GroupBy(x => new { x.BugId, x.BugSubmissionHashNum }) .ToDictionary(x => x.Key, x => x.ToList()) .ForEach(x => AddGroupedSubsToGridSubs(listGridSubmissions, x.Value)); butAddJob.Enabled = false; //Can not add jobs in this mode. #endregion break; } if (_minGroupingCount > 0) { listGridSubmissions.RemoveAll(x => (x.TagCustom as List <BugSubmission>).Count < _minGroupingCount); } #endregion #region Sorting Logic BugSubmissionEvent.Fire(ODEventType.BugSubmission, "Sorting Data"); switch (comboSortBy.SelectedIndex) { case 0: listGridSubmissions = listGridSubmissions.OrderByDescending(x => new Version(x.ProgramVersion)) .ThenByDescending(x => GetGroupCount(x)) .ThenByDescending(x => x.SubmissionDateTime).ToList(); break; } #endregion #region Fill gridSubs BugSubmissionEvent.Fire(ODEventType.BugSubmission, "Filling Grid"); foreach (BugSubmission sub in listGridSubmissions) { gridSubs.ListGridRows.Add(GetODGridRowForSub(sub)); } gridSubs.EndUpdate(); #endregion loadingProgress?.Invoke(); Cursor = Cursors.Default; }
private void FillSubGrid(bool isRefreshNeeded = false, string grouping95 = "") { Action loadingProgress = null; Cursor = Cursors.WaitCursor; bugSubmissionControl.ClearCustomerInfo(); bugSubmissionControl.SetTextDevNoteEnabled(false); if (isRefreshNeeded) { loadingProgress = ODProgressOld.ShowProgressStatus("FormBugSubmissions", this, Lan.g(this, "Refreshing Data") + "...", false); #region Refresh Logic if (_viewMode.In(FormBugSubmissionMode.ViewOnly, FormBugSubmissionMode.ValidationMode)) { _listAllSubs = ListViewedSubs; } else { _listAllSubs = BugSubmissions.GetAllInRange(dateRangePicker.GetDateTimeFrom(), dateRangePicker.GetDateTimeTo()); } try { _dictPatients = RegistrationKeys.GetPatientsByKeys(_listAllSubs.Select(x => x.RegKey).ToList()); } catch (Exception e) { e.DoNothing(); _dictPatients = new Dictionary <string, Patient>(); } #endregion } gridSubs.BeginUpdate(); #region gridSubs columns gridSubs.Columns.Clear(); gridSubs.Columns.Add(new ODGridColumn("Submitter", 140)); gridSubs.Columns.Add(new ODGridColumn("Vers.", 55, GridSortingStrategy.VersionNumber)); if (comboGrouping.SelectedIndex == 0) //Group by 'None' { gridSubs.Columns.Add(new ODGridColumn("DateTime", 75, GridSortingStrategy.DateParse)); } else { gridSubs.Columns.Add(new ODGridColumn("Count", 75, GridSortingStrategy.AmountParse)); } gridSubs.Columns.Add(new ODGridColumn("HasBug", 50, HorizontalAlignment.Center)); gridSubs.Columns.Add(new ODGridColumn("Msg Text", 300)); gridSubs.AllowSortingByColumn = true; #endregion #region Filter Logic ODEvent.Fire(new ODEventArgs("FormBugSubmissions", "Filtering Data")); List <string> listSelectedVersions = comboVersions.ListSelectedItems.Select(x => (string)x).ToList(); if (listSelectedVersions.Contains("All")) { listSelectedVersions.Clear(); } List <string> listSelectedRegKeys = comboRegKeys.ListSelectedItems.Select(x => (string)x).ToList(); if (listSelectedRegKeys.Contains("All")) { listSelectedRegKeys.Clear(); } List <string> listStackFilters = textStackFilter.Text.Split(',') .Where(x => !string.IsNullOrWhiteSpace(x)) .Select(x => x.ToLower()).ToList(); List <string> listPatNumFilters = textPatNums.Text.Split(',') .Where(x => !string.IsNullOrWhiteSpace(x)) .Select(x => x.ToLower()).ToList(); _listAllSubs.ForEach(x => x.TagOD = null); List <BugSubmission> listFilteredSubs = _listAllSubs.Where(x => PassesFilterValidation(x, listSelectedRegKeys, listStackFilters, listPatNumFilters, listSelectedVersions, grouping95) ).ToList(); if (isRefreshNeeded) { FillVersionsFilter(listFilteredSubs); FillRegKeyFilter(listFilteredSubs); } #endregion #region Grouping Logic List <BugSubmission> listGroupedSubs; int index = 0; List <BugSubmission> listGridSubmissions = new List <BugSubmission>(); foreach (BugSubmission sub in listFilteredSubs) { ODEvent.Fire(new ODEventArgs("FormBugSubmissions", "Grouping Data: " + POut.Double(((double)index++ / (double)listFilteredSubs.Count) * 100) + "%")); if (sub.TagOD != null) { continue; } switch (comboGrouping.SelectedIndex) { case 0: #region None sub.TagOD = new List <BugSubmission>() { sub }; //Tag is a specific bugSubmission listGridSubmissions.Add(sub.Copy()); #endregion break; case 1: #region RegKey/Ver/Stack listGroupedSubs = listFilteredSubs.FindAll(x => x.TagOD == null && x.RegKey == sub.RegKey && x.Info.DictPrefValues[PrefName.ProgramVersion] == sub.Info.DictPrefValues[PrefName.ProgramVersion] && x.ExceptionStackTrace == sub.ExceptionStackTrace && x.BugId == sub.BugId); if (listGroupedSubs.Count == 0) { continue; } listGroupedSubs = listGroupedSubs.OrderByDescending(x => new Version(x.Info.DictPrefValues[PrefName.ProgramVersion])) .ThenByDescending(x => x.SubmissionDateTime).ToList(); listGroupedSubs.ForEach(x => x.TagOD = true); //So we don't considered previously handled submissions. listGroupedSubs.First().TagOD = listGroupedSubs; //First element is what is shown in grid, still wont be considered again. listGridSubmissions.Add(listGroupedSubs.First().Copy()); #endregion break; case 2: #region StackTrace listGroupedSubs = listFilteredSubs.FindAll(x => x.TagOD == null && x.ExceptionStackTrace == sub.ExceptionStackTrace && x.BugId == sub.BugId); if (listGroupedSubs.Count == 0) { continue; } listGroupedSubs = listGroupedSubs.OrderByDescending(x => new Version(x.Info.DictPrefValues[PrefName.ProgramVersion])) .ThenByDescending(x => x.SubmissionDateTime).ToList(); listGroupedSubs.ForEach(x => x.TagOD = true); //So we don't considered previously handled submissions. listGroupedSubs.First().TagOD = listGroupedSubs; //First element is what is shown in grid, still wont be considered again. listGridSubmissions.Add(listGroupedSubs.First().Copy()); #endregion break; case 3: #region 95% //At this point all bugSubmissions in listFilteredSubs is at least a 95% match. Group them all together in a single row. listGroupedSubs = listFilteredSubs; listGroupedSubs = listGroupedSubs.OrderByDescending(x => new Version(x.Info.DictPrefValues[PrefName.ProgramVersion])) .ThenByDescending(x => x.SubmissionDateTime).ToList(); listGroupedSubs.ForEach(x => x.TagOD = true); //So we don't considered previously handled submissions. listGroupedSubs.First().TagOD = listGroupedSubs; //First element is what is shown in grid, still wont be considered again. listGridSubmissions.Add(listGroupedSubs.First().Copy()); #endregion break; } } #endregion #region Sorting Logic ODEvent.Fire(new ODEventArgs("FormBugSubmissions", "Sorting Data")); switch (comboSortBy.SelectedIndex) { case 0: listGridSubmissions = listGridSubmissions.OrderByDescending(x => new Version(x.Info.DictPrefValues[PrefName.ProgramVersion])) .ThenByDescending(x => GetGroupCount(x)) .ThenByDescending(x => x.SubmissionDateTime).ToList(); break; } #endregion #region Fill gridSubs gridSubs.Rows.Clear(); index = 0; foreach (BugSubmission sub in listGridSubmissions) { ODEvent.Fire(new ODEventArgs("FormBugSubmissions", "Filling Grid: " + POut.Double(((double)index++ / (double)listFilteredSubs.Count) * 100) + "%")); gridSubs.Rows.Add(GetODGridRowForSub(sub)); } gridSubs.EndUpdate(); #endregion try { loadingProgress?.Invoke(); //When this function executes quickly this can fail rarely, fail silently because of WaitCursor. } catch (Exception ex) { ex.DoNothing(); } Cursor = Cursors.Default; }