Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
doug24 committed May 29, 2017
1 parent 27da67e commit 778a588
Show file tree
Hide file tree
Showing 79 changed files with 3,272 additions and 4,573 deletions.
3 changes: 3 additions & 0 deletions Dependencies/SplitButton/Demo/app.config
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/></startup></configuration>
92 changes: 45 additions & 47 deletions NLog.XmlLayout/Serialization.cs
@@ -1,59 +1,57 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Collections;
using System.Xml;

namespace NLog.XmlLayout
{
public class Serialization
{
/// <summary>
/// Serializes exception into XML. If exception or stream is null
/// does nothing.
/// </summary>
/// <param name="currentException"></param>
/// <param name="writer"></param>
public static void SerializeException(Exception currentException, XmlTextWriter writer)
{
if (currentException == null || writer == null)
return;
public class Serialization
{
/// <summary>
/// Serializes exception into XML. If exception or stream is null
/// does nothing.
/// </summary>
/// <param name="currentException"></param>
/// <param name="writer"></param>
public static void SerializeException(Exception currentException, XmlTextWriter writer)
{
if (currentException == null || writer == null)
return;

writer.WriteStartElement("Exception");
writer.WriteStartElement("Exception");

writer.WriteStartElement("Message");
writer.WriteString(currentException.Message);
writer.WriteEndElement();
writer.WriteStartElement("Message");
writer.WriteString(currentException.Message);
writer.WriteEndElement();

writer.WriteStartElement("Source");
writer.WriteString(currentException.Source);
writer.WriteEndElement();
writer.WriteStartElement("Source");
writer.WriteString(currentException.Source);
writer.WriteEndElement();


if (currentException.StackTrace != null)
{
writer.WriteStartElement("Stack");
writer.WriteString(currentException.StackTrace);
writer.WriteEndElement();
}
if (currentException.Data.Count > 0)
{
foreach (DictionaryEntry item in currentException.Data)
{
writer.WriteStartElement("Data");
if (item.Key != null)
XmlLayoutRenderer.WriteToAttribute(writer, "key", item.Key.ToString());
if (item.Value != null)
XmlLayoutRenderer.WriteToAttribute(writer, "value", item.Value.ToString());
writer.WriteEndElement();
}
}
if (currentException.StackTrace != null)
{
writer.WriteStartElement("Stack");
writer.WriteString(currentException.StackTrace);
writer.WriteEndElement();
}
if (currentException.Data.Count > 0)
{
foreach (DictionaryEntry item in currentException.Data)
{
writer.WriteStartElement("Data");
if (item.Key != null)
XmlLayoutRenderer.WriteToAttribute(writer, "key", item.Key.ToString());
if (item.Value != null)
XmlLayoutRenderer.WriteToAttribute(writer, "value", item.Value.ToString());
writer.WriteEndElement();
}
}

if (currentException.InnerException != null)
{
SerializeException(currentException.InnerException, writer);
}
writer.WriteEndElement();
}
}
if (currentException.InnerException != null)
{
SerializeException(currentException.InnerException, writer);
}
writer.WriteEndElement();
}
}
}
142 changes: 70 additions & 72 deletions NLog.XmlLayout/XmlLayout.cs
@@ -1,98 +1,96 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using NLog.LayoutRenderers;
using System.Xml;
using System.Collections;
using System.IO;
using System.Globalization;

using NLog.LayoutRenderers;

namespace NLog.XmlLayout
{
[LayoutRenderer("xml")]
public class XmlLayoutRenderer : LayoutRenderer
{
private string elementName;
[LayoutRenderer("xml")]
public class XmlLayoutRenderer : LayoutRenderer
{
private string elementName;

public string ElementName
{
get { return elementName; }
set { elementName = value; }
}
public string ElementName
{
get { return elementName; }
set { elementName = value; }
}

protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{
using (StringWriter stringWriter = new UTF8StringWriter(builder))
using (XmlTextWriter writer = new XmlTextWriter(stringWriter))
{
writer.Formatting = Formatting.Indented;
// Create the eventNode element
writer.WriteStartElement((elementName == null ? logEvent.Level.ToString() : elementName));
if (elementName != null)
{
WriteToAttribute(writer, "type", logEvent.Level.ToString());
}
using (XmlTextWriter writer = new XmlTextWriter(stringWriter))
{
writer.Formatting = Formatting.Indented;
// Create the eventNode element
writer.WriteStartElement((elementName == null ? logEvent.Level.ToString() : elementName));

if (elementName != null)
{
WriteToAttribute(writer, "type", logEvent.Level.ToString());
}

WriteToAttribute(writer, "time", logEvent.TimeStamp.ToString("M/d/yyyy HH:mm:ss tt"));
writer.WriteStartElement("Message");
writer.WriteString(logEvent.Message);
writer.WriteEndElement();
if (logEvent.Parameters != null)
{
foreach (object obj in logEvent.Parameters)
{
writer.WriteStartElement("Parameter");
if (obj is KeyValuePair<string, string>)
{
KeyValuePair<string, string> p = (KeyValuePair<string, string>)obj;
WriteToAttribute(writer, "name", p.Key);
WriteToAttribute(writer, "value", p.Value);
}
WriteToAttribute(writer, "time", logEvent.TimeStamp.ToString("M/d/yyyy HH:mm:ss tt"));
writer.WriteStartElement("Message");
writer.WriteString(logEvent.Message);
writer.WriteEndElement();
if (logEvent.Parameters != null)
{
foreach (object obj in logEvent.Parameters)
{
writer.WriteStartElement("Parameter");
if (obj is KeyValuePair<string, string>)
{
KeyValuePair<string, string> p = (KeyValuePair<string, string>)obj;
WriteToAttribute(writer, "name", p.Key);
WriteToAttribute(writer, "value", p.Value);
}
else if (obj is Exception)
{
Exception ex = obj as Exception;
string msg = ex.GetType().ToString() + ex.StackTrace;
WriteToAttribute(writer, "value", msg);
WriteToAttribute(writer, "value", msg);
}
else
{
WriteToAttribute(writer, "value", obj.ToString());
}
else
{
WriteToAttribute(writer, "value", obj.ToString());
}
writer.WriteEndElement();
}
}
if (logEvent.Exception != null)
{
Serialization.SerializeException(logEvent.Exception, writer);
}
writer.WriteEndElement();
stringWriter.Flush();
}
}
writer.WriteEndElement();
}
}
if (logEvent.Exception != null)
{
Serialization.SerializeException(logEvent.Exception, writer);
}
writer.WriteEndElement();
stringWriter.Flush();
}
}

internal static void WriteToAttribute(XmlTextWriter writer, string attribute, string value)
{
WriteToAttribute(writer, attribute, value, false);
}
internal static void WriteToAttribute(XmlTextWriter writer, string attribute, string value)
{
WriteToAttribute(writer, attribute, value, false);
}

internal static void WriteToAttribute(XmlTextWriter writer, string attribute, DateTime value)
{
WriteToAttribute(writer, attribute, value.ToString(DateTimeFormatInfo.InvariantInfo.ShortDatePattern + " " + DateTimeFormatInfo.InvariantInfo.ShortTimePattern), false);
}
internal static void WriteToAttribute(XmlTextWriter writer, string attribute, DateTime value)
{
WriteToAttribute(writer, attribute, value.ToString(DateTimeFormatInfo.InvariantInfo.ShortDatePattern + " " + DateTimeFormatInfo.InvariantInfo.ShortTimePattern), false);
}

internal static void WriteToAttribute(XmlTextWriter writer, string attribute, string value, bool writeIfEmptyValue)
{
if (writeIfEmptyValue || !string.IsNullOrEmpty(value))
writer.WriteAttributeString(attribute, value);
}
}
internal static void WriteToAttribute(XmlTextWriter writer, string attribute, string value, bool writeIfEmptyValue)
{
if (writeIfEmptyValue || !string.IsNullOrEmpty(value))
writer.WriteAttributeString(attribute, value);
}
}

public class UTF8StringWriter : StringWriter
{
public UTF8StringWriter()
:base()
: base()
{
}

Expand Down
34 changes: 15 additions & 19 deletions Tests/BookmarkTest.cs
@@ -1,23 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;
using dnGREP.Common;
using Xunit;
using dnGREP;
using dnGREP.Common;

namespace Tests
{
public class BookmarkTest : TestBase
{
[Fact]
public void TestBookmarks()
{
BookmarkLibrary.Instance.Bookmarks.Clear();
BookmarkLibrary.Instance.Bookmarks.Add(new Bookmark("test1", "test2", "test3", "test4"));
BookmarkLibrary.Save();
BookmarkLibrary.Load();
Assert.Equal(BookmarkLibrary.Instance.Bookmarks.Count, 1);
Assert.Equal(BookmarkLibrary.Instance.Bookmarks[0].Description, "test4");
}
}
{
public class BookmarkTest : TestBase
{
[Fact]
public void TestBookmarks()
{
BookmarkLibrary.Instance.Bookmarks.Clear();
BookmarkLibrary.Instance.Bookmarks.Add(new Bookmark("test1", "test2", "test3", "test4"));
BookmarkLibrary.Save();
BookmarkLibrary.Load();
Assert.Equal(BookmarkLibrary.Instance.Bookmarks.Count, 1);
Assert.Equal(BookmarkLibrary.Instance.Bookmarks[0].Description, "test4");
}
}
}

0 comments on commit 778a588

Please sign in to comment.