/////////////////////////////////////////////////////////// // 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 { /// /// AyaNova IntegrationLog used to insert integration events in the database. /// /// Automatically removes all log entries more than 45 days old /// /// [Serializable] public class IntegrationLog : BusinessBase { #region Attributes private Guid _IntegrationID; private string _Message; #endregion #region Constructor /// /// Private constructor to prevent direct instantiation /// private IntegrationLog(Guid IntegrationID, string Message) { _IntegrationID=IntegrationID; if(Message.Length>500) _Message=Message.Substring(0,500); else _Message=Message; } #endregion #region Static methods /// /// 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. /// /// Guid of integration application /// 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. public static void Log(Guid IntegrationID, string Message) { DataPortal.Update(new IntegrationLog( IntegrationID, Message )); } #endregion #region DAL DATA ACCESS /// /// Called by DataPortal to delete/add/update data into the database /// 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