IsSupportedFile() public static method

public static IsSupportedFile ( string filepath ) : bool
filepath string
return bool
示例#1
0
        private async Task PerformMainLandingNavigation(MainWindow window, LaunchActivatedEventArgs e)
        {
            var deeplink = ParseDeepLink(e);

            if (this.Log().IsEnabled(LogLevel.Debug))
            {
                typeof(App).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);
                }

                await window.OpenLocalPackage(file.FullName);
            }
            else if (deeplink is string searchTerm)
            {
                await window.OpenPackageFromRepository(searchTerm);
            }
            else if (deeplink is PackageIdentity identity)
            {
                await window.DownloadAndOpenDataServicePackage(
                    NuGetPackageExplorer.Constants.NuGetOrgSource,
                    identity.Id,
                    identity.Version
                    );
            }
        }
示例#2
0
 private static bool LoadFile(MainWindow window, string file)
 {
     if (FileUtility.IsSupportedFile(file) && File.Exists(file))
     {
         window.OpenLocalPackage(file);
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#3
0
        private void Window_DragOver(object sender, DragEventArgs e)
        {
            var data = e.Data;

            if (data.GetDataPresent(DataFormats.FileDrop))
            {
                var value = data.GetData(DataFormats.FileDrop);
                if (value is string[] filenames && filenames.Length > 0)
                {
                    var firstFile = filenames[0];
                    if (FileUtility.IsSupportedFile(firstFile))
                    {
                        e.Effects = DragDropEffects.Copy;
                        e.Handled = true;
                        return;
                    }
                }
            }

            e.Effects = DragDropEffects.None;
            e.Handled = true;
        }
示例#4
0
        private void Window_Drop(object sender, DragEventArgs e)
        {
            var data = e.Data;

            if (data.GetDataPresent(DataFormats.FileDrop))
            {
                object   value     = data.GetData(DataFormats.FileDrop);
                string[] filenames = value as string[];
                if (filenames != null && filenames.Length > 0)
                {
                    string firstFile = filenames.FirstOrDefault(f => FileUtility.IsSupportedFile(f));
                    if (firstFile != null)
                    {
                        e.Handled = true;

                        bool canceled = AskToSaveCurrentFile();
                        if (!canceled)
                        {
                            OpenLocalPackage(firstFile);
                        }
                    }
                }
            }
        }
示例#5
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>();
            }
        }