private async void btnSync_Click(object sender, EventArgs e) { this.btnSync.Enabled = false; var jiraLabels = this.txtLabelList.Text; if (jiraLabels.Trim().Length == 0) { MessageBox.Show("Please enter some jira labels related release version like 9.0.4"); this.btnSync.Enabled = true; return; } dicDeliveryCaseMapper.Clear(); string[] jiraLabelList = jiraLabels.Split(','); foreach (string label in jiraLabelList) { if (String.IsNullOrEmpty(label) || String.IsNullOrWhiteSpace(label)) { continue; } var GetIssueList = JiraProxy.GetIssueListByLabel(label); var issueList = await GetIssueList; if (issueList == null || issueList.Count == 0) { continue; } List <AccelaIssueCaseMapper> jiraIssues = dicDeliveryCaseMapper.ContainsKey(label) ? dicDeliveryCaseMapper[label] : new List <AccelaIssueCaseMapper>(); foreach (var issue in issueList) { if (issue == null) { continue; } AccelaIssueCaseMapper issueMapper = new AccelaIssueCaseMapper(); // Product issueMapper.SFProduct = issue.fields.customfield_10904; // Jira Key issueMapper.JiraKey = issue.key; // Salesforce ID issueMapper.CaseNumber = issue.fields.customfield_10600; // Customer issueMapper.SFCustomer = issue.fields.customfield_10900; // Summary issueMapper.Description = issue.fields.summary; // Type issueMapper.IssueType = (issue.fields.issueType == null ? "" : issue.fields.issueType.name); // Severity issueMapper.Priority = (issue.fields.Priority == null ? "" : issue.fields.Priority.name); // Fix Version issueMapper.FixVersions = new List <string>(); if (issue.fields.fixVersions != null) { foreach (var fixVersion in issue.fields.fixVersions) { if (fixVersion == null) { continue; } issueMapper.FixVersions.Add(fixVersion.name); } issueMapper.FixVersions.Sort(); } // Jira Status issueMapper.Status = (issue.fields.status == null ? "" : issue.fields.status.name); // Assignee(Dev) issueMapper.Assignee = (issue.fields.assignee == null ? "" : issue.fields.assignee.displayName); // Assignee(QA) issueMapper.AssigneeQA = (issue.fields.customfield_11702 == null ? "" : issue.fields.customfield_11702.displayName); List <Comment> comments = new List <Comment>(); if (this.chkRootCause.Checked || this.chkSolution.Checked || this.chkImpactArea.Checked) { if ("ENGSUPP-12597".Equals(issue.key)) { System.Console.WriteLine("" + issue.key); } var Comments = await JiraProxy.GetComments(issue); foreach (var comment in Comments) { if (this.chkRootCause.Checked && comment.body.Contains("Root Cause")) { comments.Add(comment); continue; } if (this.chkSolution.Checked && comment.body.Contains("Solution")) { comments.Add(comment); continue; } if (this.chkImpactArea.Checked && comment.body.Contains("Impact Area")) { comments.Add(comment); continue; } } } issueMapper.Comments = comments; issueMapper.ReleaseNote = issue.fields.customfield_11500; jiraIssues.Add(issueMapper); } dicDeliveryCaseMapper[label] = jiraIssues; } DataTable table = new DataTable("Delivery Progress Report"); table.Columns.Add("No", typeof(int)); table.Columns.Add("Product", typeof(string)); table.Columns.Add("JiraKey", typeof(string)); table.Columns.Add("SalesforceID", typeof(string)); table.Columns.Add("Customer", typeof(string)); table.Columns.Add("Description", typeof(string)); table.Columns.Add("IssueType", typeof(string)); table.Columns.Add("Severity", typeof(string)); table.Columns.Add("FixVersions", typeof(List <string>)); table.Columns.Add("FixVersionsForUI", typeof(string)); table.Columns.Add("JiraStatus", typeof(string)); table.Columns.Add("AssigneeDev", typeof(string)); table.Columns.Add("AssigneeQA", typeof(string)); table.Columns.Add("Comments", typeof(List <Comment>)); table.Columns.Add("CemmentCount", typeof(int)); table.Columns.Add("ReleaseNote", typeof(string)); int index = 1; int labelIndex = 1; foreach (string versionLabel in jiraLabelList) { if (String.IsNullOrEmpty(versionLabel) || String.IsNullOrWhiteSpace(versionLabel)) { continue; } List <AccelaIssueCaseMapper> jiraIssueList = dicDeliveryCaseMapper.ContainsKey(versionLabel) ? dicDeliveryCaseMapper[versionLabel] : new List <AccelaIssueCaseMapper>(); if (jiraIssueList.Count == 0) { continue; } foreach (AccelaIssueCaseMapper jiraIssue in jiraIssueList) { DataRow row = table.NewRow(); row["No"] = index++; row["Product"] = jiraIssue.SFProduct; row["JiraKey"] = jiraIssue.JiraKey; row["SalesforceID"] = jiraIssue.CaseNumber; row["Customer"] = jiraIssue.SFCustomer; row["Description"] = jiraIssue.Description; row["IssueType"] = jiraIssue.IssueType; row["Severity"] = jiraIssue.Priority; row["FixVersions"] = jiraIssue.FixVersions; string fixVersionsForUI = String.Empty; foreach (string versionUI in jiraIssue.FixVersions) { if (String.IsNullOrEmpty(fixVersionsForUI)) { fixVersionsForUI = versionUI; } else { fixVersionsForUI += "," + versionUI; } } row["FixVersionsForUI"] = fixVersionsForUI; row["JiraStatus"] = jiraIssue.Status; row["AssigneeDev"] = jiraIssue.Assignee; row["AssigneeQA"] = jiraIssue.AssigneeQA; row["Comments"] = jiraIssue.Comments; row["CemmentCount"] = jiraIssue.Comments.Count; row["ReleaseNote"] = jiraIssue.ReleaseNote; table.Rows.Add(row); } if (labelIndex < jiraLabelList.Length) { labelIndex++; table.Rows.Add(table.NewRow()); } } //DataView dataTableView = table.DefaultView; //dataTableView.Sort = "Severity ASC"; //table = dataTableView.ToTable(); grdCaseList.AutoGenerateColumns = false; grdCaseList.DataSource = table; this.btnSync.Enabled = true; }
private async void btnLookUpInJiraAndSF_Click(object sender, EventArgs e) { this.btnLookUpInJiraAndSF.Enabled = false; string emailAddress = this.ddlReviewerEmailAddress.SelectedValue as string; if ("*****@*****.**" == emailAddress) { emailAddress = emailAddress.Replace("@missionsky.com", ""); } var issues = await JiraProxy.GetIssueList(emailAddress); List <string> caseList = new List <string>(); Dictionary <string, AccelaIssueCaseMapper> JiraMapping = new Dictionary <string, AccelaIssueCaseMapper>(); foreach (var issue in issues) { AccelaIssueCaseMapper accelaIssueCaseMapper = new AccelaIssueCaseMapper(); accelaIssueCaseMapper.CaseNumber = issue.fields.customfield_10600; accelaIssueCaseMapper.Assignee = (issue.fields.assignee == null ? "" : issue.fields.assignee.displayName); accelaIssueCaseMapper.JiraKey = issue.key; accelaIssueCaseMapper.JiraId = issue.id; accelaIssueCaseMapper.Status = issue.fields.status.name; accelaIssueCaseMapper.HotCase = issue.fields.labels.Contains("HotCase"); if (String.IsNullOrEmpty(accelaIssueCaseMapper.CaseNumber)) { continue; } if (!JiraMapping.ContainsKey(accelaIssueCaseMapper.CaseNumber)) { JiraMapping.Add(accelaIssueCaseMapper.CaseNumber, accelaIssueCaseMapper); } else { System.Console.WriteLine("Duplicated Case: " + accelaIssueCaseMapper.CaseNumber); if ("CLOSED".Equals(JiraMapping[accelaIssueCaseMapper.CaseNumber].Status, StringComparison.CurrentCultureIgnoreCase)) { JiraMapping[accelaIssueCaseMapper.CaseNumber] = accelaIssueCaseMapper; } } caseList.Add(accelaIssueCaseMapper.CaseNumber); } DataTable table = new DataTable("CaseList"); table.Columns.Add("ID", typeof(string)); table.Columns.Add("No", typeof(int)); table.Columns.Add("Product", typeof(string)); table.Columns.Add("SalesforceID", typeof(string)); table.Columns.Add("JiraKey", typeof(string)); table.Columns.Add("JiraID", typeof(string)); table.Columns.Add("Type", typeof(string)); table.Columns.Add("Version", typeof(string)); table.Columns.Add("Priority", typeof(string)); table.Columns.Add("Customer", typeof(string)); table.Columns.Add("Summary", typeof(string)); table.Columns.Add("Reviewer", typeof(string)); table.Columns.Add("ReopenedCount", typeof(string)); table.Columns.Add("SFQueue", typeof(string)); table.Columns.Add("SFStatus", typeof(string)); table.Columns.Add("JiraStatus", typeof(string)); table.Columns.Add("JiraNextStatus", typeof(string)); if (caseList.Count == 0) { this.grdCaseList.DataSource = table; this.grdCaseList.AutoGenerateColumns = false; this.btnLookUpInJiraAndSF.Enabled = true; return; } Dictionary <string, string> Reviewers = new Dictionary <string, string>(); Reviewers.Add("Jessy", "Jessy.Zhang"); Reviewers.Add("Adger", "Adger.Chen"); Reviewers.Add("Tim", "Tim.Liu"); Reviewers.Add("Mia", "Mia.Huang"); Reviewers.Add("Alvin", "Alvin.Li"); Reviewers.Add("Mina", "Mina.Xiong"); Reviewers.Add("Peter", "Peter.Peng"); Reviewers.Add("John", "John.Huang"); Reviewers.Add("Bass", "Bass.Yang"); Reviewers.Add("Star", "Star.Li"); Reviewers.Add("Shaun", "Shaun.Qiu"); Reviewers.Add("Lex", "Lex.Wu"); Reviewers.Add("Louis", "Louis.He"); Reviewers.Add("Likko", "Likko.Zhang"); Reviewers.Add("Sandy", "Sandy.Zheng"); Reviewers.Add("Weber", "Weber.Yan"); Reviewers.Add("Rick", "Rick.Liu"); Reviewers.Add("Matt", "Matt.Ao"); Reviewers.Add("Hyman", "Hyman.Zhang"); Reviewers.Add("Feng", "Feng.Xuan"); Reviewers.Add("Cheng", "Cheng.Xu"); Reviewers.Add("Alex", "Alex.Li"); Reviewers.Add("Mandy", "Mandy.Zhou"); Reviewers.Add("Linda", "Linda.Xiao"); Reviewers.Add("Leo", "Leo.Liu"); Reviewers.Add("Abel", "Abel.Yu"); Reviewers.Add("Claire", "Claire.Cao"); Reviewers.Add("Viola", "Viola.Shi"); Reviewers.Add("Larry", "Larry.Francisco"); Reviewers.Add("Gordon", "Gordon.Chen"); Reviewers.Add("Tracy", "Tracy.Xiang"); Reviewers.Add("Jessie", "Jessie.Zhang"); Reviewers.Add("William", "William.Wang"); Reviewers.Add("Carly", "Carly.Xu"); Reviewers.Add("Janice", "Janice.Zhong"); Reviewers.Add("Jane", "Jane.Hu"); Reviewers.Add("Amy", "Amy.Bao"); Reviewers.Add("Iris", "Iris.Wang"); Reviewers.Add("Grace", "Grace.Tang"); Reviewers.Add("Cloud", "Clouid.Qi"); Reviewers.Add("Carol", "Carol.Gong"); Reviewers.Add("Manasi", "*****@*****.**"); Reviewers.Add("Sasirekha", "*****@*****.**"); Reviewers.Add("Jerry", "Jerry.Lu"); var jiraId = ""; var jiraKey = ""; var customer = ""; var assignee = ""; var jiaStstus = ""; var reopenCount = 0; bool isCommentedToday = false; int index = 1; AccelaIssueCaseMapper tempIssue = null; var cases = await SalesforceProxy.GetCaseList(caseList); foreach (var caseinfo in cases) { tempIssue = null; if (JiraMapping.ContainsKey(caseinfo.CaseNumber)) { tempIssue = JiraMapping[caseinfo.CaseNumber]; } DataRow row = table.NewRow(); row["ID"] = caseinfo.Id; row["No"] = index; row["Product"] = AccelaCaseUtil.AdjustProductName(caseinfo.Product, caseinfo.Solution, caseinfo.Subject, caseinfo.Description); row["SalesforceID"] = caseinfo.CaseNumber; jiraId = (tempIssue != null ? tempIssue.JiraId : ""); row["JiraID"] = jiraId; jiraKey = (tempIssue != null ? tempIssue.JiraKey : ""); row["JiraKey"] = jiraKey; row["Type"] = caseinfo.Type; row["Version"] = caseinfo.CurrentVersion; string[] severity = caseinfo.Priority.Split(' '); row["Priority"] = severity[1]; customer = (caseinfo.Customer != null && !String.IsNullOrEmpty(caseinfo.Customer.Name) ? caseinfo.Customer.Name : (caseinfo.Account != null ? caseinfo.Account.Name : "")); row["Customer"] = customer; row["Summary"] = caseinfo.Subject; reopenCount = (caseinfo.CaseComments != null && caseinfo.CaseComments.Records != null ? caseinfo.CaseComments.Records.Count - 1 : 0); row["ReopenedCount"] = reopenCount; row["SFQueue"] = caseinfo.Owner.Name; row["SFStatus"] = caseinfo.Status; jiaStstus = (tempIssue != null ? tempIssue.Status : ""); row["JiraStatus"] = jiaStstus; assignee = (tempIssue != null ? tempIssue.Assignee : ""); isCommentedToday = false; if (caseinfo.CaseComments != null && caseinfo.CaseComments.Records != null) { CaseComment comment = caseinfo.CaseComments.Records[0]; isCommentedToday = (comment.CreatedDate.Year == DateTime.Now.Year && comment.CreatedDate.Month == DateTime.Now.Month && comment.CreatedDate.Day == DateTime.Now.Day ? true : false); if (!String.IsNullOrEmpty(assignee) && comment.CommentBody.ToUpper().Contains(assignee.ToUpper())) { } else { foreach (var key in Reviewers.Keys) { string value = Reviewers[key]; string value1 = value.Replace('.', ' '); if (comment.CommentBody.ToUpper().EndsWith(key.ToUpper()) || comment.CommentBody.ToUpper().EndsWith(value.ToUpper()) || comment.CommentBody.ToUpper().EndsWith(value1.ToUpper())) { assignee = Reviewers[key]; break; } } } } /* * if ("CLOSED".Equals(caseinfo.Status, StringComparison.InvariantCultureIgnoreCase) * && !"CLOSED".Equals(jiaStstus, StringComparison.InvariantCultureIgnoreCase)) * { * row["JiraNextStatus"] = "Closed"; * } * * if ("engineering".Equals(caseinfo.Owner.Name, StringComparison.InvariantCultureIgnoreCase) * && "eng new".Equals(caseinfo.Status, StringComparison.InvariantCultureIgnoreCase)) * { * if (isCommentedToday) * { * row["JiraNextStatus"] = "Pending"; * } * else * { * if (!"Open".Equals(jiaStstus, StringComparison.InvariantCultureIgnoreCase) * && !"In Progress".Equals(jiaStstus, StringComparison.InvariantCultureIgnoreCase)) * { * row["JiraNextStatus"] = "In Progress"; * } * } * } * * if (isCommentedToday && !"Pending".Equals(jiaStstus, StringComparison.InvariantCultureIgnoreCase)) * { * row["JiraNextStatus"] = "Pending"; * } * */ row["JiraNextStatus"] = AccelaCaseUtil.GetNextJIRAStatus(caseinfo.Owner.Name, caseinfo.Status, jiaStstus, isCommentedToday); row["Reviewer"] = assignee; table.Rows.Add(row); index++; } this.grdCaseList.AutoGenerateColumns = false; this.grdCaseList.DataSource = table; this.btnLookUpInJiraAndSF.Enabled = true; }
private async void btnSyncWithJiraAndSF_Click(object sender, EventArgs e) { this.btnSendSummaryReport.Enabled = false; this.btnSyncWithJiraAndSF.Enabled = false; List <string> problemCaseIDList = new List <string>(); // 1, Construct one case list from the specified case list // 1.1 Check if the case list formate is valid or not // 1.2 Construct one case list string caseIDs = this.txtCaseIDList.Text; List <string> caseIdList = new List <string>(); if (String.IsNullOrEmpty(caseIDs) || caseIDs.Trim().Length == 0) { // Show one error message "ERROR: Please enter case id" (this.MdiParent as MainForm).ShowStatusMessage("ERROR: Please enter case id"); this.btnSendSummaryReport.Enabled = true; this.btnSyncWithJiraAndSF.Enabled = true; return; } else { (this.MdiParent as MainForm).ShowStatusMessage(""); string[] caseIDArray = caseIDs.Split(','); Regex reg = new Regex(@"\d{2}ACC-\d{5}"); foreach (string caseId in caseIDArray) { if (reg.IsMatch(caseId)) { if (!caseIdList.Contains(caseId.Trim())) { caseIdList.Add(caseId.Trim()); } } else { // Show one error message "ERROR: Invalid Format for XXXX" (this.MdiParent as MainForm).ShowStatusMessage("ERROR: Invalid Format for " + caseId); this.btnSendSummaryReport.Enabled = true; this.btnSyncWithJiraAndSF.Enabled = true; return; } } } var caseList = new List <AccelaCase>(); var issueList = new List <Issue>(); int N = 1; for (int i = 0; i < caseIdList.Count;) { List <string> caseIdListTemp = new List <string>(); for (; i < N * 50 && i < caseIdList.Count; i++) { caseIdListTemp.Add(caseIdList[i]); } N = N + 1; var GetCaseList = SalesforceProxy.GetCaseList(caseIdListTemp); var GetIssueList = JiraProxy.GetIssueList(caseIdListTemp); var caseListTmp = await GetCaseList; var issueListTmp = await GetIssueList; if (caseIdListTemp.Count != caseListTmp.Count) { foreach (var tempCase in caseListTmp) { string caseID = tempCase.CaseNumber; if (caseIdListTemp.Contains(caseID)) { caseIdListTemp.Remove(caseID); } } problemCaseIDList.AddRange(caseIdListTemp); } caseList.AddRange(caseListTmp); issueList.AddRange(issueListTmp); } if (problemCaseIDList != null && problemCaseIDList.Count > 0) { System.Console.WriteLine("Below case id are lost."); foreach (string lostCaseId in problemCaseIDList) { System.Console.WriteLine(lostCaseId); } } Dictionary <string, AccelaIssueCaseMapper> JiraMapping = new Dictionary <string, AccelaIssueCaseMapper>(); foreach (var issue in issueList) { if (!JiraMapping.ContainsKey(issue.fields.customfield_10600)) { AccelaIssueCaseMapper accelaIssueCaseMapper = new AccelaIssueCaseMapper(); accelaIssueCaseMapper.CaseNumber = issue.fields.customfield_10600; accelaIssueCaseMapper.Assignee = (issue.fields.assignee == null ? "" : issue.fields.assignee.displayName); accelaIssueCaseMapper.AssigneeQA = (issue.fields.customfield_11702 == null ? "" : issue.fields.customfield_11702.displayName); accelaIssueCaseMapper.JiraId = issue.id; accelaIssueCaseMapper.JiraKey = issue.key; accelaIssueCaseMapper.IssueCategory = (issue.fields.customfield_11502 != null && issue.fields.customfield_11502.Count > 0 ? issue.fields.customfield_11502[0].value : "--NONE--"); accelaIssueCaseMapper.LastModified = issue.fields.customfield_10903; accelaIssueCaseMapper.Status = issue.fields.status.name; accelaIssueCaseMapper.HotCase = issue.fields.labels.Contains("HotCase"); accelaIssueCaseMapper.Missionsky = issue.fields.labels.Contains("Missionsky"); accelaIssueCaseMapper.JiraLabels = issue.fields.labels; accelaIssueCaseMapper.FixVersions = new List <string>(); if (issue.fields.fixVersions != null) { foreach (var fixVersion in issue.fields.fixVersions) { accelaIssueCaseMapper.FixVersions.Add(fixVersion.name); } } JiraMapping.Add(accelaIssueCaseMapper.CaseNumber, accelaIssueCaseMapper); } } DataTable table = new DataTable("Daily Report"); table.Columns.Add("ID", typeof(string)); table.Columns.Add("No", typeof(int)); table.Columns.Add("HotCase", typeof(bool)); table.Columns.Add("Missionsky", typeof(bool)); table.Columns.Add("JiraLabels", typeof(List <string>)); table.Columns.Add("ProductForUI", typeof(string)); table.Columns.Add("Product", typeof(string)); table.Columns.Add("Solution", typeof(string)); table.Columns.Add("Orgin", typeof(string)); table.Columns.Add("OpenDate", typeof(string)); table.Columns.Add("Severity", typeof(string)); table.Columns.Add("Rank", typeof(int)); table.Columns.Add("SalesforceID", typeof(string)); table.Columns.Add("JiraID", typeof(string)); table.Columns.Add("JiraKey", typeof(string)); table.Columns.Add("Type", typeof(string)); table.Columns.Add("Version", typeof(string)); table.Columns.Add("Customer", typeof(string)); table.Columns.Add("Summary", typeof(string)); table.Columns.Add("Description", typeof(string)); table.Columns.Add("Reviewer", typeof(string)); table.Columns.Add("Comments", typeof(string)); table.Columns.Add("ReopenedCount", typeof(string)); table.Columns.Add("JiraStatus", typeof(string)); table.Columns.Add("NextJiraStatus", typeof(string)); table.Columns.Add("SFQueue", typeof(string)); table.Columns.Add("SFStatus", typeof(string)); table.Columns.Add("SFLastModified", typeof(string)); table.Columns.Add("CaseComment", typeof(CaseComment)); table.Columns.Add("FixVersions", typeof(string)); table.Columns.Add("ReleaseInfo", typeof(string)); table.Columns.Add("TargetedRelease", typeof(string)); table.Columns.Add("InternalType", typeof(string)); table.Columns.Add("EngineeringStatus", typeof(string)); table.Columns.Add("BZID", typeof(string)); table.Columns.Add("IssueCategory", typeof(string)); table.Columns.Add("Assignee", typeof(string)); table.Columns.Add("AssigneeQA", typeof(string)); table.Columns.Add("CaseComments", typeof(List <CaseComment>)); Dictionary <string, string> Reviewers = SalesforceProxy.GetReviewerNamesList(); int index = 1; AccelaIssueCaseMapper tempIssue = null; string openDate = ""; string jiraKey = ""; string jiraId = ""; string customer = ""; string assignee = ""; int reopenCount = 0; string jiaStstus = ""; string[] Severity = null; string temComment = ""; string lastModifiedDate = ""; int rank = 0; foreach (var caseinfo in caseList) { tempIssue = null; if (JiraMapping.ContainsKey(caseinfo.CaseNumber)) { tempIssue = JiraMapping[caseinfo.CaseNumber]; } if (caseinfo.ReleaseInfo != null) { //SalesforceProxy.GetReleaseInfoById(caseinfo.ReleaseInfo); } DataRow row = table.NewRow(); row["ID"] = caseinfo.Id; row["No"] = index; row["HotCase"] = (tempIssue != null && tempIssue.HotCase); row["Missionsky"] = (tempIssue != null && tempIssue.Missionsky); row["JiraLabels"] = (tempIssue != null ? tempIssue.JiraLabels : null); row["IssueCategory"] = (tempIssue != null ? tempIssue.IssueCategory : null); row["Assignee"] = (tempIssue != null ? tempIssue.Assignee : null); row["AssigneeQA"] = (tempIssue != null ? tempIssue.AssigneeQA : null); //row["HotCase"] = true; row["ProductForUI"] = AccelaCaseUtil.AdjustProductName(caseinfo.Product, caseinfo.Solution, caseinfo.Subject, caseinfo.Description); row["Product"] = caseinfo.Product; row["Solution"] = caseinfo.Solution; row["Orgin"] = caseinfo.Origin; //openDate = caseinfo.CreatedDate.ToShortDateString(); openDate = (caseinfo.CreatedDate.Month < 10 ? "0" + caseinfo.CreatedDate.Month : "" + caseinfo.CreatedDate.Month) + "/" + (caseinfo.CreatedDate.Day < 10 ? "0" + caseinfo.CreatedDate.Day : "" + caseinfo.CreatedDate.Day) + "/" + ("" + caseinfo.CreatedDate.Year); row["OpenDate"] = openDate; Severity = caseinfo.Priority.Split(' '); row["Severity"] = Severity[1]; rank = 0; if (!String.IsNullOrEmpty(caseinfo.RankOrder)) { rank = int.Parse(caseinfo.RankOrder); } else if (!String.IsNullOrEmpty(caseinfo.ServicesRank)) { rank = int.Parse(caseinfo.ServicesRank); } else { rank = 0; } row["Rank"] = rank; row["SalesforceID"] = caseinfo.CaseNumber; jiraKey = (tempIssue != null ? tempIssue.JiraKey : ""); jiraId = (tempIssue != null ? tempIssue.JiraId : ""); row["JiraKey"] = jiraKey; row["JiraID"] = jiraId; row["Type"] = (String.IsNullOrEmpty(caseinfo.InternalType) ? caseinfo.Type : "Production " + caseinfo.InternalType); row["Version"] = caseinfo.CurrentVersion; customer = (caseinfo.Customer != null && !String.IsNullOrEmpty(caseinfo.Customer.Name) ? caseinfo.Customer.Name : (caseinfo.Account != null ? caseinfo.Account.Name : "")); if (customer.IndexOf("Accela") >= 0 && caseinfo.Account != null && !String.IsNullOrEmpty(caseinfo.Account.Name)) { customer = caseinfo.Account.Name; } row["Customer"] = customer; row["Summary"] = caseinfo.Subject; row["Description"] = caseinfo.Description; assignee = (tempIssue != null ? tempIssue.Assignee : ""); temComment = ""; //lastModifiedDate = DateTime.Now.Year + "-" + (DateTime.Now.Month < 10 ? "0" + DateTime.Now.Month : "" + DateTime.Now.Month) + "-" + (DateTime.Now.Day < 10 ? "0" + DateTime.Now.Day : "" + DateTime.Now.Day); DateTime Yesterday = DateTime.Now.AddDays(-1); lastModifiedDate = Yesterday.Year + "-" + Yesterday.Month + "-" + Yesterday.Day; if (caseinfo.CaseComments != null && caseinfo.CaseComments.Records != null) { row["CaseComments"] = caseinfo.CaseComments.Records; CaseComment comment = caseinfo.CaseComments.Records[0]; //lastModifiedDate = comment.CreatedDate.Year + "-" + (comment.CreatedDate.Month < 10 ? "0" + comment.CreatedDate.Month : "" + comment.CreatedDate.Month) + "-" + (comment.CreatedDate.Day < 10 ? "0" + comment.CreatedDate.Day : "" + comment.CreatedDate.Day); if (DateTime.Now.Year != comment.CreatedDate.Year && DateTime.Now.Month != comment.CreatedDate.Month && DateTime.Now.Day != comment.CreatedDate.Day) { lastModifiedDate = comment.CreatedDate.Year + "-" + comment.CreatedDate.Month + "-" + comment.CreatedDate.Day; } row["CaseComment"] = comment; if (!String.IsNullOrEmpty(comment.CommentBody)) { if (comment.CommentBody.ToUpper().IndexOf("BUB") > 0) { temComment += "This is a bug.<br>"; } if (comment.CommentBody.ToUpper().IndexOf("DEFECT") > 0) { temComment += "This is a defect.<br>"; } } if (!String.IsNullOrEmpty(assignee) && comment.CommentBody.ToUpper().Contains(assignee.ToUpper())) { } else { foreach (var key in Reviewers.Keys) { string value = Reviewers[key]; string value1 = value.Replace('.', ' '); if (comment.CommentBody.ToUpper().EndsWith(key.ToUpper()) || comment.CommentBody.ToUpper().EndsWith(value.ToUpper()) || comment.CommentBody.ToUpper().EndsWith(value1.ToUpper())) { assignee = Reviewers[key]; break; } } } } row["Reviewer"] = assignee; row["Comments"] = temComment; reopenCount = (caseinfo.CaseComments != null && caseinfo.CaseComments.Records != null ? caseinfo.CaseComments.Records.Count - 1 : 0); row["ReopenedCount"] = reopenCount; jiaStstus = (tempIssue != null ? tempIssue.Status : ""); row["JiraStatus"] = jiaStstus; row["SFQueue"] = caseinfo.Owner.Name; row["SFStatus"] = caseinfo.Status; bool isCommentedToday = false; if (caseinfo.CaseComments != null && caseinfo.CaseComments.Records != null) { CaseComment comment = caseinfo.CaseComments.Records[0]; isCommentedToday = (comment.CreatedDate.Year == DateTime.Now.Year && comment.CreatedDate.Month == DateTime.Now.Month && comment.CreatedDate.Day == DateTime.Now.Day ? true : false); } row["NextJiraStatus"] = AccelaCaseUtil.GetNextJIRAStatus(caseinfo.Owner.Name, caseinfo.Status, jiaStstus, isCommentedToday); row["SFLastModified"] = lastModifiedDate; if (tempIssue != null && String.IsNullOrEmpty(tempIssue.LastModified)) { System.Console.WriteLine("Last Modified Date is empty"); } if (tempIssue != null && tempIssue.FixVersions != null) { bool isFirst = true; foreach (var fixVersion in tempIssue.FixVersions) { if (isFirst) { row["FixVersions"] = fixVersion; isFirst = false; } else { row["FixVersions"] += "," + fixVersion; } } } row["ReleaseInfo"] = caseinfo.ReleaseInfo; row["TargetedRelease"] = caseinfo.TargetedRelease; row["BZID"] = caseinfo.BZID; row["InternalType"] = caseinfo.InternalType; row["EngineeringStatus"] = caseinfo.EngineeringStatus; table.Rows.Add(row); index++; } grdCaseList.AutoGenerateColumns = false; grdCaseList.DataSource = table; this.btnSendSummaryReport.Enabled = true; this.btnSyncWithJiraAndSF.Enabled = true; }
private async void btnSyncWithJIRA_Click(object sender, EventArgs e) { this.btnSendNotificationEmail.Enabled = false; this.btnSyncWithJIRA.Enabled = false; // 1, Construct one case list from the specified case list // 1.1 Check if the case list formate is valid or not // 1.2 Construct one case list string caseIDs = this.txtCaseIDList.Text; List<string> caseIdList = new List<string>(); if (String.IsNullOrEmpty(caseIDs) || caseIDs.Trim().Length == 0) { // Show one error message "ERROR: Please enter case id" (this.MdiParent as MainForm).ShowStatusMessage("ERROR: Please enter case id"); return; } else { (this.MdiParent as MainForm).ShowStatusMessage(""); string[] caseIDArray = caseIDs.Split(','); Regex reg = new Regex(@"\d{2}ACC-\d{5}"); foreach (string caseId in caseIDArray) { if (reg.IsMatch(caseId)) { caseIdList.Add(caseId.Trim()); } else { // Show one error message "ERROR: Invalid Format for XXXX" (this.MdiParent as MainForm).ShowStatusMessage("ERROR: Invalid Format for " + caseId); return; } } } var GetCaseList = SalesforceProxy.GetCaseList(caseIdList); var GetIssueList = JiraProxy.GetIssueList(caseIdList); var caseList = await GetCaseList; var issueList = await GetIssueList; Dictionary<string, AccelaIssueCaseMapper> JiraMapping = new Dictionary<string, AccelaIssueCaseMapper>(); foreach (var issue in issueList) { if (!JiraMapping.ContainsKey(issue.fields.customfield_10600)) { AccelaIssueCaseMapper accelaIssueCaseMapper = new AccelaIssueCaseMapper(); accelaIssueCaseMapper.CaseNumber = issue.fields.customfield_10600; accelaIssueCaseMapper.Assignee = (issue.fields.assignee == null ? "" : issue.fields.assignee.displayName); accelaIssueCaseMapper.JiraId = issue.id; accelaIssueCaseMapper.JiraKey = issue.key; accelaIssueCaseMapper.LastModified = issue.fields.customfield_10903; accelaIssueCaseMapper.Status = issue.fields.status.name; accelaIssueCaseMapper.HotCase = issue.fields.labels.Contains("HotCase"); accelaIssueCaseMapper.JiraLabels = issue.fields.labels; JiraMapping.Add(accelaIssueCaseMapper.CaseNumber, accelaIssueCaseMapper); } } DataTable table = new DataTable("Daily Report"); table.Columns.Add("ID", typeof(string)); table.Columns.Add("No", typeof(int)); table.Columns.Add("HotCase", typeof(bool)); table.Columns.Add("JiraLabels", typeof(List<string>)); table.Columns.Add("ProductForUI", typeof(string)); table.Columns.Add("Product", typeof(string)); table.Columns.Add("Solution", typeof(string)); table.Columns.Add("Orgin", typeof(string)); table.Columns.Add("OpenDate", typeof(string)); table.Columns.Add("Severity", typeof(string)); table.Columns.Add("SalesforceID", typeof(string)); table.Columns.Add("JiraID", typeof(string)); table.Columns.Add("JiraKey", typeof(string)); table.Columns.Add("Type", typeof(string)); table.Columns.Add("Version", typeof(string)); table.Columns.Add("Customer", typeof(string)); table.Columns.Add("Summary", typeof(string)); table.Columns.Add("Description", typeof(string)); table.Columns.Add("Reviewer", typeof(string)); table.Columns.Add("Comments", typeof(string)); table.Columns.Add("ReopenedCount", typeof(string)); table.Columns.Add("JiraStatus", typeof(string)); table.Columns.Add("NextJiraStatus", typeof(string)); table.Columns.Add("SFQueue", typeof(string)); table.Columns.Add("SFStatus", typeof(string)); table.Columns.Add("SFLastModified", typeof(string)); table.Columns.Add("CaseComment", typeof(CaseComment)); Dictionary<string, string> Reviewers = new Dictionary<string, string>(); Reviewers.Add("Alvin", "Alvin.Li"); Reviewers.Add("Rick", "Rick.Liu"); Reviewers.Add("Weber", "Weber.Yan"); Reviewers.Add("John", "John.Huang"); Reviewers.Add("Hyman", "Hyman.Zhang"); Reviewers.Add("Star", "Star.Li"); Reviewers.Add("Lex", "Lex.Wu"); Reviewers.Add("Bass", "Bass.Yang"); Reviewers.Add("Mandy", "Mandy.Zhou"); Reviewers.Add("Linda", "Linda.Xiao"); Reviewers.Add("Abel", "Abel.Yu"); Reviewers.Add("Matt", "Matt.Ao"); Reviewers.Add("Peter", "Peter.Peng"); Reviewers.Add("Sandy", "Sandy.Zheng"); Reviewers.Add("Likko", "Likko.Zhang"); Reviewers.Add("Mina", "Mina.Xiong"); Reviewers.Add("Jessy", "Jessy.Zhang"); Reviewers.Add("Louis", "Louis.He"); Reviewers.Add("Leo", "Leo.Liu"); Reviewers.Add("Adger", "Adger.Chen"); Reviewers.Add("Tim", "Tim.Liu"); Reviewers.Add("Mia", "Mia.Huang"); Reviewers.Add("Jessie", "Jessie.Zhang"); Reviewers.Add("William", "William.Wang"); Reviewers.Add("Cheng", "Cheng.Xu"); Reviewers.Add("Gordon", "Gordon.Chen"); Reviewers.Add("Tracy", "Tracy.Xiang"); int index = 1; AccelaIssueCaseMapper tempIssue = null; string openDate = ""; string jiraKey = ""; string jiraId = ""; string customer = ""; string assignee = ""; int reopenCount = 0; string jiaStstus = ""; string[] Severity = null; string temComment = ""; foreach (var caseinfo in caseList) { tempIssue = null; if (JiraMapping.ContainsKey(caseinfo.CaseNumber)) { tempIssue = JiraMapping[caseinfo.CaseNumber]; } DataRow row = table.NewRow(); row["ID"] = caseinfo.Id; row["No"] = index; row["HotCase"] = (tempIssue != null && tempIssue.HotCase); row["JiraLabels"] = (tempIssue != null ? tempIssue.JiraLabels : null); //row["HotCase"] = true; row["ProductForUI"] = AccelaCaseUtil.AdjustProductName(caseinfo.Product, caseinfo.Solution, caseinfo.Subject, caseinfo.Description); row["Product"] = caseinfo.Product; row["Solution"] = caseinfo.Solution; row["Orgin"] = caseinfo.Origin; //openDate = caseinfo.CreatedDate.ToShortDateString(); openDate = (caseinfo.CreatedDate.Month < 10 ? "0" + caseinfo.CreatedDate.Month : "" + caseinfo.CreatedDate.Month) + "/" + (caseinfo.CreatedDate.Day < 10 ? "0" + caseinfo.CreatedDate.Day : "" + caseinfo.CreatedDate.Day) + "/" + ("" + caseinfo.CreatedDate.Year); row["OpenDate"] = openDate; Severity = caseinfo.Priority.Split(' '); row["Severity"] = Severity[1]; row["SalesforceID"] = caseinfo.CaseNumber; jiraKey = (tempIssue != null ? tempIssue.JiraKey : ""); jiraId = (tempIssue != null ? tempIssue.JiraId : ""); row["JiraKey"] = jiraKey; row["JiraID"] = jiraId; row["Type"] = caseinfo.Type; row["Version"] = caseinfo.CurrentVersion; customer = (caseinfo.Customer != null && !String.IsNullOrEmpty(caseinfo.Customer.Name) ? caseinfo.Customer.Name : caseinfo.Account.Name); row["Customer"] = customer; row["Summary"] = caseinfo.Subject; row["Description"] = caseinfo.Description; assignee = (tempIssue != null ? tempIssue.Assignee : ""); temComment = ""; if (caseinfo.CaseComments != null && caseinfo.CaseComments.Records != null) { CaseComment comment = caseinfo.CaseComments.Records[0]; row["CaseComment"] = comment; if (!String.IsNullOrEmpty(comment.CommentBody)) { if (comment.CommentBody.ToUpper().IndexOf("BUB") > 0) { temComment += "This is a bug.<br>"; } if (comment.CommentBody.ToUpper().IndexOf("DEFECT") > 0) { temComment += "This is a defect.<br>"; } } if (!String.IsNullOrEmpty(assignee) && comment.CommentBody.ToUpper().Contains(assignee.ToUpper())) { } else { foreach (var key in Reviewers.Keys) { string value = Reviewers[key]; string value1 = value.Replace('.', ' '); if (comment.CommentBody.ToUpper().EndsWith(key.ToUpper()) || comment.CommentBody.ToUpper().EndsWith(value.ToUpper()) || comment.CommentBody.ToUpper().EndsWith(value1.ToUpper())) { assignee = Reviewers[key]; break; } } } } row["Reviewer"] = assignee; row["Comments"] = temComment; reopenCount = (caseinfo.CaseComments != null && caseinfo.CaseComments.Records != null ? caseinfo.CaseComments.Records.Count - 1 : 0); row["ReopenedCount"] = reopenCount; jiaStstus = (tempIssue != null ? tempIssue.Status : ""); row["JiraStatus"] = jiaStstus; row["SFQueue"] = caseinfo.Owner.Name; row["SFStatus"] = caseinfo.Status; bool isCommentedToday = false; if (caseinfo.CaseComments != null && caseinfo.CaseComments.Records != null) { CaseComment comment = caseinfo.CaseComments.Records[0]; isCommentedToday = (comment.CreatedDate.Year == DateTime.Now.Year && comment.CreatedDate.Month == DateTime.Now.Month && comment.CreatedDate.Day == DateTime.Now.Day ? true : false); } row["NextJiraStatus"] = AccelaCaseUtil.GetNextJIRAStatus(caseinfo.Owner.Name, caseinfo.Status, jiaStstus, isCommentedToday); row["SFLastModified"] = (tempIssue != null ? tempIssue.LastModified : ""); table.Rows.Add(row); index++; } grdCaseList.AutoGenerateColumns = false; grdCaseList.DataSource = table; this.btnSendNotificationEmail.Enabled = true; this.btnSyncWithJIRA.Enabled = true; }
private async void btnSyncWithJIRA_Click(object sender, EventArgs e) { this.btnSendNotificationEmail.Enabled = false; this.btnSyncWithJIRA.Enabled = false; // 1, Construct one case list from the specified case list // 1.1 Check if the case list formate is valid or not // 1.2 Construct one case list string caseIDs = this.txtCaseIDList.Text; List <string> caseIdList = new List <string>(); if (String.IsNullOrEmpty(caseIDs) || caseIDs.Trim().Length == 0) { // Show one error message "ERROR: Please enter case id" (this.MdiParent as MainForm).ShowStatusMessage("ERROR: Please enter case id"); return; } else { (this.MdiParent as MainForm).ShowStatusMessage(""); string[] caseIDArray = caseIDs.Split(','); Regex reg = new Regex(@"\d{2}ACC-\d{5}"); foreach (string caseId in caseIDArray) { if (reg.IsMatch(caseId)) { caseIdList.Add(caseId.Trim()); } else { // Show one error message "ERROR: Invalid Format for XXXX" (this.MdiParent as MainForm).ShowStatusMessage("ERROR: Invalid Format for " + caseId); return; } } } var GetCaseList = SalesforceProxy.GetCaseList(caseIdList); var GetIssueList = JiraProxy.GetIssueList(caseIdList); var caseList = await GetCaseList; var issueList = await GetIssueList; Dictionary <string, AccelaIssueCaseMapper> JiraMapping = new Dictionary <string, AccelaIssueCaseMapper>(); foreach (var issue in issueList) { if (!JiraMapping.ContainsKey(issue.fields.customfield_10600)) { AccelaIssueCaseMapper accelaIssueCaseMapper = new AccelaIssueCaseMapper(); accelaIssueCaseMapper.CaseNumber = issue.fields.customfield_10600; accelaIssueCaseMapper.Assignee = (issue.fields.assignee == null ? "" : issue.fields.assignee.displayName); accelaIssueCaseMapper.JiraId = issue.id; accelaIssueCaseMapper.JiraKey = issue.key; accelaIssueCaseMapper.LastModified = issue.fields.customfield_10903; accelaIssueCaseMapper.Status = issue.fields.status.name; accelaIssueCaseMapper.HotCase = issue.fields.labels.Contains("HotCase"); accelaIssueCaseMapper.JiraLabels = issue.fields.labels; JiraMapping.Add(accelaIssueCaseMapper.CaseNumber, accelaIssueCaseMapper); } } DataTable table = new DataTable("Daily Report"); table.Columns.Add("ID", typeof(string)); table.Columns.Add("No", typeof(int)); table.Columns.Add("HotCase", typeof(bool)); table.Columns.Add("JiraLabels", typeof(List <string>)); table.Columns.Add("ProductForUI", typeof(string)); table.Columns.Add("Product", typeof(string)); table.Columns.Add("Solution", typeof(string)); table.Columns.Add("Orgin", typeof(string)); table.Columns.Add("OpenDate", typeof(string)); table.Columns.Add("Severity", typeof(string)); table.Columns.Add("SalesforceID", typeof(string)); table.Columns.Add("JiraID", typeof(string)); table.Columns.Add("JiraKey", typeof(string)); table.Columns.Add("Type", typeof(string)); table.Columns.Add("Version", typeof(string)); table.Columns.Add("Customer", typeof(string)); table.Columns.Add("Summary", typeof(string)); table.Columns.Add("Description", typeof(string)); table.Columns.Add("Reviewer", typeof(string)); table.Columns.Add("Comments", typeof(string)); table.Columns.Add("ReopenedCount", typeof(string)); table.Columns.Add("JiraStatus", typeof(string)); table.Columns.Add("NextJiraStatus", typeof(string)); table.Columns.Add("SFQueue", typeof(string)); table.Columns.Add("SFStatus", typeof(string)); table.Columns.Add("SFLastModified", typeof(string)); table.Columns.Add("CaseComment", typeof(CaseComment)); Dictionary <string, string> Reviewers = new Dictionary <string, string>(); Reviewers.Add("Alvin", "Alvin.Li"); Reviewers.Add("Rick", "Rick.Liu"); Reviewers.Add("Weber", "Weber.Yan"); Reviewers.Add("John", "John.Huang"); Reviewers.Add("Hyman", "Hyman.Zhang"); Reviewers.Add("Star", "Star.Li"); Reviewers.Add("Lex", "Lex.Wu"); Reviewers.Add("Bass", "Bass.Yang"); Reviewers.Add("Mandy", "Mandy.Zhou"); Reviewers.Add("Linda", "Linda.Xiao"); Reviewers.Add("Abel", "Abel.Yu"); Reviewers.Add("Matt", "Matt.Ao"); Reviewers.Add("Peter", "Peter.Peng"); Reviewers.Add("Sandy", "Sandy.Zheng"); Reviewers.Add("Likko", "Likko.Zhang"); Reviewers.Add("Mina", "Mina.Xiong"); Reviewers.Add("Jessy", "Jessy.Zhang"); Reviewers.Add("Louis", "Louis.He"); Reviewers.Add("Leo", "Leo.Liu"); Reviewers.Add("Adger", "Adger.Chen"); Reviewers.Add("Tim", "Tim.Liu"); Reviewers.Add("Mia", "Mia.Huang"); Reviewers.Add("Jessie", "Jessie.Zhang"); Reviewers.Add("William", "William.Wang"); Reviewers.Add("Cheng", "Cheng.Xu"); Reviewers.Add("Gordon", "Gordon.Chen"); Reviewers.Add("Tracy", "Tracy.Xiang"); int index = 1; AccelaIssueCaseMapper tempIssue = null; string openDate = ""; string jiraKey = ""; string jiraId = ""; string customer = ""; string assignee = ""; int reopenCount = 0; string jiaStstus = ""; string[] Severity = null; string temComment = ""; foreach (var caseinfo in caseList) { tempIssue = null; if (JiraMapping.ContainsKey(caseinfo.CaseNumber)) { tempIssue = JiraMapping[caseinfo.CaseNumber]; } DataRow row = table.NewRow(); row["ID"] = caseinfo.Id; row["No"] = index; row["HotCase"] = (tempIssue != null && tempIssue.HotCase); row["JiraLabels"] = (tempIssue != null ? tempIssue.JiraLabels : null); //row["HotCase"] = true; row["ProductForUI"] = AccelaCaseUtil.AdjustProductName(caseinfo.Product, caseinfo.Solution, caseinfo.Subject, caseinfo.Description); row["Product"] = caseinfo.Product; row["Solution"] = caseinfo.Solution; row["Orgin"] = caseinfo.Origin; //openDate = caseinfo.CreatedDate.ToShortDateString(); openDate = (caseinfo.CreatedDate.Month < 10 ? "0" + caseinfo.CreatedDate.Month : "" + caseinfo.CreatedDate.Month) + "/" + (caseinfo.CreatedDate.Day < 10 ? "0" + caseinfo.CreatedDate.Day : "" + caseinfo.CreatedDate.Day) + "/" + ("" + caseinfo.CreatedDate.Year); row["OpenDate"] = openDate; Severity = caseinfo.Priority.Split(' '); row["Severity"] = Severity[1]; row["SalesforceID"] = caseinfo.CaseNumber; jiraKey = (tempIssue != null ? tempIssue.JiraKey : ""); jiraId = (tempIssue != null ? tempIssue.JiraId : ""); row["JiraKey"] = jiraKey; row["JiraID"] = jiraId; row["Type"] = caseinfo.Type; row["Version"] = caseinfo.CurrentVersion; customer = (caseinfo.Customer != null && !String.IsNullOrEmpty(caseinfo.Customer.Name) ? caseinfo.Customer.Name : caseinfo.Account.Name); row["Customer"] = customer; row["Summary"] = caseinfo.Subject; row["Description"] = caseinfo.Description; assignee = (tempIssue != null ? tempIssue.Assignee : ""); temComment = ""; if (caseinfo.CaseComments != null && caseinfo.CaseComments.Records != null) { CaseComment comment = caseinfo.CaseComments.Records[0]; row["CaseComment"] = comment; if (!String.IsNullOrEmpty(comment.CommentBody)) { if (comment.CommentBody.ToUpper().IndexOf("BUB") > 0) { temComment += "This is a bug.<br>"; } if (comment.CommentBody.ToUpper().IndexOf("DEFECT") > 0) { temComment += "This is a defect.<br>"; } } if (!String.IsNullOrEmpty(assignee) && comment.CommentBody.ToUpper().Contains(assignee.ToUpper())) { } else { foreach (var key in Reviewers.Keys) { string value = Reviewers[key]; string value1 = value.Replace('.', ' '); if (comment.CommentBody.ToUpper().EndsWith(key.ToUpper()) || comment.CommentBody.ToUpper().EndsWith(value.ToUpper()) || comment.CommentBody.ToUpper().EndsWith(value1.ToUpper())) { assignee = Reviewers[key]; break; } } } } row["Reviewer"] = assignee; row["Comments"] = temComment; reopenCount = (caseinfo.CaseComments != null && caseinfo.CaseComments.Records != null ? caseinfo.CaseComments.Records.Count - 1 : 0); row["ReopenedCount"] = reopenCount; jiaStstus = (tempIssue != null ? tempIssue.Status : ""); row["JiraStatus"] = jiaStstus; row["SFQueue"] = caseinfo.Owner.Name; row["SFStatus"] = caseinfo.Status; bool isCommentedToday = false; if (caseinfo.CaseComments != null && caseinfo.CaseComments.Records != null) { CaseComment comment = caseinfo.CaseComments.Records[0]; isCommentedToday = (comment.CreatedDate.Year == DateTime.Now.Year && comment.CreatedDate.Month == DateTime.Now.Month && comment.CreatedDate.Day == DateTime.Now.Day ? true : false); } row["NextJiraStatus"] = AccelaCaseUtil.GetNextJIRAStatus(caseinfo.Owner.Name, caseinfo.Status, jiaStstus, isCommentedToday); row["SFLastModified"] = (tempIssue != null ? tempIssue.LastModified : ""); table.Rows.Add(row); index++; } grdCaseList.AutoGenerateColumns = false; grdCaseList.DataSource = table; this.btnSendNotificationEmail.Enabled = true; this.btnSyncWithJIRA.Enabled = true; }
/// <summary> /// Export the case list from salesforce.com with the specified case list /// </summary> private async void btnSyncWithJiraAndSF_Click(object sender, EventArgs e) { this.btnSendDailyCaseSummaryReport.Enabled = false; this.btnSyncWithJiraAndSF.Enabled = false; // 1, Construct one case list from the specified case list // 1.1 Check if the case list formate is valid or not // 1.2 Construct one case list string caseIDs = this.txtCaseIDList.Text; List<string> caseIdList = new List<string>(); if (String.IsNullOrEmpty(caseIDs) || caseIDs.Trim().Length == 0) { // Refresh Today Case List this.DisplayTodayCaseList(); // Show one error message "ERROR: Please enter case id" (this.MdiParent as MainForm).ShowStatusMessage("ERROR: Please enter case id"); this.btnSendDailyCaseSummaryReport.Enabled = true; this.btnSyncWithJiraAndSF.Enabled = true; return; } else { (this.MdiParent as MainForm).ShowStatusMessage(""); string[] caseIDArray = caseIDs.Split(','); Regex reg = new Regex(@"\d{2}ACC-\d{5}"); foreach (string caseId in caseIDArray) { if (reg.IsMatch(caseId)) { if (!caseIdList.Contains(caseId.Trim())) { caseIdList.Add(caseId.Trim()); } } else { // Show one error message "ERROR: Invalid Format for XXXX" (this.MdiParent as MainForm).ShowStatusMessage("ERROR: Invalid Format for " + caseId); this.btnSendDailyCaseSummaryReport.Enabled = true; this.btnSyncWithJiraAndSF.Enabled = true; return; } } } var caseList = new List<AccelaCase>(); var issueList = new List<Issue>(); int N = 1; for (int i=0; i < caseIdList.Count; ) { List<string> caseIdListTemp = new List<string>(); for (; i < N * 50 && i < caseIdList.Count; i++) { caseIdListTemp.Add(caseIdList[i]); } N = N + 1; var GetCaseList = SalesforceProxy.GetCaseList(caseIdListTemp); var GetIssueList = JiraProxy.GetIssueList(caseIdListTemp); var caseListTmp = await GetCaseList; var issueListTmp = await GetIssueList; caseList.AddRange(caseListTmp); issueList.AddRange(issueListTmp); } Dictionary<string, AccelaIssueCaseMapper> JiraMapping = new Dictionary<string, AccelaIssueCaseMapper>(); foreach (var issue in issueList) { if (!JiraMapping.ContainsKey(issue.fields.customfield_10600)) { AccelaIssueCaseMapper accelaIssueCaseMapper = new AccelaIssueCaseMapper(); accelaIssueCaseMapper.CaseNumber = issue.fields.customfield_10600; accelaIssueCaseMapper.Assignee = (issue.fields.assignee == null ? "" : issue.fields.assignee.displayName); accelaIssueCaseMapper.AssigneeQA = (issue.fields.customfield_11702 == null ? "" : issue.fields.customfield_11702.displayName); accelaIssueCaseMapper.JiraId = issue.id; accelaIssueCaseMapper.JiraKey = issue.key; accelaIssueCaseMapper.IssueCategory = (issue.fields.customfield_11502 != null && issue.fields.customfield_11502.Count > 0 ? issue.fields.customfield_11502[0].value : "--NONE--"); accelaIssueCaseMapper.LastModified = issue.fields.customfield_10903; accelaIssueCaseMapper.Status = issue.fields.status.name; accelaIssueCaseMapper.HotCase = issue.fields.labels.Contains("HotCase"); accelaIssueCaseMapper.Missionsky = issue.fields.labels.Contains("Missionsky"); accelaIssueCaseMapper.JiraLabels = issue.fields.labels; JiraMapping.Add(accelaIssueCaseMapper.CaseNumber, accelaIssueCaseMapper); } } DataTable table = new DataTable("Daily Report"); table.Columns.Add("ID", typeof(string)); table.Columns.Add("No", typeof(int)); table.Columns.Add("HotCase", typeof(bool)); table.Columns.Add("Missionsky", typeof(bool)); table.Columns.Add("JiraLabels", typeof(List<string>)); table.Columns.Add("ProductForUI", typeof(string)); table.Columns.Add("Product", typeof(string)); table.Columns.Add("Solution", typeof(string)); table.Columns.Add("Orgin", typeof(string)); table.Columns.Add("OpenDate", typeof(string)); table.Columns.Add("Severity", typeof(string)); table.Columns.Add("Rank", typeof(int)); table.Columns.Add("SalesforceID", typeof(string)); table.Columns.Add("JiraID", typeof(string)); table.Columns.Add("JiraKey", typeof(string)); table.Columns.Add("Type", typeof(string)); table.Columns.Add("Version", typeof(string)); table.Columns.Add("Customer", typeof(string)); table.Columns.Add("Summary", typeof(string)); table.Columns.Add("Description", typeof(string)); table.Columns.Add("Reviewer", typeof(string)); table.Columns.Add("Comments", typeof(string)); table.Columns.Add("ReopenedCount", typeof(string)); table.Columns.Add("JiraStatus", typeof(string)); table.Columns.Add("NextJiraStatus", typeof(string)); table.Columns.Add("SFQueue", typeof(string)); table.Columns.Add("SFStatus", typeof(string)); table.Columns.Add("SFLastModified", typeof(string)); table.Columns.Add("CaseComment", typeof(CaseComment)); table.Columns.Add("TargetedRelease", typeof(string)); table.Columns.Add("BZID", typeof(string)); table.Columns.Add("IssueCategory", typeof(string)); table.Columns.Add("Assignee", typeof(string)); table.Columns.Add("AssigneeQA", typeof(string)); table.Columns.Add("CaseComments", typeof(List<CaseComment>)); Dictionary<string, string> Reviewers = SalesforceProxy.GetReviewerNamesList(); int index = 1; AccelaIssueCaseMapper tempIssue = null; string openDate = ""; string jiraKey = ""; string jiraId = ""; string customer = ""; string assignee = ""; int reopenCount = 0; string jiaStstus = ""; string[] Severity = null; string temComment = ""; string lastModifiedDate = ""; int rank = 0; foreach (var caseinfo in caseList) { tempIssue = null; if (JiraMapping.ContainsKey(caseinfo.CaseNumber)) { tempIssue = JiraMapping[caseinfo.CaseNumber]; } DataRow row = table.NewRow(); row["ID"] = caseinfo.Id; row["No"] = index; row["HotCase"] = (tempIssue != null && tempIssue.HotCase); row["Missionsky"] = (tempIssue != null && tempIssue.Missionsky); row["JiraLabels"] = (tempIssue != null ? tempIssue.JiraLabels : null); row["IssueCategory"] = (tempIssue != null ? tempIssue.IssueCategory : null); row["Assignee"] = (tempIssue != null ? tempIssue.Assignee : null); row["AssigneeQA"] = (tempIssue != null ? tempIssue.AssigneeQA : null); //row["HotCase"] = true; row["ProductForUI"] = AccelaCaseUtil.AdjustProductName(caseinfo.Product, caseinfo.Solution, caseinfo.Subject, caseinfo.Description); row["Product"] = caseinfo.Product; row["Solution"] = caseinfo.Solution; row["Orgin"] = caseinfo.Origin; //openDate = caseinfo.CreatedDate.ToShortDateString(); openDate = (caseinfo.CreatedDate.Month < 10 ? "0" + caseinfo.CreatedDate.Month : "" + caseinfo.CreatedDate.Month) + "/" + (caseinfo.CreatedDate.Day < 10 ? "0" + caseinfo.CreatedDate.Day : "" + caseinfo.CreatedDate.Day) + "/" + ("" + caseinfo.CreatedDate.Year); row["OpenDate"] = openDate; Severity = caseinfo.Priority.Split(' '); row["Severity"] = Severity[1]; rank = 0; if (!String.IsNullOrEmpty(caseinfo.RankOrder)) { rank = int.Parse(caseinfo.RankOrder); } else if (!String.IsNullOrEmpty(caseinfo.ServicesRank)) { rank = int.Parse(caseinfo.ServicesRank); } else { rank = 0; } row["Rank"] = rank; row["SalesforceID"] = caseinfo.CaseNumber; jiraKey = (tempIssue != null ? tempIssue.JiraKey : ""); jiraId = (tempIssue != null ? tempIssue.JiraId : ""); row["JiraKey"] = jiraKey; row["JiraID"] = jiraId; row["Type"] = (String.IsNullOrEmpty(caseinfo.InternalType) ? caseinfo.Type : "Production " + caseinfo.InternalType); row["Version"] = caseinfo.CurrentVersion; customer = (caseinfo.Customer != null && !String.IsNullOrEmpty(caseinfo.Customer.Name) ? caseinfo.Customer.Name : (caseinfo.Account != null ? caseinfo.Account.Name : "")); if (customer.IndexOf("Accela") >= 0 && caseinfo.Account != null && !String.IsNullOrEmpty(caseinfo.Account.Name)) { customer = caseinfo.Account.Name; } row["Customer"] = customer; row["Summary"] = caseinfo.Subject; row["Description"] = caseinfo.Description; assignee = (tempIssue != null ? tempIssue.Assignee : ""); temComment = ""; //lastModifiedDate = DateTime.Now.Year + "-" + (DateTime.Now.Month < 10 ? "0" + DateTime.Now.Month : "" + DateTime.Now.Month) + "-" + (DateTime.Now.Day < 10 ? "0" + DateTime.Now.Day : "" + DateTime.Now.Day); DateTime Yesterday = DateTime.Now.AddDays(-1); lastModifiedDate = Yesterday.Year + "-" + Yesterday.Month + "-" + Yesterday.Day; if (caseinfo.CaseComments != null && caseinfo.CaseComments.Records != null) { row["CaseComments"] = caseinfo.CaseComments.Records; CaseComment comment = caseinfo.CaseComments.Records[0]; //lastModifiedDate = comment.CreatedDate.Year + "-" + (comment.CreatedDate.Month < 10 ? "0" + comment.CreatedDate.Month : "" + comment.CreatedDate.Month) + "-" + (comment.CreatedDate.Day < 10 ? "0" + comment.CreatedDate.Day : "" + comment.CreatedDate.Day); if (DateTime.Now.Year != comment.CreatedDate.Year && DateTime.Now.Month != comment.CreatedDate.Month && DateTime.Now.Day != comment.CreatedDate.Day) { lastModifiedDate = comment.CreatedDate.Year + "-" + comment.CreatedDate.Month + "-" + comment.CreatedDate.Day; } row["CaseComment"] = comment; if (!String.IsNullOrEmpty(comment.CommentBody)) { if (comment.CommentBody.ToUpper().IndexOf("BUB") > 0) { temComment += "This is a bug.<br>"; } if (comment.CommentBody.ToUpper().IndexOf("DEFECT") > 0) { temComment += "This is a defect.<br>"; } } if (!String.IsNullOrEmpty(assignee) && comment.CommentBody.ToUpper().Contains(assignee.ToUpper())) { } else { foreach (var key in Reviewers.Keys) { string value = Reviewers[key]; string value1 = value.Replace('.', ' '); if (comment.CommentBody.ToUpper().EndsWith(key.ToUpper()) || comment.CommentBody.ToUpper().EndsWith(value.ToUpper()) || comment.CommentBody.ToUpper().EndsWith(value1.ToUpper())) { assignee = Reviewers[key]; break; } } } } row["Reviewer"] = assignee; row["Comments"] = temComment; reopenCount = (caseinfo.CaseComments != null && caseinfo.CaseComments.Records != null ? caseinfo.CaseComments.Records.Count - 1 : 0); row["ReopenedCount"] = reopenCount; jiaStstus = (tempIssue != null ? tempIssue.Status : ""); row["JiraStatus"] = jiaStstus; row["SFQueue"] = caseinfo.Owner.Name; row["SFStatus"] = caseinfo.Status; bool isCommentedToday = false; if (caseinfo.CaseComments != null && caseinfo.CaseComments.Records != null) { CaseComment comment = caseinfo.CaseComments.Records[0]; isCommentedToday = (comment.CreatedDate.Year == DateTime.Now.Year && comment.CreatedDate.Month == DateTime.Now.Month && comment.CreatedDate.Day == DateTime.Now.Day ? true : false); } row["NextJiraStatus"] = AccelaCaseUtil.GetNextJIRAStatus(caseinfo.Owner.Name, caseinfo.Status, jiaStstus, isCommentedToday); row["SFLastModified"] = lastModifiedDate; if (tempIssue != null && String.IsNullOrEmpty(tempIssue.LastModified)) { System.Console.WriteLine("Last Modified Date is empty"); } row["TargetedRelease"] = caseinfo.TargetedRelease; row["BZID"] = caseinfo.BZID; table.Rows.Add(row); index++; } DataView dataTableView = table.DefaultView; dataTableView.Sort = "Severity ASC"; table = dataTableView.ToTable(); grdCaseList.AutoGenerateColumns = false; grdCaseList.DataSource = table; // 2, Exclude the exported case // 2.1 Exclude those case which exists in database already CaseBusiness caseBusiness = new CaseBusiness(); List<CaseModel> caseModelList = caseBusiness.BatchQuery(caseIdList); // 2.2 Construct one new case list // 3, Invoke Salesforce REST API caseBusiness.ImportCasesFromSalesforce(caseIdList); // 4, Display today case list with the status value as "In Progress" or "" this.btnSendDailyCaseSummaryReport.Enabled = true; this.btnSyncWithJiraAndSF.Enabled = true; }
private async void btnLookUpInJiraAndSF_Click(object sender, EventArgs e) { this.btnLookUpInJiraAndSF.Enabled = false; string emailAddress = this.ddlReviewerEmailAddress.SelectedValue as string; if ("*****@*****.**" == emailAddress) { emailAddress = emailAddress.Replace("@missionsky.com", ""); } var issues = await JiraProxy.GetIssueList(emailAddress); List<string> caseList = new List<string>(); Dictionary<string, AccelaIssueCaseMapper> JiraMapping = new Dictionary<string, AccelaIssueCaseMapper>(); foreach (var issue in issues) { AccelaIssueCaseMapper accelaIssueCaseMapper = new AccelaIssueCaseMapper(); accelaIssueCaseMapper.CaseNumber = issue.fields.customfield_10600; accelaIssueCaseMapper.Assignee = (issue.fields.assignee == null ? "" : issue.fields.assignee.displayName); accelaIssueCaseMapper.JiraKey = issue.key; accelaIssueCaseMapper.JiraId = issue.id; accelaIssueCaseMapper.Status = issue.fields.status.name; accelaIssueCaseMapper.HotCase = issue.fields.labels.Contains("HotCase"); if (String.IsNullOrEmpty(accelaIssueCaseMapper.CaseNumber)) { continue; } if (!JiraMapping.ContainsKey(accelaIssueCaseMapper.CaseNumber)) { JiraMapping.Add(accelaIssueCaseMapper.CaseNumber, accelaIssueCaseMapper); } else { System.Console.WriteLine("Duplicated Case: " + accelaIssueCaseMapper.CaseNumber); if ("CLOSED".Equals(JiraMapping[accelaIssueCaseMapper.CaseNumber].Status, StringComparison.CurrentCultureIgnoreCase)) { JiraMapping[accelaIssueCaseMapper.CaseNumber] = accelaIssueCaseMapper; } } caseList.Add(accelaIssueCaseMapper.CaseNumber); } DataTable table = new DataTable("CaseList"); table.Columns.Add("ID", typeof(string)); table.Columns.Add("No", typeof(int)); table.Columns.Add("Product", typeof(string)); table.Columns.Add("SalesforceID", typeof(string)); table.Columns.Add("JiraKey", typeof(string)); table.Columns.Add("JiraID", typeof(string)); table.Columns.Add("Type", typeof(string)); table.Columns.Add("Version", typeof(string)); table.Columns.Add("Priority", typeof(string)); table.Columns.Add("Customer", typeof(string)); table.Columns.Add("Summary", typeof(string)); table.Columns.Add("Reviewer", typeof(string)); table.Columns.Add("ReopenedCount", typeof(string)); table.Columns.Add("SFQueue", typeof(string)); table.Columns.Add("SFStatus", typeof(string)); table.Columns.Add("JiraStatus", typeof(string)); table.Columns.Add("JiraNextStatus", typeof(string)); if (caseList.Count == 0) { this.grdCaseList.DataSource = table; this.grdCaseList.AutoGenerateColumns = false; this.btnLookUpInJiraAndSF.Enabled = true; return; } Dictionary<string, string> Reviewers = new Dictionary<string, string>(); Reviewers.Add("Jessy", "Jessy.Zhang"); Reviewers.Add("Adger", "Adger.Chen"); Reviewers.Add("Tim", "Tim.Liu"); Reviewers.Add("Mia", "Mia.Huang"); Reviewers.Add("Alvin", "Alvin.Li"); Reviewers.Add("Mina", "Mina.Xiong"); Reviewers.Add("Peter", "Peter.Peng"); Reviewers.Add("John", "John.Huang"); Reviewers.Add("Bass", "Bass.Yang"); Reviewers.Add("Star", "Star.Li"); Reviewers.Add("Shaun", "Shaun.Qiu"); Reviewers.Add("Lex", "Lex.Wu"); Reviewers.Add("Louis", "Louis.He"); Reviewers.Add("Likko", "Likko.Zhang"); Reviewers.Add("Sandy", "Sandy.Zheng"); Reviewers.Add("Weber", "Weber.Yan"); Reviewers.Add("Rick", "Rick.Liu"); Reviewers.Add("Matt", "Matt.Ao"); Reviewers.Add("Hyman", "Hyman.Zhang"); Reviewers.Add("Feng", "Feng.Xuan"); Reviewers.Add("Cheng", "Cheng.Xu"); Reviewers.Add("Alex", "Alex.Li"); Reviewers.Add("Mandy", "Mandy.Zhou"); Reviewers.Add("Linda", "Linda.Xiao"); Reviewers.Add("Leo", "Leo.Liu"); Reviewers.Add("Abel", "Abel.Yu"); Reviewers.Add("Claire", "Claire.Cao"); Reviewers.Add("Viola", "Viola.Shi"); Reviewers.Add("Larry", "Larry.Francisco"); Reviewers.Add("Gordon", "Gordon.Chen"); Reviewers.Add("Tracy", "Tracy.Xiang"); Reviewers.Add("Jessie", "Jessie.Zhang"); Reviewers.Add("William", "William.Wang"); Reviewers.Add("Carly", "Carly.Xu"); Reviewers.Add("Janice", "Janice.Zhong"); Reviewers.Add("Jane", "Jane.Hu"); Reviewers.Add("Amy", "Amy.Bao"); Reviewers.Add("Iris", "Iris.Wang"); Reviewers.Add("Grace", "Grace.Tang"); Reviewers.Add("Cloud", "Clouid.Qi"); Reviewers.Add("Carol", "Carol.Gong"); Reviewers.Add("Manasi", "*****@*****.**"); Reviewers.Add("Sasirekha", "*****@*****.**"); Reviewers.Add("Jerry", "Jerry.Lu"); var jiraId = ""; var jiraKey = ""; var customer = ""; var assignee = ""; var jiaStstus = ""; var reopenCount = 0; bool isCommentedToday = false; int index = 1; AccelaIssueCaseMapper tempIssue = null; var cases = await SalesforceProxy.GetCaseList(caseList); foreach(var caseinfo in cases) { tempIssue = null; if (JiraMapping.ContainsKey(caseinfo.CaseNumber)) { tempIssue = JiraMapping[caseinfo.CaseNumber]; } DataRow row = table.NewRow(); row["ID"] = caseinfo.Id; row["No"] = index; row["Product"] = AccelaCaseUtil.AdjustProductName(caseinfo.Product, caseinfo.Solution, caseinfo.Subject, caseinfo.Description); row["SalesforceID"] = caseinfo.CaseNumber; jiraId = (tempIssue != null ? tempIssue.JiraId : ""); row["JiraID"] = jiraId; jiraKey = (tempIssue != null ? tempIssue.JiraKey : ""); row["JiraKey"] = jiraKey; row["Type"] = caseinfo.Type; row["Version"] = caseinfo.CurrentVersion; string[] severity = caseinfo.Priority.Split(' '); row["Priority"] = severity[1]; customer = (caseinfo.Customer != null && !String.IsNullOrEmpty(caseinfo.Customer.Name) ? caseinfo.Customer.Name : (caseinfo.Account != null ? caseinfo.Account.Name : "")); row["Customer"] = customer; row["Summary"] = caseinfo.Subject; reopenCount = (caseinfo.CaseComments != null && caseinfo.CaseComments.Records != null ? caseinfo.CaseComments.Records.Count - 1 : 0); row["ReopenedCount"] = reopenCount; row["SFQueue"] = caseinfo.Owner.Name; row["SFStatus"] = caseinfo.Status; jiaStstus = (tempIssue != null ? tempIssue.Status : ""); row["JiraStatus"] = jiaStstus; assignee = (tempIssue != null ? tempIssue.Assignee : ""); isCommentedToday = false; if (caseinfo.CaseComments != null && caseinfo.CaseComments.Records != null) { CaseComment comment = caseinfo.CaseComments.Records[0]; isCommentedToday = (comment.CreatedDate.Year == DateTime.Now.Year && comment.CreatedDate.Month == DateTime.Now.Month && comment.CreatedDate.Day == DateTime.Now.Day ? true : false); if (!String.IsNullOrEmpty(assignee) && comment.CommentBody.ToUpper().Contains(assignee.ToUpper())) { } else { foreach (var key in Reviewers.Keys) { string value = Reviewers[key]; string value1 = value.Replace('.', ' '); if (comment.CommentBody.ToUpper().EndsWith(key.ToUpper()) || comment.CommentBody.ToUpper().EndsWith(value.ToUpper()) || comment.CommentBody.ToUpper().EndsWith(value1.ToUpper())) { assignee = Reviewers[key]; break; } } } } /* if ("CLOSED".Equals(caseinfo.Status, StringComparison.InvariantCultureIgnoreCase) && !"CLOSED".Equals(jiaStstus, StringComparison.InvariantCultureIgnoreCase)) { row["JiraNextStatus"] = "Closed"; } if ("engineering".Equals(caseinfo.Owner.Name, StringComparison.InvariantCultureIgnoreCase) && "eng new".Equals(caseinfo.Status, StringComparison.InvariantCultureIgnoreCase)) { if (isCommentedToday) { row["JiraNextStatus"] = "Pending"; } else { if (!"Open".Equals(jiaStstus, StringComparison.InvariantCultureIgnoreCase) && !"In Progress".Equals(jiaStstus, StringComparison.InvariantCultureIgnoreCase)) { row["JiraNextStatus"] = "In Progress"; } } } if (isCommentedToday && !"Pending".Equals(jiaStstus, StringComparison.InvariantCultureIgnoreCase)) { row["JiraNextStatus"] = "Pending"; } * */ row["JiraNextStatus"] = AccelaCaseUtil.GetNextJIRAStatus(caseinfo.Owner.Name, caseinfo.Status, jiaStstus, isCommentedToday); row["Reviewer"] = assignee; table.Rows.Add(row); index++; } this.grdCaseList.AutoGenerateColumns = false; this.grdCaseList.DataSource = table; this.btnLookUpInJiraAndSF.Enabled = true; }