Пример #1
0
        /// <summary>
        /// Handles the DownloadCompleted event of the IFileDownloader control.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="Microsoft.Practices.Prism.Modularity.DownloadCompletedEventArgs"/> instance containing
        ///     the event data.
        /// </param>
        private void IFileDownloader_DownloadCompleted(object sender, DownloadCompletedEventArgs e)
        {
            // A new IFileDownloader instance is created for each download.
            // I unregister the event to allow for garbage collection.
            var fileDownloader = (IFileDownloader)sender;

            fileDownloader.DownloadProgressChanged -= this.IFileDownloader_DownloadProgressChanged;
            fileDownloader.DownloadCompleted       -= this.IFileDownloader_DownloadCompleted;

            // I ensure the download completed is on the UI thread so that types can be loaded into the application domain.
            if (!Deployment.Current.Dispatcher.CheckAccess())
            {
                Deployment.Current.Dispatcher.BeginInvoke(
                    new Action <DownloadCompletedEventArgs>(
                        param =>
                        ServiceLocator.Current.GetInstance <IExternalPartsLoader>()
                        .LoadExternalParts(param.Result, () => this.HandleModuleDownloaded(param))),
                    e);
            }
            else
            {
                ServiceLocator.Current.GetInstance <IExternalPartsLoader>()
                .LoadExternalParts(e.Result, () => this.HandleModuleDownloaded(e));
            }
        }
Пример #2
0
        private void IFileDownloader_DownloadCompleted(object sender, DownloadCompletedEventArgs e)
        {
            // A new IFileDownloader instance is created for each download.
            // I unregister the event to allow for garbage collection.
            IFileDownloader fileDownloader = (IFileDownloader)sender;

            fileDownloader.DownloadProgressChanged -= this.IFileDownloader_DownloadProgressChanged;
            fileDownloader.DownloadCompleted       -= this.IFileDownloader_DownloadCompleted;

            // I ensure the download completed is on the UI thread so that types can be loaded into the application domain.
            if (!Deployment.Current.Dispatcher.CheckAccess())
            {
                Deployment.Current.Dispatcher.BeginInvoke(new Action <DownloadCompletedEventArgs>(this.HandleModuleDownloaded), e);
            }
            else
            {
                this.HandleModuleDownloaded(e);
            }
        }
Пример #3
0
        private void HandleModuleDownloaded(DownloadCompletedEventArgs e)
        {
            Uri uri = (Uri)e.UserState;
            List <ModuleInfo> moduleInfos = this.GetDownloadingModules(uri);

            Exception error = e.Error;

            if (error == null)
            {
                try
                {
                    this.RecordDownloadComplete(uri);

                    Debug.Assert(!e.Cancelled, "Download should not be cancelled");
                    Stream stream = e.Result;

                    foreach (AssemblyPart part in GetParts(stream))
                    {
                        LoadAssemblyFromStream(stream, part);
                    }

                    this.RecordDownloadSuccess(uri);
                }
                catch (Exception ex)
                {
                    error = ex;
                }
                finally
                {
                    e.Result.Close();
                }
            }

            foreach (ModuleInfo moduleInfo in moduleInfos)
            {
                this.RaiseLoadModuleCompleted(moduleInfo, error);
            }
        }
 public void InvokeOpenReadCompleted(DownloadCompletedEventArgs args)
 {
     DownloadCompleted.Invoke(this, args);
 }
Пример #5
0
        private void HandleModuleDownloaded(DownloadCompletedEventArgs e)
        {
            Uri uri = (Uri)e.UserState;
            List<ModuleInfo> moduleInfos = this.GetDownloadingModules(uri);

            Exception error = e.Error;
            if (error == null)
            {
                try
                {
                    this.RecordDownloadComplete(uri);

                    Debug.Assert(!e.Cancelled, "Download should not be cancelled");
                    Stream stream = e.Result;

                    foreach (AssemblyPart part in GetParts(stream))
                    {
                        LoadAssemblyFromStream(stream, part);
                    }

                    this.RecordDownloadSuccess(uri);
                }
                catch (Exception ex)
                {
                    error = ex;
                }
                finally
                {
                    e.Result.Close();
                }
            }

            foreach (ModuleInfo moduleInfo in moduleInfos)
            {
                this.RaiseLoadModuleCompleted(moduleInfo, error);
            }
        }
Пример #6
0
        private void IFileDownloader_DownloadCompleted(object sender, DownloadCompletedEventArgs e)
        {
            // A new IFileDownloader instance is created for each download.
            // I unregister the event to allow for garbage collection.
            IFileDownloader fileDownloader = (IFileDownloader)sender;
            fileDownloader.DownloadProgressChanged -= this.IFileDownloader_DownloadProgressChanged;
            fileDownloader.DownloadCompleted -= this.IFileDownloader_DownloadCompleted;

            // I ensure the download completed is on the UI thread so that types can be loaded into the application domain.
            if (!Deployment.Current.Dispatcher.CheckAccess())
            {
                Deployment.Current.Dispatcher.BeginInvoke(new Action<DownloadCompletedEventArgs>(this.HandleModuleDownloaded), e);
            }
            else
            {
                this.HandleModuleDownloaded(e);
            }
        }