近几日,本人在对一个老的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中以客户端加载另一项目客户端(先登录后加载的一般实现)的更多相关文章

  1. Linux下文件 ~/.bashrc 和 ~/.bash_profile 和 /etc/bashrc 和 /etc/profile 的区别 | 用户登录后加载配置文件的顺序

    转自 https://blog.csdn.net/secondjanuary/article/details/9206151 文件说明: /ect/profile 此文件为系统的每个用户设置环境信息, ...

  2. ArcGIS API for Silverlight中加载Google地形图(瓦片图)

    原文:ArcGIS API for Silverlight中加载Google地形图(瓦片图) 在做水利.气象.土地等行业中,若能使用到Google的地形图那是再合适不过了,下面就介绍如何在ArcGIS ...

  3. SharePoint 2013 Silverlight中使用Net客户端对象模型

    1.创建Silverlight时,选择Silverlight 4,不要选择版本5,试了很久版本5都调用不了,自己也不知道什么原因,谷歌也没找到答案,后来尝试版本4,可以调用: 至于Host the S ...

  4. Android中使用ListView实现分页刷新(线程休眠模拟)(滑动加载列表)

    当要显示的数据过多时,为了更好的提升用户感知,在很多APP中都会使用分页刷新显示,比如浏览新闻,向下滑动到当前ListView的最后一条信息(item)时,会提示刷新加载,然后加载更新后的内容.此过程 ...

  5. EF如何操作内存中的数据和加载外键数据:延迟加载、贪婪加载、显示加载

    EF如何操作内存中的数据和加载外键数据:延迟加载.贪婪加载.显示加载 之前的EF Code First系列讲了那么多如何配置实体和数据库表的关系,显然配置只是辅助,使用EF操作数据库才是每天开发中都需 ...

  6. git问题:git提交的时候总是提示key加载失败,总是需要手工将key加到Pageant中

    问题描述: 重装过一次系统,在重装之前git+tortoisegit配合很好,提交的时候都能自动加载ppk,但是重装系统后,也重新生成pulic key上传到了服务器,但是每次提交的时候都提示key加 ...

  7. WPF中Style文件的引用——使用xaml代码或者C#代码动态加载

    原文:WPF中Style文件的引用--使用xaml代码或者C#代码动态加载 WPF中控件拥有很多依赖属性(Dependency Property),我们可以通过编写自定义Style文件来控制控件的外观 ...

  8. 在Myeclipse中没有部署jeesite项目,但是每次运行其他项目时,还是会加载jeesite项目

    解决办法: 一.在以下路径中找到jeesite文件,并删除 1.Tomcat 7.0\conf\Catalina\localhost 2.Tomcat 7.0\webapps 3.Tomcat 7.0 ...

  9. vue-router中,require代替import解决vue项目首页加载时间过久的问题

    vue的路由配置文件(routers.js),一般使用import引入的写法,当项目打包时路由里的所有component都会打包在一个js中,在项目刚进入首页的时候,就会加载所有的组件,所以导致首页加 ...

随机推荐

  1. [河南省ACM省赛-第三届] AMAZING AUCTION (nyoj 251)

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=251 规则: 1.若某竞标价唯一,则胜出 2.若不存在唯一竞标价,则投标次数最少竞标价中标 ...

  2. 连续多个git提交发生了冲突时

    git checkout -b test 创建并切换到分支test git clone git branch master git merge test 合并test到master (git merg ...

  3. 转 错误:ORA-28002: the password will expire within 7 days 解决方法

    今天在使用sqlplus时出现 =============================================== ERROR:ORA-28002: the password will e ...

  4. 大学二三事——那些事(1)

    虽然另外一个队友早上忽然拉肚子没有办法去了,我个阿骚还是决定出发. 本来以为早点过去签到可以躲过李导,没想到在她上班的路上被她撞见.   坐在早上那班发往周至县的客车的时候,天气忽好忽坏.   从周至 ...

  5. linux的用户,群组和其他用户

    1 linux 安全模型:(多任务,多用户的操作系统) 1)使用user和group控制使用者对文件的存储权限. 2)用户使用账户和口令登录linux 3)每个文件都有owner(创建者),owner ...

  6. php 编程效率(2)

    1.尽量静态化: 如果一个方法能被静态,那就声明它为静态的,速度可提高1/4,甚至我测试的时候,这个提高了近三倍. 当然了,这个测试方法需要在十万级以上次执行,效果才明显. 其实静态方法和非静态方法的 ...

  7. 【HELLO WAKA】WAKA iOS客户端 之二 架构设计与实现篇

    上一篇主要做了MAKA APP的需求分析,功能结构分解,架构分析,API分析,API数据结构分析. 这篇主要讲如何从零做iOS应用架构. 全系列 [HELLO WAKA]WAKA iOS客户端 之一 ...

  8. Java缓存框架

      JBossCache/TreeCache  JBossCache是一个复制的事务处理缓存,它允许你缓存企业级应用数据来更好的改善性能.缓存数据被自动复制,让你轻松进行Jboss服务器之间的集群工作 ...

  9. HDU 5867 Water problem

    处理出1-99的,之后的加上多少hundred和and即可.整百和一千的时候注意一下. #pragma comment(linker, "/STACK:1024000000,10240000 ...

  10. [转]修改python默认的编码方式

    今天碰到了 python 编码问题, 报错信息如下Traceback (most recent call last):  File "ntpath.pyc", line 108, ...