Files
2018-06-29 19:47:36 +00:00

136 lines
3.6 KiB
C#

///////////////////////////////////////////////////////////
// IntegrationLog.cs
// Implementation of Class IntegrationLog
// CSLA type: Editable Root
// Created on: 09-Feb-2006
// Object design: John
// Coded: John 09-Feb-2006
///////////////////////////////////////////////////////////
using System;
using System.Data;
using CSLA.Data;
using GZTW.Data;
using CSLA;
using System.Threading;
using CSLA.Security;
namespace GZTW.AyaNova.BLL
{
/// <summary>
/// AyaNova IntegrationLog used to insert integration events in the database.
///
/// Automatically removes all log entries more than 45 days old
///
/// </summary>
[Serializable]
public class IntegrationLog : BusinessBase
{
#region Attributes
private Guid _IntegrationID;
private string _Message;
#endregion
#region Constructor
/// <summary>
/// Private constructor to prevent direct instantiation
/// </summary>
private IntegrationLog(Guid IntegrationID, string Message)
{
_IntegrationID=IntegrationID;
if(Message.Length>500)
_Message=Message.Substring(0,500);
else
_Message=Message;
}
#endregion
#region Static methods
/// <summary>
/// Used to log an entry visible to Administrative users
/// regarding an integration event of interest
///
/// Use this object with your integration application if you wish
/// to log events that are visible to the users within AyaNova itself.
///
/// This is the preferred way of logging an integration application, at a minimum
/// any errors should be logged here so that end users who can't get your application
/// to work will get a meaningful message here about it.
///
/// The integration object will log various events here automatically as it is
/// accessed, but that is no substitute for logging from the integrating application
/// itself.
/// </summary>
/// <param name="IntegrationID">Guid of integration application</param>
/// <param name="Message">500 Unicode character maximum (will truncate).
/// Date and time of the event is logged automatically so no need to include that
/// information in the message.</param>
public static void Log(Guid IntegrationID, string Message)
{
DataPortal.Update(new IntegrationLog(
IntegrationID, Message
));
}
#endregion
#region DAL DATA ACCESS
/// <summary>
/// Called by DataPortal to delete/add/update data into the database
/// </summary>
protected override void DataPortal_Update()
{
//Remove any entries older than 45 days
DBCommandWrapper cmTrim = DBUtil.GetCommandFromSQL(
"DELETE FROM aIntegrationLog " +
"WHERE (aCreated < @FORTYFIVE)"
);
cmTrim.AddInParameter("@FORTYFIVE", DbType.DateTime, DBUtil.ToUTC(DBUtil.CurrentWorkingDateTime.AddDays(-45)));
DBUtil.DB.ExecuteNonQuery(cmTrim);
//Insert log entry
DBCommandWrapper cm = DBUtil.GetCommandFromSQL(
"INSERT INTO aIntegrationLog (aIntegrationID, aCreated, aCreator, aMessage ) " +
"VALUES (@IntegrationID,@Created, @Creator, @Message )"
);
cm.AddInParameter("@IntegrationID",DbType.Guid,this._IntegrationID);
cm.AddInParameter("@Creator",DbType.Guid,User.CurrentThreadUserID);
cm.AddInParameter("@Created", DbType.DateTime, DBUtil.ToUTC(DBUtil.CurrentWorkingDateTime));
cm.AddInParameter("@Message",DbType.String,this._Message);
DBUtil.DB.ExecuteNonQuery(cm);
}
#endregion
}//end IntegrationLog
}//end namespace GZTW.AyaNova.BLL