WEB开发网
开发学院图形图像Flash 使用SilverLight构建插件式应用程序(二) 阅读

使用SilverLight构建插件式应用程序(二)

 2008-10-23 11:44:00 来源:WEB开发网   
核心提示: 下载插件文件:void DownLoadPlugin(string pluginName){ WebClient wc = new WebClient();if (wc.IsBusy){wc.CancelAsync();}wc.OpenReadCompleted += new OpenRe

下载插件文件:

void DownLoadPlugin(string pluginName)
    {
      WebClient wc = new WebClient();
      if (wc.IsBusy)
      {
        wc.CancelAsync();
      }
  
      wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
      wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
      wc.OpenReadAsync(new Uri(pluginName, UriKind.Relative));
  
    }

下载完成之后就开始加载到显示界面:

void ShowLoadPlugin(PluginConf plugin)
    {
      //在界面上加载的插件内容
      using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
      {
        if (store.FileExists(plugin.filename))
        {
          BinaryReader reader = new BinaryReader(store.OpenFile(plugin.filename, FileMode.Open, FileAccess.Read));
          Byte[] info = reader.ReadBytes((int)reader.BaseStream.Length);
  
          AssemblyPart ap = new AssemblyPart();
          Assembly assembly = ap.Load(reader.BaseStream);
  
          IPlugin element = assembly.CreateInstance(plugin.typename) as IPlugin;
          //校验加载的dll是否实现了契约,当然此处也可以用Attribute来实现
          element.Application =this;
          element.SetVisibility(Visibility.Collapsed);
          AddService(element.ToString(), element);
  
          UserControl pageWindow = element.LoadUserControl();
  
          //添加到界面中
  
          pageWindow.SetValue(Grid.RowProperty, 2);
          pageWindow.SetValue(Grid.ColumnProperty, 0);
          this.LayoutRoot.Children.Insert(0, pageWindow);
        }
      }
    }

至此,插件加载完成;

使用SilverLight构建插件式应用程序(二)

http://www.prolightsoft.com

上一页  1 2 3 

Tags:使用 SilverLight 构建

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接