Exemplo n.º 1
0
 private void SetupFormEventHandlers()
 {
     Session.OnAudioDataArrived += new Action <byte[]>(bytes =>
     {
         playbackManager.AddBytesToPlayingStream(bytes);
     });
     Session.OnAudioStreamComplete += new Action <object>(obj =>
     {
         playbackManager.fullyDownloaded = true;
         Session.UnloadPlayer();
     });
     playbackManager.OnEndOfTrack          += new Action(HandleEndOfCurrentTrack);
     playbackManager.OnPlayingTrackChanged += new Action(HandleChangeOfTrack);
     updater.NewVersionDetected            += new EventHandler((sender, e) =>
     {
         Version newVersion   = sender as Version;
         string updateMessage = StringStore.AnUpdateToBlindspotIsAvailableQuestionNoVersion;
         if (newVersion != null)
         {
             updateMessage = String.Format(StringStore.AnUpDateToBlindspotIsAvailableQuestionWithVersion, newVersion.Major, newVersion.Minor, newVersion.Build);
         }
         if (MessageBox.Show(updateMessage, StringStore.NewVersionAvailable, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             updater.DownloadNewVersion();
         }
     });
     updater.UpdateDownloaded += new EventHandler((sender, e) =>
     {
         MessageBox.Show(StringStore.NewVersionDownloadedSuccessfully, StringStore.ReadyToInstall, MessageBoxButtons.OK, MessageBoxIcon.Information);
         downloadedUpdate = true;
         updater.RunInstaller();
     });
     updater.UpdateFailed += new EventHandler((sender, e) =>
     {
         var exception = sender as Exception;
         if (exception != null)
         {
             MessageBox.Show(String.Format("{0}. {1}: {2}", StringStore.AnUnexpectedErrorOccurred, exception.GetType().ToString(), exception.Message), StringStore.ErrorDuringUpdate, MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     });
     // comment this out for debugging, so that exceptions appear naturally
     Application.ThreadException += new System.Threading.ThreadExceptionEventHandler((sender, e) =>
     {
         if (e.Exception is OutOfMemoryException)
         {
             MessageBox.Show(StringStore.CriticalError + "\r\n" + String.Format("{0}: {1}", e.Exception.GetType().ToString(), e.Exception.Message), "Out of cheese error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             this.Close(); // on OutOfMemory exceptions, we should close immediately
             return;
         }
         else
         {
             MessageBox.Show(StringStore.AnUnexpectedErrorOccurred + "\r\n" + String.Format("{0}: {1}", e.Exception.GetType().ToString(), e.Exception.Message), StringStore.Oops, MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     });
 }