コード例 #1
0
        // Define the event handlers.
        private static void OnChanged(object source, FileSystemEventArgs e)
        {
            FileSystemWatcher watcher = source as FileSystemWatcher;

            // read in tracking file
            TimeTrackingFile timeTracking = TimeTrackingFile.toObject(File.ReadAllText(Program.TRACKING_FILE_PATH));

            if (timeTracking.currentTracking == null)
            {
                timeTracking.currentTracking           = new TimeTrackingFile.TimeTrackingInstance();
                timeTracking.currentTracking.startTime = DateTime.Now;
                timeTracking.currentTracking.message   = "Auto-generated based on file changes to " + watcher.Path;

                TimeTrackingFile.SaveToFile(timeTracking);
            }
            else if ((DateTime.Now - timeTracking.currentTracking.startTime).TotalMinutes >= 15)
            {
                timeTracking.currentTracking.endTime    = DateTime.Now;
                timeTracking.currentTracking.totalHours = (timeTracking.currentTracking.endTime - timeTracking.currentTracking.startTime).TotalHours;
                timeTracking.currentTracking.message    = "Auto-generated based on file changes to " + watcher.Path;

                // move current tracking to historicals
                timeTracking.previousTimes.Add(timeTracking.currentTracking);
                timeTracking.currentTracking = null;

                // save
                TimeTrackingFile.SaveToFile(timeTracking);
            }

            // Specify what is done when a file is changed, created, or deleted.
            // Console.WriteLine($"File: {e.FullPath} {e.ChangeType}");
        }
コード例 #2
0
        public static int Run(CleanOptions options)
        {
            bool proceed = options.Force;

            if (!options.Force)
            {
                Console.WriteLine("This operation will delete all kronos tracking data.");
                Console.Write("Are you sure you would like to proceed? (Y/N) ");
                string answer = Console.ReadLine();
                Console.Write(answer);
                proceed = (answer.ToUpper() == "Y" || answer.Length == 0);
            }

            if (proceed)
            {
                File.WriteAllText(Program.TRACKING_FILE_PATH, TimeTrackingFile.GenerateEmptyTrackingJson());

                // write out success message
                ConsoleColor userDefaultColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Successfully deleted all tracking data");
                Console.ForegroundColor = userDefaultColor;
            }

            return(0);
        }
コード例 #3
0
        public static String GenerateEmptyTrackingJson()
        {
            TimeTrackingFile t = new TimeTrackingFile();

            t.currentTracking = null;
            t.previousTimes   = new List <TimeTrackingFile.TimeTrackingInstance>();

            return(TimeTrackingFile.toJSON(t));
        }
コード例 #4
0
        public static int Run(StartOptions options, string[] args)
        {
            // read in tracking file
            TimeTrackingFile timeTracking = TimeTrackingFile.toObject(File.ReadAllText(Program.TRACKING_FILE_PATH));

            if (timeTracking == null)
            {
                // write out error message
                ConsoleColor userDefaultColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error: Encountered error generating kronos time.");
                Console.WriteLine("Open " + Program.TRACKING_FILE_PATH + " to view all times.");
                Console.WriteLine("Run kronos clean to fix and reset (note you will lose all previously logged times).");
                Console.ForegroundColor = userDefaultColor;

                return(1);
            }

            // if not currently tracking anything, start new tracker
            if (timeTracking.currentTracking == null)
            {
                timeTracking.currentTracking           = new TimeTrackingFile.TimeTrackingInstance();
                timeTracking.currentTracking.startTime = DateTime.Now;

                TimeTrackingFile.SaveToFile(timeTracking);

                // write out success message
                ConsoleColor userDefaultColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Successfully started work session.");
                Console.ForegroundColor = userDefaultColor;

                return(0);
            }
            // if currently tracking, send error because can't start another
            else
            {
                // write out error message
                ConsoleColor userDefaultColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error: Work session already in progress.");

                if (timeTracking.currentTracking.message != null && timeTracking.currentTracking.message.Length > 0)
                {
                    Console.WriteLine("Work session message: " + timeTracking.currentTracking.message + "\n");
                }

                Console.WriteLine("Run kronos stop to finish the current work session.");
                Console.ForegroundColor = userDefaultColor;

                return(2);
            }
        }
コード例 #5
0
        private static void kronosSetup()
        {
            // generate home .kronos directory if doesn't exist
            if (!Directory.Exists(DIRECTORY_PATH))
            {
                Directory.CreateDirectory(DIRECTORY_PATH);
            }

            // generate tracking file if doesn't exist
            if (!File.Exists(TRACKING_FILE_PATH))
            {
                File.WriteAllText(TRACKING_FILE_PATH, TimeTrackingFile.GenerateEmptyTrackingJson());
            }
        }
コード例 #6
0
        public static int Run(LogOptions options, string[] args)
        {
            // read in tracking file and mark default console color
            TimeTrackingFile timeTracking     = TimeTrackingFile.toObject(File.ReadAllText(Program.TRACKING_FILE_PATH));
            ConsoleColor     userDefaultColor = Console.ForegroundColor;

            if (timeTracking == null)
            {
                // write out error message
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error: Encountered error generating kronos time.");
                Console.WriteLine("Open " + Program.TRACKING_FILE_PATH + " to view all times.");
                Console.WriteLine("Run kronos clean to fix and reset (note you will lose all previously logged times.");
                Console.ForegroundColor = userDefaultColor;

                return(1);
            }

            DateTime startTime;

            if (options.Start.Length == 0)
            {
                // write out error message
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error: No start time provided. Use --start to denote a start time.");
                Console.ForegroundColor = userDefaultColor;

                return(2);
            }

            if (!DateTime.TryParse(options.Start, out startTime))
            {
                // write out error message
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error: Start time not formatted properly.");
                Console.ForegroundColor = userDefaultColor;

                return(3);
            }

            DateTime endTime;

            if (options.Stop.Length == 0)
            {
                // write out error message
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error: No end time provided. Use --stop to denote an end time.");
                Console.ForegroundColor = userDefaultColor;

                return(2);
            }

            if (!DateTime.TryParse(options.Stop, out endTime))
            {
                // write out error message
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error: End time not formatted properly.");
                Console.ForegroundColor = userDefaultColor;

                return(3);
            }

            TimeTrackingFile.TimeTrackingInstance instance = new TimeTrackingFile.TimeTrackingInstance();
            instance.startTime  = startTime;
            instance.endTime    = endTime;
            instance.message    = options.Message;
            instance.totalHours = (endTime - startTime).TotalHours;

            // add to array of previous times and save
            timeTracking.previousTimes.Add(instance);
            TimeTrackingFile.SaveToFile(timeTracking);

            // write out success message
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Successfully logged work session.");
            Console.ForegroundColor = userDefaultColor;

            return(0);
        }
コード例 #7
0
        public static int Run(ReportOptions options)
        {
            // read in tracking file
            TimeTrackingFile timeTracking = TimeTrackingFile.toObject(File.ReadAllText(Program.TRACKING_FILE_PATH));

            if (timeTracking == null)
            {
                // write out error message
                ConsoleColor userDefaultColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error: Encountered error generating kronos time");
                Console.WriteLine("Open " + Program.TRACKING_FILE_PATH + " to view all times");
                Console.WriteLine("Run kronos clean to fix and reset (note you will lose all previously logged times");
                Console.ForegroundColor = userDefaultColor;

                return(1);
            }

            // generate header
            Console.Write("\nKronos Report -- ");
            Console.WriteLine(options.All ? "all time" : "last 14 days");

            // write out current session if in progress
            if (timeTracking.currentTracking != null)
            {
                Console.WriteLine();
                Console.WriteLine("In progress work session:");

                Console.WriteLine("    Start time: " +
                                  timeTracking.currentTracking.startTime.ToLongDateString() + ", " +
                                  timeTracking.currentTracking.startTime.ToLongTimeString() +
                                  (timeTracking.currentTracking.message != null && timeTracking.currentTracking.message.Length > 0 ? ", \n    " + timeTracking.currentTracking.message : ""));
            }

            // sort by start time
            var arrayCast = timeTracking.previousTimes.ToArray();

            Array.Sort(arrayCast,
                       delegate(TimeTrackingFile.TimeTrackingInstance x, TimeTrackingFile.TimeTrackingInstance y) { return(x.startTime.CompareTo(y.startTime)); });
            timeTracking.previousTimes = new List <TimeTrackingFile.TimeTrackingInstance>(arrayCast);

            // set header and current date we're looping through
            Console.WriteLine("\nPast work sessions:");
            DateTime currentDate = default(DateTime);

            // write out past work sessions
            foreach (TimeTrackingFile.TimeTrackingInstance t in timeTracking.previousTimes)
            {
                if (options.All || (DateTime.Now - t.endTime).TotalDays <= 14)
                {
                    if (currentDate == default(DateTime) || t.startTime.ToShortDateString() != currentDate.ToShortDateString())
                    {
                        Console.WriteLine("\n" + t.startTime.ToShortDateString());
                    }

                    Console.WriteLine("   " +
                                      " Start time: " + t.startTime.ToShortTimeString() + "," +
                                      " End time: " + t.endTime.ToShortTimeString() + "," +
                                      " Hours: " + Math.Round(t.totalHours, 2) +
                                      (t.message != null && t.message.Length > 0 ? ", Message: " + t.message : ""));

                    currentDate = t.startTime;
                }
            }

            Console.WriteLine();
            return(0);
        }
コード例 #8
0
 public static String toJSON(TimeTrackingFile obj)
 {
     return(JsonConvert.SerializeObject(obj));
 }
コード例 #9
0
 public static void SaveToFile(TimeTrackingFile obj)
 {
     SaveToFile(toJSON(obj));
 }
コード例 #10
0
        public static int Run(StopOptions options, string[] args)
        {
            // read in tracking file
            TimeTrackingFile timeTracking = TimeTrackingFile.toObject(File.ReadAllText(Program.TRACKING_FILE_PATH));

            if (timeTracking == null)
            {
                // write out error message
                ConsoleColor userDefaultColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error: Encountered error generating kronos time.");
                Console.WriteLine("Open " + Program.TRACKING_FILE_PATH + " to view all times.");
                Console.WriteLine("Run kronos clean to fix and reset (note you will lose all previously logged times.");
                Console.ForegroundColor = userDefaultColor;

                return(1);
            }

            // if not currently tracking anything, send error
            if (timeTracking.currentTracking == null)
            {
                // write out error message
                ConsoleColor userDefaultColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error: No work session in progress.");
                Console.WriteLine("Run kronos log to start a work session.");
                Console.ForegroundColor = userDefaultColor;

                return(2);
            }
            // if currently tracking, close out and save
            else
            {
                timeTracking.currentTracking.endTime    = DateTime.Now;
                timeTracking.currentTracking.totalHours = (timeTracking.currentTracking.endTime - timeTracking.currentTracking.startTime).TotalHours;

                // figure out message
                List <string> trimmedArgs = new List <string>(args);
                trimmedArgs.RemoveAll(s => s.StartsWith("-") || s == "stop");

                if (trimmedArgs.Count > 0)
                {
                    timeTracking.currentTracking.message = trimmedArgs.ToArray()[0];
                }

                // move current tracking to historicals
                timeTracking.previousTimes.Add(timeTracking.currentTracking);
                timeTracking.currentTracking = null;

                // save
                TimeTrackingFile.SaveToFile(timeTracking);

                // write out success message
                ConsoleColor userDefaultColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Successfully closed work session.");
                Console.ForegroundColor = userDefaultColor;

                return(0);
            }
        }