(FlightSide) Adding FromStream method to W3CEnumerable

This commit is contained in:
georgis 2014-02-13 16:52:50 -08:00
Родитель 9eba0a8857
Коммит c2035016ba
2 изменённых файлов: 39 добавлений и 27 удалений

Просмотреть файл

@ -5,5 +5,5 @@ using System.Reflection;
[assembly: AssemblyCompany("MS Open Tech")]
[assembly: AssemblyProduct("Tx (LINQ to Logs and Traces)")]
[assembly: AssemblyCopyright("Copyright © MS Open Tech 2012")]
[assembly: AssemblyVersion("1.0.40127.0")]
[assembly: AssemblyFileVersion("1.0.40127.0")]
[assembly: AssemblyVersion("1.0.40213.0")]
[assembly: AssemblyFileVersion("1.0.40213.0")]

Просмотреть файл

@ -26,38 +26,50 @@ namespace Tx.Windows
{
using (var reader = File.OpenText(file))
{
Expression<Func<string[], W3CEvent>> transformExpression;
Func<string[], W3CEvent> transform = null;
IEnumerable<W3CEvent> enumerable = FromStream(reader);
for (;;)
{
string line = reader.ReadLine();
if (line == null)
yield break;
foreach (var e in enumerable)
yield return e;
if (line.StartsWith("#Fields:"))
{
transformExpression = GetTransformExpression(line);
transform = transformExpression.Compile();
continue;
}
if (line.StartsWith("#"))
continue;
string[] tokens = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < tokens.Length; i++)
if (tokens[i] == "-")
tokens[i] = null;
W3CEvent e = transform(tokens);
yield return e;
break;
}
}
}
public static IEnumerable<W3CEvent> FromStream(StreamReader reader)
{
Expression<Func<string[], W3CEvent>> transformExpression;
Func<string[], W3CEvent> transform = null;
for (;;)
{
string line = reader.ReadLine();
if (line == null)
yield break;
if (line.StartsWith("#Fields:"))
{
transformExpression = GetTransformExpression(line);
transform = transformExpression.Compile();
continue;
}
if (line.StartsWith("#"))
continue;
string[] tokens = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < tokens.Length; i++)
if (tokens[i] == "-")
tokens[i] = null;
W3CEvent e = transform(tokens);
yield return e;
}
}
static Expression<Func<string[], W3CEvent>> GetTransformExpression(string fieldsHeader)
{
Expression<Func<string[], W3CEvent>> template = (tok) => new W3CEvent { c_ip = tok[8] };