Example #1
0
        private LfxFileFlags GetFileFlags(GitCmdArgs args, bool pointer = false, bool content = false)
        {
            var flags = default(LfxFileFlags);

            if (args.IsSet(LfxCmdSwitches.Cached, LfxCmdSwitches.C))
            {
                flags |= LfxFileFlags.Tracked;
            }

            if (args.IsSet(LfxCmdSwitches.Others, LfxCmdSwitches.O))
            {
                flags |= LfxFileFlags.Untracked;
            }

            if (args.IsSet(LfxCmdSwitches.Content))
            {
                flags |= LfxFileFlags.Content;
            }

            if (args.IsSet(LfxCmdSwitches.Pointer))
            {
                flags |= LfxFileFlags.Pointer;
            }

            if (flags == default(LfxFileFlags))
            {
                flags = LfxFileFlags.Tracked;
            }

            if (pointer)
            {
                flags |= LfxFileFlags.Pointer;
            }

            if (content)
            {
                flags |= LfxFileFlags.Content;
            }

            return(flags);
        }
Example #2
0
        private void Batch <T>(GitCmdArgs args, IEnumerable <T> source, Func <T, Task> action)
        {
            var quite = args.IsSet(LfxCmdSwitches.Q, LfxCmdSwitches.Quite);

            int    count = 0;
            double total = source.Count();
            var    top   = Console.CursorTop;
            var    sw    = new Stopwatch();

            sw.Start();

            var block = new ActionBlock <T>(async o => {
                if (!quite)
                {
                    Interlocked.Increment(ref count);
                    lock (Lock) {
                        Console.SetCursorPosition(0, top);
                        Console.Write($"Progress: {count}/{total}={count / total:P}, t={sw.Elapsed:hh':'mm':'ss'.'ff}, {o}"
                                      .ExpandOrTrim(Console.BufferWidth - 1));
                    }
                }

                try {
                    await action(o);
                } catch (Exception e) {
                    Console.WriteLine();
                    Console.WriteLine(e.Message);
                }
            });

            foreach (var o in source)
            {
                block.Post(o);
            }
            block.Complete();
            block.Completion.Wait();

            Console.SetCursorPosition(0, top);
            Console.Write($"Progress: {count}/{total}={count / total:P}, t={sw.Elapsed:hh':'mm':'ss'.'ff}"
                          .ExpandOrTrim(Console.BufferWidth - 1));
            Console.WriteLine();
        }