private async Task SelectSample(SampleInfo selectedSample) { if (selectedSample == null) { return; } SampleTitleBlock.Text = selectedSample.SampleName; SampleManager.Current.SelectedSample = selectedSample; DescriptionContainer.SetSample(selectedSample); ShowSampleTab(); // Call a function to clear any existing credentials from AuthenticationManager ClearCredentials(); try { if (selectedSample.OfflineDataItems != null) { CancellationTokenSource cancellationSource = new CancellationTokenSource(); // Show waiting page SampleContainer.Content = new WPF.Viewer.WaitPage(cancellationSource); // Wait for offline data to complete await DataManager.EnsureSampleDataPresent(selectedSample, cancellationSource.Token); } // Show the sample SampleContainer.Content = SampleManager.Current.SampleToControl(selectedSample); SourceCodeContainer.LoadSourceCode(); } catch (OperationCanceledException) { CategoriesRegion.Visibility = Visibility.Visible; SampleContainer.Visibility = Visibility.Collapsed; return; } catch (Exception exception) { // failed to create new instance of the sample SampleContainer.Content = new WPF.Viewer.ErrorPage(exception); } CategoriesRegion.Visibility = Visibility.Collapsed; SampleContainer.Visibility = Visibility.Visible; }
private async Task SelectSample(SampleInfo selectedSample) { if (selectedSample == null) { return; } // The following code removes the API key when using the Create and save map sample. if (nameof(SampleManager.Current.SelectedSample) != nameof(selectedSample)) { // Remove API key if opening Create and save map sample. if (selectedSample.FormalName == "AuthorMap") { ApiKeyManager.DisableKey(); } // Restore API key if leaving Create and save map sample. else if (SampleManager.Current?.SelectedSample?.FormalName == "AuthorMap") { ApiKeyManager.EnableKey(); } } SampleTitleBlock.Text = selectedSample.SampleName; SampleManager.Current.SelectedSample = selectedSample; DescriptionContainer.SetSample(selectedSample); ShowSampleTab(); // Call a function to clear any existing credentials from AuthenticationManager ClearCredentials(); try { if (selectedSample.OfflineDataItems != null) { CancellationTokenSource cancellationSource = new CancellationTokenSource(); // Show waiting page SampleContainer.Content = new WPF.Viewer.WaitPage(cancellationSource); // Wait for offline data to complete await DataManager.EnsureSampleDataPresent(selectedSample, cancellationSource.Token); } // Show the sample SampleContainer.Content = SampleManager.Current.SampleToControl(selectedSample); SourceCodeContainer.LoadSourceCode(); } catch (OperationCanceledException) { CategoriesRegion.Visibility = Visibility.Visible; SampleContainer.Visibility = Visibility.Collapsed; return; } catch (Exception exception) { // failed to create new instance of the sample SampleContainer.Content = new WPF.Viewer.ErrorPage(exception); } CategoriesRegion.Visibility = Visibility.Collapsed; SampleContainer.Visibility = Visibility.Visible; }