List <ExtendedTimeEntry> GetEntries(DateTime from, DateTime to, long workspaceId) { var timeEntryParams = new TimeEntryParams { StartDate = from, EndDate = to, WorkspaceId = workspaceId }; List <ExtendedTimeEntry> entries = timeEntryService.List(timeEntryParams) .Where(x => x.WorkspaceId.Value == workspaceId) .Select(x => new ExtendedTimeEntry(x)).ToList(); foreach (var entry in entries) { foreach (var clientNameResolver in clientNameResolvers.OrderByDescending(x => x.Weight)) { if (entry.IsClientNameDefined == true) { break; } if (clientNameResolver.TryResolve(entry, out IClient client)) { entry.DefineClientName(client.Name); } } foreach (var projectNameResolver in projectNameResolvers.OrderByDescending(x => x.Weight)) { if (entry.IsProjectNameDefined == true) { break; } if (projectNameResolver.TryResolve(entry, out IProject project)) { entry.DefineProjectName(project.Name); } } foreach (var tagResolver in tagResolvers.OrderByDescending(x => x.Weight)) { // maybe break here in case we already have found tag? if (tagResolver.TryResolve(entry, out ITag tag)) { entry.AddTagName(tag.Name); } } } return(entries); }
public WorkLogEntry[] GetEntries(DateTime startDate, DateTime endDate, IEnumerable <string> jiraProjectKeys) { var togglTimeEntries = _timeEntryService .List(new TimeEntryParams { StartDate = startDate, EndDate = endDate }) .Where(w => !string.IsNullOrEmpty(w.Description) && w.Stop != null); var jiraWorkLogEntries = togglTimeEntries.Select(t => ToWorkLogEntry(t, _descriptionTemplate, jiraProjectKeys)); jiraWorkLogEntries = jiraWorkLogEntries.Where(j => j.HasIssueKeyAssigned()); return(jiraWorkLogEntries.ToArray()); }
public async Task Start(TimeSpan interval) { while (true) { await Task.Delay(interval); List <TimeEntry> timeEntries = new List <TimeEntry>(); try { timeEntries = _timeEntryService.List(); } catch (Exception) { _balloonNotification.Show("Could not retrieve time entries from Toggl.", "Make sure your internet connection is up and your Toggl API key is valid."); continue; } var currentEntry = timeEntries.SingleOrDefault(x => x.Duration < 0); if (currentEntry == null) { _balloonNotification.Show("You have no active timer at the moment.", "Toggl your work now!"); continue; } if (string.IsNullOrWhiteSpace(currentEntry.Description)) { _balloonNotification.Show("Your active timer has no description.", "Better add one now!"); continue; } _balloonNotification.Show(currentEntry.Description, "That's not what you are doing right now? Toggl your work now!"); } }