Catrobat.IDE.Core.ViewModels.Main.OnlinePrograms.DetailedProgramViewModel.Download C# (CSharp) Method

Download() private method

private Download ( ) : void
return void
    private async void Download()
    {
      // TODO: Taken from previous version, needs to be redone.
      lock (_importLock)
      {
        if (IsDownloading)
        {
          ServiceLocator.NotifictionService.ShowMessageBox(
              AppResourcesHelper.Get("Main_OnlineProgramLoading"),
              AppResourcesHelper.Get("Main_OnlineProgramDownloadBusy"),
              CancelImportCallback, MessageBoxOptions.OkCancel);
          return;
        }

        IsDownloading = true;
      }

      var message = new GenericMessage<string>(Program.Name);
      Messenger.Default.Send(message, ViewModelMessagingToken.DownloadProgramStartedListener);

      try
      {
        ServiceLocator.DispatcherService.RunOnMainThread(() =>
            ServiceLocator.NavigationService.NavigateBack<ProgramsViewModel>());

        ServiceLocator.ProgramImportService.SetDownloadHeader(Program);
        await Task.Run(() => ServiceLocator.ProgramImportService.TryImportWithStatusNotifications()).ConfigureAwait(false);
      }
      finally
      {
        ServiceLocator.DispatcherService.RunOnMainThread(() =>
        {
          lock (_importLock) { IsDownloading = false; }
        });
      }
    }