随笔 - 31  文章 - 0  评论 - 1134  阅读 - 39万

基于 Silverlight的精简框架之版本升级及使用

      最近研究了下RIA Services+EF自动生成Silverlight context代码非常方便,但是只有使用EF/Linqtosql + LinqToEntitiesDomainService的方式才能同Silverlight结合的很好,且可控性不是很好,在领域模型耦合度还是比较高,难以同传统的三层架构无缝结合。
      然后回顾了自己的EasySL框架,究其量也只是个轻量级的DomainService,所以提取出核心的数据传输服务,作为独立的版本发布,如果不适应RIA Services的开发方式,可以借以了解下EasySL.


-----------------------------------------------------------------------------------------------------------------------

  • 你可以在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个项目共享同份代码

 

复制代码
代码
 1 public class Product : INotifyPropertyChanged
 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>

 

复制代码
代码
 1 public class 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

 

单任务:
复制代码
代码
 1 Task task = new Task();
 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();
复制代码

 

多任务(串行执行):

复制代码
代码
 1 TaskList taskList = new TaskList();
 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:
 
代码
1 EasySL.Core.Requestor.OnResponse += response =>
2                 {
3                     if (response.Status == ResponseStatus.ServiceException)
4                         EasySL.Controls.Window.Alert(response.Message);
5                 };



Demo: http://guozili.25u.com/2009/#6
posted on   guozili  阅读(2492)  评论(5编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
< 2010年9月 >
29 30 31 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 1 2
3 4 5 6 7 8 9

点击右上角即可分享
微信分享提示