예제 #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);
            }
        }