Exemplo n.º 1
0
        public override Task <bool> Handle(ConsoleCommandEvent <ProcessConsoleCommand> request, CancellationToken cancellationToken)
        {
            var process = Process.GetCurrentProcess();

            Console.WriteLine($"PID: {process.Id}", Color.Gray);
            Console.WriteLine($"Memory used: {process.PrivateMemorySize64.Bytes().ToString("#.##")}", Color.Gray);
            Console.WriteLine($"GC Gen-0: {GC.CollectionCount(0)} (fast/blocking)", Color.Gray);
            Console.WriteLine($"GC Gen-1: {GC.CollectionCount(1)} (fast/blocking)", Color.Gray);
            Console.WriteLine($"GC Gen-2: {GC.CollectionCount(2)} (slow/nonblocking)", Color.Gray);
            Console.WriteLine($"Is64BitOperatingSystem: {Environment.Is64BitOperatingSystem}", Color.Gray);
            Console.WriteLine($"Is64BitProcess: {Environment.Is64BitProcess}", Color.Gray);

            if (request.Command.Collect)
            {
                Console.WriteLine("GC collect", Color.Gray);
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            //"PhysicalPath", HostingEnvironment.ApplicationPhysicalPath);
            //"Machine", Environment.MachineName);
            //"ProcessorCount", Environment.ProcessorCount);
            //"ThreadId", Environment.CurrentManagedThreadId);
            //"WorkingSetMemory", Environment.WorkingSet.Bytes().ToString("MB"));
            //"AvailableMemory", $"{new PerformanceCounter("Memory", "Available MBytes").NextValue()} MB");
            //"Cpu", $"{new PerformanceCounter("Processor", "% Processor Time", "_Total").NextValue()}%");
            //"Is64BitProcess", Environment.Is64BitProcess);
            //"Domain", Environment.UserDomainName);

            //this.logger.LogInformation(text);
            return(Task.FromResult(true));
        }
Exemplo n.º 2
0
        public override Task <bool> Handle(ConsoleCommandEvent <ExitConsoleCommand> request, CancellationToken cancellationToken)
        {
            this.SaveHistory();

            Environment.Exit((int)ExitCode.Termination);

            return(Task.FromResult(true));
        }
Exemplo n.º 3
0
        public override Task <bool> Handle(ConsoleCommandEvent <LogoConsoleCommand> request, CancellationToken cancellationToken)
        {
            Console2.WriteTextLogo();
            Colorful.Console.Write($"    {this.serviceDescriptor}", Color.White);
            Colorful.Console.WriteLine($" [{this.serviceDescriptor.Tags.ToString("|")}]", Color.Gray);
            Colorful.Console.WriteLine();

            return(Task.FromResult(true));
        }
Exemplo n.º 4
0
        public override Task <bool> Handle(ConsoleCommandEvent <HelpConsoleCommand> request, CancellationToken cancellationToken)
        {
            foreach (var command in this.commands.OrderBy(c => c.GetType().Name))
            {
                Colorful.Console.WriteLine($"{command.GetType().GetAttributeValue<VerbAttribute, string>(a => a.Name) ?? "?NAME?"} - {command.GetType().GetAttributeValue<VerbAttribute, string>(a => a.HelpText)}", Color.Gray); // ({command.GetType()})
            }

            return(Task.FromResult(true));
        }
Exemplo n.º 5
0
        public override Task <bool> Handle(ConsoleCommandEvent <HistoryConsoleCommand> request, CancellationToken cancellationToken)
        {
            foreach (var item in ReadLine.GetHistory().Distinct())
            {
                Console.WriteLine(item, Color.Gray);
            }

            return(Task.FromResult(true));
        }
Exemplo n.º 6
0
        public override Task <bool> Handle(ConsoleCommandEvent <EchoConsoleCommand> request, CancellationToken cancellationToken)
        {
            var text = request.Command.Text ?? "+++ hello from echo console command";

            if (request.Command.Timestamp)
            {
                text += $" {DateTime.UtcNow.ToEpoch()}";
            }

            //this.logger.LogInformation(text);
            Console.WriteLine(text, Color.Gray);
            return(Task.FromResult(true));
        }
Exemplo n.º 7
0
        public override Task <bool> Handle(ConsoleCommandEvent <ClearScreenConsoleCommand> request, CancellationToken cancellationToken)
        {
            System.Console.Clear();

            return(Task.FromResult(true));
        }
Exemplo n.º 8
0
 public abstract Task <bool> Handle(ConsoleCommandEvent <TCommand> request, CancellationToken cancellationToken);