Exemplo n.º 1
0
        private void OnDownloadCompleted(object o, DownloadCompletedEventArgs e)
        {
            ((IFileDownloader)o).DownloadCompleted -= this.OnDownloadCompleted;
            Exception error = e.Error;

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

                    foreach (AssemblyPart part in GetParts(stream))
                    {
                        LoadAssemblyFromStream(stream, part);
                    }
                }
                catch (Exception ex)
                {
                    error = ex;
                }
                finally
                {
                    e.Result.Close();
                }
            }

            List <ModuleTypeLoaderCallbackMetadata> callbacks;

            lock (this.typeLoadingCallbacks)
            {
                Uri requestUri = (Uri)e.UserState;
                Debug.Assert(requestUri != null, "UserState should hold a reference to the request uri");
                callbacks = this.typeLoadingCallbacks[requestUri];
                this.typeLoadingCallbacks.Remove(requestUri);
            }

            foreach (ModuleTypeLoaderCallbackMetadata loaderCallbackMetadata in callbacks)
            {
                loaderCallbackMetadata.Callback(loaderCallbackMetadata.ModuleInfo, error);
            }
        }
Exemplo n.º 2
0
        private void OnDownloadCompleted(object o, DownloadCompletedEventArgs e)
        {
            ((IFileDownloader)o).DownloadCompleted -= this.OnDownloadCompleted;
            Exception error = e.Error;
            if (e.Error == null)
            {
                try
                {
                    Debug.Assert(!e.Cancelled, "Download should not be cancelled");
                    Stream stream = e.Result;

                    foreach (AssemblyPart part in GetParts(stream))
                    {
                        LoadAssemblyFromStream(stream, part);
                    }
                }
                catch (Exception ex)
                {
                    error = ex;
                }
                finally
                {
                    e.Result.Close();
                }
            }

            List<ModuleTypeLoaderCallbackMetadata> callbacks;
            lock (this.typeLoadingCallbacks)
            {
                Uri requestUri = (Uri)e.UserState;
                Debug.Assert(requestUri != null, "UserState should hold a reference to the request uri");
                callbacks = this.typeLoadingCallbacks[requestUri];
                this.typeLoadingCallbacks.Remove(requestUri);
            }

            foreach (ModuleTypeLoaderCallbackMetadata loaderCallbackMetadata in callbacks)
            {
                loaderCallbackMetadata.Callback(loaderCallbackMetadata.ModuleInfo, error);
            }
        }
 public void InvokeOpenReadCompleted(DownloadCompletedEventArgs args)
 {
     DownloadCompleted.Invoke(this, args);
 }