using System;
using System.Windows;
using DevExpress.Xpo;
namespace HowToImplementTheInstantFeedbackModeXPO
{
/// <summary>
/// 메인 윈도우
/// </summary>
public partial class MainWindow : Window
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainWindow()
/// <summary>
/// 생성자
/// </summary>
public MainWindow()
{
InitializeDataAccessLayer();
GenerateTestData(100000);
InitializeComponent();
XPInstantFeedbackSource xpInstantFeedbackSource = new XPInstantFeedbackSource(typeof(TestObject));
xpInstantFeedbackSource.ResolveSession += xpInstantFeedbackSource_ResolveSession;
xpInstantFeedbackSource.DismissSession += xpInstantFeedbackSource_DismissSession;
this.gridControl.ItemsSource = xpInstantFeedbackSource;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region XP 즉시 피드백 소스 세션 Resolve 처리하기 - xpInstantFeedbackSource_ResolveSession(sender, e)
/// <summary>
/// XP 즉시 피드백 소스 세션 Resolve 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void xpInstantFeedbackSource_ResolveSession(object sender, ResolveSessionEventArgs e)
{
e.Session = new UnitOfWork();
}
#endregion
#region XP 즉시 피드백 소스 세션 Dismiss 처리하기 - xpInstantFeedbackSource_DismissSession(sender, e)
/// <summary>
/// XP 즉시 피드백 소스 세션 Dismiss 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void pXPInstantFeedbackSource_DismissSession(object sender, ResolveSessionEventArgs e)
{
IDisposable disposable = e.Session as IDisposable;
if(disposable != null)
{
disposable.Dispose();
}
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 데이터 액세스 레이어 초기화 하기 - InitializeDataAccessLayer()
/// <summary>
/// 데이터 액세스 레이어 초기화 하기
/// </summary>
private static void InitializeDataAccessLayer()
{
XpoDefault.Session = null;
XpoDefault.DataLayer = XpoDefault.GetDataLayer
(
DevExpress.Xpo.DB.AccessConnectionProvider.GetConnectionString("test.mdb"),
DevExpress.Xpo.DB.AutoCreateOption.DatabaseAndSchema
);
}
#endregion
#region 테스트 데이터 생성하기 - GenerateTestData(recordCount)
/// <summary>
/// 테스트 데이터 생성하기
/// </summary>
/// <param name="recordCount">레코드 수</param>
private void GenerateTestData(int recordCount)
{
using(UnitOfWork unitOfWork = new UnitOfWork())
{
if(unitOfWork.FindObject<TestObject>(null) != null)
{
return;
}
for(int i = 0; i < recordCount; i++)
{
TestObject testObject = new TestObject(unitOfWork)
{
HasAttachment = false,
Sent = DateTime.Now,
Subject = string.Format("Subject {0}", i)
};
}
unitOfWork.CommitChanges();
}
}
#endregion
}
}