private void WriteException(ITextWriter report, Exception exception, int indent = 0) { report.WriteLine(" Type: {0}", exception.GetType().Name); report.WriteLine("Message: {0}", exception.Message); report.WriteLine(exception.StackTrace); if (exception.InnerException != null) { WriteException(report, exception.InnerException, indent + 1); } }
public override async Task <AcquireResult> Fetch(HttpClient httpClient) { var parse = new GlobalJsonFileLocator(_writer).Parse(); if (!parse.IsSuccess) { _writer.WriteLine(parse.ErrorMessage); return(new AcquireResult()); } var version = parse.GlobalJsonFile.Sdk.Version; var channelVersion = ParseChannelVersion(version); using var releasesResponse = await JsonDocument.ParseAsync(await httpClient.GetStreamAsync(ReleaseIndex)); var channel = releasesResponse.RootElement.GetProperty("releases-index").EnumerateArray() .First(x => x.GetProperty("channel-version").GetString() == channelVersion); var channelJson = channel.GetProperty("releases.json").GetString(); return(new AcquireResult { ChannelJson = channelJson, Version = version }); }
public void Launch(string installerPath) { if (!_args.Headless) { LaunchInstallerProcess(installerPath); return; } if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { _writer.WriteLine($"The SDK has been downloaded to: {installerPath}"); return; } if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { Run("sudo", $"installer -pkg {installerPath} -target /"); return; } if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Run(installerPath, $"/install /quiet /norestart"); return; } throw new PlatformNotSupportedException(); }
public override void Execute() { _decoratedCommand.Execute(); if (_decoratedCommand.Summary != default(string)) { _textWriter.WriteLine(_decoratedCommand.Summary); } }
public static void PHPInclude(ITextWriter e, string src) { if (!src.EndsWith(".php")) { src += ".php"; } e.WriteLine("require_once '" + src + "';"); }
public static void DefineScript(ITextWriter w, string src) { if (!src.EndsWith(".js")) { src += ".js"; } w.WriteLine("<script type='text/javascript' src='" + src + "'></script>"); }
static async Task Main(string[] args) { var startWord = args[0]; var endWord = args[1]; var result = await _inputHandler.Run(startWord.ToUpperInvariant(), endWord.ToUpperInvariant()); _writer.WriteLine(result); _writer.ReadLine(); }
public static async Task RunAsync(Acquirable acquirable, ITextWriter writer, ToolArguments args) { try { var sdkAcquirer = new SdkAcquirer(new HttpClient(), writer, new InstallerLauncher(writer, args), new PlatformIdentifier(), new DotnetInfo()); await sdkAcquirer.Acquire(acquirable); } catch (FileNotFoundException e) { writer.WriteLine(e.Message); } catch (TaskCanceledException e) { if (!e.CancellationToken.IsCancellationRequested) { writer.WriteLine("Connection to acquire .NET SDK timed out, please try again"); } } }
/// <summary>Writes a string followed by a line terminator to the text string or stream.</summary> /// <param name="value">The string to write. If <paramref name="value" /> is null, only the line terminator is written. </param> /// <exception cref="T:System.ObjectDisposedException">The <see cref="T:System.IO.TextWriter" /> is closed. </exception> /// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception> public void WriteLine(string value) { _console.SafeCall(console => { var foreground = _console.ForegroundColor; console.ForegroundColor = ConsoleColor.Red; _writer.WriteLine(value); console.ForegroundColor = foreground; }); }
void CheckHash(string filePath, string fileHash) { using var sha512 = new SHA512Managed(); var hash = sha512.ComputeHash(File.OpenRead(filePath)); var hashString = BitConverter.ToString(hash).Replace("-", ""); if (hashString != fileHash) { _textWriter.WriteLine("The downloaded file contents did not match expected hash."); } }
public async Task <Word> Run(string startWord, string endWord) { this.startWord = startWord.ToUpper(); this.endWord = endWord.ToUpper(); words = await _fileProcessor.ReadDictionaryFile("words-english.txt"); if (!CheckWordsExist(startWord, endWord)) { _writer.WriteLine("The words could not be found in the dictionary"); return(null); } if (!CheckWordsAreOfLength(startWord, endWord, _config.Value.WordSize)) { _writer.WriteLine($"The words are not of length {_config.Value.WordSize}"); return(null); } var responseWord = CompleteWords(new Word(this.startWord)); return(responseWord); }
public void Write(params string[] columns) { if (_writer == null) { throw new NullReferenceException("The writer cannot be used anymore. Pleaser reinitializate it."); } if (columns == null) { throw new ArgumentNullException(nameof(columns), "Please provide at least 1 column"); } var outPut = string.Join("\t", columns); _writer.WriteLine(outPut); }
public void ShowUsage(ITextWriter output) { output.WriteLine(); output.WriteLine("[vswhere.exe options]"); var psi = new ProcessStartInfo(vswherePath) { RedirectStandardOutput = true, ArgumentList = { "-nologo", "-?" } }; var process = Process.Start(psi); string line; while ((line = process.StandardOutput.ReadLine()) != null) { if (line.StartsWith("Usage:") || line.StartsWith("Options:")) { continue; } output.WriteLine(line); } }
public void WriteLine(string text = null) { writer.WriteLine(text); }
public static Tasks.Task <bool> WriteLine <T>(this ITextWriter me, T value) where T : IConvertible { return(me.WriteLine(value.ToString((IFormatProvider)System.Globalization.CultureInfo.InvariantCulture.GetFormat(typeof(T))))); }
public static Tasks.Task <bool> WriteLine(this ITextWriter me, string format, params object[] arguments) { return(me.WriteLine(string.Format(format, arguments))); }
public static Tasks.Task <bool> WriteLine(this ITextWriter me, Generic.IEnumerable <char> value) { return(me.WriteLine(value.GetEnumerator())); }
public static async Tasks.Task <bool> WriteLine(this ITextWriter me, Generic.IEnumerator <char> value) { return(await me.Write(value) && await me.WriteLine()); }
public static void DefineSpawnPoint(ITextWriter w, string alias, string data) { w.WriteLine("<input type='hidden' value='" + Convert.ToBase64String(Encoding.ASCII.GetBytes(data)) + "' class='" + alias + "' />"); }
protected void WriteLine() => _textWriter.WriteLine();
public void EmptyLine() { _w.WriteLine(); }
public static Tasks.Task <bool> WriteLine(this ITextWriter me, string value) { return(me.WriteLine((Generic.IEnumerable <char>)value)); }
public static void WriteLine(this ITextWriter tw, string format, params object[] args) => tw.WriteLine(args == null ? format : string.Format(format, args));
public void SayHello() { _writer.WriteLine("Hello world"); }
private void AddToOutputStream(string message, bool includeTrailingLine = true) { _sw?.WriteLine(message + (includeTrailingLine ? Environment.NewLine : string.Empty)); }
public static void WriteLine(this ITextWriter tw) => tw.WriteLine(string.Empty);
public async Task Acquire(Acquirable acquirable) { var result = await acquirable.Fetch(_httpClient); if (!result.IsSuccess) { return; } if (await CheckSdkExists(result.Version)) { _textWriter.WriteLine($"SDK version {result.Version} is already installed."); return; } using var channelResponse = await JsonDocument.ParseAsync(await _httpClient.GetStreamAsync(result.ChannelJson)); var file = channelResponse .RootElement.GetProperty("releases").EnumerateArray() .SelectMany(x => { IEnumerable <JsonElement> GetSdks() { yield return(x.GetProperty("sdk")); if (x.TryGetProperty("sdks", out var sdks)) { foreach (var y in sdks.EnumerateArray()) { yield return(y); } } } return(GetSdks()); }) .First(x => x.GetProperty("version").GetString() == result.Version) .GetProperty("files") .EnumerateArray() .First(FileFilter); var name = file.GetProperty("name").GetString(); var installerUrl = file.GetProperty("url").GetString(); var fileHash = file.GetProperty("hash").GetString(); var filePath = Path.Combine(Path.GetTempPath(), name); _textWriter.WriteLine($"Starting download of .NET Core SDK Version {result.Version}"); using (var installerStream = await _httpClient.GetStreamAsync(installerUrl)) { using var fileStream = new FileStream(filePath, FileMode.Create); var progress = new Progress <long>(); var lastReportedBytesMbs = 0; progress.ProgressChanged += (sender, totalBytes) => { var currentBytesMbs = (int)Math.Floor(totalBytes / Math.Pow(2, 20)); if (currentBytesMbs <= lastReportedBytesMbs) { return; } lastReportedBytesMbs = currentBytesMbs; _textWriter.SetCursorPosition(0, Console.CursorTop); _textWriter.Write($"Downloading: {currentBytesMbs}MB"); }; await CopyToWithProgress(installerStream, fileStream, progress); } CheckHash(filePath, fileHash); _installerLauncher.Launch(filePath); }
public void DoEpicStuff() { _writer.WriteLine("I used to have a dog and it's name was Bingo!"); }
public static Tasks.Task <bool> WriteLine(this ITextWriter me, params char[] buffer) { return(me.WriteLine((Generic.IEnumerable <char>)buffer)); }