/// <summary>
        /// Create a new Worklogs object.
        /// </summary>
        /// <param name="id">Initial value of ID.</param>
        /// <param name="time">Initial value of Time.</param>
        /// <param name="message">Initial value of Message.</param>
        public static Worklogs CreateWorklogs(int id, global::System.DateTime time, string message)
        {
            Worklogs worklogs = new Worklogs();

            worklogs.ID      = id;
            worklogs.Time    = time;
            worklogs.Message = message;
            return(worklogs);
        }
Ejemplo n.º 2
0
        protected override List <Worklog> CalculateReportData()
        {
            Logger.Info("Getting worklogs in range {0} to {1}", _from, _till);

            var result    = new List <Worklog>();
            var userNames = _userReporter.Report()
                            .Select(x => x.Login)
                            .ToList();

            Worklogs worklogs = _jiraApiClient.GetWorklogs(userNames, _from, _till);

            foreach (var user in userNames)
            {
                Timesheet personTimesheet = worklogs.GetTimesheet(user) ?? new Timesheet(user);
                result.AddRange(personTimesheet.Worklogs.Select(x => Worklog.FromWorklog(x, user)));
            }

            return(result);
        }
 /// <summary>
 /// There are no comments for Worklogs in the schema.
 /// </summary>
 public void AddToWorklogs(Worklogs worklogs)
 {
     base.AddObject("Worklogs", worklogs);
 }
Ejemplo n.º 4
0
 public double GetTotalHoursByIssue(IssueViewModel issue)
 {
     return(TimeSpan.FromSeconds(Worklogs.Where(x => x.Issue == issue).Sum(x => x.TimeSpendSeconds)).TotalHours);
 }
Ejemplo n.º 5
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);
        }