閑談Silverlight精簡(jiǎn)框架應(yīng)用方式
Silverlight的應(yīng)用在一定程度上解決了開發(fā)人員對(duì)于多媒體處理方面的難題。并且根據(jù)實(shí)際的使用最大限度的提高了開發(fā)效率。我們?cè)谶@里將會(huì)為大家介紹有關(guān)Silverlight精簡(jiǎn)框架的一些應(yīng)用方法。#t#
Silverlight的數(shù)據(jù)請(qǐng)求需要架設(shè)wcf、webservice或者webclient,而且中間數(shù)據(jù)需要序列化和反序列化,或者自己用linq解析,易用性不是很強(qiáng),且比較麻煩,基于目前還沒有統(tǒng)一和規(guī)范的silverlight開發(fā)模式,所以從五六個(gè)自己做過的基于Silverlight的中型項(xiàng)目,抽出核型代碼形成一套精簡(jiǎn)框架,方便調(diào)用,擴(kuò)充和分布式部署。
Silverlight精簡(jiǎn)框架項(xiàng)目文件說明:
- EasySL.Controls 封裝了一些基于Silverlight的
自定義控件,目前還沒加進(jìn)來 - EasySL.Core 請(qǐng)求數(shù)據(jù),返回?cái)?shù)據(jù)的json序
列化和反序列化機(jī)制,較之webservice xml性能好些 - EasySL.Core.SL 和上面一樣,Silverlight項(xiàng)目用
- EasySL.Data 數(shù)據(jù)訪問層實(shí)現(xiàn)
- EasySL.Data.Interface 數(shù)據(jù)訪問層接口
- EasySL.Entity 實(shí)體層
- EasySL.Service 業(yè)務(wù)邏輯,數(shù)據(jù)加工,緩存處理
- EasySL.Share 一些常用helper
- EasySL.Server Remoting server
- EasySL.UI Silverlight主控件
- EasySL.Web asp.net主頁面
Silverlight精簡(jiǎn)框架部署方式:
1.web.config里設(shè)置ServerEnable為false,將不需要開啟remoting server,由web層直接請(qǐng)求業(yè)務(wù)邏輯層(EasySL.Service)
2.web.config里設(shè)置ServerEnable為true,然后啟動(dòng)remoting server(EasySL.Server),
將由remoting server代理訪問業(yè)務(wù)邏輯層,易于分布式部署
Silverlight精簡(jiǎn)框架簡(jiǎn)單使用:
- //UI層page.xmal.cs
- //初始化一個(gè)task
- this.getProductListTask = new Task();
- //初始化請(qǐng)求數(shù)據(jù)
- getProductListTask.BeforeStart += new
EventHandler<EventArgs>(getProductList
Task_BeforeStart);- //回調(diào)時(shí)更新界面
- getProductListTask.Callback += new
GetDataAsyncCompleted(GetProductLis
tCallBack);- void getProductListTask_BeforeStart
(object sender, EventArgs e)- {
- Task task = sender as Task;
- task.MethodName = "GetProductList";
//對(duì)應(yīng)于數(shù)據(jù)層的方法名- task.ReturnType = typeof(List<Product>);
//對(duì)應(yīng)于數(shù)據(jù)層的返回類型- task.SetParameter("count", int.Parse
(this.count.Text)); //對(duì)應(yīng)于數(shù)據(jù)層的方法的參數(shù)- }
- public void GetProductListCallBack
(Response response)- {
- List<Product> product = reponse.
data as List<Product>;- //update UI.
- }
- //所以你需要在數(shù)據(jù)訪問層增加對(duì)應(yīng)的方法:
- public List<Product> Get
ProductList(int count)- {
- //get data from xml or database
- }
Silverlight精簡(jiǎn)框架的相關(guān)應(yīng)用放就為大家介紹到這里。