コード例 #1
0
ファイル: ArticleViewModel.cs プロジェクト: neurosoup/mymoon
 private void FileDownloaderDownloadCompleted(object sender, DownloadCompletedEventArgs e)
 {
     if (e.Error == null)
     {
         using (StreamReader sr = new StreamReader(e.Result))
         {
             Content = sr.ReadToEnd();
         }
     } else
     {
         string message = string.Format("Chargement de l'article {0} a échoué : {1}", e.UserState, e.Error.Message);
         Content = message;
     }
 }
コード例 #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);
        }