Ejemplo n.º 1
0
        /// <summary>
        /// User has clicked download.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event arguments.</param>
        private async void OnDownloadClicked(object sender, EventArgs e)
        {
            // Ask user for download path.
            string path = ViewBase.AskUserForFileName("Choose a download folder",
                                                      Utility.FileDialog.FileActionType.SelectFolder,
                                                      "",
                                                      ApsimNG.Cloud.Azure.AzureSettings.Default.OutputDir);

            if (!string.IsNullOrEmpty(path))
            {
                ApsimNG.Cloud.Azure.AzureSettings.Default.OutputDir = path;
                ApsimNG.Cloud.Azure.AzureSettings.Default.Save();

                presenter.ShowWaitCursor(true);

                try
                {
                    foreach (int listViewIndex in jobListView.SelectedIndicies)
                    {
                        var jobListIndex = ConvertListViewIndexToJobIndex(listViewIndex);

                        DownloadOptions options = new DownloadOptions()
                        {
                            Name  = jobList[jobListIndex].DisplayName,
                            Path  = ApsimNG.Cloud.Azure.AzureSettings.Default.OutputDir,
                            JobID = Guid.Parse(jobList[jobListIndex].Id)
                        };

                        await cloudInterface.DownloadResultsAsync(options, cancelToken.Token, p => { });

                        if (cancelToken.IsCancellationRequested)
                        {
                            return;
                        }
                    }
                    presenter.ShowMessage($"Results were successfully downloaded to {ApsimNG.Cloud.Azure.AzureSettings.Default.OutputDir}", Simulation.MessageType.Information);
                }
                catch (Exception err)
                {
                    presenter.ShowError(err);
                }
                finally
                {
                    presenter.ShowWaitCursor(false);
                }
            }
        }