Silverlight中以客户端加载另一项目客户端(先登录后加载的一般实现)
2014-02-20 15:04
267 查看
近几日,本人在对一个老的Silverlight的GIS项目进行维护,发现该项目的实现是先把所有的资源加载至客户端,其中包括登录部分和业务实现部分,我就在想可不可以把登录部分和业务实现部分开来。如果用户输入的账号密码正确才开始加载业务实现方面的资源(1.由于Silverlight的运行资源的加载是一次性的。2.现在主流的实现都是如此)
如下是我在代码中的实现
当然还有其他功能可以实现,比如地址的跳转等。
如下是我在代码中的实现
private const string odll = "SilverlightApplication2.dll"; private const string LoaderPageName = "SilverlightApplication2.MainPage"; private void button1_Click(object sender, RoutedEventArgs e) { const string name = "SilverlightApplication2.xap"; var uri = new Uri(name, UriKind.Relative); WebClient webClient=new WebClient(); if (webClient.IsBusy) { webClient.CancelAsync(); } webClient.OpenReadCompleted -= new OpenReadCompletedEventHandler(webClient_OpenReadCompleted); webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted); webClient.DownloadProgressChanged -= new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged); webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged); webClient.OpenReadAsync(uri); } void webClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { //throw new NotImplementedException(); this.textBlock1.Text = "已经加载 " + e.ProgressPercentage; if (e.ProgressPercentage == 100) { return; } } void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { //throw new NotImplementedException(); try { Stream streamLoadXap = e.Result; if (streamLoadXap != null) { Assembly assemblyDll = LoadAssemblyFromXap(streamLoadXap, odll); if (assemblyDll != null) { UIElement elementXapMain = assemblyDll.CreateInstance(LoaderPageName) as UIElement; if (elementXapMain != null) { this.Content = elementXapMain; } else { MessageBox.Show("惨了,程序加载失败了!!!"); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } /// <summary> /// 从程序中获取程序集 /// </summary> /// <param name="streamLoadXap"></param> /// <param name="strAssemblyName"></param> /// <returns></returns> public Assembly LoadAssemblyFromXap(Stream streamLoadXap, string strAssemblyName) { try { Stream streamXml = Application.GetResourceStream(new StreamResourceInfo(streamLoadXap, null), new Uri("AppManifest.xaml", UriKind.Relative)).Stream; String appManifestString = new StreamReader(streamXml).ReadToEnd(); XElement deploymentRoot = XDocument.Parse(appManifestString).Root; //创建XML文件,并增加加载的程序集内容新内容 if (deploymentRoot != null) { List<XElement> deploymentParts = (from assemblyParts in deploymentRoot.Elements().Elements() select assemblyParts).ToList(); Assembly asm = null; foreach (var xElement in deploymentParts) { XAttribute xAttribute = xElement.Attribute("Source"); if (xAttribute != null) { string source = xAttribute.Value; AssemblyPart assemblyPart = new AssemblyPart {Source = source}; StreamResourceInfo sri = Application.GetResourceStream(new StreamResourceInfo(streamLoadXap, "application/binary"), new Uri(source, UriKind.Relative)); if (source.Equals(odll)) { asm = assemblyPart.Load(sri.Stream); } else { assemblyPart.Load(sri.Stream); } } } return asm; } } catch (Exception ex) { MessageBox.Show(ex.Message); return null; } return null; }
当然还有其他功能可以实现,比如地址的跳转等。
相关文章推荐
- 将基于WCF实现与客户端通信的Silverlight项目部署到IIS7.0
- Android项目之无线点餐(2)--用户登录的客户端和服务器端实现
- 启动就加载(一)----注解方式实现的。static项目启动的时候就加载进来(一般用于常用参数)
- java在线聊天项目1.1版 ——开启多个客户端,分别实现注册和登录功能,使用客户端与服务端信息request机制,重构线程,将单独的登录和注册线程合并
- java在线聊天项目1.2版 ——开启多个客户端,分别实现数据库注册和登录功能后,成功登陆则登录框消失,好友列表窗出现
- Centos 6.3上用OpenSSH实现无密码登录过程中出现问题的一般调试步骤
- Android客户端post方式连接web(servlet)服务器实现简单登录
- Android客户端实现注册/登录详解(二)
- SharpStreaming项目开发纪实:构建基本的服务器及客户端应用(七)——服务器界面实现
- android学习笔记之使用Eclipse搭建web服务器实现Android客户端登录
- PlayPlugin插件类实现(插件能够在项目启动的时候自动的加载)
- ArcGIS Server 10.1动态图层 以及Windows Phone/Silverlight客户端实现
- 【CSDN开源夏令营】 基于Web的SSH客户端,实现跨平台的云服务管理(三)远程登录功能的实现
- Silverlight实现查询建模(七) 工具栏的实现与加载
- VS2008创建或加载Silverlight项目出错的解决办法
- Oracle客户端+PLSQLDeveloper实现远程登录Oracle数据库
- Silverlight学习笔记一(理解一下机制,使用一下布局,实现一个简单的用户登录)
- 用Balder开源3D引擎实现Silverlight客户端的3D 地图效果
- web 项目中一般在登录的时候都会用到记住密码功能。
- Android腾讯微博客户端开发5:利用FootView实现ListView滑动动态加载实现分页