示例#1
0
        public static void Main(params string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Please provide your toggl API key as application argument.");
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            _notifyIcon = new NotifyIcon
            {
                Icon        = Resources.time,
                Visible     = true,
                ContextMenu = new ContextMenu
                {
                    MenuItems =
                    {
                        new MenuItem("Exit", OnExitClick)
                    }
                }
            };

            var timeEntryService = new TimeEntryService(args[0]);

            var notifyIconBalloonNotification = new NotifyIconBalloonNotification(_notifyIcon);
            var annoyService = new AnnoyService(timeEntryService, notifyIconBalloonNotification);

            annoyService.Start(TimeSpan.FromMinutes(5));

            Application.Run();
        }
示例#2
0
        private async Task GetJiraTicketSummaryAsync(JiraWorklogEntry jiraWorklogEntry)
        {
            jiraWorklogEntry.Summary = "Loading...";
            var result = await TimeEntryService.GetJiraTicketSummaryAsync(jiraWorklogEntry.Ticket);

            jiraWorklogEntry.Summary = result;
        }
示例#3
0
        public async Task CanRequestReportForSpecificMonthAndYearWithoutDashParsingIssues(string dateEntry)
        {
            DateTime         date             = new DateTime(2018, 2, 1);
            var              user             = database.Users.First();
            TimeEntryService timeEntryService = new TimeEntryService(user.UserId, database);
            await timeEntryService.CreateBillableTimeEntry(date, 2, 1);

            await timeEntryService.CreateNonBillableTimeEntry(date.AddDays(1), 3, null, TimeEntryTypeEnum.Vacation);

            await timeEntryService.CreateNonBillableTimeEntry(date.AddDays(2), 1, "flu", TimeEntryTypeEnum.Sick);

            DateTime mayDate = new DateTime(2019, 5, 18);
            await timeEntryService.CreateBillableTimeEntry(mayDate, 2, 1);


            var response = await orchestrator.HandleCommand(new SlashCommandPayload
            {
                text      = "summary month " + dateEntry,
                user_id   = user.SlackUserId,
                user_name = user.UserName
            });

            response.Text.Should().Contain($"February {date.Year} Billable Hours: 2.0");
            response.Text.Should().Contain($"February {date.Year} Vacation Hours: 3.0");
            response.Text.Should().Contain($"February {date.Year} Sick Hours: 1.0");
            response.Text.Should().Contain($"February {date.Year} Other Non-billable Hours: 0.0");
        }
示例#4
0
        public TimeEntryServiceTest()
        {
            var inMemoryDatabase = new InMemoryDatabaseWithProjectsAndUsers();

            database         = inMemoryDatabase.Database;
            timeEntryService = new TimeEntryService(userId, database);
        }
示例#5
0
        ///// <summary>
        ///// Get Custom Templates for specific Type passed
        ///// </summary>
        ///// <param name="dataAccessToken"></param>
        ///// <param name="type"></param>
        ///// <returns>CustomTemplateListBO</returns>
        //public CustomTemplateListBO GetCustomTemplates(string dataAccessToken, string type)
        //{
        //    CustomTemplateListBO outputCustomTemplates = new CustomTemplateListBO(); ;

        //    try
        //    {
        //        // Calls GetCustomTemplates of Integration layer to fetch custom templates for specific type
        //        TimeEntryService integrationService = new TimeEntryService();
        //        outputCustomTemplates.CustomTemplates = integrationService.GetCustomTemplates(Constants.CONSUMER_SECRET_TOKEN, UtilityService.DecryptedText(dataAccessToken), Constants.VERSION_5, type);
        //    }
        //    catch (DovicoException e)
        //    {
        //        logger.Log(LogLevel.Error, e);
        //        outputCustomTemplates.ErrorMessage = e.Message;
        //    }
        //    catch (Exception e)
        //    {
        //        logger.Log(LogLevel.Error, e);
        //        outputCustomTemplates.ErrorMessage = "Error Fetching Custom Templates";
        //    }

        //    return outputCustomTemplates;
        //}

        /// <summary>
        /// Get Custom Templates for the Task
        /// </summary>
        /// <param name="dataAccessToken"></param>
        /// <param name="taskId"></param>
        /// <returns>CustomTemplateListBO</returns>
        public CustomTemplateListBO GetCustomTemplates(string dataAccessToken, string apiVersion, string taskId)
        {
            CustomTemplateListBO outputCustomTemplates = new CustomTemplateListBO();;

            try
            {
                // Calls GetCustomTemplates of Integration layer to fetch custom templates for the task
                TimeEntryService integrationService = new TimeEntryService();
                outputCustomTemplates.CustomTemplates = integrationService.GetCustomTemplates(Constants.CONSUMER_SECRET_TOKEN,
                                                                                              UtilityService.DecryptedText(dataAccessToken),
                                                                                              apiVersion, taskId);
            }
            catch (DovicoException e)
            {
                logger.Log(LogLevel.Error, e);
                outputCustomTemplates.ErrorMessage = e.Message;
            }
            catch (Exception e)
            {
                logger.Log(LogLevel.Error, e);
                outputCustomTemplates.ErrorMessage = "Error Fetching Custom Templates";
            }

            return(outputCustomTemplates);
        }
示例#6
0
        public async Task WhenRequestingNonSpecificReport_ReportIncludesCurrentWeekSummary()
        {
            DateTime         date             = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day - 2);
            var              user             = database.Users.First();
            TimeEntryService timeEntryService = new TimeEntryService(user.UserId, database);
            await timeEntryService.CreateBillableTimeEntry(date, 2, 1);

            await timeEntryService.CreateNonBillableTimeEntry(date.AddDays(1), 3, null, TimeEntryTypeEnum.Vacation);

            await timeEntryService.CreateNonBillableTimeEntry(date.AddDays(2), 1, "flu", TimeEntryTypeEnum.Sick);

            date = date.AddMonths(1);
            await timeEntryService.CreateBillableTimeEntry(date, 2, 1);

            await timeEntryService.CreateNonBillableTimeEntry(date.AddDays(1), 3, null, TimeEntryTypeEnum.Vacation);

            await timeEntryService.CreateNonBillableTimeEntry(date.AddDays(2), 1, "flu", TimeEntryTypeEnum.Sick);

            var response = await orchestrator.HandleCommand(new SlashCommandPayload
            {
                text      = "summary",
                user_id   = user.SlackUserId,
                user_name = user.UserName
            });

            response.Text.Should().Contain($"This Week Billable Hours: 2.0");
            response.Text.Should().Contain($"This Week Vacation Hours: 3.0");
            response.Text.Should().Contain($"This Week Sick Hours: 1.0");
            response.Text.Should().Contain($"This Week Other Non-billable Hours: 0.0");
        }
示例#7
0
        /// <summary>
        /// Creates new <see cref="TogglClient"/>
        /// </summary>
        /// <param name="apiToken">Toggl API token</param>
        /// <param name="throttler">Throttler to use when invoking methods. If null, no throttling is performed</param>
        public TogglClient(string apiToken, IThrottler throttler = null)
        {
            Clients     = new ClientService(this);
            TimeEntries = new TimeEntryService(this);
            Projects    = new ProjectService(this);
            Tags        = new TagService(this);
            Tasks       = new TaskService(this);
            Users       = new UserService(this);
            Workspaces  = new WorkspaceService(this);
            Reports     = new ReportService(this);

            _jsonSerializer = JsonSerializer.CreateDefault();
            _throttler      = throttler ?? new NeutralThrottler();

            _togglHttpClient = new HttpClient();
            _togglHttpClient.DefaultRequestHeaders.Accept.Clear();
            _togglHttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            if (UserAgent != null)
            {
                _togglHttpClient.DefaultRequestHeaders.UserAgent.Add(UserAgent);
            }

            // authorization (basic)
            var authorizationParameter = Convert.ToBase64String(Encoding.GetEncoding("ascii").GetBytes($"{apiToken}:api_token"));
            var header = new AuthenticationHeaderValue("Basic", authorizationParameter);

            _togglHttpClient.DefaultRequestHeaders.Authorization = header;
        }
示例#8
0
        public void Edit()
        {
            var timeEntry = TimeEntryService.Add(new TimeEntry()
            {
                IsBillable  = true,
                CreatedWith = "TogglAPI.Net",
                Duration    = 900,
                Start       = DateTime.Now.ToIsoDateStr(),
                WorkspaceId = DefaultWorkspaceId
            });

            Assert.IsNotNull(timeEntry);

            var loadedTimeEntry = TimeEntryService.Get(timeEntry.Id.Value);

            Assert.IsNotNull(loadedTimeEntry);

            loadedTimeEntry.Duration = 1200;
            var editedTimeEntry = TimeEntryService.Edit(loadedTimeEntry);

            Assert.AreEqual(timeEntry.Id, editedTimeEntry.Id);
            Assert.AreEqual(timeEntry.IsBillable, editedTimeEntry.IsBillable);
            Assert.AreEqual(timeEntry.CreatedWith, editedTimeEntry.CreatedWith);
            Assert.AreEqual(loadedTimeEntry.Duration, editedTimeEntry.Duration);
            Assert.AreEqual(timeEntry.WorkspaceId, editedTimeEntry.WorkspaceId);
        }
示例#9
0
        public void GetTimeEntriesByDateRange()
        {
            var startDate = DateTime.Now.AddMonths(-2);
            var endDate   = DateTime.Now.AddMonths(-1);

            for (int i = 0; i < 3; i++)
            {
                var te = TimeEntryService.Add(new TimeEntry()
                {
                    IsBillable  = true,
                    CreatedWith = "TogglAPI.Net",
                    Duration    = 900,
                    Start       = startDate.AddMonths(i).ToIsoDateStr(),
                    WorkspaceId = DefaultWorkspaceId
                });
                Assert.IsNotNull(te);
            }

            var rte = new TimeEntryParams {
                StartDate = startDate, EndDate = endDate
            };

            Assert.AreEqual(2, TimeEntryService.List(rte).Count());
            rte = new TimeEntryParams {
                StartDate = startDate, EndDate = DateTime.Now
            };
            Assert.AreEqual(3, TimeEntryService.List(rte).Count());
        }
示例#10
0
        public async Task WhenRequestingReportForSpecificDate_ReportIncludesAllHoursForThatDay()
        {
            DateTime         date             = new DateTime(2018, 2, 9);
            var              user             = database.Users.First();
            TimeEntryService timeEntryService = new TimeEntryService(user.UserId, database);
            await timeEntryService.CreateBillableTimeEntry(date, 2, 1);

            await timeEntryService.CreateNonBillableTimeEntry(date, 3, null, TimeEntryTypeEnum.Vacation);

            await timeEntryService.CreateNonBillableTimeEntry(date, 1, "flu", TimeEntryTypeEnum.Sick);

            DateTime mayDate = new DateTime(2019, 5, 18);
            await timeEntryService.CreateBillableTimeEntry(mayDate, 2, 1);


            var response = await orchestrator.HandleCommand(new SlashCommandPayload
            {
                text      = "summary date Feb-9-2018",
                user_id   = user.SlackUserId,
                user_name = user.UserName
            });

            response.Text.Should().Contain($"February {date.Day} {date.Year} Billable Hours: 2.0");
            response.Text.Should().Contain($"February {date.Day} {date.Year} Vacation Hours: 3.0");
            response.Text.Should().Contain($"February {date.Day} {date.Year} Sick Hours: 1.0");
            response.Text.Should().Contain($"February {date.Day} {date.Year} Other Non-billable Hours: 0.0");
        }
示例#11
0
        public void GetDetailedReportSince()
        {
            var timeEntryService = new TimeEntryService(Constants.ApiToken);

            for (int i = 0; i < 6; i++)
            {
                var timeEntry = new TimeEntry()
                {
                    IsBillable  = true,
                    CreatedWith = "TimeEntryTestAdd",
                    Description = "Test Desc" + DateTime.Now.Ticks,
                    Duration    = 900,
                    Start       = DateTime.Now.AddDays(-i).ToIsoDateStr(),
                    Stop        = DateTime.Now.AddDays(-i).AddMinutes(20).ToIsoDateStr(),
                    ProjectId   = DefaultProjectId,
                    WorkspaceId = DefaultWorkspaceId
                };
                var expTimeEntry = timeEntryService.Add(timeEntry);
                Assert.IsNotNull(expTimeEntry);
            }

            var standardParams = new DetailedReportParams()
            {
                UserAgent   = "TogglAPI.Net",
                WorkspaceId = DefaultWorkspaceId
            };

            var result = ReportService.Detailed(standardParams);

            Assert.AreEqual(result.Data.Count, 6);
            Assert.AreEqual(result.TotalCount, 6);

            var te = new TimeEntry()
            {
                IsBillable  = true,
                CreatedWith = "TimeEntryTestAdd",
                Description = "Test Desc" + DateTime.Now.Ticks,
                Duration    = 900,
                Start       = DateTime.Now.AddDays(-7).ToIsoDateStr(),
                Stop        = DateTime.Now.AddDays(-7).AddMinutes(20).ToIsoDateStr(),
                ProjectId   = DefaultProjectId,
                WorkspaceId = DefaultWorkspaceId
            };
            var expTe = timeEntryService.Add(te);

            Assert.IsNotNull(expTe);

            result = ReportService.Detailed(standardParams);
            Assert.AreEqual(result.Data.Count, 6);
            Assert.AreEqual(result.TotalCount, 6);

            result = ReportService.Detailed(new DetailedReportParams()
            {
                UserAgent   = "test_api",
                WorkspaceId = DefaultWorkspaceId,
                Since       = DateTime.Now.AddDays(-7).ToIsoDateStr()
            });
            Assert.AreEqual(result.Data.Count, 7);
            Assert.AreEqual(result.TotalCount, 7);
        }
示例#12
0
        public void GetDetailedReport()
        {
            for (int i = 0; i < 6; i++)
            {
                var expTimeEntry = TimeEntryService.Add(new TimeEntry()
                {
                    IsBillable  = true,
                    CreatedWith = "TimeEntryTestAdd",
                    Duration    = 900,
                    Start       = DateTime.Now.AddDays(-i).ToIsoDateStr(),
                    Stop        = DateTime.Now.AddDays(-i).AddMinutes(20).ToIsoDateStr(),
                    ProjectId   = DefaultProjectId,
                    WorkspaceId = DefaultWorkspaceId
                });
                Assert.IsNotNull(expTimeEntry);
            }

            var standardParams = new DetailedReportParams()
            {
                UserAgent   = "TogglAPI.Net",
                WorkspaceId = DefaultWorkspaceId,
                Since       = DateTime.Now.AddYears(-1).ToIsoDateStr()
            };

            var result = ReportService.Detailed(standardParams);

            Assert.AreEqual(result.Data.Count, 6);
            Assert.AreEqual(result.TotalCount, 6);
        }
        public void GetDashboard()
        {
            var expTimeEntry = TimeEntryService.Add(new TimeEntry()
            {
                IsBillable  = true,
                CreatedWith = "TimeEntryTestAdd",
                Description = "Test",
                Duration    = 900,
                Start       = DateTime.Now.ToIsoDateStr(),
                Stop        = DateTime.Now.AddMinutes(20).ToIsoDateStr(),
                ProjectId   = DefaultProjectId,
                WorkspaceId = DefaultWorkspaceId,
                TagNames    = new List <string> {
                    Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                }
            });

            Assert.IsNotNull(expTimeEntry);

            var currentUser = UserService.GetCurrent();

            Assert.IsNotNull(currentUser);
            Assert.IsNotNull(currentUser.DefaultWorkspaceId);

            var result = DashboardService.Get((int)currentUser.DefaultWorkspaceId);

            Assert.IsNotNull(result);
        }
示例#14
0
 public void Setup()
 {
     _databaseSetup = new DatabaseSetup();
     _databaseSetup.CleanDatabase();
     _databaseSetup.CreateStandardDatabase();
     _timeEntryService = new TimeEntryService(_databaseSetup.GetTrexConnection);
 }
示例#15
0
        public async Task WhenRequestingReportForSpecificMonth_ReportOnlyIncludesHoursForTheMonth()
        {
            DateTime         date             = new DateTime(DateTime.UtcNow.Year, 3, 18);
            var              user             = database.Users.First();
            TimeEntryService timeEntryService = new TimeEntryService(user.UserId, database);
            await timeEntryService.CreateBillableTimeEntry(date, 2, 1);

            await timeEntryService.CreateNonBillableTimeEntry(date.AddDays(1), 3, null, TimeEntryTypeEnum.Vacation);

            await timeEntryService.CreateNonBillableTimeEntry(date.AddDays(2), 1, "flu", TimeEntryTypeEnum.Sick);

            DateTime mayDate = new DateTime(DateTime.UtcNow.Year, 5, 18);
            await timeEntryService.CreateBillableTimeEntry(mayDate, 2, 1);


            var response = await orchestrator.HandleCommand(new SlashCommandPayload
            {
                text      = "summary month mar",
                user_id   = user.SlackUserId,
                user_name = user.UserName
            });

            response.Text.Should().Contain($"March {date.Year} Billable Hours: 2.0");
            response.Text.Should().Contain($"March {date.Year} Vacation Hours: 3.0");
            response.Text.Should().Contain($"March {date.Year} Sick Hours: 1.0");
            response.Text.Should().Contain($"March {date.Year} Other Non-billable Hours: 0.0");
        }
示例#16
0
        public void GetTimeEntriesByTaskId()
        {
            var task1 = TaskService.Add(new Task
            {
                IsActive         = true,
                Name             = "task1",
                EstimatedSeconds = 3600,
                WorkspaceId      = DefaultWorkspaceId,
                ProjectId        = DefaultProjectId
            });

            Assert.IsNotNull(task1);

            var task2 = TaskService.Add(new Task
            {
                IsActive         = true,
                Name             = "task2",
                EstimatedSeconds = 3600,
                WorkspaceId      = DefaultWorkspaceId,
                ProjectId        = DefaultProjectId
            });

            Assert.IsNotNull(task2);

            for (int i = 0; i < 3; i++)
            {
                var timeEntry = TimeEntryService.Add(new TimeEntry()
                {
                    IsBillable  = true,
                    CreatedWith = "TogglAPI.Net",
                    Duration    = 900,
                    Start       = DateTime.Now.ToIsoDateStr(),
                    WorkspaceId = DefaultWorkspaceId,
                    TaskId      = task1.Id
                });

                Assert.IsNotNull(timeEntry);
            }

            for (int i = 0; i < 3; i++)
            {
                var timeEntry = TimeEntryService.Add(new TimeEntry()
                {
                    IsBillable  = true,
                    CreatedWith = "TogglAPI.Net",
                    Duration    = 900,
                    Start       = DateTime.Now.ToIsoDateStr(),
                    WorkspaceId = DefaultWorkspaceId,
                    TaskId      = task2.Id
                });

                Assert.IsNotNull(timeEntry);
            }

            Assert.AreEqual(3, TimeEntryService.List().Count(te => te.TaskId == task1.Id));
            Assert.AreEqual(3, TimeEntryService.List().Count(te => te.TaskId == task2.Id));
        }
        public async Task EditTimeEntryAsync_Success(string jsonEntity)
        {
            var req = JsonConvert.DeserializeObject <EditTimeEntryRequest>(jsonEntity);

            var service = new TimeEntryService(timeMapper, timeRepo);
            var result  = await service.EditTimeEntryAsync(req);

            result.ShouldNotBeNull();
        }
        public async Task DeleteTimeEntryAsync_Success_DoesNotExist(string jsonEntity)
        {
            var req = JsonConvert.DeserializeObject <DeleteTimeEntryRequest>(jsonEntity);

            var service = new TimeEntryService(timeMapper, timeRepo);

            var result = await service.DeleteTimeEntryAsync(req);

            result.ShouldBeTrue();
        }
示例#19
0
        public Toggl(string apiToken)
        {
            var apiService = new ApiService(apiToken);

            _workspaceService = new WorkspaceService(apiService);
            _clientService    = new ClientService(apiService);
            _projectService   = new ProjectService(apiService);
            _timeEntryService = new TimeEntryService(apiService);
            _reportService    = new ReportService(apiService);
        }
示例#20
0
        /// <summary>
        /// Gets CustomTerminology
        /// </summary>
        /// <param name="consumerSecretToken"></param>
        /// <param name="dataAccessToken"></param>
        /// <param name="version"></param>
        /// <returns>CustomTerminologyBO</returns>
        private CustomTerminologyBO GetCustomTerminology(string consumerSecretToken, string dataAccessToken, string apiVersion)
        {
            TimeEntryService    integrationService  = new TimeEntryService();
            CustomTerminologyBO customTerminologyBO = new CustomTerminologyBO();

            // Calls GetCustomTerminology of Integration layer
            customTerminologyBO = integrationService.GetCustomTerminology(Constants.CONSUMER_SECRET_TOKEN, UtilityService.DecryptedText(dataAccessToken), apiVersion);

            return(customTerminologyBO);
        }
示例#21
0
        protected override async Task <SlackMessageResponse> RespondTo(HoursInterpretedMessage message)
        {
            var userService = new UserService(dbContext);

            var user = await userService.FindOrCreateSlackUser(message.UserId, message.UserName);

            var timeEntryService = new TimeEntryService(user.UserId, dbContext);

            if (message.IsBillable)
            {
                // resolve client and project
                var projectSvc = new ProjectService(dbContext);
                var project    = await projectSvc.FindProjectFromName(message.Project);

                if (project == null)
                {
                    return(new SlackMessageResponse($"Invalid Project Name {message.Project}", false));
                }

                await timeEntryService.CreateBillableTimeEntry(
                    message.Date, message.Hours, project.ProjectId);

                return(new SlackMessageResponse(
                           $"Registered *{message.Hours:F1} hours* for project *{message.Project}* {message.Date:D}. " +
                           (message.IsWorkFromHome ? "_Worked From Home_" : ""), true));
            }

            switch (message.TimeEntryType)
            {
            case TimeEntryTypeEnum.Sick:
                await timeEntryService.CreateNonBillableTimeEntry(message.Date, message.Hours,
                                                                  message.NonBillReason, message.TimeEntryType);

                return(new SlackMessageResponse(
                           $"Registered *{message.Hours:F1} hours* for Sick reason: {message.NonBillReason} for date: {message.Date:D}",
                           true));

            case TimeEntryTypeEnum.Vacation:
                await timeEntryService.CreateNonBillableTimeEntry(message.Date, message.Hours,
                                                                  message.NonBillReason, message.TimeEntryType);

                return(new SlackMessageResponse(
                           $"Registered *{message.Hours:F1} hours* for Vacation for date: {message.Date:D}",
                           true));

            default:
                await timeEntryService.CreateNonBillableTimeEntry(message.Date, message.Hours,
                                                                  message.NonBillReason, message.TimeEntryType);

                return(new SlackMessageResponse(
                           $"Registered *{message.Hours:F1} hours* for Nonbillable reason: {message.NonBillReason ?? message.TimeEntryType.ToString()} for date: {message.Date:D}",
                           true));
            }
        }
        public async Task DeleteTimeEntryAsync_Failure_DoesNotExist(string jsonEntity)
        {
            var req = JsonConvert.DeserializeObject <DeleteTimeEntryRequest>(jsonEntity);

            var service = new TimeEntryService(timeMapper, timeRepo);

            await Assert.ThrowsAsync <DbUpdateConcurrencyException>(async() =>
            {
                var result = await service.DeleteTimeEntryAsync(req);
            });
        }
示例#23
0
 public Toggl(string key)
 {
     ApiService = new ApiService(key);
     Client     = new ClientService(ApiService);
     Project    = new ProjectService(ApiService);
     Tag        = new TagService(ApiService);
     Task       = new TaskService(ApiService);
     TimeEntry  = new TimeEntryService(ApiService);
     User       = new UserService(ApiService);
     Workspace  = new WorkspaceService(ApiService);
 }
示例#24
0
        public void Start()
        {
            var timeEntry = TimeEntryService.Add(new TimeEntry()
            {
                CreatedWith = "TogglAPI.Net",
                Description = "Start a new task",
                WorkspaceId = DefaultWorkspaceId
            });

            Assert.IsNotNull(timeEntry);
        }
示例#25
0
        private async Task HandleValidSubmitAsync()
        {
            // I believe this is still being called, even when a JiraWorklogEntry has invalid data, because I'm working with a collection of objects rather than individual objects.
            // ".NET Core 3.1 Preview 2 introduces experimental support for object graph validation using data annotations" tells me that my list validation simply isn't supported yet.
            Console.WriteLine("Handling Valid Submit");
            _isSubmitting = true;
            var result = await TimeEntryService.SubmitJiraWorklogEntriesAsync(_jiraWorklogEntries);

            _jiraWorklogEntries = result;
            UpdateTotalTime();
            _isSubmitting = false;
            //TODO: Issue #2, show a popup dialog or something saying "Submitted # entires"
        }
示例#26
0
        public IEnumerable <WorkLogEntry> GetEntries(DateTime startDate, DateTime endDate)
        {
            var timeEntryService = new TimeEntryService(_apiKey);

            var hours = timeEntryService
                        .List(new TimeEntryParams
            {
                StartDate = startDate,
                EndDate   = endDate
            })
                        .Where(w => !string.IsNullOrEmpty(w.Description) && w.Stop != null);

            return(hours.Select(ToWorkLogEntry));
        }
示例#27
0
        public void Add()
        {
            var timeEntry = TimeEntryService.Add(new TimeEntry()
            {
                IsBillable  = true,
                CreatedWith = "TogglAPI.Net",
                Duration    = 900,
                Start       = DateTime.Now.ToIsoDateStr(),
                Stop        = DateTime.Now.AddMinutes(10).ToIsoDateStr(),
                WorkspaceId = DefaultWorkspaceId
            });

            Assert.IsNotNull(timeEntry);
            Assert.AreEqual(1, TimeEntryService.List().Count());
        }
示例#28
0
        public async Task HandleCommand_deleteHours_returnsDeletedMessage_andDeletesHours()
        {
            var user             = database.Users.First();
            var timeEntryService = new TimeEntryService(user.UserId, database);
            await timeEntryService.CreateBillableTimeEntry(DateTime.UtcNow.Date, 7, 1);

            var slackMessage = await orchestrator.HandleCommand(new SlashCommandPayload()
            {
                text      = "delete",
                user_id   = user.SlackUserId,
                user_name = user.UserName
            });

            slackMessage.Text.Should().Be($"Deleted {7d:F1} hours for date: {DateTime.UtcNow.Date:D}");
            database.TimeEntries.Count().Should().Be(0);
        }
示例#29
0
        public void Delete()
        {
            var timeEntry = TimeEntryService.Add(new TimeEntry()
            {
                IsBillable  = true,
                CreatedWith = "TogglAPI.Net",
                Duration    = 900,
                Start       = DateTime.Now.ToIsoDateStr(),
                WorkspaceId = DefaultWorkspaceId
            });

            Assert.IsNotNull(timeEntry);
            Assert.AreEqual(1, TimeEntryService.List().Count());
            Assert.IsTrue(TimeEntryService.Delete(timeEntry.Id.Value));
            Assert.AreEqual(0, TimeEntryService.List().Count());
        }
示例#30
0
        public async Task GetAllUsersByDateReport_filtersUsersWithHoursForDates_whenFilterByProject()
        {
            var baseDate = new DateTime(DateTime.UtcNow.Date.Year, 3, 15);

            await PopulateTimeEntries(2, baseDate);

            var timeEntryService = new TimeEntryService(Guid.NewGuid(), database);
            await timeEntryService.CreateBillableTimeEntry(baseDate, 8, 1);

            var report = await adminReportService.GetAllUsersByDate(
                new DateTime(DateTime.UtcNow.Date.Year, 2, 1),
                new DateTime(DateTime.UtcNow.Date.Year, 3, 30), 2);

            report.Should().HaveCount(1);
            report.First().BillableHoursYtd.Should().Be(12);
        }
示例#31
0
		public virtual void Init()
		{
			WorkspaceService = new WorkspaceService(Constants.ApiToken);
			var workspaces = WorkspaceService.List();

			ClientService = new ClientService(Constants.ApiToken);
			TaskService = new TaskService(Constants.ApiToken);
			TagService = new TagService(Constants.ApiToken);
			ProjectService = new ProjectService(Constants.ApiToken);
			UserService = new UserService(Constants.ApiToken);
			TimeEntryService = new TimeEntryService(Constants.ApiToken);
			ReportService = new ReportService(Constants.ApiToken);

			foreach (var workspace in workspaces)
			{
				var projects = WorkspaceService.Projects(workspace.Id.Value);
				var tasks = WorkspaceService.Tasks(workspace.Id.Value);
				var tags = WorkspaceService.Tags(workspace.Id.Value); // TODO
				var users = WorkspaceService.Users(workspace.Id.Value); // TODO
				var clients = WorkspaceService.Clients(workspace.Id.Value);
				var rte = new TimeEntryParams { StartDate = DateTime.Now.AddYears(-1)};
				var timeEntries = TimeEntryService.List(rte);

				Assert.IsTrue(TimeEntryService.DeleteIfAny(timeEntries.Select(te => te.Id.Value).ToArray()));
				Assert.IsTrue(ProjectService.DeleteIfAny(projects.Select(p => p.Id.Value).ToArray()));				
				Assert.IsTrue(TaskService.DeleteIfAny(tasks.Select(t => t.Id.Value).ToArray()));
				Assert.IsTrue(ClientService.DeleteIfAny(clients.Select(c => c.Id.Value).ToArray()));

				Assert.IsFalse(WorkspaceService.Projects(workspace.Id.Value).Any());
				Assert.IsFalse(WorkspaceService.Tasks(workspace.Id.Value).Any());
				Assert.IsFalse(WorkspaceService.Clients(workspace.Id.Value).Any());
				Assert.IsFalse(TimeEntryService.List(rte).Any());
			}

			DefaultWorkspaceId = workspaces.First().Id.Value;
		}
        /// <summary>
        /// Constructs the Freshbooks API authentication and wrapper class
        /// </summary>
        /// <param name="accountName">The account name for which you are trying to access</param>
        /// <param name="consumerKey">The developer's freshbooks account name</param>
        /// <param name="oauthSecret">The developer's oauth-secret provided by freshbooks</param>
        public FreshbooksApi(string accountName, string consumerKey, string oauthSecret)
        {
            _accountName = accountName;
            _consumerKey = consumerKey;
            _oauthSecret = oauthSecret ?? String.Empty;

            _baseUri = new UriBuilder { Scheme = "https", Host = accountName + ".freshbooks.com" }.Uri;
            _serviceUri = new Uri(_baseUri, "/api/2.1/xml-in");
            Clear();

            UserAgent = String.Format("{0}/{1} ({2})", 
                GetType().Name,
                GetType().Assembly.GetName().Version.ToString(2), 
                GetType().Assembly.FullName);

            Callback = new CallbackService(new ServiceProxy(this, "callback"));
            Category = new CategoryService(new ServiceProxy(this, "category"));
            Client = new ClientService(new ServiceProxy(this, "client"));
            Estimate = new EstimateService(new ServiceProxy(this, "estimate"));
            Expense = new ExpenseService(new ServiceProxy(this, "expense"));
            Gateway = new GatewayService(new ServiceProxy(this, "gateway"));
            Invoice = new InvoiceService(new ServiceProxy(this, "invoice"));
            Item = new ItemService(new ServiceProxy(this, "item"));
            Language = new LanguageService(new ServiceProxy(this, "language"));
            Payment = new PaymentService(new ServiceProxy(this, "payment"));
            Project = new ProjectService(new ServiceProxy(this, "project"));
            Recurring = new RecurringService(new ServiceProxy(this, "recurring"));
            System = new SystemService(new ServiceProxy(this, "system"));
            Staff = new StaffService(new ServiceProxy(this, "staff"));
            Task = new TaskService(new ServiceProxy(this, "task"));
            Tax = new TaxService(new ServiceProxy(this, "tax"));
            TimeEntry = new TimeEntryService(new ServiceProxy(this, "time_entry"));
        }