Example #1
0
        public static void Message(string header, string text = null)
        {
            var col = Console.ForegroundColor;

            Consoler.Breaker();
            Console.ForegroundColor = ConsoleColor.White;
            Consoler.Write(header);
            Logger.LogInformation(header);

            Console.ForegroundColor = ConsoleColor.DarkGreen;

            if (!string.IsNullOrEmpty(text))
            {
                Consoler.Write(text);
            }

            Consoler.Breaker();
            Console.ForegroundColor = col;
        }
Example #2
0
        public static string GetTokenFromConsole()
        {
            string           cmd       = "$(az account get-access-token --query 'accessToken' -o tsv)";
            ProcessStartInfo startInfo = new ProcessStartInfo();
            bool             isLinux   = RuntimeInformation
                                         .IsOSPlatform(OSPlatform.Linux);

            if (isLinux)
            {
                startInfo.FileName  = @"/bin/bash";
                startInfo.Arguments = $"-c \"echo {cmd}\"";
            }
            else
            {
                startInfo.FileName  = @"powershell.exe";
                startInfo.Arguments = $@"-Command echo {cmd}";
            }
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError  = true;
            startInfo.UseShellExecute        = false;
            startInfo.CreateNoWindow         = true;
            Process process = new Process();

            process.StartInfo = startInfo;
            process.Start();

            string output = process.StandardOutput.ReadToEnd();

            if (!string.IsNullOrEmpty(output))
            {
                string trim = output.Trim();
                Console.WriteLine("TOKEN");
                Console.WriteLine(trim);
                Consoler.TitleEnd("Login GetTokenFromConsole");
                return(trim);
            }

            string errors = process.StandardError.ReadToEnd();

            throw new ApplicationException(errors);
        }