Silverlight中以客户端加载另一项目客户端(先登录后加载的一般实现)
近几日,本人在对一个老的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 == )
{
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;
}
当然还有其他功能可以实现,比如地址的跳转等。
Silverlight中以客户端加载另一项目客户端(先登录后加载的一般实现)的更多相关文章
- Linux下文件 ~/.bashrc 和 ~/.bash_profile 和 /etc/bashrc 和 /etc/profile 的区别 | 用户登录后加载配置文件的顺序
转自 https://blog.csdn.net/secondjanuary/article/details/9206151 文件说明: /ect/profile 此文件为系统的每个用户设置环境信息, ...
- ArcGIS API for Silverlight中加载Google地形图(瓦片图)
原文:ArcGIS API for Silverlight中加载Google地形图(瓦片图) 在做水利.气象.土地等行业中,若能使用到Google的地形图那是再合适不过了,下面就介绍如何在ArcGIS ...
- SharePoint 2013 Silverlight中使用Net客户端对象模型
1.创建Silverlight时,选择Silverlight 4,不要选择版本5,试了很久版本5都调用不了,自己也不知道什么原因,谷歌也没找到答案,后来尝试版本4,可以调用: 至于Host the S ...
- Android中使用ListView实现分页刷新(线程休眠模拟)(滑动加载列表)
当要显示的数据过多时,为了更好的提升用户感知,在很多APP中都会使用分页刷新显示,比如浏览新闻,向下滑动到当前ListView的最后一条信息(item)时,会提示刷新加载,然后加载更新后的内容.此过程 ...
- EF如何操作内存中的数据和加载外键数据:延迟加载、贪婪加载、显示加载
EF如何操作内存中的数据和加载外键数据:延迟加载.贪婪加载.显示加载 之前的EF Code First系列讲了那么多如何配置实体和数据库表的关系,显然配置只是辅助,使用EF操作数据库才是每天开发中都需 ...
- git问题:git提交的时候总是提示key加载失败,总是需要手工将key加到Pageant中
问题描述: 重装过一次系统,在重装之前git+tortoisegit配合很好,提交的时候都能自动加载ppk,但是重装系统后,也重新生成pulic key上传到了服务器,但是每次提交的时候都提示key加 ...
- WPF中Style文件的引用——使用xaml代码或者C#代码动态加载
原文:WPF中Style文件的引用--使用xaml代码或者C#代码动态加载 WPF中控件拥有很多依赖属性(Dependency Property),我们可以通过编写自定义Style文件来控制控件的外观 ...
- 在Myeclipse中没有部署jeesite项目,但是每次运行其他项目时,还是会加载jeesite项目
解决办法: 一.在以下路径中找到jeesite文件,并删除 1.Tomcat 7.0\conf\Catalina\localhost 2.Tomcat 7.0\webapps 3.Tomcat 7.0 ...
- vue-router中,require代替import解决vue项目首页加载时间过久的问题
vue的路由配置文件(routers.js),一般使用import引入的写法,当项目打包时路由里的所有component都会打包在一个js中,在项目刚进入首页的时候,就会加载所有的组件,所以导致首页加 ...
随机推荐
- 域名注册商namesilo价格便宜,赠送whois保护,最新优惠码:geekradio
注册域名,不懂事的中国人一般去国内奸商万网注册,价格贵,域名管理风险大,甚至注册.cn域名,花钱还吃亏.精明一点的中国人选godaddy,namecheap,gandi这类国外域名注册商,价格不贵,你 ...
- java 时间
package com.grace.test; import java.text.DateFormat; import java.text.ParseException; import java.te ...
- SQL in优化将In转化为联合查询
in查询有时候会非常影响性能,最好能转化为联合查询,但有的网友说sqlserver会自动将in转化为联合查询,但我实际遇到的有时候却不是这样.所以最好还是不要用in. 我自己的例子,用in的时候耗费了 ...
- php分类
<?php /* * PHP分页类 * @package Page * @Created 2013-03-27 * @Modify 2013-03-27 * @link http://www.6 ...
- Petya and Spiders【二进制状压】
题目链接[http://codeforces.com/problemset/problem/111/C] 题意:给出大小为N*M的图(1 ≤ n, m ≤ 40, n·m ≤ 40),每个图中有一个蜘 ...
- 本地yum库的搭建
1.建立yum服务器 yum服务器可以使用http或者ftp的方式,我们这里选择使用http的方式进行,需要先进行httpd的安装 # yum install httpd 在本地建立包目录 # mkd ...
- openstack私有云布署实践【6 RabbitMQ】
生产环境建议在集群三台controller上做rabbitmq 使用到队列的openstack组件 OpenStack Compute OpenStack Block Storage OpenStac ...
- NYIST OJ 题目42 一笔画问题
水题.无向图欧拉通路的判定.用并查集判定是不是连通图! #include<cstdio> #include<cstring> #include<cmath> #in ...
- 理解Load Average做好压力测试
http://www.blogjava.net/cenwenchu/archive/2008/06/30/211712.html CPU时间片 为了提高程序执行效率,大家在很多应用中都采用了多线程模式 ...
- control
group:多个脚本之间按照独立设置模式跑,各个脚本可以单独设置虚拟用户.运行时间等 scenario:多个脚本之间按照相同的模式跑,将总的虚拟用户数按照一定的比例分配给各个脚本 ---------- ...