Skip to content

Commit

Permalink
custom logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ahwm committed Oct 23, 2018
1 parent 9bcb5ef commit 7041c82
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 47 deletions.
201 changes: 161 additions & 40 deletions src/Cardknox.NET/Cardknox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@ namespace CardknoxApi
/// </summary>
public class Cardknox
{
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public delegate void RequestStartedEventHandler(object sender, CardknoxEventArgs e);
/// <summary>
///
/// </summary>
public event RequestStartedEventHandler RequestStarted;
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public delegate void RequestCompletedEventHandler(object sender, CardknoxEventArgs e);
/// <summary>
///
/// </summary>
public event RequestCompletedEventHandler RequestCompleted;

/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -107,10 +128,15 @@ public CardknoxResponse CCSale(CCSale _sale, bool force = false)

AddSpecialFields(_sale);

Log.LogRequest(_values);
if (RequestStarted != null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
Log.LogResponse(resp);
if (RequestCompleted != null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

return new CardknoxResponse(resp);
}

Expand Down Expand Up @@ -180,10 +206,15 @@ public CardknoxResponse CCSave(CCSave _save, bool force = false)
if (!IsNullOrWhiteSpace(_save.IP))
_values.Add("xIP", _save.IP);

Log.LogRequest(_values);
if (RequestStarted != null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
Log.LogResponse(resp);
if (RequestCompleted != null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

return new CardknoxResponse(resp);
}

Expand Down Expand Up @@ -219,10 +250,15 @@ public CardknoxResponse CCRefund(CCRefund _refund, bool force = false)
_values.Add("xRefNum", _refund.RefNum);
// END required information

Log.LogRequest(_values);
if (RequestStarted != null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
Log.LogResponse(resp);
if (RequestCompleted != null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

return new CardknoxResponse(resp);
}

Expand Down Expand Up @@ -296,10 +332,15 @@ public CardknoxResponse CCAuthOnly(CCAuthOnly _auth, bool force = false)

AddSpecialFields(_auth);

Log.LogRequest(_values);
if (RequestStarted != null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
Log.LogResponse(resp);
if (RequestCompleted != null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

return new CardknoxResponse(resp);
}

Expand Down Expand Up @@ -350,10 +391,15 @@ public CardknoxResponse CCCapture(CCCapture _capture, bool force = false)

AddSpecialFields(_capture);

Log.LogRequest(_values);
if (RequestStarted != null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
Log.LogResponse(resp);
if (RequestCompleted != null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

return new CardknoxResponse(resp);
}

Expand Down Expand Up @@ -427,10 +473,15 @@ public CardknoxResponse CCCredit(CCCredit _credit, bool force = false)

AddSpecialFields(_credit);

Log.LogRequest(_values);
if (RequestStarted != null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
Log.LogResponse(resp);
if (RequestCompleted != null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

return new CardknoxResponse(resp);
}

Expand Down Expand Up @@ -462,10 +513,15 @@ public CardknoxResponse CCVoid(CCVoid _void, bool force = false)
_values.Add("xRefNum", _void.RefNum);
// END required information

Log.LogRequest(_values);
if (RequestStarted != null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
Log.LogResponse(resp);
if (RequestCompleted != null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

return new CardknoxResponse(resp);
}

Expand Down Expand Up @@ -512,10 +568,15 @@ public CardknoxResponse CCAdjust(CCAdjust _adjust, bool force = false)
if (!IsNullOrWhiteSpace(_adjust.IP))
_values.Add("xIP", _adjust.IP);

Log.LogRequest(_values);
if (RequestStarted != null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
Log.LogResponse(resp);
if (RequestCompleted != null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

return new CardknoxResponse(resp);
}

Expand Down Expand Up @@ -565,10 +626,15 @@ public CardknoxResponse CCPostAuth(CCPostAuth _auth, bool force = false)

AddSpecialFields(_auth);

Log.LogRequest(_values);
if (RequestStarted != null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
Log.LogResponse(resp);
if (RequestCompleted != null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

return new CardknoxResponse(resp);
}

Expand Down Expand Up @@ -600,10 +666,15 @@ public CardknoxResponse CCVoidRefund(CCVoidRefund _refund, bool force = false)
_values.Add("xRefNum", _refund.RefNum);
// END required information

Log.LogRequest(_values);
if (RequestStarted != null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
Log.LogResponse(resp);
if (RequestCompleted != null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

return new CardknoxResponse(resp);
}

Expand Down Expand Up @@ -635,10 +706,15 @@ public CardknoxResponse CCVoidRelease(CCVoidRelease _release, bool force = false
_values.Add("xRefNum", _release.RefNum);
// END required information

Log.LogRequest(_values);
if (RequestStarted != null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
Log.LogResponse(resp);
if (RequestCompleted != null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

return new CardknoxResponse(resp);
}
#endregion
Expand Down Expand Up @@ -702,10 +778,15 @@ public CardknoxResponse CheckSale(CheckSale _sale, bool force = false)

AddSpecialFields(_sale);

Log.LogRequest(_values);
if (RequestStarted != null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
Log.LogResponse(resp);
if (RequestCompleted != null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

return new CardknoxResponse(resp);
}

Expand Down Expand Up @@ -766,10 +847,15 @@ public CardknoxResponse CheckCredit(CheckCredit _credit, bool force = false)

AddSpecialFields(_credit);

Log.LogRequest(_values);
if (RequestStarted != null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
Log.LogResponse(resp);
if (RequestCompleted != null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

return new CardknoxResponse(resp);
}

Expand Down Expand Up @@ -818,10 +904,15 @@ public CardknoxResponse CheckSave(CheckSave _save, bool force = false)
if (!IsNullOrWhiteSpace(_save.IP))
_values.Add("xIP", _save.IP);

Log.LogRequest(_values);
if (RequestStarted != null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
Log.LogResponse(resp);
if (RequestCompleted != null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

return new CardknoxResponse(resp);
}

Expand Down Expand Up @@ -856,10 +947,15 @@ public CardknoxResponse CheckVoid(CheckVoid _void, bool force = false)
_values.Add("xRefNum", _void.RefNum);
// END required information

Log.LogRequest(_values);
if (RequestStarted != null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
Log.LogResponse(resp);
if (RequestCompleted != null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

return new CardknoxResponse(resp);
}

Expand Down Expand Up @@ -894,10 +990,15 @@ public CardknoxResponse CheckRefund(CheckRefund _refund, bool force = false)
_values.Add("xRefNum", _refund.RefNum);
// END required information

Log.LogRequest(_values);
if (RequestStarted != null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
Log.LogResponse(resp);
if (RequestCompleted != null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

return new CardknoxResponse(resp);
}
#endregion
Expand Down Expand Up @@ -965,10 +1066,15 @@ public CardknoxResponse EBTFSSale(EBTFSSale _sale, bool force = false)

AddSpecialFields(_sale);

Log.LogRequest(_values);
if (RequestStarted != null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
Log.LogResponse(resp);
if (RequestCompleted != null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

return new CardknoxResponse(resp);
}
/// <summary>
Expand Down Expand Up @@ -1033,10 +1139,15 @@ public CardknoxResponse EBTFSCredit(EBTFSCredit _credit, bool force = false)

AddSpecialFields(_credit);

Log.LogRequest(_values);
if (RequestStarted != null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
Log.LogResponse(resp);
if (RequestCompleted != null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

return new CardknoxResponse(resp);
}
/// <summary>
Expand Down Expand Up @@ -1088,10 +1199,15 @@ public CardknoxResponse EBTFSBalance(EBTFSBalance _bal, bool force = false)
if (!IsNullOrWhiteSpace(_bal.IP))
_values.Add("xIP", _bal.IP);

Log.LogRequest(_values);
if (RequestStarted != null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
Log.LogResponse(resp);
if (RequestCompleted != null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

return new CardknoxResponse(resp);
}
/// <summary>
Expand Down Expand Up @@ -1156,10 +1272,15 @@ public CardknoxResponse EBTFSVoucher(EBTFSVoucher _voucher, bool force = false)

AddSpecialFields(_voucher);

Log.LogRequest(_values);
if (RequestStarted != null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
Log.LogResponse(resp);
if (RequestCompleted != null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

return new CardknoxResponse(resp);
}
#endregion
Expand Down
Loading

0 comments on commit 7041c82

Please sign in to comment.