本文整理汇总了C#中System.IO.TextReader.ReadToEnd方法的典型用法代码示例。如果您正苦于以下问题:C# TextReader.ReadToEnd方法的具体用法?C# TextReader.ReadToEnd怎么用?C# TextReader.ReadToEnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.TextReader
的用法示例。
在下文中一共展示了TextReader.ReadToEnd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
/// <summary>
/// Parse a query string
/// </summary>
/// <param name="reader">string to parse</param>
/// <param name="parameters">Parameter collection to fill</param>
/// <returns>A collection</returns>
/// <exception cref="ArgumentNullException"><c>reader</c> is <c>null</c>.</exception>
public void Parse(TextReader reader, IParameterCollection parameters)
{
if (reader == null)
throw new ArgumentNullException("reader");
var canRun = true;
while (canRun)
{
var result = reader.ReadToEnd("&=");
var name = Uri.UnescapeDataString(result.Value);
switch (result.Delimiter)
{
case '&':
parameters.Add(name, string.Empty);
break;
case '=':
result = reader.ReadToEnd("&");
parameters.Add(name, Uri.UnescapeDataString(result.Value));
break;
case char.MinValue:
// EOF = no delimiter && no value
if (!string.IsNullOrEmpty(name))
parameters.Add(name, string.Empty);
break;
}
canRun = result.Delimiter != char.MinValue;
}
}
示例2: Exec
public static int Exec(string filename, string args, TextReader stdIn = null, TextWriter stdOut = null, TextWriter stdErr = null, Encoding encoding = null, string workingDirectory = null)
{
using (Process process = new Process())
{
ProcessStartInfo psi = process.StartInfo;
psi.RedirectStandardError = psi.RedirectStandardInput = psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
psi.FileName = filename;
psi.Arguments = args;
if (workingDirectory != null)
psi.WorkingDirectory = workingDirectory;
if (encoding != null)
{
psi.StandardOutputEncoding = encoding;
psi.StandardErrorEncoding = encoding;
}
if (stdOut != null)
{
process.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e)
{
stdOut.WriteLine(e.Data);
};
}
if (stdErr != null)
{
process.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e)
{
stdErr.WriteLine(e.Data);
};
}
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
if (stdIn != null)
{
if (encoding != null)
{
// There's no Process.Standard*Input*Encoding, so write specified encoding's raw bytes to base input stream
using (var encodedStdIn = new StreamWriter(process.StandardInput.BaseStream, encoding))
encodedStdIn.Write(stdIn.ReadToEnd());
}
else
{
using (process.StandardInput)
process.StandardInput.Write(stdIn.ReadToEnd());
}
}
process.WaitForExit();
return process.ExitCode;
}
}
示例3: Parse
public override void Parse(TextReader reader, IProcessorContext context)
{
if (AssetPipeline.MinifyJs)
{
var compressor = new JavaScriptCompressor(reader.ReadToEnd());
context.Output.Write(compressor.Compress());
}
else
{
context.Output.Write(reader.ReadToEnd());
}
}
示例4: Parse
/// <summary>
/// Parses the specified pattern returned by the reader and localizes error messages with the text manager specified
/// </summary>
/// <param name="reader">The reader.</param>
/// <param name="textManager">The text manager.</param>
/// <returns></returns>
public override Expression Parse(TextReader reader, TextManager textManager)
{
try
{
_reader = reader.ReadToEnd();
_pos = -1;
MoveNext();
var expr = ParseExpression();
if (_current != Eof)
{
UnexpectedToken("Expression", "" + _current);
}
expr.Accept(_trimmer);
return expr;
}
catch (InnerParserException template)
{
throw new SyntaxErrorException(template.Message, template.Construct, template.Pos);
}
}
示例5: ReaderPackageJsonSource
public ReaderPackageJsonSource(TextReader reader) {
try {
var text = reader.ReadToEnd();
try {
// JsonConvert and JObject.Parse exhibit slightly different behavior,
// so fall back to JObject.Parse if JsonConvert does not properly deserialize
// the object.
Package = JsonConvert.DeserializeObject(text);
} catch (ArgumentException) {
Package = JObject.Parse(text);
}
} catch (JsonReaderException jre) {
WrapExceptionAndRethrow(jre);
} catch (JsonSerializationException jse) {
WrapExceptionAndRethrow(jse);
} catch (FormatException fe) {
WrapExceptionAndRethrow(fe);
} catch (ArgumentException ae) {
throw new PackageJsonException(
string.Format(CultureInfo.CurrentCulture, @"Error reading package.json. The file may be parseable JSON but may contain objects with duplicate properties.
The following error occurred:
{0}", ae.Message),
ae);
}
}
示例6: Deserialize
public override object Deserialize(TextReader tr)
{
if (tr != null)
{
string value = tr.ReadToEnd();
ICalendarObject co = SerializationContext.Peek() as ICalendarObject;
if (co != null)
{
EncodableDataType dt = new EncodableDataType();
dt.AssociatedObject = co;
value = Decode(dt, value);
}
value = TextUtil.Normalize(value, SerializationContext).ReadToEnd();
try
{
Uri uri = new Uri(value);
return uri;
}
catch
{
}
}
return null;
}
示例7: Execute
/// <summary>
/// Execute script from stream.
/// </summary>
public void Execute(TextReader reader)
{
// Read script
string script = reader.ReadToEnd();
// Execute
ExecuteScriptText(script);
}
示例8: Deserialize
public object Deserialize (TextReader input)
{
if (input == null)
throw new ArgumentNullException ("input");
return Deserialize (input.ReadToEnd ());
}
示例9: Parse
/// <summary>
/// Parse and filter the supplied modifications. The position of each modification in the list is used as the ChangeNumber.
/// </summary>
/// <param name="history"></param>
/// <param name="from"></param>
/// <param name="to"></param>
/// <returns></returns>
public Modification[] Parse(TextReader history, DateTime from, DateTime to)
{
StringReader sr = new StringReader(string.Format(@"<ArrayOfModification xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">{0}</ArrayOfModification>"
, history.ReadToEnd()));
XmlSerializer serializer = new XmlSerializer(typeof(Modification[]));
Modification[] mods;
try
{
mods = (Modification[])serializer.Deserialize(sr);
}
catch (Exception ex)
{
throw new CruiseControlException("History Parsing Failed", ex);
}
ArrayList results = new ArrayList();
int change = 0;
foreach (Modification mod in mods)
{
change++;
mod.ChangeNumber = change;
if ((mod.ModifiedTime >= from) & (mod.ModifiedTime <= to))
{
results.Add(mod);
}
}
return (Modification[])results.ToArray(typeof(Modification));
}
示例10: ObjectMapTable
/// <summary>
/// Initializes a new instance of the <see cref="ObjectMapTable"/> class.
/// </summary>
/// <param name="bufferedReader">The buffered reader.</param>
public ObjectMapTable(TextReader bufferedReader)
: this()
{
try
{
XmlDocument XmlData = new XmlDocument();
XmlData.LoadXml(bufferedReader.ReadToEnd());
//add projects to treeview
XmlNodeList Classes = XmlData.SelectNodes("ObjectMap/Class");
if (Classes != null && Classes.Count > 0)
{
foreach (XmlElement nodeClass in Classes)
{
// Add path and class to the object mapping
ObjectMapping theMapping = new ObjectMapping(nodeClass);
_objectMapList.Add(theMapping);
}
}
}
catch (Exception ex)
{
throw new Exception("error reading map file", ex);
}
finally
{
bufferedReader.Close();
}
}
示例11: Parse
public object Parse(TextReader sourceReader)
{
if (sourceReader == null)
throw new ArgumentNullException("sourceReader");
return Parse(new TextParser(sourceReader.ReadToEnd()));
}
示例12: Deserialize
public override object Deserialize(TextReader tr)
{
string value = tr.ReadToEnd();
IUTCOffset offset = CreateAndAssociate() as IUTCOffset;
if (offset != null)
{
// Decode the value as necessary
value = Decode(offset, value);
Match match = Regex.Match(value, @"(\+|-)(\d{2})(\d{2})(\d{2})?");
if (match.Success)
{
try
{
// NOTE: Fixes bug #1874174 - TimeZone positive UTCOffsets don't parse correctly
if (match.Groups[1].Value == "+")
offset.Positive = true;
offset.Hours = Int32.Parse(match.Groups[2].Value);
offset.Minutes = Int32.Parse(match.Groups[3].Value);
if (match.Groups[4].Success)
offset.Seconds = Int32.Parse(match.Groups[4].Value);
}
catch
{
return null;
}
return offset;
}
return false;
}
return null;
}
示例13: Parse
/// <inheritdoc />
public IParseForest Parse(TextReader reader)
{
// CONTRACT: Inherited from IParser
// Unger requires the whole input to be known beforehand.
return Parse(reader.ReadToEnd());
}
示例14: TokenStream
public override TokenStream TokenStream(string fieldName, TextReader reader)
{
string str = reader.ReadToEnd();
string[] parts = str.Split('.');
StringBuilder tokenString = new StringBuilder();
for (int i = 0; i < parts.Length; i++)
{
if (parts[i].IndexOf('(') > 0)
parts[i] = parts[i].Substring(0, parts[i].IndexOf('('));
if (parts[i].IndexOf('<') > 0)
parts[i] = parts[i].Substring(0, parts[i].IndexOf('<'));
parts[i] = new string(parts[i].Where(c => char.IsUpper(c) || char.IsNumber(c)).ToArray());
}
tokenString.AppendLine(parts[parts.Length - 1]);
for (int i = parts.Length - 2; i >= 0; i--)
{
tokenString.AppendLine(string.Join(".", parts, i, parts.Length - i));
}
return new WhitespaceTokenizer(new StringReader(tokenString.ToString().ToLowerInvariant()));
}
示例15: Parse
public Modification[] Parse(TextReader history, DateTime from, DateTime to)
{
string historyLog = history.ReadToEnd();
Regex regex = new Regex(Alienbrain.NO_CHANGE);
if (regex.Match(historyLog).Success == true)
{
return new Modification[0];
}
regex = new Regex(FILE_REGEX);
var result = new List<Modification>();
string oldfile = ",";
for (Match match = regex.Match(historyLog); match.Success; match = match.NextMatch())
{
string[] modificationParams = AllModificationParams(match.Value);
if (modificationParams.Length > 1)
{
string file = modificationParams[1];
if (file != oldfile)
{
result.Add(ParseModification(modificationParams));
oldfile = file;
}
}
}
return result.ToArray();
}