基于 Silverlight的精简框架之版本升级及使用
时间:2010-09-10 来源:[email protected]
-----------------------------------------------------------------------------------------------------------------------
- 你可以在http://www.codeplex.com/EasySL下载到最新的代码;
- 最新的版本在2.0文件夹里,已经精简到只有两个项目EasySL.Core 和 EasySL.Control,里面还包括了一个Sample文件夹,主要是提供了一个DataGrid+DataForm基于Easy实现CRUD及分页的示例;
- 此版本已经去掉大部分控件,remoting分布式部署,只保留数据交互核心模块。
-----------------------------------------------------------------------------------------------------------------------
Usage:
-----------------------------------------------------------------------------------------------------------------------
1. 在你的web项目中引用EasySL.Core,在你的web项目里新建Service.ashx,作为data/domain service用
1 public class Service : DataServiceHandler<EasySL.Data.DAO>
-----------------------------------------------------------------------------------------------------------------------
2. 建立entity项目,YourProject.Entity和YourProject.EntitySL,2个项目共享同份代码

2 {
3 private string name;
4
5 public string Name
6 {
7 get { return name; }
8 set {
9 if (string.IsNullOrEmpty(value))
10 throw new Exception("Name cant be null");
11
12 name = value;
13 NotifyPropertyChanged("Name");
14 }
15 }
16 }
-----------------------------------------------------------------------------------------------------------------------
3.建立data项目,YourProject.Data(DAL),建立DAO数据实体,对应web项目中的DataServiceHandler<EasySL.Data.DAO>

2 {
3 public int GetProductCount()
4
5 public List<Product> GetProducts(int pageIndex, int pageSize)
6
7 public void SaveOrAddProduct(Product product)
8
9 public void DeleteProduct(int id)
10 }
-----------------------------------------------------------------------------------------------------------------------
4.在你的silverlight项目中引用EasySL.Core.SL
单任务:

2
3 task.Begin += (t) =>
4 {
5 t.MethodName = "GetProducts";
6 t.SetParameter("pageIndex", pager.PageIndex);
7 t.SetParameter("pageSize", pager.PageSize);
8 t.ReturnType = typeof(List<Product>);
9
10 this.loading.Show("Get products...................");
11 };
12
13 task.End += res =>
14 {
15 this.products = res.Data as List<Product>;
16
17 this.dg.ItemsSource = this.df.ItemsSource = this.products;
18 this.loading.Hide();
19 });
20 };
21 task.Start();
多任务(串行执行):

2
3 Task task1 = new Task();
4 task1.Begin += ...
5 task1.End += ...
6
7 Task task2 = new Task();
8 task2.Begin += ...
9 task2.End += ...
10
11 taskList.Add(task1);
12 taskList.Add(task2);
13 taskList.Start();
-----------------------------------------------------------------------------------------------------------------------
5. Task全局异常处理
如果你需要捕获服务端异常,在page.xaml页面文件里注册Requestor:

2 {
3 if (response.Status == ResponseStatus.ServiceException)
4 EasySL.Controls.Window.Alert(response.Message);
5 };
Demo: http://guozili.25u.com/2009/#6