Support for "length" attribute for strings in the manifest

This commit is contained in:
georgis 2014-03-11 06:33:09 -07:00
Родитель ddefb19fcc
Коммит b44091452b
4 изменённых файлов: 44 добавлений и 15 удалений

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

@ -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.40213.0")]
[assembly: AssemblyFileVersion("1.0.40213.0")]
[assembly: AssemblyVersion("1.0.40311.0")]
[assembly: AssemblyFileVersion("1.0.40311.0")]

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

@ -23,7 +23,7 @@ namespace Tx.Windows
public ManifestParser(string manifest)
{
XElement localization;
XElement resources;
XElement resources = null;
_root = XElement.Parse(manifest);
_instrumentation = _root.Element(ElementNames.Instrumentation);
@ -31,7 +31,10 @@ namespace Tx.Windows
{
_instrumentation = _root.Element(ElementNames.Instrumentation1);
localization = _root.Element(ElementNames.Localization1);
resources = localization.Element(ElementNames.Resources1);
if (localization != null)
resources = localization.Element(ElementNames.Resources1);
if (resources != null)
_stringTable = resources.Element(ElementNames.StringTable1);
}
@ -281,8 +284,19 @@ using System;");
if (order > 0)
sb.AppendLine();
sb.AppendFormat(" [EventField(\"{0}\")]",
var length = f.Attribute(AttributeNames.Length);
if (null != length)
{
sb.AppendFormat(" [EventField(\"{0}\", \"{1}\")]",
f.Attribute(AttributeNames.InType).Value, length.Value);
}
else
{
sb.AppendFormat(" [EventField(\"{0}\")]",
f.Attribute(AttributeNames.InType).Value);
}
sb.AppendLine();
if (f.Attribute(AttributeNames.Map) == null)
@ -765,6 +779,7 @@ using System;");
public const string Message = "message";
public const string EventGuid = "eventGUID";
public const string MofValue = "mofValue";
public const string Length = "length";
public const string Level = "level";
public const string Channel = "channel";
public const string Chid = "chid";

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

@ -379,17 +379,17 @@ namespace Tx.Windows
public string ReadAnsiStringPrefixLen()
{
int length = ReadInt16();
string str = Marshal.PtrToStringAnsi((IntPtr) _data, length);
_data += length;
// reads a string, assuming the lenght was win:UInt32 right before it in the manifest
string str = Marshal.PtrToStringAnsi((IntPtr) _data, (int)_length);
_data += _length;
return str;
}
public string ReadUnicodeStringPrefixLen()
{
int length = ReadInt16()/2;
var chars = new char[length];
for (int i = 0; i < length; i++)
// reads a string, assuming the lenght was win:UInt32 right before it in the manifest
var chars = new char[_length];
for (int i = 0; i < _length; i++)
{
chars[i] = (char) ReadInt16();
}

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

@ -118,10 +118,13 @@ namespace Tx.Windows
break;
case "win:UnicodeString":
int len = 0;
if (int.TryParse(attribute.Length, out len))
if (!String.IsNullOrEmpty(attribute.Length))
{
readExpression = MakeExpression(r => r.ReadUnicodeString(len), reader);
int len = 0;
if (int.TryParse(attribute.Length, out len))
readExpression = MakeExpression(r => r.ReadUnicodeString(len), reader);
else
readExpression = MakeExpression(r => r.ReadUnicodeStringPrefixLen(), reader);
}
else
{
@ -130,7 +133,18 @@ namespace Tx.Windows
break;
case "win:AnsiString":
readExpression = MakeExpression(r => r.ReadAnsiString(), reader);
if (!String.IsNullOrEmpty(attribute.Length))
{
int len = 0;
if (int.TryParse(attribute.Length, out len))
readExpression = MakeExpression(r => r.ReadAnsiString(len), reader);
else
readExpression = MakeExpression(r => r.ReadAnsiStringPrefixLen(), reader);
}
else
{
readExpression = MakeExpression(r => r.ReadAnsiString(), reader);
}
break;
case "win:FILETIME":