예제 #1
0
        public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
        {
            using (var stream = StreamUtility.MakeSeekable(selectedFile.GetStream(), true))
            {
                // don't display file bigger than 1MB
                if (stream.Length > 1024 * 1024)
                {
                    return("** This file is too big to view inline. ***");
                }

                var rtf = new RichTextBox
                {
                    IsReadOnly                    = true,
                    BorderThickness               = new System.Windows.Thickness(0),
                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto
                };
                rtf.Document.MinPageWidth = 800;

                var range = new TextRange(rtf.Document.ContentStart, rtf.Document.ContentEnd);
                range.Load(stream, System.Windows.DataFormats.Rtf);

                return(rtf);
            }
        }
예제 #2
0
 private void OnOpenDocumentCommandExecute(IPackageContent document)
 {
     if (document == null)
     {
         return;
     }
     if (document is DocumentUnopen)
     {
         var docUnopen = document as DocumentUnopen;
         if (docUnopen.KeepAliveWhenClose)
         {
             var documentViewMoel = (IDocumentViewModel)docUnopen.DocClosedButAlive;
             ShellService.OpenDocument(documentViewMoel);
             ShellService.ActivateDocument(documentViewMoel);
             ShellService.DocumentsUnopen.Remove(docUnopen);
         }
         else
         {
             using (Package package = Package.Open(CurrentPackagePath, FileMode.Open))
             {
                 var documentViewMoel = OpenPackageContent(package, docUnopen.ContentId) as DocumentViewModel;
                 ShellService.OpenDocument(documentViewMoel);
                 ShellService.ActivateDocument(documentViewMoel);
                 var shellService = (ShellService as ShellService);
                 ShellService.DocumentsUnopen.Remove(docUnopen);
                 SaveDocumentsUnopen(package, ShellService.DocumentsUnopen);
                 SavePanelLayout(package);
             }
         }
     }
     else
     {
         ShellService.ActivateDocument(document as IDocumentViewModel);
     }
 }
        protected override async Task ExecuteAsync(IPackage package, CancellationToken cancellationToken)
        {
            bool execute = true;

            if (Executing != null)
            {
                execute = await Executing();
            }

            if (execute)
            {
                IPackageContent packageContent = await package.GetContentAsync(cancellationToken);

                string pluginPath = Path.Combine(service.Path, package.Id);
                await packageContent.RemoveFromAsync(pluginPath, cancellationToken);

                // do not delete the plugin directory if it still contains files (e.g. data files)
                if (Directory.Exists(pluginPath) && !Directory.EnumerateFileSystemEntries(pluginPath).Any())
                {
                    Directory.Delete(pluginPath);
                }

                cancellationToken.ThrowIfCancellationRequested();

                service.Uninstall(package);
            }

            Completed?.Invoke();
        }
예제 #4
0
        public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
        {
            DiagnosticsClient.TrackEvent("ImageFileViewer");

            using (var stream = StreamUtility.MakeSeekable(selectedFile.GetStream(), true))
            {
                var source = new BitmapImage();
                source.BeginInit();
                source.CacheOption  = BitmapCacheOption.OnLoad;
                source.StreamSource = stream;
                source.EndInit();

                var image = new Image
                {
                    Source = source,
                    Width  = source.Width,
                    Height = source.Height,
                };

                return(new ScrollViewer
                {
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                    VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                    Content = image
                });
            }
        }
예제 #5
0
        protected override async Task ExecuteAsync(IPackage package, CancellationToken cancellationToken)
        {
            IPackageContent packageContent = await package.GetContentAsync(cancellationToken);

            await packageContent.RemoveFromAsync(service.Path, cancellationToken);

            await packageContent.ExtractToAsync(service.Path, cancellationToken);
        }
예제 #6
0
        protected override async Task ExecuteAsync(IPackage package, CancellationToken cancellationToken)
        {
            IPackageContent packageContent = await package.GetContentAsync(cancellationToken);

            string pluginPath = Path.Combine(service.Path, package.Id);
            await packageContent.RemoveFromAsync(pluginPath, cancellationToken);

            await packageContent.ExtractToAsync(pluginPath, cancellationToken);
        }
        public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
        {
            DiagnosticsClient.TrackEvent("PdbFileViewer");

            AssemblyDebugDataViewModel?data = null;

            // Get the PE file, exe or dll that matches
            var filename = Path.GetFileNameWithoutExtension(selectedFile.Name);
            var pe       = peerFiles.FirstOrDefault(pc => pc.Path != selectedFile.Path &&
                                                    Path.GetFileNameWithoutExtension(pc.Name) !.Equals(filename, StringComparison.OrdinalIgnoreCase) &&
                                                    (".dll".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase) ||
                                                     ".exe".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase)));

            Stream?peStream = null;

            try
            {
                if (pe != null) // we have a matching file
                {
                    peStream = StreamUtility.MakeSeekable(pe.GetStream(), true);
                }


                // This might throw an exception because we don't know if it's a full PDB or portable
                // Try anyway in case it succeeds as a ppdb
                try
                {
                    using (var stream = StreamUtility.MakeSeekable(selectedFile.GetStream(), true))
                    {
                        data = new AssemblyDebugDataViewModel(AssemblyMetadataReader.ReadDebugData(peStream, stream));
                    }

                    return(new ScrollViewer
                    {
                        HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                        VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                        Content = new Controls.PdbFileViewer
                        {
                            DataContext = data
                        }
                    });
                }
                catch (ArgumentNullException)
                {
                }
            }
            finally
            {
                peStream?.Dispose();
            }

            return(new TextBlock()
            {
                Text = "Full PDB files rquired the EXE or DLL to be alongside."
            });
        }
예제 #8
0
        public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
        {
            DiagnosticsClient.TrackEvent("PdbFileViewer");

            AssemblyDebugDataViewModel?data = null;

            // Get the PE file, exe or dll that matches
            var pe = peerFiles.FirstOrDefault(pc => ".dll".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase) ||
                                              ".exe".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase) ||
                                              ".winmd".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase));

#pragma warning disable CA2000 // Dispose objects before losing scope -- ReadDebugData will dispose
            Stream?peStream = null;

            if (pe != null) // we have a matching file
            {
                peStream = StreamUtility.MakeSeekable(pe.GetStream(), true);
            }


            // This might throw an exception because we don't know if it's a full PDB or portable
            // Try anyway in case it succeeds as a ppdb
            try
            {
                var stream = StreamUtility.MakeSeekable(selectedFile.GetStream(), true);
                data = new AssemblyDebugDataViewModel(AssemblyMetadataReader.ReadDebugData(peStream, stream));


                return(new ScrollViewer
                {
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                    VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                    Content = new Controls.PdbFileViewer
                    {
                        DataContext = data
                    }
                });
            }
            catch (ArgumentNullException)
            {
            }
#pragma warning restore CA2000 // Dispose objects before losing scope
            return(new TextBlock()
            {
                Text = "Full PDB files requires the EXE or DLL to be alongside."
            });
        }
예제 #9
0
 private bool OnOpenDocumentCommandCanExecute(IPackageContent document)
 {
     if (document is DocumentUnopen)
     {
         var unopenDoc = document as DocumentUnopen;
         if (unopenDoc.KeepAliveWhenClose)
         {
             return(true);
         }
         else
         {
             if (string.IsNullOrEmpty(CurrentPackagePath))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
예제 #10
0
        protected override async Task ExecuteAsync(IPackage package, CancellationToken cancellationToken)
        {
            bool execute = true;

            if (Executing != null)
            {
                execute = await Executing();
            }

            if (execute)
            {
                IPackageContent packageContent = await package.GetContentAsync(cancellationToken);

                await packageContent.ExtractToAsync(service.Path, cancellationToken);

                service.Install(package);
            }

            Completed?.Invoke();
        }
        protected override async Task ExecuteAsync(IPackage package, CancellationToken cancellationToken)
        {
            bool execute = true;

            if (Executing != null)
            {
                execute = await Executing();
            }

            if (execute)
            {
                IPackageContent packageContent = await package.GetContentAsync(cancellationToken);

                string pluginPath = Path.Combine(service.Path, package.Id);
                Directory.CreateDirectory(pluginPath);
                await packageContent.ExtractToAsync(pluginPath, cancellationToken);

                service.Install(package);
            }

            Completed?.Invoke();
        }
예제 #12
0
        protected override async Task ExecuteAsync(IPackage package, CancellationToken cancellationToken)
        {
            bool execute = true;

            if (Executing != null)
            {
                execute = await Executing();
            }

            if (execute)
            {
                IPackageContent packageContent = await package.GetContentAsync(cancellationToken);

                await packageContent.RemoveFromAsync(service.Path, cancellationToken);

                cancellationToken.ThrowIfCancellationRequested();

                service.Uninstall(package);
            }

            Completed?.Invoke();
        }
        protected override async Task ExecuteAsync(PackageUpdateViewModel package, CancellationToken cancellationToken)
        {
            bool execute = true;

            if (Executing != null)
            {
                execute = await Executing();
            }

            if (execute)
            {
                if (package.IsSelf && !selfUpdate.IsSelfUpdate)
                {
                    selfUpdate.Update(package.Target);
                    return;
                }

                IPackageContent packageContent = await package.Current.Model.GetContentAsync(cancellationToken);

                string pluginPath = Path.Combine(install.Path, package.Current.Id);
                await packageContent.RemoveFromAsync(pluginPath, cancellationToken);

                install.Uninstall(package.Current.Model);

                packageContent = await package.Target.GetContentAsync(cancellationToken);

                await packageContent.ExtractToAsync(pluginPath, cancellationToken);

                install.Install(package.Target);

                if (package.IsSelf)
                {
                    selfUpdate.RunNewInstance(package.Target);
                }
            }

            Completed?.Invoke();
        }
예제 #14
0
        // 保存文件。
        public static bool Save()
        {
            bool result = true;

#if !DEBUG
            try
#endif
            {
                IPackageContent packageContent = PackageContentVersions.CreateLatestVersion();

                packageContent.TranslateFrom(_PhylogeneticTree);

                _Package.SaveToFile(packageContent);
            }
#if !DEBUG
            catch
            {
                result = false;
            }
#endif

            return(result);
        }
예제 #15
0
        public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
        {
            DiagnosticsClient.TrackEvent("PdbFileViewer");

            // Get the PE file, exe or dll that matches
            var pe = peerFiles.FirstOrDefault(pc => ".dll".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase) ||
                                              ".exe".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase) ||
                                              ".winmd".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase));

#pragma warning disable CA2000 // Dispose objects before losing scope -- ReadDebugData will dispose
            var peStream = pe != null
                ? StreamUtility.MakeSeekable(pe.GetStream(), true)
                : null;

            // This might throw an exception because we don't know if it's a full PDB or portable
            // Try anyway in case it succeeds as a ppdb
            try
            {
                var stream = StreamUtility.MakeSeekable(selectedFile.GetStream(), true);
                var data   = new AssemblyDebugDataViewModel(AssemblyMetadataReader.ReadDebugData(peStream, stream));

#if !HAS_UNO
                // Tab control with two pages
                var tc = new TabControl()
                {
                    Items =
                    {
                        new TabItem
                        {
                            Header  = "PDB Info",
                            Content = new ScrollViewer
                            {
                                HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                Content = new Controls.PdbInfoViewer
                                {
                                    DataContext = data
                                }
                            }
                        },
                        new TabItem
                        {
                            Header  = "PDB Sources",
                            Content = new ScrollViewer
                            {
                                HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                Content = new Controls.PdbSourcesViewer
                                {
                                    DataContext = data
                                }
                            }
                        }
                    }
                };

                return(tc);
#else
                // returning UIElement from here works.
                // however due to performance issues, we are just
                // returning the datacontext and letting the xaml to handle the view.
                // also, the ui layout is vastely different compared to the #if-block above
                return(new AssemblyFileViewer.AssemblyFileContent()
                {
                    Metadata = null,
                    DebugData = data,
                });
#endif
            }
            catch (ArgumentNullException)
            {
            }
            catch (Exception e)
            {
#if HAS_UNO
                this.Log().Error("Failed to generate view", e);
#endif
            }

#pragma warning restore CA2000 // Dispose objects before losing scope
            return(new TextBlock()
            {
                Text = "Full PDB files requires the EXE or DLL to be alongside."
            });
        }
        public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
        {
            var tempFile = Path.GetTempFileName();

            try
            {
                using (var str = selectedFile.GetStream())
                    using (var fileStream = File.OpenWrite(tempFile))
                    {
                        str.CopyTo(fileStream);
                    }

                var assemblyMetadata = AssemblyMetadataReader.ReadMetaData(tempFile);
                AssemblyDebugDataViewModel debugDataViewModel = null;
                if (assemblyMetadata.DebugData != null)
                {
                    debugDataViewModel = new AssemblyDebugDataViewModel(assemblyMetadata.DebugData);
                }

                // No debug data to display
                if (assemblyMetadata != null && debugDataViewModel == null)
                {
                    var orderedAssemblyDataEntries = assemblyMetadata.GetMetadataEntriesOrderedByImportance();

                    var grid = CreateAssemblyMetadataGrid(orderedAssemblyDataEntries);

                    return(new ScrollViewer
                    {
                        HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                        VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                        Content = grid,
                    });
                }
                else if (assemblyMetadata != null && debugDataViewModel != null)
                {
                    var orderedAssemblyDataEntries = assemblyMetadata.GetMetadataEntriesOrderedByImportance();

                    // Tab control with two pages
                    var tc = new TabControl()
                    {
                        Items =
                        {
                            new TabItem
                            {
                                Header  = "Assembly Attributes",
                                Content = new ScrollViewer()
                                {
                                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                    Content = CreateAssemblyMetadataGrid(orderedAssemblyDataEntries)
                                }
                            },
                            new TabItem
                            {
                                Header  = "Embedded PDB Data",
                                Content = new ScrollViewer
                                {
                                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                    Content = new Controls.PdbFileViewer
                                    {
                                        DataContext = debugDataViewModel
                                    }
                                }
                            }
                        }
                    };

                    return(tc);
                }
            }
            catch { }
            finally
            {
                if (File.Exists(tempFile))
                {
                    try
                    {
                        File.Delete(tempFile);
                    }
                    catch
                    {
                    }
                }
            }

            return(new Grid());
        }
예제 #17
0
 public void ExtractToAsync()
 {
     IPackageContent packageContent = package.GetContentAsync(default).Result;
예제 #18
0
        public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
        {
            DiagnosticsClient.TrackEvent("AssemblyFileViewer");

            try
            {
                using var str      = selectedFile.GetStream();
                using var tempFile = new TemporaryFile(str);

                var debugData        = (selectedFile as PackageFile)?.DebugData;
                var assemblyMetadata = AssemblyMetadataReader.ReadMetaData(tempFile.FileName);

                if (debugData == null)
                {
                    if (assemblyMetadata?.DebugData.HasDebugInfo == true)
                    {
                        debugData = assemblyMetadata.DebugData;
                    }
                }

                AssemblyDebugDataViewModel?debugDataViewModel = null;

                if (debugData != null)
                {
                    debugDataViewModel = new AssemblyDebugDataViewModel(Task.FromResult(debugData));
                }

#if !HAS_UNO
                // No debug data to display
                if (assemblyMetadata != null && debugDataViewModel == null)
                {
                    var orderedAssemblyDataEntries = GetMetadataEntriesOrderedByImportance(assemblyMetadata);

                    var grid = CreateAssemblyMetadataGrid(orderedAssemblyDataEntries);

                    return(new ScrollViewer
                    {
                        HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                        VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                        Content = grid,
                    });
                }
                else if (assemblyMetadata != null && debugDataViewModel != null)
                {
                    var orderedAssemblyDataEntries = GetMetadataEntriesOrderedByImportance(assemblyMetadata);

                    // Tab control with three pages
                    var tc = new TabControl()
                    {
#if HAS_UNO
                        IsAddTabButtonVisible = false,
                        TabItems =
#else
                        Items =
#endif
                        {
                            new TabItem
                            {
                                Header  = "Assembly Attributes",
                                Content = new ScrollViewer()
                                {
                                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                    Content = CreateAssemblyMetadataGrid(orderedAssemblyDataEntries)
                                }
                            },
                            new TabItem
                            {
                                Header  = "PDB Info",
                                Content = new ScrollViewer
                                {
                                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                    Content = new Controls.PdbInfoViewer
                                    {
                                        DataContext = debugDataViewModel
                                    }
                                }
                            },
                            new TabItem
                            {
                                Header  = "PDB Sources",
                                Content = new ScrollViewer
                                {
                                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                    Content = new Controls.PdbSourcesViewer
                                    {
                                        DataContext = debugDataViewModel
                                    }
                                }
                            }
                        }
                    };

                    return(tc);
                }
#else
                // returning UIElement from here works.
                // however due to performance issues, we are just
                // returning the datacontext and letting the xaml to handle the view.
                // also, the ui layout is vastely different compared to the #if-block above
                return(new AssemblyFileContent()
                {
                    Metadata = assemblyMetadata
                               ?.SelectOrDefault(GetMetadataEntriesOrderedByImportance)
                               .ToArray(),
                    DebugData = debugDataViewModel,
                });
#endif
            }
            catch (Exception e)
            {
#if HAS_UNO
                this.Log().Error("Failed to generate view", e);
#endif
            }

#if !HAS_UNO
            return(new Grid());
#else
            // the empty object is needed for branching via type-checking
            return(new AssemblyFileContent());
#endif
        }
        public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
        {
            DiagnosticsClient.TrackEvent("AssemblyFileViewer");



            try
            {
                using var str      = selectedFile.GetStream();
                using var tempFile = new TemporaryFile(str);

                var debugData        = (selectedFile as PackageFile)?.DebugData;
                var assemblyMetadata = AssemblyMetadataReader.ReadMetaData(tempFile.FileName);

                if (debugData == null)
                {
                    if (assemblyMetadata?.DebugData.HasDebugInfo == true)
                    {
                        debugData = assemblyMetadata.DebugData;
                    }
                }

                AssemblyDebugDataViewModel?debugDataViewModel = null;

                if (debugData != null)
                {
                    debugDataViewModel = new AssemblyDebugDataViewModel(Task.FromResult(debugData));
                }

                // No debug data to display
                if (assemblyMetadata != null && debugDataViewModel == null)
                {
                    var orderedAssemblyDataEntries = GetMetadataEntriesOrderedByImportance(assemblyMetadata);

                    var grid = CreateAssemblyMetadataGrid(orderedAssemblyDataEntries);

                    return(new ScrollViewer
                    {
                        HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                        VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                        Content = grid,
                    });
                }
                else if (assemblyMetadata != null && debugDataViewModel != null)
                {
                    var orderedAssemblyDataEntries = GetMetadataEntriesOrderedByImportance(assemblyMetadata);

                    // Tab control with three pages
                    var tc = new TabControl()
                    {
                        Items =
                        {
                            new TabItem
                            {
                                Header  = "Assembly Attributes",
                                Content = new ScrollViewer()
                                {
                                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                    Content = CreateAssemblyMetadataGrid(orderedAssemblyDataEntries)
                                }
                            },
                            new TabItem
                            {
                                Header  = "PDB Info",
                                Content = new ScrollViewer
                                {
                                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                    Content = new Controls.PdbInfoViewer
                                    {
                                        DataContext = debugDataViewModel
                                    }
                                }
                            },
                            new TabItem
                            {
                                Header  = "PDB Sources",
                                Content = new ScrollViewer
                                {
                                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                    Content = new Controls.PdbSourcesViewer
                                    {
                                        DataContext = debugDataViewModel
                                    }
                                }
                            }
                        }
                    };

                    return(tc);
                }
            }
            catch { }

            return(new Grid());
        }
예제 #20
0
 public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
 {
     return(new Grid());
 }