Test
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Pattern.Memento;
public partial class Memento : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlMessage m = new SqlMessage();
m.Message = "Message內容";
m.PublishTime = DateTime.Now;
MessageModelCaretaker mmc = new MessageModelCaretaker();
mmc.MessageModel = m.SaveMemento();
bool bln = false;
while (!bln)
{
bln = m.Insert(new MessageModel(m.Message, m.PublishTime));
Response.Write(m.Message + " " + m.PublishTime.ToString() + " " + bln.ToString());
Response.Write("<br />");
if (!bln)
{
System.Threading.Thread.Sleep(1000);
m.RestoreMemento(mmc.MessageModel);
m.PublishTime = DateTime.Now;
}
}
}
}
運行結果
Message內容 2007-5-23 21:32:13 False
Message內容 2007-5-23 21:32:14 False
Message內容 2007-5-23 21:32:15 True
參考
http://www.dofactory.com/Patterns/PatternMemento.ASPx
OK