本文整理汇总了C#中System.IO.StringReader.ReadLineAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StringReader.ReadLineAsync方法的具体用法?C# StringReader.ReadLineAsync怎么用?C# StringReader.ReadLineAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StringReader
的用法示例。
在下文中一共展示了StringReader.ReadLineAsync方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PostTurnoutSwipe
public async Task<IHttpActionResult> PostTurnoutSwipe(TurnoutSwipeDto dto)
{
using (var reader = new StringReader(dto.Data))
{
string line;
while ((line = await reader.ReadLineAsync()) != null)
{
var match = Regex.Match(line, @"^([+-])\x02\w{2}(\w{8})\w{2}\x03\x03$");
if (!match.Success) continue;
var sign = match.Groups[1].ToString();
var hexRfid = match.Groups[2].ToString();
var rfid = Convert.ToInt64(hexRfid, 16);
var scout = await Db.Scouts.FirstOrDefaultAsync(s => s.Rfid == rfid);
if (scout == null) continue;
var point = new TurnoutPoint
{
Amount = sign == "+" ? 1 : -1,
HouseId = scout.HouseId,
Time = DateTime.Now
};
Db.TurnoutPoints.Add(point);
await Db.SaveChangesAsync();
ScoreUpdated();
}
return Ok();
}
}
示例2: LoadAsync
public async Task LoadAsync(Stream input, CancellationToken cancellationToken)
{
if (input == null) throw new ArgumentNullException(nameof(input));
var headerSizeBuffer = BitConverter.GetBytes(default(int));
await input.ReadAsync(headerSizeBuffer, 0, headerSizeBuffer.Length, cancellationToken);
var headerSize = BitConverter.ToInt32(headerSizeBuffer, 0);
var headerBuffer = new byte[headerSize];
await input.ReadAsync(headerBuffer, 0, headerBuffer.Length, cancellationToken);
// Clear the files
this.Files.Clear();
using (var sr = new StringReader(Encoding.Unicode.GetString(headerBuffer, 0, headerBuffer.Length)))
{
var separator = new[] { '|' };
string line;
while ((line = await sr.ReadLineAsync()) != null)
{
var values = line.Split(separator);
this.Add(values[0], int.Parse(values[1]));
}
}
}
示例3: ParseEconomicEventsAsync
protected override async Task<IList<EconomicEvent>> ParseEconomicEventsAsync(string rawData)
{
var reader = new StringReader(rawData);
var results = new List<EconomicEvent>();
string header = await reader.ReadLineAsync().ConfigureAwait(false);
VerifyHeader(header);
string line = string.Empty;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
if (string.IsNullOrEmpty(line))
break;
string[] colums = line.Split(',');
// be careful about not available data, n/a tentative etc etc
try
{
results.Add(new EconomicEvent
{
DateTime = ParseDateTime(colums[0].Trim('"')),
Name = colums[1].Trim('"'),
Country = colums[2].Trim('"'),
Currency = CurrencyRegistry.ForCountry(colums[2].Trim('"')),
Volatility = colums[3].Trim('"'),
Actual = colums[4].Trim('"'),
Previous = colums[5].Trim('"'),
Consensus = colums[6].Trim('"')
});
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
return results;
}
示例4: FsharpWorker
static FsharpWorker()
{
requestQueue = new BufferBlock<FsharpRequest>();
worker = Task.Run(async ()=>{
while(true){
var request = await requestQueue.ReceiveAsync();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "fsharpi";
startInfo.Arguments = "--nologo";
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
var process = Process.Start(startInfo);
var reader = process.StandardOutput;
var writer = process.StandardInput;
using(var sr = new StringReader(request.Body)){
string line;
while((line=await sr.ReadLineAsync())!=null){
writer.WriteLine(line);
}
}
writer.WriteLine(";;");
writer.WriteLine("#quit;;");
string output;
string response="";
while((output = await reader.ReadLineAsync())!=null){
response+=output;
response+="\r\n";
}
if (!process.WaitForExit(200)){
Console.WriteLine("fsharpi process failed to quit in time");
}
request.SetResult(response);
}
});
}
示例5: Parse
public static async Task<List<GitCommit>> Parse(string output) {
GitCommit commit = null;
List<GitCommit> commits = new List<GitCommit>();
bool processingMessage = false;
using (StringReader strReader = new StringReader(output)) {
do {
string line = await strReader.ReadLineAsync();
if (line.StartsWith("commit ")) {
if (commit != null)
commits.Add(commit);
commit = new GitCommit();
commit.Sha = line.Split(' ')[1];
}
if (startsWithHeader(line)) {
var header = line.Split(':')[0];
var val = string.Join(":", line.Split(':').Skip(1)).Trim();
// headers
commit.Headers.Add(header, val);
}
if (string.IsNullOrEmpty(line)) {
// commit message divider
processingMessage = !processingMessage;
}
if (line.Length > 0 && line[0] == '\t') {
// commit message.
commit.Message += line;
}
if (line.Length > 1 && Char.IsLetter(line[0]) && line[1] == '\t') {
var status = line.Split('\t')[0];
var file = line.Split('\t')[1];
commit.Files.Add(new GitFileStatus() { Status = status, File = file });
}
}
while (strReader.Peek() != -1);
}
if (commit != null)
commits.Add(commit);
return commits;
}
示例6: WriteMessage
public async Task WriteMessage(Message message)
{
if (message == null) throw new ArgumentNullException("message");
var headers = message.Headers;
if (headers != null)
{
foreach (var header in headers)
{
var headerName = header.Key;
var headerValue = header.Value;
await _writer.WriteAsync(string.Format("{0}: ", headerName));
using (var headerValueReader = new StringReader(headerValue))
{
var multilineContinuation = false;
string line;
while ((line = await headerValueReader.ReadLineAsync()) != null)
{
if (multilineContinuation)
{
// Prefix continuation with whitespace so that subsequent
// lines are not confused with different headers.
line = " " + line;
}
await _writer.WriteLineAsync(line);
multilineContinuation = true;
}
}
}
}
// Blank line separates headers from content
await _writer.WriteLineAsync();
var content = message.Content;
if (!string.IsNullOrWhiteSpace(content))
{
// No special formatting required for content. Content is defined as
// everything following the blank line.
await _writer.WriteAsync(content);
}
}
示例7: CheckRemoteFilePublicationDateAsync
private async Task<DateTime> CheckRemoteFilePublicationDateAsync(string file)
{
DateTime dt = DateTime.MinValue;
using (StringReader sr = new StringReader(file))
{
string line = string.Empty;
while ((line = await sr.ReadLineAsync().ConfigureAwait(false)) != null)
{
if (line.StartsWith("# -"))
{
int indexOfDateFirstCharacter = line.IndexOf(":") + 2;
int indexOfDateLastCharacter = line.IndexOf(" ", indexOfDateFirstCharacter);
int lengthOfDate = (indexOfDateLastCharacter - indexOfDateFirstCharacter) + 1;
string dateAsString = line.Substring(indexOfDateFirstCharacter, lengthOfDate);
if (DateTime.TryParse(dateAsString, out dt) == false)
{
dt = new DateTime(2000, 1, 1);
}
}
}
}
return dt;
}
示例8: ConvertRemoteHosts
private async Task<List<string>> ConvertRemoteHosts(string remote)
{
List<string> formatted = new List<string>();
using (StringReader sr = new StringReader(remote))
{
string line = string.Empty;
while ((line = await sr.ReadLineAsync().ConfigureAwait(false)) != null)
{
if (line.StartsWith("0.0.0.0"))
{
string domain = GetDomainName(line);
string s = FormatDomainName(domain);
formatted.Add(s);
}
}
}
return formatted;
}
示例9: Report
protected override void Report(TextWriter writer)
{
using (var reader = new StringReader(_output.ToString()))
{
string line;
while ((line = reader.ReadLineAsync().Result) != null)
writer.WriteLineAsync(line).Wait();
}
}
示例10: GetResponseKeyValuePairList
private static async Task<List<KeyValuePair<string, string>>> GetResponseKeyValuePairList(string responseString)
{
var list = new List<KeyValuePair<string, string>>();
if (!string.IsNullOrEmpty(responseString))
{
using (var stringReader = new StringReader(responseString))
{
string line = string.Empty;
while (!string.IsNullOrEmpty(line = await stringReader.ReadLineAsync())
&& !line.Equals(MPDKeyWords.Response.OK))
{
var pair = line.Split(MPDKeyWords.Response.KEYVALUESEPERATION.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
var key = (pair.Length > 0)
? pair[0]
: string.Empty;
if (pair.Length > 1)
pair[1] = pair[1].TrimStart(MPDKeyWords.Response.SPACE.ToCharArray());
var value = string.Empty;
for(var i = 1; i < pair.Length; i++)
{
value += pair[i];
if(i != pair.Length - 1) value += MPDKeyWords.Response.KEYVALUESEPERATION;
}
list.Add(new KeyValuePair<string, string>(key, value));
}
}
}
return list;
}