Esempio n. 1
0
        private async void OpenLocalPackage(object sender, RoutedEventArgs e)
        {
            // TODO: move file interaction to DialogService or UIService
            var picker = new FileOpenPicker();

            picker.SuggestedStartLocation = PickerLocationId.Downloads;
            picker.FileTypeFilter.Add(Constants.PackageExtension);
            picker.FileTypeFilter.Add(Constants.SymbolPackageExtension);

            var file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                var vm = await InspectPackageViewModel.CreateFromLocalPackage(file);

                NavigationService.NavigateTo(vm);
            }
        }
Esempio n. 2
0
        private async Task PerformShellLandingNavigation(Shell shell, LaunchActivatedEventArgs e)
        {
            var navigation = Container.GetExportedValue <NavigationService>() !;
            var deeplink   = default(object?);

            try
            {
                deeplink = ParseDeepLink(e);

                if (this.Log().IsEnabled(LogLevel.Debug))
                {
                    this.Log().Debug("handling deeplink: " + (deeplink ?? "<null>"));
                }

                if (deeplink is FileInfo file)
                {
                    if (!FileUtility.IsSupportedFile(file.FullName))
                    {
                        throw new InvalidOperationException("Unsupported file type: " + file.Extension);
                    }
                    if (!file.Exists)
                    {
                        throw new FileNotFoundException("No such file", file.FullName);
                    }

                    var vm = await InspectPackageViewModel.CreateFromLocalPackage(file.FullName);

                    navigation.NavigateTo(vm);

                    DiagnosticsClient.TrackEvent("AppStart", new Dictionary <string, string> {
                        { "launchType", "filePath" }
                    });
                }
                else if (deeplink is string searchTerm)
                {
                    var vm = new FeedPackagePickerViewModel(searchTerm);

                    navigation.NavigateTo(vm);

                    DiagnosticsClient.TrackEvent("AppStart", new Dictionary <string, string> {
                        { "launchType", "searchTerm" }
                    });
                }
                else if (deeplink is PackageIdentity identity)
                {
                    var vm = await InspectPackageViewModel.CreateFromRemotePackageWithFallback(identity);

                    navigation.NavigateTo(vm);

                    DiagnosticsClient.TrackEvent("AppStart", new Dictionary <string, string> {
                        { "launchType", "packageIdentity" }
                    });
                }
                else
                {
                    navigation.NavigateTo <FeedPackagePickerViewModel>();

                    DiagnosticsClient.TrackEvent("AppStart", new Dictionary <string, string> {
                        { "launchType", "nugetOrgFeed" }
                    });
                }
            }
            catch (PackageNotFoundException ex)
            {
                DiagnosticsClient.TrackException(ex);

                await new MessageDialog(ex.Message, nameof(PackageNotFoundException)).ShowAsync();

                if (deeplink is not PackageIdentity identity)
                {
                    throw new InvalidOperationException();
                }

                var vm = new FeedPackagePickerViewModel(identity.Id);

                navigation.NavigateTo(vm);
            }
            catch (Exception ex)
            {
                DiagnosticsClient.TrackException(ex);

                if (this.Log().IsEnabled(LogLevel.Error))
                {
                    this.Log().Error("landing navigation failed:", ex);
                    this.Log().Error("attempting home navigatation instead...");
                }

                navigation.NavigateTo <FeedPackagePickerViewModel>();
            }
        }