Example #1
0
        private CaseAnalysisInfo ConstructCaseAnalysisInfoModel(AccelaCase caseInfo, int SFCaseCommentCount, int SFDevCaseCommentCount, int SFQACaseCommentCount, Dictionary <DateTime, string> CommentHistories)
        {
            CaseAnalysisInfo caseAnalysisInfo = new CaseAnalysisInfo();

            caseAnalysisInfo.Product               = caseInfo.Product;
            caseAnalysisInfo.SFID                  = caseInfo.CaseNumber;
            caseAnalysisInfo.JiraKey               = String.Empty;
            caseAnalysisInfo.SFCaseCommentCount    = SFCaseCommentCount;
            caseAnalysisInfo.SFDevCaseCommentCount = SFDevCaseCommentCount;
            caseAnalysisInfo.SFQACaseCommentCount  = SFQACaseCommentCount;

            string 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;
            }

            caseAnalysisInfo.Customer = customer;

            caseAnalysisInfo.Severity         = caseInfo.Priority;
            caseAnalysisInfo.Version          = caseInfo.CurrentVersion;
            caseAnalysisInfo.OpenDate         = caseInfo.CreatedDate.ToShortDateString();
            caseAnalysisInfo.Summary          = caseInfo.Subject;
            caseAnalysisInfo.SFQueue          = caseInfo.Owner.Name;
            caseAnalysisInfo.SFStatus         = caseInfo.Status;
            caseAnalysisInfo.CommentHistories = CommentHistories;

            return(caseAnalysisInfo);
        }
        private CaseAnalysisInfo ConstructCaseAnalysisInfoModel(AccelaCase caseInfo, int SFCaseCommentCount, int SFDevCaseCommentCount, int SFQACaseCommentCount, Dictionary<DateTime, string> CommentHistories)
        {
            CaseAnalysisInfo caseAnalysisInfo = new CaseAnalysisInfo();
            caseAnalysisInfo.Product = caseInfo.Product;
            caseAnalysisInfo.SFID = caseInfo.CaseNumber;
            caseAnalysisInfo.JiraKey = String.Empty;
            caseAnalysisInfo.SFCaseCommentCount = SFCaseCommentCount;
            caseAnalysisInfo.SFDevCaseCommentCount = SFDevCaseCommentCount;
            caseAnalysisInfo.SFQACaseCommentCount = SFQACaseCommentCount;

            string 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;
            }

            caseAnalysisInfo.Customer = customer;

            caseAnalysisInfo.Severity = caseInfo.Priority;
            caseAnalysisInfo.Version = caseInfo.CurrentVersion;
            caseAnalysisInfo.OpenDate = caseInfo.CreatedDate.ToShortDateString();
            caseAnalysisInfo.Summary = caseInfo.Subject;
            caseAnalysisInfo.SFQueue = caseInfo.Owner.Name;
            caseAnalysisInfo.SFStatus = caseInfo.Status;
            caseAnalysisInfo.CommentHistories = CommentHistories;

            return caseAnalysisInfo;
        }
        private async void btnSync_Click(object sender, EventArgs e)
        {
            this.btnSync.Enabled = false;
            this.btnSend.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.txtInputCaseList.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.btnSync.Enabled = true;
                this.btnSend.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.btnSync.Enabled = true;
                        this.btnSend.Enabled = true;

                        return;
                    }
                }
            }

            List<string> DevNameList = null;
            List<string> QANameList = SalesforceProxy.GetQAReviewerNamesList();
            QANameList = SalesforceProxy.GetSupportQAList(this.chkExcludeAccela.Checked);
            DevNameList = SalesforceProxy.GetSupportDevList(this.chkExcludeAccela.Checked);
            Dictionary<string, string> Reviewers = SalesforceProxy.GetReviewerNamesList(this.chkExcludeAccela.Checked);

            var caseList = new List<CaseAnalysisInfo>();
            var issueList = new List<Issue>();

            int N = 1;
            int index1 = 1;
            for (int i = 0; i < caseIdList.Count; )
            {
                List<string> caseIdListTemp = new List<string>();
                for (; i < N * 100 && i < caseIdList.Count; i++)
                {
                    caseIdListTemp.Add(caseIdList[i]);
                }

                N = N + 1;

                var GetCaseList = SalesforceProxy.GetCaseList(caseIdListTemp, true);
                var GetIssueList = JiraProxy.GetIssueList(caseIdListTemp);

                var caseListTmp = await GetCaseList;
                var issueListTmp = await GetIssueList;

                Dictionary<string, CaseAnalysisInfo> JIRAMapper = new Dictionary<string, CaseAnalysisInfo>();
                foreach (var issue in issueListTmp)
                {
                    CaseAnalysisInfo caseAnalysisInfo = new CaseAnalysisInfo();
                    caseAnalysisInfo.SFID = issue.fields.customfield_10600;
                    caseAnalysisInfo.JiraKey = issue.key;
                    caseAnalysisInfo.IssueCategory = (issue.fields.customfield_11502 != null && issue.fields.customfield_11502.Count > 0 ? issue.fields.customfield_11502[0].value : "NONE");
                    if (!JIRAMapper.ContainsKey(issue.fields.customfield_10600))
                    {
                        JIRAMapper.Add(issue.fields.customfield_10600, caseAnalysisInfo);
                    }
                }

                foreach (var caseInfo in caseListTmp)
                {
                    Dictionary<DateTime, string> CommentHistories = new Dictionary<DateTime, string>();
                    bool isFound = false;
                    int sfCommentCount = 0;
                    int sfDevCommentCount = 0;
                    int sfQACommentCount = 0;

                    System.Console.WriteLine("[" + (index1++) + "] " + caseInfo.CaseNumber);

                    if (caseInfo.CaseComments != null && caseInfo.CaseComments.Records  != null && caseInfo.CaseComments.Records.Count > 0)
                    {
                        foreach (CaseComment comment in caseInfo.CaseComments.Records)
                        {                            
                            if (comment == null
                                || comment.CommentBody == null
                                || comment.LastModifiedDate.Year != 2016
                                || comment.LastModifiedDate.Month != this.dtpSpecifyDate.Value.Month)
                            {
                                continue;
                            }

                            if (this.chkSpecifyDate.Checked)
                            {
                                DateTime date = this.dtpSpecifyDate.Value;

                                if (comment == null
                                || comment.CommentBody == null
                                || comment.LastModifiedDate.Year != date.Year
                                || comment.LastModifiedDate.Month != date.Month
                                || comment.LastModifiedDate.Day != date.Day)
                                {
                                    continue;
                                }
                            }

                            string assignee = "";                           

                            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())
                                    || comment.LastModifiedBy.Name.ToUpper().StartsWith(value.ToUpper())
                                    || comment.LastModifiedBy.Name.ToUpper().StartsWith(value1.ToUpper()))
                                {
                                    isFound = true;
                                    sfCommentCount++;
                                    assignee = Reviewers[key];                                    
                                    if (QANameList.Contains(assignee))
                                    {
                                        sfQACommentCount++;
                                    }
                                    
                                    if (DevNameList.Contains(assignee))
                                    {
                                        sfDevCommentCount++;
                                    }

                                    CommentHistories.Add(comment.LastModifiedDate, assignee);
                                    break;
                                }
                            }       
                        }
                    }

                    if (isFound)
                    {
                        CaseAnalysisInfo caseAnalysisInfo = ConstructCaseAnalysisInfoModel(caseInfo, sfCommentCount, sfDevCommentCount, sfQACommentCount, CommentHistories);

                        if (JIRAMapper.ContainsKey(caseAnalysisInfo.SFID))
                        {
                            CaseAnalysisInfo tempCaseAnalysisInfo = JIRAMapper[caseAnalysisInfo.SFID];
                            caseAnalysisInfo.JiraKey = tempCaseAnalysisInfo.JiraKey;
                            caseAnalysisInfo.IssueCategory = tempCaseAnalysisInfo.IssueCategory;
                        }

                        System.Console.WriteLine("Add " + caseInfo.CaseNumber);
                        caseList.Add(caseAnalysisInfo);
                    }
                    else
                    {
                        System.Console.WriteLine("Skip " + caseInfo.CaseNumber);
                    }
                }
                
                //issueList.AddRange(issueListTmp);
            }

            DataTable table = new DataTable("Case Analysis Report");            
            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("SFCaseCommentCount", typeof(int));
            table.Columns.Add("SFDevCaseCommentCount", typeof(int));
            table.Columns.Add("SFQACaseCommentCount", typeof(int));
            table.Columns.Add("Customer", typeof(string));
            table.Columns.Add("Severity", typeof(string));
            table.Columns.Add("Version", typeof(string));
            table.Columns.Add("OpenDate", typeof(string));
            table.Columns.Add("Summary", typeof(string));
            table.Columns.Add("CommentHistories", typeof(Dictionary<DateTime, string>));
            table.Columns.Add("IssueCategory", typeof(string));           
            table.Columns.Add("SFQueue", typeof(string));
            table.Columns.Add("SFStatus", typeof(string));

            int index = 1;
            foreach (CaseAnalysisInfo caseAnalysisInfo in caseList)
            {
                DataRow row = table.NewRow();
                row["No"] = index;
                row["Product"] = caseAnalysisInfo.Product;
                row["SalesforceID"] = caseAnalysisInfo.SFID;
                row["JiraKey"] = caseAnalysisInfo.JiraKey;
                row["SFCaseCommentCount"] = caseAnalysisInfo.SFCaseCommentCount;
                row["SFDevCaseCommentCount"] = caseAnalysisInfo.SFDevCaseCommentCount;
                row["SFQACaseCommentCount"] = caseAnalysisInfo.SFQACaseCommentCount;
                row["Customer"] = caseAnalysisInfo.Customer;
                row["Severity"] = caseAnalysisInfo.Severity;
                row["Version"] = caseAnalysisInfo.Version;
                row["OpenDate"] = caseAnalysisInfo.OpenDate;
                row["Summary"] = caseAnalysisInfo.Summary;
                row["CommentHistories"] = caseAnalysisInfo.CommentHistories;
                row["IssueCategory"] = caseAnalysisInfo.IssueCategory;
                row["SFQueue"] = caseAnalysisInfo.SFQueue;
                row["SFStatus"] = caseAnalysisInfo.SFStatus;

                table.Rows.Add(row);
                index++;
            }

            DataView dataTableView = table.DefaultView;
            dataTableView.Sort = "SalesforceID ASC";
            table = dataTableView.ToTable();

            grdCaseList.AutoGenerateColumns = false;
            grdCaseList.DataSource = table;

                       
            this.btnSync.Enabled = true;
            this.btnSend.Enabled = true;
        }
Example #4
0
        private async void btnSync_Click(object sender, EventArgs e)
        {
            this.btnSync.Enabled = false;
            this.btnSend.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.txtInputCaseList.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.btnSync.Enabled = true;
                this.btnSend.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.btnSync.Enabled = true;
                        this.btnSend.Enabled = true;

                        return;
                    }
                }
            }

            List <string> DevNameList = null;
            List <string> QANameList  = SalesforceProxy.GetQAReviewerNamesList();

            QANameList  = SalesforceProxy.GetSupportQAList(this.chkExcludeAccela.Checked);
            DevNameList = SalesforceProxy.GetSupportDevList(this.chkExcludeAccela.Checked);
            Dictionary <string, string> Reviewers = SalesforceProxy.GetReviewerNamesList(this.chkExcludeAccela.Checked);

            var caseList  = new List <CaseAnalysisInfo>();
            var issueList = new List <Issue>();

            int N      = 1;
            int index1 = 1;

            for (int i = 0; i < caseIdList.Count;)
            {
                List <string> caseIdListTemp = new List <string>();
                for (; i < N * 100 && i < caseIdList.Count; i++)
                {
                    caseIdListTemp.Add(caseIdList[i]);
                }

                N = N + 1;

                var GetCaseList  = SalesforceProxy.GetCaseList(caseIdListTemp, true);
                var GetIssueList = JiraProxy.GetIssueList(caseIdListTemp);

                var caseListTmp  = await GetCaseList;
                var issueListTmp = await GetIssueList;

                Dictionary <string, CaseAnalysisInfo> JIRAMapper = new Dictionary <string, CaseAnalysisInfo>();
                foreach (var issue in issueListTmp)
                {
                    CaseAnalysisInfo caseAnalysisInfo = new CaseAnalysisInfo();
                    caseAnalysisInfo.SFID          = issue.fields.customfield_10600;
                    caseAnalysisInfo.JiraKey       = issue.key;
                    caseAnalysisInfo.IssueCategory = (issue.fields.customfield_11502 != null && issue.fields.customfield_11502.Count > 0 ? issue.fields.customfield_11502[0].value : "NONE");
                    if (!JIRAMapper.ContainsKey(issue.fields.customfield_10600))
                    {
                        JIRAMapper.Add(issue.fields.customfield_10600, caseAnalysisInfo);
                    }
                }

                foreach (var caseInfo in caseListTmp)
                {
                    Dictionary <DateTime, string> CommentHistories = new Dictionary <DateTime, string>();
                    bool isFound           = false;
                    int  sfCommentCount    = 0;
                    int  sfDevCommentCount = 0;
                    int  sfQACommentCount  = 0;

                    System.Console.WriteLine("[" + (index1++) + "] " + caseInfo.CaseNumber);

                    if (caseInfo.CaseComments != null && caseInfo.CaseComments.Records != null && caseInfo.CaseComments.Records.Count > 0)
                    {
                        foreach (CaseComment comment in caseInfo.CaseComments.Records)
                        {
                            if (comment == null ||
                                comment.CommentBody == null ||
                                comment.CreatedDate.Year != this.dtpSpecifyDate.Value.Year ||
                                comment.CreatedDate.Month != this.dtpSpecifyDate.Value.Month)
                            {
                                continue;
                            }

                            if (this.chkSpecifyDate.Checked)
                            {
                                DateTime date = this.dtpSpecifyDate.Value;

                                if (comment == null ||
                                    comment.CommentBody == null ||
                                    comment.CreatedDate.Year != date.Year ||
                                    comment.CreatedDate.Month != date.Month ||
                                    comment.CreatedDate.Day != date.Day)
                                {
                                    continue;
                                }
                            }

                            string assignee = "";

                            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()) ||
                                    comment.LastModifiedBy.Name.ToUpper().StartsWith(value.ToUpper()) ||
                                    comment.LastModifiedBy.Name.ToUpper().StartsWith(value1.ToUpper()))
                                {
                                    isFound = true;
                                    sfCommentCount++;
                                    assignee = Reviewers[key];
                                    if (QANameList.Contains(assignee))
                                    {
                                        sfQACommentCount++;
                                    }

                                    if (DevNameList.Contains(assignee))
                                    {
                                        sfDevCommentCount++;
                                    }

                                    CommentHistories.Add(comment.LastModifiedDate, assignee);
                                    break;
                                }
                            }
                        }
                    }

                    if (isFound)
                    {
                        CaseAnalysisInfo caseAnalysisInfo = ConstructCaseAnalysisInfoModel(caseInfo, sfCommentCount, sfDevCommentCount, sfQACommentCount, CommentHistories);

                        if (JIRAMapper.ContainsKey(caseAnalysisInfo.SFID))
                        {
                            CaseAnalysisInfo tempCaseAnalysisInfo = JIRAMapper[caseAnalysisInfo.SFID];
                            caseAnalysisInfo.JiraKey       = tempCaseAnalysisInfo.JiraKey;
                            caseAnalysisInfo.IssueCategory = tempCaseAnalysisInfo.IssueCategory;
                        }

                        System.Console.WriteLine("Add " + caseInfo.CaseNumber);
                        caseList.Add(caseAnalysisInfo);
                    }
                    else
                    {
                        System.Console.WriteLine("Skip " + caseInfo.CaseNumber);
                    }
                }

                //issueList.AddRange(issueListTmp);
            }

            DataTable table = new DataTable("Case Analysis Report");

            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("SFCaseCommentCount", typeof(int));
            table.Columns.Add("SFDevCaseCommentCount", typeof(int));
            table.Columns.Add("SFQACaseCommentCount", typeof(int));
            table.Columns.Add("Customer", typeof(string));
            table.Columns.Add("Severity", typeof(string));
            table.Columns.Add("Version", typeof(string));
            table.Columns.Add("OpenDate", typeof(string));
            table.Columns.Add("Summary", typeof(string));
            table.Columns.Add("CommentHistories", typeof(Dictionary <DateTime, string>));
            table.Columns.Add("IssueCategory", typeof(string));
            table.Columns.Add("SFQueue", typeof(string));
            table.Columns.Add("SFStatus", typeof(string));

            int index = 1;

            foreach (CaseAnalysisInfo caseAnalysisInfo in caseList)
            {
                DataRow row = table.NewRow();
                row["No"]                    = index;
                row["Product"]               = caseAnalysisInfo.Product;
                row["SalesforceID"]          = caseAnalysisInfo.SFID;
                row["JiraKey"]               = caseAnalysisInfo.JiraKey;
                row["SFCaseCommentCount"]    = caseAnalysisInfo.SFCaseCommentCount;
                row["SFDevCaseCommentCount"] = caseAnalysisInfo.SFDevCaseCommentCount;
                row["SFQACaseCommentCount"]  = caseAnalysisInfo.SFQACaseCommentCount;
                row["Customer"]              = caseAnalysisInfo.Customer;
                row["Severity"]              = caseAnalysisInfo.Severity;
                row["Version"]               = caseAnalysisInfo.Version;
                row["OpenDate"]              = caseAnalysisInfo.OpenDate;
                row["Summary"]               = caseAnalysisInfo.Summary;
                row["CommentHistories"]      = caseAnalysisInfo.CommentHistories;
                row["IssueCategory"]         = caseAnalysisInfo.IssueCategory;
                row["SFQueue"]               = caseAnalysisInfo.SFQueue;
                row["SFStatus"]              = caseAnalysisInfo.SFStatus;

                table.Rows.Add(row);
                index++;
            }

            DataView dataTableView = table.DefaultView;

            dataTableView.Sort = "SalesforceID ASC";
            table = dataTableView.ToTable();

            grdCaseList.AutoGenerateColumns = false;
            grdCaseList.DataSource          = table;


            this.btnSync.Enabled = true;
            this.btnSend.Enabled = true;
        }