add netcore and refactoring

This commit is contained in:
2019-11-26 15:34:16 +01:00
parent 57f343c908
commit bd6472e5e4
47 changed files with 4897 additions and 5569 deletions
+25 -28
View File
@@ -17,34 +17,31 @@ Contributors:
using System;
using System.Collections;
namespace uPLibrary.Networking.M2Mqtt.Utility
{
namespace uPLibrary.Networking.M2Mqtt.Utility {
/// <summary>
/// Extension class for a Queue
/// </summary>
internal static class QueueExtension {
/// <summary>
/// Extension class for a Queue
/// Predicate for searching inside a queue
/// </summary>
internal static class QueueExtension
{
/// <summary>
/// Predicate for searching inside a queue
/// </summary>
/// <param name="item">Item of the queue</param>
/// <returns>Result of predicate</returns>
internal delegate bool QueuePredicate(object item);
/// <summary>
/// Get (without removing) an item from queue based on predicate
/// </summary>
/// <param name="queue">Queue in which to search</param>
/// <param name="predicate">Predicate to verify to get item</param>
/// <returns>Item matches the predicate</returns>
internal static object Get(Queue queue, QueuePredicate predicate)
{
foreach (var item in queue)
{
if (predicate(item))
return item;
}
return null;
}
}
/// <param name="item">Item of the queue</param>
/// <returns>Result of predicate</returns>
internal delegate Boolean QueuePredicate(Object item);
/// <summary>
/// Get (without removing) an item from queue based on predicate
/// </summary>
/// <param name="queue">Queue in which to search</param>
/// <param name="predicate">Predicate to verify to get item</param>
/// <returns>Item matches the predicate</returns>
internal static Object Get(Queue queue, QueuePredicate predicate) {
foreach (Object item in queue) {
if (predicate(item)) {
return item;
}
}
return null;
}
}
}
+51 -67
View File
@@ -14,73 +14,57 @@ Contributors:
Paolo Patierno - initial API and implementation and/or initial documentation
*/
using System;
using System.Diagnostics;
namespace uPLibrary.Networking.M2Mqtt.Utility
{
/// <summary>
/// Tracing levels
/// </summary>
public enum TraceLevel
{
Error = 0x01,
Warning = 0x02,
Information = 0x04,
Verbose = 0x0F,
Frame = 0x10,
Queuing = 0x20
}
// delegate for writing trace
public delegate void WriteTrace(string format, params object[] args);
/// <summary>
/// Tracing class
/// </summary>
public static class Trace
{
public static TraceLevel TraceLevel;
public static WriteTrace TraceListener;
[Conditional("DEBUG")]
public static void Debug(string format, params object[] args)
{
if (TraceListener != null)
{
TraceListener(format, args);
}
}
public static void WriteLine(TraceLevel level, string format)
{
if (TraceListener != null && (level & TraceLevel) > 0)
{
TraceListener(format);
}
}
public static void WriteLine(TraceLevel level, string format, object arg1)
{
if (TraceListener != null && (level & TraceLevel) > 0)
{
TraceListener(format, arg1);
}
}
public static void WriteLine(TraceLevel level, string format, object arg1, object arg2)
{
if (TraceListener != null && (level & TraceLevel) > 0)
{
TraceListener(format, arg1, arg2);
}
}
public static void WriteLine(TraceLevel level, string format, object arg1, object arg2, object arg3)
{
if (TraceListener != null && (level & TraceLevel) > 0)
{
TraceListener(format, arg1, arg2, arg3);
}
}
}
namespace uPLibrary.Networking.M2Mqtt.Utility {
/// <summary>
/// Tracing levels
/// </summary>
public enum TraceLevel {
Error = 0x01,
Warning = 0x02,
Information = 0x04,
Verbose = 0x0F,
Frame = 0x10,
Queuing = 0x20
}
// delegate for writing trace
public delegate void WriteTrace(String format, params Object[] args);
/// <summary>
/// Tracing class
/// </summary>
public static class Trace {
public static TraceLevel TraceLevel;
public static WriteTrace TraceListener;
[Conditional("DEBUG")]
public static void Debug(String format, params Object[] args) => TraceListener?.Invoke(format, args);
public static void WriteLine(TraceLevel level, String format) {
if ((level & TraceLevel) > 0) {
TraceListener.Invoke(format);
}
}
public static void WriteLine(TraceLevel level, String format, Object arg1) {
if ( (level & TraceLevel) > 0) {
TraceListener.Invoke(format, arg1);
}
}
public static void WriteLine(TraceLevel level, String format, Object arg1, Object arg2) {
if ((level & TraceLevel) > 0) {
TraceListener.Invoke(format, arg1, arg2);
}
}
public static void WriteLine(TraceLevel level, String format, Object arg1, Object arg2, Object arg3) {
if ((level & TraceLevel) > 0) {
TraceListener.Invoke(format, arg1, arg2, arg3);
}
}
}
}