コード例 #1
0
        private static IAssemblyFile TryGetExistingAssemblyFile(IDataContext context, out ISolution solution)
        {
            solution = context.GetData(JetBrains.ProjectModel.DataContext.DataConstants.SOLUTION);
            if (solution == null)
            {
                return(null);
            }
            IList <TreeModelNode> data = context.GetData(TreeModelBrowser.TREE_MODEL_NODES);

            if (data == null || data.Count != 1)
            {
                return(null);
            }
            IAssemblyFile assemblyFile = GetAssemblyFile(data.First());

            if (assemblyFile == null)
            {
                return(null);
            }
            var component = solution.TryGetComponent <AssemblyInfoCache>();

            if (component == null)
            {
                return(null);
            }
            if (!assemblyFile.Location.ExistsFile || AssemblyExplorerUtil.AssemblyIsBroken(assemblyFile.Location, component))
            {
                return(null);
            }

            return(assemblyFile);
        }
コード例 #2
0
        public void Execute(IDataContext context, DelegateExecute nextExecute)
        {
            ISolution solution = context.GetData <ISolution>(JetBrains.ProjectModel.DataContext.DataConstants.SOLUTION);

            if (solution == null)
            {
                return;
            }

            var assemblyExplorerManager = SolutionEx.GetComponent <IAssemblyExplorerManager>(solution);
            var assemblyExplorer        = assemblyExplorerManager.Opened;

            if (assemblyExplorer == null)
            {
                return;
            }

#if DP10
            Assembly asm        = Assembly.GetExecutingAssembly();
            Stream   iconStream = asm.GetManifestResourceStream("JetBrains.DotPeek.Plugins.Console.Console.png");
            var      decoder    = new PngBitmapDecoder(iconStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
            var      icon       = decoder.Frames[0];

            //var icon = new BitmapImage(new Uri(@"pack://application:,,,/JetBrains.DotPeek.Plugins.Console.1.0;Console.png", UriKind.RelativeOrAbsolute));
            //Assembly asm = Assembly.GetExecutingAssembly();
            //Stream iconStream = asm.GetManifestResourceStream("Console.png");
            //BitmapImage bitmap = new BitmapImage();
            //bitmap.BeginInit();
            //bitmap.StreamSource = iconStream;
            //bitmap.EndInit();
            //icon.Source = bitmap;
#elif DP11 || DP12
            IThemedIconManager themedIconManager = SolutionEx.GetComponent <IThemedIconManager>(solution);
            var icon = themedIconManager.GetIcon <ConsoleThemedIcons.Console>().CurrentImageSource;
#endif

            var console       = new ConsoleToolWindow(assemblyExplorerManager);
            var consoleWindow = new Window
            {
                Title   = "Console",
                Icon    = icon,
                Content = console,
                Width   = 640,
                Height  = 520,
                WindowStartupLocation = WindowStartupLocation.CenterScreen,
                ResizeMode            = ResizeMode.CanResize
            };
            consoleWindow.Show();

            // Do we have an assembly node selected somewhere? If so, load the assembly in the console
            var data = context.GetData(TreeModelBrowser.TREE_MODEL_NODES);
            if (data != null)
            {
                var node = data.FirstOrDefault();
                if (node != null)
                {
                    IAssemblyFile     assemblyFile     = null;
                    IAssemblyFileNode assemblyFileNode = node.DataValue as IAssemblyFileNode;
                    if (assemblyFileNode != null)
                    {
                        assemblyFile = ExplorerNodeEx.GetAssemblyFile(assemblyFileNode);
                    }
                    else
                    {
                        AssemblyReferenceNode assemblyReferenceNode = node.DataValue as AssemblyReferenceNode;
                        if (assemblyReferenceNode != null)
                        {
#if DP10
                            IAssembly assemblyResolveResult = ModuleReferencesResolveStoreEx.ResolveResult(assemblyReferenceNode.Reference);
#elif DP11 || DP12
                            IAssembly assemblyResolveResult = ModuleReferencesResolveStoreEx.GetModuleToAssemblyResolveResult(assemblyReferenceNode.Reference);
#endif
                            if (assemblyResolveResult != null)
                            {
                                assemblyFile = Enumerable.FirstOrDefault(assemblyResolveResult.GetFiles());
                            }
                        }
                    }

                    AssemblyInfoCache component = SolutionEx.TryGetComponent <AssemblyInfoCache>(solution);
#if DP10
                    if (component != null && assemblyFile.Location.ExistsFile)
                    {
                        console.LoadAssemblies(new[] { assemblyFile.Location.FullPath });
                    }
#elif DP11 || DP12
                    if (component != null && assemblyFile.Location.ExistsFile && !AssemblyExplorerUtil.AssemblyIsBroken(assemblyFile.Location, component))
                    {
                        console.LoadAssemblies(new[] { assemblyFile.Location.FullPath });
                    }
#endif
                }
            }
        }