Server-Side Timestamping in the Audit Trail System (XAF时间戳在审核中的应用代码)

ExpandedBlockStart.gif 代码: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;
            }
        }
    }
}

 

ExpandedBlockStart.gif 代码: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
    }
}

 

ExpandedBlockStart.gif 代码: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;
        }
    }

 
   
 

 

 

ExpandedBlockStart.gif 代码: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
    }

 
   
 


 
 
  
  

 

 

 

转载于:https://www.cnblogs.com/ddlzq/archive/2010/10/08/1845942.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值