代码:BusinessObjects.cs
using System;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Xpo;
using DevExpress.Persistent.AuditTrail;

namespace AuditDemo.Module {
    [DefaultClassOptions]
    
public class Album : BaseObject {
        
public Album(Session session) : base(session) { }
        
private string name;
        
public string Name {
            
get {
                
return name;
            }
            
set {
                SetPropertyValue(
"Name"ref name, value);
            }
        }
        
private int year;
        
public int Year {
            
get {
                
return year;
            }
            
set {
                SetPropertyValue(
"Year"ref year, value);
            }
        }
        
private Artist artist;
        [Association(
"Artist-Albums")]
        
public Artist Artist {
            
get {
                
return artist;
            }
            
set {
                SetPropertyValue(
"Artist"ref artist, value);
            }
        }
        
private XPCollection<AuditDataItemPersistent> auditTrail;
        
public XPCollection<AuditDataItemPersistent> AuditTrail {
            
get {
                
if(auditTrail == null) {
                    auditTrail 
= AuditedObjectWeakReference.GetAuditTrail(Session, this);
                }
                
return auditTrail;
            }
        }
    }
    [DefaultClassOptions]
    
public class Artist : BaseObject {
        
public Artist(Session session) : base(session) { }
        
private string name;
        
public string Name {
            
get {
                
return name;
            }
            
set {
                SetPropertyValue(
"Name"ref name, value);
            }
        }
        [Association(
"Artist-Albums")]
        
public XPCollection<Album> Albums {
            
get {
                
return GetCollection<Album>("Albums");
            }
        }
        
private XPCollection<AuditDataItemPersistent> auditTrail;
        
public XPCollection<AuditDataItemPersistent> AuditTrail {
            
get {
                
if(auditTrail == null) {
                    auditTrail 
= AuditedObjectWeakReference.GetAuditTrail(Session, this);
                }
                
return auditTrail;
            }
        }
    }
}

 

代码:MSSqlServerTimestampStrategy.cs
using System;
using System.Data.SqlClient;
using DevExpress.Xpo;
using DevExpress.Persistent.AuditTrail;

namespace AuditDemo.Module {
    
public class MSSqlServerTimestampStrategy : IAuditTimestampStrategy{
        DateTime cachedTimeStamp;
        
#region IAuditTimeStampStrategy Members
        
public DateTime GetTimestamp(AuditDataItem auditDataItem) {
            
return cachedTimeStamp;
        }
        
public void OnBeginSaveTransaction(Session session) {
            SqlCommand command 
= new SqlCommand("select getdate()", (SqlConnection)session.Connection);
            cachedTimeStamp 
= (DateTime)command.ExecuteScalar();
        }
        
#endregion
    }
}

 

代码:TimestampService.asmx.cs
using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;

namespace TimestampWebService {
    [WebService(Namespace 
= "http://localhost/")]
    [WebServiceBinding(ConformsTo 
= WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(
false)]
    
public class TimestampService : System.Web.Services.WebService {
        [WebMethod]
        
public DateTime GetTime() {
            
return DateTime.Now;
        }
    }

 
   
 

 

 

代码:WebServiceTimestampStrategy.cs
using System;
using DevExpress.Persistent.AuditTrail;
using DevExpress.Xpo;
using AuditDemo.Module.TimestampWebService;

namespace AuditDemo.Module {
    
public class WebServiceTimestampStrategy : IAuditTimestampStrategy {
        DateTime cachedTimeStamp;
        
#region IAuditTimeStampStrategy Members
        
public DateTime GetTimestamp(AuditDataItem auditDataItem) {
            
return cachedTimeStamp;
        }
        
public void OnBeginSaveTransaction(Session session) {
            
try {
                TimestampService service 
= new TimestampService();
                cachedTimeStamp 
= service.GetTime();
            }
            
catch {
                
throw new Exception("Cannot access the TimeStampWebService. Make sure it's running.");
            }
        }
        
#endregion
    }

 
   
 


 
 
  
  

 

 

 

posted on 2010-10-08 16:24  EricLi  阅读(284)  评论(0编辑  收藏  举报