-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
200 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
|
||
namespace Contiva.SAP.NWRfc | ||
{ | ||
public interface ILogger | ||
{ | ||
void LogException(Exception exception, string message); | ||
void LogException(Exception exception); | ||
void LogTrace(string message, object data); | ||
void LogError(string message, object data); | ||
|
||
void LogDebug(string message, object data); | ||
|
||
void LogTrace(string message); | ||
void LogDebug(string message); | ||
void LogError(string message); | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Contiva.SAP.NWRfc; | ||
using Newtonsoft.Json; | ||
|
||
namespace SAPSystemTests | ||
{ | ||
public class SimpleConsoleLogger : ILogger | ||
{ | ||
public void LogException(Exception exception, string message) | ||
{ | ||
Console.WriteLine($"{message} - Exception: {exception}"); | ||
} | ||
|
||
public void LogException(Exception exception) | ||
{ | ||
LogException(exception, ""); | ||
} | ||
|
||
public void LogTrace(string message, object data) | ||
{ | ||
Console.WriteLine($"TRACE\t{message}{ObjectToString(data)}"); | ||
} | ||
|
||
public void LogError(string message, object data) | ||
{ | ||
Console.WriteLine($"ERROR\t{message}{ObjectToString(data)}"); | ||
} | ||
|
||
public void LogDebug(string message, object data) | ||
{ | ||
Console.WriteLine($"DEBUG\t{message}{ObjectToString(data)}"); | ||
} | ||
|
||
public void LogTrace(string message) | ||
{ | ||
LogTrace(message, null); | ||
} | ||
|
||
public void LogDebug(string message) | ||
{ | ||
LogDebug(message, null); | ||
} | ||
|
||
public void LogError(string message) | ||
{ | ||
LogError(message, null); | ||
} | ||
|
||
public static string ObjectToString(object valueObject) | ||
{ | ||
var dataString = new StringBuilder(); | ||
if (valueObject == null) | ||
return ""; | ||
|
||
dataString.Append(", Data: "); | ||
|
||
dataString.Append(JsonConvert.SerializeObject(valueObject, new JsonSerializerSettings | ||
{ | ||
Converters = new List<JsonConverter>(new[]{new HandleToStringJsonConverter() }) | ||
})); | ||
|
||
return dataString.ToString(); | ||
|
||
} | ||
|
||
class HandleToStringJsonConverter : JsonConverter | ||
{ | ||
public override bool CanConvert(Type objectType) | ||
{ | ||
if(objectType.BaseType != null | ||
&& objectType.BaseType.FullName != null | ||
&& (objectType.BaseType.FullName.StartsWith("Contiva.SAP.NWRfc.Native.HandleBase") | ||
|| objectType.BaseType.FullName.StartsWith("Contiva.SAP.NWRfc.Native.DataContainerBase"))) | ||
return true; | ||
return false; | ||
} | ||
|
||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
var typeName = value.GetType().Name; | ||
writer.WriteValue($"{typeName}<{value}>"); | ||
} | ||
|
||
public override bool CanRead | ||
{ | ||
get { return false; } | ||
} | ||
|
||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} | ||
} |