Пример #1
0
        public IEnumerable <JiraAbsence> GetAbsences(Dictionary <string, string> userNameInitialsDictionary)
        {
            var result = new List <JiraAbsence>();
            ConcurrentBag <dynamic> issuesJsons = new ConcurrentBag <dynamic>();

            var items = GetAbsencePage(0);

            PagingJob issuesPagingJob = new PagingJob(items.issues.Count, items.total.Value);

            issuesJsons.Add(items);

            if (issuesPagingJob.IsPagingNecessary)
            {
                Parallel.ForEach(issuesPagingJob.GetPageStarts(), pageStart =>
                {
                    issuesJsons.Add(GetAbsencePage(pageStart));
                });
            }

            foreach (var item in issuesJsons)
            {
                foreach (var issue in item.issues)
                {
                    result.Add(AbsenceMapper.MapAbsence(issue, userNameInitialsDictionary, _jiraBaseUrl));
                }
            }

            return(result);
        }
Пример #2
0
        public virtual Worklogs GetWorklogs(IEnumerable <string> users, DateTime from, DateTime till)
        {
            Worklogs results = new Worklogs();

            ConcurrentBag <dynamic> issuesJsons = new ConcurrentBag <dynamic>();
            dynamic   firstIssuesJson           = GetIssuesWithWorklogs(users, from, till, 0);
            PagingJob issuesPagingJob           = new PagingJob(firstIssuesJson.issues.Count, firstIssuesJson.total.Value);

            issuesJsons.Add(firstIssuesJson);

            if (issuesPagingJob.IsPagingNecessary)
            {
                Parallel.ForEach(issuesPagingJob.GetPageStarts(), new ParallelOptions {
                    MaxDegreeOfParallelism = 1
                }, pageStart =>
                {
                    issuesJsons.Add(GetIssuesWithWorklogs(users, from, till, pageStart));
                });
            }

            ConcurrentBag <dynamic>           worklogsJsons      = new ConcurrentBag <dynamic>();
            ConcurrentBag <WorklogsPagingJob> worklogsPagingJobs = new ConcurrentBag <WorklogsPagingJob>();

            foreach (dynamic issuesJson in issuesJsons)
            {
                Parallel.ForEach(issuesJson.issues, new ParallelOptions {
                    MaxDegreeOfParallelism = 1
                }, (Action <dynamic>)(issueJson =>
                {
                    if (issueJson.fields != null && issueJson.fields.worklog != null)
                    {
                        List <string> labels = new List <string>();
                        if (issueJson.fields.parent != null)
                        {
                            dynamic issueParent = GetIssue((string)issueJson.fields.parent.key, "labels");
                            foreach (dynamic label in issueParent.fields.labels)
                            {
                                labels.Add((string)label);
                            }
                        }
                        else if (issueJson.fields.labels != null)
                        {
                            foreach (dynamic label in issueJson.fields.labels)
                            {
                                labels.Add((string)label);
                            }
                        }

                        dynamic firstWorklogsJson           = issueJson.fields.worklog;
                        WorklogsPagingJob worklogsPagingJob = new WorklogsPagingJob(issueJson.key.Value, labels, firstWorklogsJson.worklogs.Count, firstWorklogsJson.total.Value);
                        if (worklogsPagingJob.IsPagingNecessary)
                        {
                            worklogsPagingJobs.Add(worklogsPagingJob);
                        }
                        else
                        {
                            firstWorklogsJson.issueKey = issueJson.key;
                            firstWorklogsJson.labels   = String.Join("||", labels);
                            worklogsJsons.Add(firstWorklogsJson);
                        }
                    }
                    else
                    {
                        worklogsPagingJobs.Add(new WorklogsPagingJob(issueJson.key.Value, Enumerable.Empty <string>(), 0, 1000));
                    }
                }));
            }

            Parallel.ForEach(worklogsPagingJobs, new ParallelOptions {
                MaxDegreeOfParallelism = 1
            }, x =>
            {
                dynamic worklogsJson  = GetWorklogsForIssue(x.IssueKey, 0);
                worklogsJson.issueKey = x.IssueKey;
                worklogsJson.labels   = String.Join("||", x.Labels);
                worklogsJsons.Add(worklogsJson);
            });

            foreach (dynamic worklogJsons in worklogsJsons)
            {
                string issueKey = worklogJsons.issueKey;
                string labels   = worklogJsons.labels ?? String.Empty;
                foreach (dynamic worklogJson in worklogJsons.worklogs)
                {
                    DateTime startTime            = worklogJson.started.Value;
                    string   workLoggedByUserName = worklogJson.author.displayName.Value;
                    string   workLoggedByUser     = users.SingleOrDefault(x => x == workLoggedByUserName);
                    if (startTime >= from && startTime <= till && workLoggedByUser != null)
                    {
                        JiraWorklog jiraWorklog = new JiraWorklog
                        {
                            IssueKey = issueKey,
                            Labels   = labels.Split(new[] { "||" }, StringSplitOptions.RemoveEmptyEntries),
                            Started  = startTime,
                            Duration = TimeSpan.FromSeconds(Convert.ToDouble(worklogJson.timeSpentSeconds.Value))
                        };
                        results.AddWorklogForUser(workLoggedByUser, jiraWorklog);
                    }
                }
            }

            return(results);
        }