Esempio n. 1
0
        public void Merge(int masterTaskId, int[] slaveTasksIds, int workspaceId, string userAgent = "TogglAPI.Net")
        {
            var reportService = new ReportService(this.ToggleSrv);
            var timeEntryService = new TimeEntryService(this.ToggleSrv);

            var reportParams = new DetailedReportParams()
            {
                UserAgent = userAgent,
                WorkspaceId = workspaceId,
                TaskIds = string.Join(",", slaveTasksIds.Select(id => id.ToString())),
                Since = DateTime.Now.AddYears(-1).ToIsoDateStr()
            };

            var result = reportService.Detailed(reportParams);

            if (result.TotalCount > result.PerPage)
                result = reportService.FullDetailedReport(reportParams);

            foreach (var reportTimeEntry in result.Data)
            {
                var timeEntry = timeEntryService.Get(reportTimeEntry.Id.Value);
                timeEntry.TaskId = masterTaskId;
                var editedTimeEntry = timeEntryService.Edit(timeEntry);
                if (editedTimeEntry == null)
                    throw new ArgumentNullException(string.Format("Can't edit timeEntry #{0}", reportTimeEntry.Id));
            }

            foreach (var slaveTaskId in slaveTasksIds)
            {
                if (!Delete(slaveTaskId))
                    throw new InvalidOperationException(string.Format("Can't delte task #{0}", slaveTaskId));
            }
        }
Esempio n. 2
0
        public void Merge(int masterTaskId, int slaveTaskId, int workspaceId, string userAgent = "TogglAPI.Net")
        {
            var reportService = new ReportService(this.ToggleSrv);
            var timeEntryService = new TimeEntryService(this.ToggleSrv);

            var reportParams = new DetailedReportParams()
            {
                UserAgent = userAgent,
                WorkspaceId = workspaceId,
                TaskIds = slaveTaskId.ToString(),
                Since = DateTime.Now.AddYears(-1).ToIsoDateStr()
            };

            var result = reportService.Detailed(reportParams);

            if (result.TotalCount > result.PerPage)
                result = reportService.FullDetailedReport(reportParams);

            foreach (var reportTimeEntry in result.Data)
            {
                var timeEntry = timeEntryService.Get(reportTimeEntry.Id.Value);
                timeEntry.TaskId = masterTaskId;
                try
                {
                    var editedTimeEntry = timeEntryService.Edit(timeEntry);
                }
                catch (Exception ex)
                {
                    var res = ex.Data;
                }
            }

            if (!Delete(slaveTaskId))
                throw new InvalidOperationException(string.Format("Can't delte task #{0}", slaveTaskId));
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
 public TogglClient(string APIToken)
 {
     _APIToken        = APIToken;
     WorkspaceService = new WorkspaceService(_APIToken);
     ProjectService   = new ProjectService(_APIToken);
     TimeEntryService = new TimeEntryService(_APIToken);
     TaskService      = new TaskService(_APIToken);
     ApiService       = new ApiService(_APIToken);
     ClientService    = new ClientService(_APIToken);
 }
Esempio n. 5
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);
 }        
Esempio n. 6
0
		public void Merge(int masterTaskId, int[] slaveTasksIds, int workspaceId, string userAgent = "TogglAPI.Net")
		{
			var reportService = new ReportService(this.ToggleSrv);
			var timeEntryService = new TimeEntryService(this.ToggleSrv);

			var reportParams = new DetailedReportParams()
			{
				UserAgent = userAgent,
				WorkspaceId = workspaceId,
				TaskIds = string.Join(",", slaveTasksIds.Select(id => id.ToString())),
				Since = DateTime.Now.AddYears(-1).ToIsoDateStr()
			};

			var result = reportService.Detailed(reportParams);

			if (result.TotalCount > result.PerPage)
				result = reportService.FullDetailedReport(reportParams);

			foreach (var reportTimeEntry in result.Data)
			{
				var timeEntry = timeEntryService.Get(reportTimeEntry.Id.Value);
				timeEntry.TaskId = masterTaskId;
				var editedTimeEntry = timeEntryService.Edit(timeEntry);
				if (editedTimeEntry == null)
					throw new ArgumentNullException(string.Format("Can't edit timeEntry #{0}", reportTimeEntry.Id));
			}

			foreach (var slaveTaskId in slaveTasksIds)
			{
				if (!Delete(slaveTaskId))
					throw new InvalidOperationException(string.Format("Can't delte task #{0}", slaveTaskId));	
			}			
		}
Esempio n. 7
0
		public void Merge(int masterTaskId, int slaveTaskId, int workspaceId, string userAgent = "TogglAPI.Net")
	    {
		    var reportService = new ReportService(this.ToggleSrv);
		    var timeEntryService = new TimeEntryService(this.ToggleSrv);

			var reportParams = new DetailedReportParams()
								{
									UserAgent = userAgent,
									WorkspaceId = workspaceId,
									TaskIds = slaveTaskId.ToString(),
									Since = DateTime.Now.AddYears(-1).ToIsoDateStr()
								};

		    var result = reportService.Detailed(reportParams);

			if (result.TotalCount > result.PerPage)
				result = reportService.FullDetailedReport(reportParams);

		    foreach (var reportTimeEntry in result.Data)
		    {
			    var timeEntry = timeEntryService.Get(reportTimeEntry.Id.Value);
				timeEntry.TaskId = masterTaskId;
			    try
			    {
				    var editedTimeEntry = timeEntryService.Edit(timeEntry);
			    }
			    catch (Exception ex)
			    {
				    var res = ex.Data;
			    }			    
		    }

		    if (!Delete(slaveTaskId))
				throw new InvalidOperationException(string.Format("Can't delte task #{0}", slaveTaskId));
	    }
Esempio n. 8
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);

			var timeEntryService = new TimeEntryService(Constants.ApiToken);
            for (int i = 0; i < 3; 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(),
                    WorkspaceId = DefaultWorkspaceId,
                    TaskId = task1.Id
                };
                var expTimeEntry = timeEntryService.Add(timeEntry);
                Assert.IsNotNull(expTimeEntry);
            }

			for (int i = 0; i < 3; 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(),
					WorkspaceId = DefaultWorkspaceId,
					TaskId = task2.Id
				};
				var expTimeEntry = timeEntryService.Add(timeEntry);
				Assert.IsNotNull(expTimeEntry);
			}

			var standardParams = new DetailedReportParams()
			{
				UserAgent = "TogglAPI.Net",
				WorkspaceId = DefaultWorkspaceId,
				Since = DateTime.Now.AddYears(-1).ToIsoDateStr(),
				TaskIds = string.Format("{0},{1}", task1.Id.Value, task2.Id.Value)
			};

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

	        standardParams.TaskIds = task1.Id.Value.ToString();

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

        }
Esempio n. 9
0
		public void MergeMoreThanTwoTasks()
		{
			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);

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

			var timeEntryService = new TimeEntryService(Constants.ApiToken);
			for (int i = 0; i < 3; 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(),
					WorkspaceId = DefaultWorkspaceId,
					TaskId = task1.Id
				};
				var expTimeEntry = timeEntryService.Add(timeEntry);
				Assert.IsNotNull(expTimeEntry);
			}

			for (int i = 0; i < 3; 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(),
					WorkspaceId = DefaultWorkspaceId,
					TaskId = task2.Id
				};
				var expTimeEntry = timeEntryService.Add(timeEntry);
				Assert.IsNotNull(expTimeEntry);
			}

			for (int i = 0; i < 3; 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(),
					WorkspaceId = DefaultWorkspaceId,
					TaskId = task3.Id
				};
				var expTimeEntry = timeEntryService.Add(timeEntry);
				Assert.IsNotNull(expTimeEntry);
			}

			Assert.AreEqual(3, TimeEntryService.List().Count(te => te.TaskId == task1.Id.Value));
			Assert.AreEqual(3, TimeEntryService.List().Count(te => te.TaskId == task2.Id.Value));
			Assert.AreEqual(3, TimeEntryService.List().Count(te => te.TaskId == task3.Id.Value));

			TaskService.Merge(task1.Id.Value, new [] { task2.Id.Value, task3.Id.Value}, DefaultWorkspaceId);

			Assert.AreEqual(9, TimeEntryService.List().Count(te => te.TaskId == task1.Id.Value));
			Assert.AreEqual(0, TimeEntryService.List().Count(te => te.TaskId == task2.Id.Value));
			Assert.AreEqual(0, TimeEntryService.List().Count(te => te.TaskId == task3.Id.Value));
			Assert.IsFalse(WorkspaceService.Tasks(DefaultWorkspaceId).Select(t => t.Id).Contains(task2.Id));
			Assert.IsFalse(WorkspaceService.Tasks(DefaultWorkspaceId).Select(t => t.Id).Contains(task3.Id));
		}		
Esempio n. 10
0
        public Task PushTime(AppSetting settings, DateTime startDate, DateTime endDate)
        {
            //tra-74

            if (settings == null)
                throw new Exception("No Jira or Toggl credentials provided.");
            this.VerifySetting(settings.JiraLogin, "JIRA login");
            this.VerifySetting(settings.JiraPassword, "JIRA password");
            this.VerifySetting(settings.JiraUrl, "JIRA URL");
            this.VerifySetting(settings.TogglApiKey, "Toggl API Key");

            var jira = new Jira(settings.JiraUrl, settings.JiraLogin, settings.JiraPassword);
            var toggl = new Toggl.Toggl(settings.TogglApiKey);

            return Task.Run(() =>
                {
                    var timeService = new TimeEntryService(settings.TogglApiKey);
                    var timeParams = new TimeEntryParams();

                    timeParams.StartDate = startDate.Date;
                    timeParams.EndDate = endDate.Date;

                    foreach (var te in timeService.List(timeParams).Where(w => (w.TagNames == null || !w.TagNames.Contains(POSTED_TAG))
                                                                                && !string.IsNullOrEmpty(w.Description)))
                    {
                        KeyValuePair<string, string> description = this.ParseDescription(te.Description);
                        if (string.IsNullOrEmpty(description.Key))
                            continue;

                        var issue = jira.GetIssue(description.Key);
                        issue.AddWorklog(new Worklog(this.GetMinutes(te.Duration.GetValueOrDefault()), DateTime.Parse(te.Start), description.Value));
                        if (te.TagNames == null)
                            te.TagNames = new List<string>();
                        te.TagNames.Add(POSTED_TAG);
                        timeService.Edit(te);
                    }
                });

            //return Task.Run(() =>
            //    {
            //        //Atlassian.Jira.Jira aa = new Atlassian.Jira.Jira("urlhere", "loginhere", "passwordhere");
            //        //var issue = aa.GetIssue("FLW6-2247");
            //        //issue.AddWorklog(new Atlassian.Jira.Worklog)

            //        //var apiKey = "apikeyhere";
            //        //var t = new Toggl.Toggl(apiKey);
            //        //var c = t.User.GetCurrent();

            //        //var timeSrv = new Toggl.Services.TimeEntryService(apiKey);
            //        //var prams = new Toggl.QueryObjects.TimeEntryParams();

            //        //// there is an issue with the date ranges have
            //        //// to step out of the range on the end.
            //        //// To capture the end of the billing range day + 1
            //        //prams.StartDate = DateTime.Now.AddMonths(-1);
            //        //prams.EndDate = DateTime.Now.AddMonths(1);

            //        //var hours = timeSrv.List(prams)
            //        //                        .Where(w => !string.IsNullOrEmpty(w.Description)).ToList();
            //    });
        }