상속: AssemblyStream
예제 #1
0
    private void DownloadPendingAssemblies()
    {
      if (_pendingDownloads.Count == 0) return;

      _busyContext.IsBusy = true;

      ThreadPool.QueueUserWorkItem(o =>
      {
        while (_pendingDownloads.Count > 0)
        {
          var fileInfo = _pendingDownloads.Dequeue();

          Dispatcher.BeginInvoke(() => { _busyContext.ItemLabel = fileInfo.Name; });
                    
          try
          {
            string extension = Path.GetExtension(fileInfo.Name);

            if (KnownFormats.Zip.Contains(extension))
            {
              StorageService.AddFileToCache(fileInfo);
              Dispatcher.BeginInvoke(() => LoadZiPackage(fileInfo));
            }
            else
            {
              var definition = AssemblyDefinition.ReadAssembly(fileInfo.OpenRead());

              string assemblyPath = definition.IsSilverlight()
                ? StorageService.CacheSilverlightAssembly(fileInfo.Name, fileInfo.OpenRead())
                : StorageService.CacheNetAssembly(fileInfo.Name, fileInfo.OpenRead());

              Dispatcher.BeginInvoke(() =>
              {
                var assemblyStream = new AssemblyFileStream(fileInfo);
                ApplicationModel.Current.AssemblyCache.LoadAssembly(assemblyStream, definition, false);
                LoadOrReplaceAssembly(definition, assemblyStream);
              });
            }
          }
          catch (Exception ex)
          {
            Debug.WriteLine(ex.Message);
            Dispatcher.BeginInvoke(() => new ErrorWindow(ex).Show());
          }
        }

        Dispatcher.BeginInvoke(() => _busyContext.IsBusy = false);
      });
    }
    private void BrowseAssembly(object sender, RoutedEventArgs e)
    {
      var dialog = new OpenFileDialog { Filter = "Assembly Files(*.exe, *.dll)|*.exe;*.dll" };
      if (dialog.ShowDialog() == false)
      {
        Definition = null;
        DialogResult = false;
        return;
      }
      
      Definition = AssemblyDefinition.ReadAssembly(dialog.File.OpenRead());
      if (Definition == null) Debugger.Break();

      if (Definition.FullName == _reference.FullName)
      {
        string assemblyPath = Definition.IsSilverlight() 
          ? StorageService.CacheSilverlightAssembly(dialog.File.Name, dialog.File.OpenRead()) 
          : StorageService.CacheNetAssembly(dialog.File.Name, dialog.File.OpenRead());

        var assemblyStream = new AssemblyFileStream(dialog.File);
        ApplicationModel.Current.AssemblyCache.LoadAssembly(assemblyStream, Definition);

        DialogResult = true;
      }
    }