惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
J
Java Code Geeks
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
Docker
腾讯CDC
The GitHub Blog
The GitHub Blog
大猫的无限游戏
大猫的无限游戏
Microsoft Security Blog
Microsoft Security Blog
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
博客园 - 司徒正美
T
The Blog of Author Tim Ferriss
Vercel News
Vercel News
P
Proofpoint News Feed
雷峰网
雷峰网
博客园_首页
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
爱范儿
爱范儿
V
V2EX
F
Fortinet All Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
MyScale Blog
MyScale Blog
S
SegmentFault 最新的问题

博客园 - guozili

分享12306抢票心得-终极秒杀思路篇 分享12306抢票心得-最终篇 分享12306全自动验证码识别提交,春运抢票准备时 分享“12306 P2P平台”创业Idea 分享12306秒票杀手锏源码 分享12306秒票心得及杀手锏 分享基于EF+MVC+Bootstrap的通用后台管理系统及架构 分享基于EF+WCF的通用三层架构及解析 基于Silverlight的快速开发框架RapidSL新特性解析 分享基于silverlight的仿“百度文库”的文档控件 分享基于silverlight的一个“树形结构图”控件 基于 Silverlight的快速开发框架RapidSL新版改进源码 基于 Silverlight的快速开发框架RapidSL之MVVM解析 基于Silverlight的快速开发框架RapidSL之开源 分享基于silverlight的一个大文件上传控件 抢火车票利器:分享一个抓取火车票转让信息的小程序 基于 Silverlight的精简框架之版本和控件更新 Silverlight project demos for MSRA in 2009,to look forward to silverlight's furture 异步编程练习
基于 Silverlight的精简框架之版本升级及使用
guozili · 2010-09-10 · via 博客园 - guozili
      最近研究了下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