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中,在项目刚进入首页的时候,就会加载所有的组件,所以导致首页加 ...
随机推荐
- Recursive - leetcode [递归]
经验tips: Recursion is the best friend of tree-related problems. 一是只要遇到字符串的子序列或配准问题首先考虑动态规划DP,二是只要遇到需要 ...
- CUDA编程入门,Dim3变量
dim3是NVIDIA的CUDA编程中一种自定义的整型向量类型,基于用于指定维度的uint3. 例如:dim3 grid(num1,num2,num3): dim3类型最终设置的是一个三维向量,三维参 ...
- C# 常用接口学习 ICollection<T>
C# 常用接口学习 ICollection<T> 作者:乌龙哈里 时间:2015-11-01 平台:Window7 64bit,Visual Studio Community 2015 参 ...
- 常用到的简单命令 Sublime Git NPM WindowsCMD MacTerminal(Unix命令)
sublime 选择标签及其内容 ctrl+shift+a连续按两次 Git 撤销 add 重置暂存区的指定文件,与上一次commit保持一致,但工作区不变 git reset [file] 撤销 c ...
- android从assets读取文件的方法
因为开发需要,经常要从工程的assets文件夹里面读取文件,现在贴一个方法以作记录: private void getFromAssets(String fileName, ArrayList< ...
- Java继承多态中的方法访问权限控制
java中的方法天生具有继承多态特性,这点与C++有很大不同(需要在父类方发上加virtual关键字),但用起来确实方便了许多. 最简单的继承多态 声明一个接口BaseIF,只包含一个方法声明 pub ...
- 编写第一个ROS(创建工作空间workspace和功能包package)
刚接触ROS,学着写了第一个程序,怕以后忘记,就将其步骤记录下来.. 首先你必须保证你电脑已安装配置好ROS. 1.创建工作空间(workspace) 我们所创建功能包package,应该全部放到一个 ...
- java基础值进制转换
十进制转换为二进制: 解: 十进制数42连续除以2,当被除数为0时停止除以2,将余数倒加即为结果 :42(10)=101010(2) 注: 计算机内部表示数的字节单位是定长的,且只能是字节(1byte ...
- 自定义控件学习之canvas和paint相关知识点学习
1,继承自view,实现ondraw方法: 初始化画笔,TextPaint paint,并设置画笔属性: paint.setFlags(Paint.ANTI_ALIAS_FLAG):画笔抗锯齿. pa ...
- iosTableView 局部全部刷新以及删除编辑操作
局部刷新方法 添加数据 NSArray *indexPaths = @[ [NSIndexPath indexPathForRow:0 inSection:0], [NSIndexPath index ...