コード例 #1
0
        private static async Task Execute(long?id, decimal?hour, string timerange, string search)
        {
            var client = Program.GetHarvestClient();

            var me = await client.GetCurrentUser();

            var selected = await SelectProjectAndTask(client, me);

            if (selected == null)
            {
                Console.WriteLine("Aborting.");
                return;
            }

            decimal hours;

            while (true)
            {
                Console.Write("Hours: ");
                var hoursString = Console.ReadLine();
                if (decimal.TryParse(hoursString, out hours))
                {
                    break;
                }
            }

            Console.Write("Notes: ");
            string notes = Console.ReadLine();

            var entry = await client.CreateTimeEntry(selected.ProjectId, selected.TaskId, hours, notes);

            TimeEntry_Show.ShowTimeEntry(entry);
        }
コード例 #2
0
        private static async Task Execute(long?id)
        {
            var client = Program.GetHarvestClient();

            TimeEntry originalEntry;

            if (id.HasValue)
            {
                originalEntry = await client.GetTimeEntry(id.Value);
            }
            else
            {
                var me = await client.GetCurrentUser();

                DateTime from, until;
                TimeRangeHelper.GetTimerangeFromString("today", out from, out until);
                var todaysEntries = await client.GetTimeEntriesForUser(me.Id, from, until);

                originalEntry = SelectionHelper.Select(todaysEntries.TimeEntries, TimeEntry_Show.ShowTimeEntry);
                if (originalEntry == null)
                {
                    Console.WriteLine("Aborting.");
                    return;
                }
            }

            TimeSpan finalElapsed = await Timer_Start.MeasureTime(originalEntry.Hours);

            var updatedEntry = await client.UpdateTimeEntry(originalEntry.Id, null, null, (decimal)finalElapsed.TotalHours, null);

            TimeEntry_Show.ShowTimeEntry(updatedEntry);
        }
コード例 #3
0
        private static async Task Execute(int id, long?projectId, long?taskId, decimal?hours, string notes)
        {
            var client = Program.GetHarvestClient();

            var entry = await client.UpdateTimeEntry(id, projectId, taskId, hours, notes);

            TimeEntry_Show.ShowTimeEntry(entry);
        }
コード例 #4
0
        private static async Task Execute(long projectId, long taskId, decimal hours, string notes)
        {
            var client = Program.GetHarvestClient();

            var entry = await client.CreateTimeEntry(projectId, taskId, hours, notes);

            TimeEntry_Show.ShowTimeEntry(entry);
        }
コード例 #5
0
        private static async Task Execute(string timerange, bool summary, bool includeIds, bool outputJson, string search)
        {
            var client = Program.GetHarvestClient();

            var me = await client.GetCurrentUser();

            DateTime from  = DateTime.Today;
            DateTime until = DateTime.Today;

            if (timerange != null)
            {
                TimeRangeHelper.GetTimerangeFromString(timerange, out from, out until);
            }

            var entries = await client.GetTimeEntriesForUser(me.Id, from, until);

            var filtered =
                entries.TimeEntries;

            if (string.IsNullOrEmpty(search) == false)
            {
                filtered = filtered
                           .Where(e => e.Project.Name.Contains(search, StringComparison.OrdinalIgnoreCase) ||
                                  e.Client.Name.Contains(search, StringComparison.OrdinalIgnoreCase) ||
                                  e.Task.Name.Contains(search, StringComparison.OrdinalIgnoreCase) ||
                                  (e.Notes != null && e.Notes.Contains(search, StringComparison.OrdinalIgnoreCase)))
                           .ToArray();
            }

            if (outputJson)
            {
                Console.WriteLine(JsonConvert.SerializeObject(filtered, Formatting.Indented));
            }
            else
            {
                decimal hours = 0.0m;
                foreach (var e in filtered)
                {
                    TimeEntry_Show.ShowTimeEntry(e, includeIds);
                    hours += e.Hours;
                }

                if (summary)
                {
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.Write("Total: ");
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.Write(hours.ToString());
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.Write(" hours");
                    Console.ResetColor();
                    Console.WriteLine();
                }
            }
        }
コード例 #6
0
        private static async Task Execute(long?id, long?projectId, long?taskId, string notes, bool interactive)
        {
            var client = Program.GetHarvestClient();

            if (interactive)
            {
                var me = await client.GetCurrentUser();

                var selected = await TimeEntry_Interactive.SelectProjectAndTask(client, me);

                if (selected == null)
                {
                    Console.WriteLine("Aborting.");
                    return;
                }

                projectId = selected.ProjectId;
                taskId    = selected.TaskId;
            }

            if (!ValidateInput(id, projectId, taskId))
            {
                return;
            }

            TimeSpan finalElapsed = await MeasureTime();

            if (notes == null && interactive)
            {
                Console.Write("Notes: ");
                notes = Console.ReadLine();
            }

            if (id.HasValue)
            {
                var originalEntry = await client.GetTimeEntry(id.Value);

                var newEntry = await TimeEntry_Copy.CopyTimeEntry(client, originalEntry, (decimal)finalElapsed.TotalHours, notes);

                TimeEntry_Show.ShowTimeEntry(newEntry);
            }
            else
            {
                var newEntry = await client.CreateTimeEntry(projectId.Value, taskId.Value, (decimal)finalElapsed.TotalHours, notes);

                TimeEntry_Show.ShowTimeEntry(newEntry);
            }
        }
コード例 #7
0
        private static async Task Execute(long?id, decimal?hours, string timerange, string search, string notes)
        {
            var client = Program.GetHarvestClient();

            DateTime from  = DateTime.Today;
            DateTime until = DateTime.Today;

            if (timerange != null)
            {
                TimeRangeHelper.GetTimerangeFromString(timerange, out from, out until);
            }
            else
            {
                TimeRangeHelper.GetTimerangeFromString("last30days", out from, out until);
            }

            TimeEntry entryToCopy = null;

            if (id.HasValue)
            {
                entryToCopy = await client.GetTimeEntry(id.Value);
            }
            else
            {
                var me = await client.GetCurrentUser();

                var entries = await client.GetTimeEntriesForUser(me.Id, from, until);

                var filtered =
                    entries.TimeEntries;

                if (string.IsNullOrEmpty(search) == false)
                {
                    filtered = filtered
                               .Where(e => e.Project.Name.Contains(search, StringComparison.OrdinalIgnoreCase) ||
                                      e.Client.Name.Contains(search, StringComparison.OrdinalIgnoreCase) ||
                                      e.Task.Name.Contains(search, StringComparison.OrdinalIgnoreCase) ||
                                      (e.Notes != null && e.Notes.Contains(search, StringComparison.OrdinalIgnoreCase)))
                               .ToArray();
                }

                filtered = filtered.ToArray();
                if (filtered.Length > 1)
                {
                    entryToCopy = SelectionHelper.Select(filtered, TimeEntry_Show.ShowTimeEntry);
                    if (entryToCopy == null)
                    {
                        Console.WriteLine("Aborting.");
                        return;
                    }
                }
                else
                {
                    entryToCopy = filtered[0];
                }
            }

            TimeEntry newEntry = await CopyTimeEntry(client, entryToCopy, hours);

            TimeEntry_Show.ShowTimeEntry(newEntry);
        }