近几日,本人在对一个老的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. 3.struts2访问Servlet API,并和mybaits实现全套增删改查

    1.创建数据库脚本userinfo.sql prompt PL/SQL Developer import file prompt Created on 2016年5月19日 by pc set fee ...

  2. PWM

    #include "sys.h" #include "beep.h" //tim5 定时器 /* tim4 定时器 定时10分钟 控制LED1 */ void ...

  3. windows中操作文件和目录的函数

    1.文件操作函数       CreateFile();//创建或打开文件      ReadFile();//从文件读      WriteFile();//向文件写      SetFilePoi ...

  4. Python基础知识学习_Day4

    一.函数 1.1函数特性 减少重复代码 使程序可扩展 使程序变得容易维护 1.2函数定义和使用 def 函数名(参数): ...... 函数体 ...... 返回值 函数定义主要特点如下: def:表 ...

  5. sqlalchemy相关知识

    #!/usr/bin/env python3.5 # -*- coding:utf8 -*- # 多对多关联 from sqlalchemy import Table, Column, Integer ...

  6. Visual Studio下使用jQuery的10个技巧

    广泛流行的jQuery是一个开源的,跨浏览器和兼容CSS 3的JavaScript库,你可以用它简化你的JavaScript编码任务和操作(添加,编辑和删除)HTML内容中的DOM元素,本文介绍10个 ...

  7. ViewPagerIndicator的使用方法

    使用方法:   1.引用library,并解决support v4 jar包冲突   2.布局文件中添加viewpager和viewpagerindicator,布局文件: <LinearLay ...

  8. rune is alias of int32

    I think chendesheng's quote gets at the root cause best: Go uses a lot of signed values, not just fo ...

  9. php,cgi,nginx关系

    nginx是服务器 什么是服务器? 例如:IIS,Apache,Nginx......主要是提供网上浏览网页的服务,应用层使用HTTP协议. CGI,FastCGI CGI全称是"公共网关接 ...

  10. winform 制作圆形图片框

    public partial class CirclePictureBox : PictureBox { public CirclePictureBox() { Circle = true; Init ...