private static string DownloadAsText(CloudBlob blobReference) { Stream? memoryStream = null; TextReader?reader = null; try { memoryStream = new MemoryStream(); blobReference.DownloadToStreamAsync(memoryStream).Wait(); memoryStream.Seek(0, SeekOrigin.Begin); reader = new StreamReader(memoryStream, Encoding.UTF8); memoryStream = null;//weird stuff to satisfy ca2202 var result = reader.ReadToEnd(); reader = null; return(result); } finally { memoryStream?.Dispose(); reader?.Dispose(); } }
public void initialize(CommandWindow commandWindow) { if (m_IsAlive) { return; } var encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false); System.Console.OutputEncoding = encoding; System.Console.InputEncoding = encoding; m_PreviousConsoleIn = System.Console.In; var enableHistory = m_Configuration.GetSection("console:history").Get <bool>(); var enableAutoComplete = m_Configuration.GetSection("console:autocomplete").Get <bool>(); m_ReadLineEnabled = enableHistory || enableAutoComplete; if (m_ReadLineEnabled) { ReadLine.HistoryEnabled = enableHistory; ReadLine.AutoCompletionHandler = enableAutoComplete ? m_AutoCompleteHandler : null; } m_IsAlive = true; m_InputThread = new Thread(OnInputThreadStart) { IsBackground = true }; m_InputThread.Start(); }
/// <summary> /// Initializes a new instance of the <see cref="XmlConfiguration" /> class. /// </summary> /// <param name="tracer">The tracer.</param> /// <param name="reader">The reader providing the XML stream.</param> public XmlConfiguration(ITracer tracer, TextReader?reader) { XNamespace? @namespace = null; XDocument? document = null; if ((reader != null) && (reader.Peek() != -1)) { try { document = XDocument.Load(reader, LoadOptions.PreserveWhitespace); var root = document.Root; if (root != null) { @namespace = root.GetDefaultNamespace(); } } catch (Exception ex) { tracer.TraceError(ex.ToString()); } } if ((@namespace == null) || !DefaultNamespace.Equals(@namespace.NamespaceName, StringComparison.Ordinal)) { @namespace = XNamespace.Get(DefaultNamespace); var root = new XElement(XName.Get("Values", @namespace.NamespaceName)); document = new XDocument(root); } _document = document ?? new XDocument(); _root = _document.Root; _keyName = XName.Get("Key"); _valueName = XName.Get("Value", @namespace.NamespaceName); }
/// <summary> /// Initializes a new instance of the <see cref="DelimitedValuesReader" /> class. /// </summary> /// <param name="source"> /// The reader that provides input. /// </param> /// <param name="settings"> /// Settings that customize the behavior of this instance. /// </param> public DelimitedValuesReader(TextReader source, DelimitedValuesReaderSettings?settings = null) { Guard.NotNull(source, nameof(source)); this.settings = settings?.Clone() ?? new DelimitedValuesReaderSettings(); this.source = source; enumerator = new DelimitedValuesEnumerator(this); }
public (int, string, string) Execute(ITestOutputHelper outputHelper, TextReader?inputReader, TextWriter?outputWriter, TextWriter?errorWriter) { var(exitCode, output, error) = lhs.Execute(outputHelper, inputReader, outputWriter, errorWriter); if (exitCode == 0) { return(exitCode, output, error); } return(rhs.Execute(outputHelper, inputReader, outputWriter, errorWriter)); }
/// <summary> /// Releases all resources used by the <see cref="T:Simmetric.IO.Csv.CsvReader"/> object /// </summary> protected virtual void Dispose(bool disposing) { if (disposing) { if (reader != null) { reader.Dispose(); reader = null; } } }
/// <summary> /// Instantiates a new CSV reader for the given stream, which must be formatted according to the given CSV format. /// </summary> /// <param name="reader">The input reader containing a CSV formatted document</param> /// <param name="format">Describes the format of the CSV document in the stream</param> public CsvReader(TextReader reader, CsvFormat format) { this.Format = format; this.reader = reader; //read headers if (Format.HasHeaders) { Format.Headers = ReadLine(); } }
/// <summary> /// Closes the underlying source (default), unless custom settings indicate otherwise. /// </summary> public void Dispose() { if (source != null) { if (settings.AutoCloseReader) { source.Dispose(); } enumerator.Dispose(); source = null; } }
public static ITextReader?ToInterface(this TextReader?reader) { if (reader == null) { return(null); } if (ReferenceEquals(reader, TextReader.Null)) { return(TextReaderAdapter.Null); } return(new TextReaderAdapter(reader)); }
public (int, string, string) Execute(ITestOutputHelper outputHelper, TextReader?inputReader, TextWriter?outputWriter, TextWriter?errorWriter) { using var process = new Process(); process.StartInfo.FileName = shellCommand; foreach (var argument in arguments) { process.StartInfo.ArgumentList.Add(argument); } // We avoid setting the current directory so that we maintain parity with // MainMethodLitCommand, which can't change the current directory. process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.CreateNoWindow = true; process.StartInfo.EnvironmentVariables.Clear(); foreach (var passthrough in passthroughEnvironmentVariables) { process.StartInfo.EnvironmentVariables.Add(passthrough, Environment.GetEnvironmentVariable(passthrough)); } process.Start(); if (inputReader != null) { string input = inputReader.ReadToEnd(); process.StandardInput.Write(input); process.StandardInput.Close(); } string output = process.StandardOutput.ReadToEnd(); outputWriter?.Write(output); outputWriter?.Flush(); string error = process.StandardError.ReadToEnd(); errorWriter?.Write(error); errorWriter?.Flush(); process.WaitForExit(); return(process.ExitCode, output, error); }
public (int, string, string) Execute(ITestOutputHelper outputHelper, TextReader?inputReader, TextWriter?outputWriter, TextWriter?errorWriter) { if (inputReader != null) { Console.SetIn(inputReader); } if (outputWriter != null) { Console.SetOut(outputWriter); } if (errorWriter != null) { Console.SetError(errorWriter); } var exitCode = (int)assembly.EntryPoint !.Invoke(null, new object[] { arguments }) !; return(exitCode, "", ""); }
internal void Clear() { chars = null !; charPos = 0; charsUsed = 0; encoding = null; stream = null; decoder = null; bytes = null; bytePos = 0; bytesUsed = 0; textReader = null; lineNo = 1; lineStartPos = -1; baseUriStr = string.Empty; baseUri = null; isEof = false; isStreamEof = false; eolNormalized = true; entityResolvedManually = false; }
public void TranslateFile(string inputFileName, string outputFileName) { TextReader?reader = null; TextWriter?writer = null; try { try { reader = fs.CreateStreamReader(inputFileName); } catch (IOException ex) { logger.Error(ex, "Unable to open file {0} for reading.", inputFileName); return; } try { writer = fs.CreateStreamWriter(fs.CreateFileStream(outputFileName, FileMode.Create, FileAccess.Write), new UTF8Encoding(false)); } catch (IOException ex) { logger.Error(ex, "Unable to open file {0} for writing.", outputFileName); return; } Translate(inputFileName, reader, writer); } finally { if (writer != null) { writer.Flush(); writer.Dispose(); } if (reader != null) { reader.Dispose(); } } }
public static TranslationFile?Deserialize(string path) { if (!File.Exists(path)) { return(null); } var serializer = new XmlSerializer(typeof(TranslationFile)); TextReader?stringReader = null; try { stringReader = new StreamReader(path); using var xmlReader = new XmlTextReader(stringReader); stringReader = null; return((TranslationFile)serializer.Deserialize(xmlReader)); } finally { stringReader?.Dispose(); } }
public FileSource(TextReader?textReader) { //Lines = System.IO.File.ReadAllLines(textReader.read); if (textReader is null) { throw new ArgumentNullException(nameof(textReader)); } while (true) { var temp = textReader.ReadLine(); if (temp == null) { break; } if (temp.Split().GetLength(0) != 2) { throw new InvalidFileException(); } _lines.Add(new Line(Parse(temp.Split()[0], null), Parse(temp.Split()[1], null))); } }
/// <summary> /// Deserializes the XML document contained by the specified TextReader. /// </summary> /// <param name="textReader"></param> /// <typeparam name="TValue"></typeparam> /// <returns></returns> public static TValue?Deserialize <TValue>(TextReader?textReader) => textReader is null ? default : (TValue?)Deserialize(typeof(TValue), textReader);
/// <summary> /// Deserializes JSON from the given TextReader as the passed type. /// /// This is equivalent to calling Deserialize<T>(TextReader, Options), except /// without requiring a generic parameter. For true dynamic deserialization, you /// should use DeserializeDynamic instead. /// /// Pass an Options object to specify the particulars (such as DateTime formats) of /// the JSON being deserialized. If omitted Options.Default is used, unless JSON.SetDefaultOptions(Options) has been /// called with a different Options object. /// </summary> /// <param name="type"></param> /// <param name="reader"></param> /// <param name="options"></param> /// <returns></returns> public static object?Deserialize(Type type, TextReader?reader, Options?options = null) => reader is null ? default : JSON.Deserialize(reader, type, options);
public static object?ReadJson(this TextReader?textReader, Type type, Options?options = null) => JilHelper.Deserialize(type, textReader, options);
public static TValue?ReadJson <TValue>(this TextReader?textReader, Options?options = null) => JilHelper.Deserialize <TValue>(textReader, options);
public static ElsaOptionsBuilder AddConsoleActivities(this ElsaOptionsBuilder options, TextReader?standardIn = default, TextWriter?standardOut = default) { options.Services .AddSingleton(standardIn ?? Console.In) .AddSingleton(standardOut ?? Console.Out); options .AddActivity <ReadLine>() .AddActivity <WriteLine>(); return(options); }
public (int, string, string) Execute(ITestOutputHelper outputHelper, TextReader?inputReader, TextWriter?outputWriter, TextWriter?errorWriter) { return(0, "", ""); }
/// <summary> /// Deserializes JSON from the given TextReader. /// /// Pass an Options object to specify the particulars (such as DateTime formats) of /// the JSON being deserialized. If omitted Options.Default is used, unless JSON.SetDefaultOptions(Options) has been /// called with a different Options object. /// </summary> /// <param name="reader"></param> /// <param name="options"></param> /// <typeparam name="TValue"></typeparam> /// <returns></returns> public static TValue?Deserialize <TValue>(TextReader?reader, Options?options = null) => reader is null ? default : JSON.Deserialize <TValue>(reader, options);
public static object?ReadXml(this TextReader?textReader, Type type) => XmlHelper.Deserialize(type, textReader);
public static async Task <int> ExecAsync(string fileName, string arguments, TextReader?stdin, TextWriter?stdout, TextWriter?stderr, CancellationToken cancellationToken) { using var p = new Process(); p.StartInfo.FileName = fileName; p.StartInfo.Arguments = arguments; p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = true; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.StandardInputEncoding = ConstStuff.UniversalUtf8Encoding; p.StartInfo.StandardOutputEncoding = ConstStuff.UniversalUtf8Encoding; p.StartInfo.StandardErrorEncoding = ConstStuff.UniversalUtf8Encoding; p.Start(); // stdin, stdout, stderr at the same time var stdinTask = Task.Run(async() => { if (stdin != null) { var buf = new char[1024]; while (true) { var len = await stdin.ReadAsync(buf, 0, buf.Length); if (len <= 0) { break; } await p.StandardInput.WriteAsync(buf, 0, len); await p.StandardInput.FlushAsync(); } } p.StandardInput.Close(); }, cancellationToken); var stdoutTask = Task.Run(async() => { var buf = new char[1024]; while (true) { var len = await p.StandardOutput.ReadAsync(buf, 0, buf.Length); if (len <= 0) { break; } if (stdout != null) { await stdout.WriteAsync(buf, 0, len); await stdout.FlushAsync(); } } if (stdout != null) { stdout.Close(); } }, cancellationToken); var stderrTask = Task.Run(async() => { var buf = new char[1024]; while (true) { var len = await p.StandardError.ReadAsync(buf, 0, buf.Length); if (len <= 0) { break; } if (stderr != null) { await stderr.WriteAsync(buf, 0, len); await stderr.FlushAsync(); } } if (stderr != null) { stderr.Close(); } }, cancellationToken); await Task.WhenAll(stdinTask, stdoutTask, stderrTask); await p.WaitForExitAsync(cancellationToken); return(p.ExitCode); }
public static TValue?ReadXml <TValue>(this TextReader?textReader) => XmlHelper.Deserialize <TValue>(textReader);
public ReadLine(TextReader input) { _input = input; }
public StreamTokenizer(TextReader reader) : this() // Calls private constructor { inReader = reader ?? throw new ArgumentNullException(nameof(reader)); }
/// <summary> /// Use given stream as input for host /// </summary> /// <param name="stream">given stream</param> /// <returns>this</returns> public SuitHostBuilder ConfigureIn(TextReader stream) { Input = stream; return(this); }