Exemplo n.º 1
0
        public static void CreateMOMCache(List <IssueItem> issuesInRedmineProject, List <IssueItem> problematicIssuesInRedmineProject, int project_id, IOutputable output)
        {
            output.Write("Cache creation...");

            List <Issue> issuesListFromRemine = CommonTools.GetIssuesFromRedmine(project_id);

            if (output.GetIsRedisUse())
            {
                cache = RedisConnectorHelper.Connection.GetDatabase();
            }

            foreach (var issue in issuesListFromRemine.Where(issue => issue.Project.Id == project_id))
            {
                string subject = issue.Subject;

                //split subject to get env and problem id
                string[] subjectSplitted = subject.Split('-');

                //get env
                string env = subjectSplitted[0].Trim();

                IssueItem item = new IssueItem();
                item.Id     = issue.Id;
                item.Status = issue.Status.Name;
                item.Desc   = subject;
                item.Env    = env;

                if (subjectSplitted.Length >= 4)
                {
                    //get MOM problem is from subject
                    item.ProblemId = subjectSplitted[1].Trim();

                    //look for sender code
                    if (subjectSplitted.Length >= 5)
                    {
                        item.SenderCode = subjectSplitted[4].Trim();
                    }
                    issuesInRedmineProject.Add(item);

                    //cache.HashSetAsync("dd", "ddd", "ddd");
                }
                else
                {
                    problematicIssuesInRedmineProject.Add(item);
                }
            }

            output.WriteLine("done!");
        }
Exemplo n.º 2
0
        private static void ProcessExcelFile(List <IssueItem> issuesInRedmineProject, List <StatItem> statItems, List <string> envsNotExistingInConfigs)
        {
            //********************************************************************************************************/
            //read data from Excel
            var xlsx = new LinqToExcel.ExcelQueryFactory(MOM_FILE_PATH);

            foreach (string tabName in xlsx.GetWorksheetNames())
            {
                output.WriteLine("--------------------------------------------");
                output.WriteLine("Processing of {0}...", tabName);
                output.WriteLine("--------------------------------------------");

                MOMEnvSettings momEnvSettings = null;
                if (!MOM_ENV_SETTINGS.TryGetValue(tabName, out momEnvSettings))
                {
                    output.WriteLine("No MOMEnvSettings for {0}", tabName);
                    envsNotExistingInConfigs.Add(tabName);
                    //output.ReadKey();
                }
                else
                {
                    output.WriteLine("Start processing: {0}", tabName);

                    StatItem statItem = new StatItem();
                    statItem.Env = tabName;

                    var query =
                        from row in xlsx.Worksheet(tabName)
                        let item = new
                    {
                        ProblemID   = row["Problem ID"].Cast <string>(),
                        ProblemCode = row["Problem Code"].Cast <string>(),
                        MessageId   = row["Message ID"].Cast <string>(),
                        EventCode   = row["Event Code"].Cast <string>(),
                        Details     = row["Details"].Cast <string>(),
                        SenderCode  = row["Sender Code"].Cast <string>(),
                    }
                    select item;

                    IdentifiableName p = IdentifiableName.Create <Project>(Consts.PROJECT_NAMES.MOM.PROBLEMS);
                    foreach (var itemFromExcel in query)
                    {
                        string subject = string.Format("{0} - {1} - {2} - {3} - {4}", tabName, itemFromExcel.ProblemID, itemFromExcel.EventCode, itemFromExcel.ProblemCode, itemFromExcel.SenderCode);

                        //check if such the item exists in the Redmine project
                        var redmineIssue = issuesInRedmineProject.Where(issueFromRedmine => issueFromRedmine.Env == tabName && issueFromRedmine.ProblemId == itemFromExcel.ProblemID);
                        if (redmineIssue.Count() == 0)
                        {
                            string details = string.Format("{0}\r\nMessage link: {1}\r\nProblem link: {2}", itemFromExcel.Details, momEnvSettings.GetMessageLink(itemFromExcel.MessageId), momEnvSettings.GetProblemLink(itemFromExcel.MessageId));

                            var newIssue = new Issue {
                                Subject = subject, Project = p, Description = details
                            };
                            RMManegerService.RMManager.CreateObject(newIssue);

                            //add a new item to local cached items from redmine
                            IssueItem item = new IssueItem();

                            item.Env       = tabName;
                            item.ProblemId = itemFromExcel.ProblemID;

                            issuesInRedmineProject.Add(item);

                            statItem.Added++;
                        }
                        else
                        {
                            output.WriteLine("Issue exists! {0}", subject);
                            statItem.AlreadyExisted++;
                        }
                    }
                    statItems.Add(statItem);
                }
            }
        }