コード例 #1
0
        void DocumentService_CollectionChanged(object sender, NotifyDocumentCollectionChangedEventArgs e)
        {
            switch (e.Type)
            {
            case NotifyDocumentCollectionType.Clear:
                vmSearch.Clear();
                break;

            case NotifyDocumentCollectionType.Add:
                // Only restart the search if the file was explicitly loaded by the user. Assembly
                // resolves shouldn't restart the search since it happens too often.
                if (e.Documents.Any(a => !a.IsAutoLoaded))
                {
                    vmSearch.Restart();
                }
                break;

            case NotifyDocumentCollectionType.Remove:
                // We only need to restart the search if the search has not completed or if any of
                // the search results contain a reference to the assembly.
                vmSearch.Restart();
                break;

            default:
                Debug.Fail("Unknown NotifyFileCollectionType");
                break;
            }
        }
コード例 #2
0
        void DocumentTabService_FileCollectionChanged(object sender, NotifyDocumentCollectionChangedEventArgs e)
        {
            Debug.Assert(dbgCodeBreakpointsService != null);
            if (dbgCodeBreakpointsService == null)
            {
                return;
            }
            switch (e.Type)
            {
            case NotifyDocumentCollectionType.Clear:
            case NotifyDocumentCollectionType.Remove:
                var existing = new HashSet <ModuleId>(documentTabService.Value.DocumentTreeView.GetAllModuleNodes().Select(a => moduleIdProvider.Value.Create(a.Document.ModuleDef)));
                var removed  = new HashSet <ModuleId>(e.Documents.Select(a => moduleIdProvider.Value.Create(a.ModuleDef)));
                existing.Remove(new ModuleId());
                removed.Remove(new ModuleId());
                List <DbgCodeBreakpoint> breakpointsToRemove = null;
                foreach (var bp in dbgCodeBreakpointsService.Breakpoints)
                {
                    if (bp.IsHidden)
                    {
                        continue;
                    }
                    if (!(bp.Location is DbgDotNetCodeLocation location))
                    {
                        continue;
                    }
                    // Don't auto-remove BPs in dynamic modules since they have no disk file. The
                    // user must delete these him/herself.
                    if (location.Module.IsDynamic)
                    {
                        continue;
                    }

                    // If the file is still in the TV, don't delete anything. This can happen if
                    // we've loaded an in-memory module and the node just got removed.
                    if (existing.Contains(location.Module))
                    {
                        continue;
                    }

                    if (removed.Contains(location.Module))
                    {
                        if (breakpointsToRemove == null)
                        {
                            breakpointsToRemove = new List <DbgCodeBreakpoint>();
                        }
                        breakpointsToRemove.Add(bp);
                    }
                }
                if (breakpointsToRemove != null)
                {
                    dbgCodeBreakpointsService.Remove(breakpointsToRemove.ToArray());
                }
                break;

            case NotifyDocumentCollectionType.Add:
                break;
            }
        }
コード例 #3
0
 void CallDocumentCollectionChanged(NotifyDocumentCollectionChangedEventArgs e)
 {
     if (disable_DocumentCollectionChanged)
     {
         return;
     }
     DocumentCollectionChanged?.Invoke(this, e);
 }
コード例 #4
0
ファイル: DsDocumentService.cs プロジェクト: haise0/dnSurgeon
 void CallCollectionChanged2(NotifyDocumentCollectionChangedEventArgs eventArgs)
 {
     if (eventArgs.Type == NotifyDocumentCollectionType.Clear)
     {
         assemblyResolver.OnAssembliesCleared();
     }
     CollectionChanged?.Invoke(this, eventArgs);
 }
コード例 #5
0
ファイル: DsDocumentService.cs プロジェクト: haise0/dnSurgeon
 void CallCollectionChanged(NotifyDocumentCollectionChangedEventArgs eventArgs, bool delayLoad = true)
 {
     if (delayLoad && dispatcher is not null)
     {
         dispatcher(() => CallCollectionChanged2(eventArgs));
     }
     else
     {
         CallCollectionChanged2(eventArgs);
     }
 }
コード例 #6
0
 public void Clear()
 {
     IDsDocument[] oldDocuments;
     lock (lockObj) {
         oldDocuments = documents.ToArray();
         documents.Clear();
     }
     if (oldDocuments.Length != 0)
     {
         CallCollectionChanged(NotifyDocumentCollectionChangedEventArgs.CreateClear(oldDocuments, null));
     }
 }
コード例 #7
0
        public IDsDocument ForceAdd(IDsDocument document, bool delayLoad, object data)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            lock (lockObj)
                documents.Add(document);

            CallCollectionChanged(NotifyDocumentCollectionChangedEventArgs.CreateAdd(document, data), delayLoad);
            return(document);
        }
コード例 #8
0
ファイル: DsDocumentService.cs プロジェクト: haise0/dnSurgeon
 public void Clear()
 {
     IDsDocument[] oldDocuments;
     rwLock.EnterWriteLock();
     try {
         oldDocuments = documents.Select(a => a.Document).ToArray();
         documents.Clear();
     }
     finally {
         rwLock.ExitWriteLock();
     }
     if (oldDocuments.Length != 0)
     {
         CallCollectionChanged(NotifyDocumentCollectionChangedEventArgs.CreateClear(oldDocuments, null));
     }
 }
コード例 #9
0
        public IDsDocument GetOrAdd(IDsDocument document)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            IDsDocument result;

            lock (lockObj)
                result = GetOrAdd_NoLock(document);
            if (result == document)
            {
                CallCollectionChanged(NotifyDocumentCollectionChangedEventArgs.CreateAdd(result, null));
            }
            return(result);
        }
コード例 #10
0
            public void Dispose()
            {
                foreach (var document in documentTabService.DocumentTreeView.DocumentService.GetDocuments())
                {
                    originalDocuments.Remove(document);
                }
                var removedDocuments = originalDocuments.ToArray();

                // Documents are added with a delay to the TV. Make sure our code executes after all
                // of the pending events.
                documentTabService.DocumentTreeView.AddAction(() => {
                    documentTabService.disable_DocumentCollectionChanged = old_disable_DocumentCollectionChanged;
                    if (removedDocuments.Length > 0)
                    {
                        documentTabService.CallDocumentCollectionChanged(NotifyDocumentCollectionChangedEventArgs.CreateRemove(removedDocuments, null));
                    }
                });
            }
コード例 #11
0
        public void Remove(IDsDocumentNameKey key)
        {
            Debug.Assert(key != null);
            if (key == null)
            {
                return;
            }

            IDsDocument removedDocument;

            lock (lockObj)
                removedDocument = Remove_NoLock(key);
            Debug.Assert(removedDocument != null);

            if (removedDocument != null)
            {
                CallCollectionChanged(NotifyDocumentCollectionChangedEventArgs.CreateRemove(removedDocument, null));
            }
        }
コード例 #12
0
        void DocumentTabService_FileCollectionChanged(object sender, NotifyDocumentCollectionChangedEventArgs e)
        {
            switch (e.Type)
            {
            case NotifyDocumentCollectionType.Clear:
            case NotifyDocumentCollectionType.Remove:
                var existing = new HashSet <ModuleId>(documentTabService.DocumentTreeView.GetAllModuleNodes().Select(a => moduleIdProvider.Create(a.Document.ModuleDef)));
                var removed  = new HashSet <ModuleId>(e.Documents.Select(a => moduleIdProvider.Create(a.ModuleDef)));
                existing.Remove(new ModuleId());
                removed.Remove(new ModuleId());
                object orbArg = null;
                if (OnRemoveBreakpoints != null)
                {
                    orbArg = OnRemoveBreakpoints(orbArg);
                }
                foreach (var ilbp in GetILCodeBreakpoints())
                {
                    // Don't auto-remove BPs in dynamic modules since they have no disk file. The
                    // user must delete these him/herself.
                    if (ilbp.MethodToken.Module.IsDynamic)
                    {
                        continue;
                    }

                    // If the file is still in the TV, don't delete anything. This can happen if
                    // we've loaded an in-memory module and the node just got removed.
                    if (existing.Contains(ilbp.MethodToken.Module))
                    {
                        continue;
                    }

                    if (removed.Contains(ilbp.MethodToken.Module))
                    {
                        Remove(ilbp);
                    }
                }
                OnRemoveBreakpoints?.Invoke(orbArg);
                break;

            case NotifyDocumentCollectionType.Add:
                break;
            }
        }
コード例 #13
0
ファイル: AnalyzerService.cs プロジェクト: pashav15/pashav
        void DocumentService_CollectionChanged(object sender, NotifyDocumentCollectionChangedEventArgs e)
        {
            switch (e.Type)
            {
            case NotifyDocumentCollectionType.Clear:
                ClearAll();
                break;

            case NotifyDocumentCollectionType.Add:
                AnalyzerTreeNodeData.HandleAssemblyListChanged(TreeView.Root, Array.Empty <IDsDocument>(), e.Documents);
                break;

            case NotifyDocumentCollectionType.Remove:
                AnalyzerTreeNodeData.HandleAssemblyListChanged(TreeView.Root, e.Documents, Array.Empty <IDsDocument>());
                break;

            default:
                break;
            }
        }
コード例 #14
0
        public void Remove(IEnumerable <IDsDocument> documents)
        {
            var removedDocuments = new List <IDsDocument>();

            lock (lockObj) {
                var dict = new Dictionary <IDsDocument, int>();
                int i    = 0;
                foreach (var n in this.documents)
                {
                    dict[n] = i++;
                }
                var list = new List <Tuple <IDsDocument, int> >(documents.Select(a => {
                    int j;
                    bool b = dict.TryGetValue(a, out j);
                    Debug.Assert(b);
                    return(Tuple.Create(a, b ? j : -1));
                }));
                list.Sort((a, b) => b.Item2.CompareTo(a.Item2));
                foreach (var t in list)
                {
                    if (t.Item2 < 0)
                    {
                        continue;
                    }
                    Debug.Assert((uint)t.Item2 < (uint)this.documents.Count);
                    Debug.Assert(this.documents[t.Item2] == t.Item1);
                    this.documents.RemoveAt(t.Item2);
                    removedDocuments.Add(t.Item1);
                }
            }

            if (removedDocuments.Count > 0)
            {
                CallCollectionChanged(NotifyDocumentCollectionChangedEventArgs.CreateRemove(removedDocuments.ToArray(), null));
            }
        }
コード例 #15
0
ファイル: DocumentTreeView.cs プロジェクト: weimingtom/dnSpy
        void DocumentService_CollectionChanged(object sender, NotifyDocumentCollectionChangedEventArgs e)
        {
            switch (e.Type)
            {
            case NotifyDocumentCollectionType.Add:
                IDsDocumentNode newNode;

                var addDocumentInfo = e.Data as AddDocumentInfo;
                int index;
                if (addDocumentInfo != null)
                {
                    newNode = addDocumentInfo.DsDocumentNode;
                    index   = addDocumentInfo.Index;
                    if (newNode.TreeNode == null)
                    {
                        TreeView.Create(newNode);
                    }
                }
                else
                {
                    newNode = CreateNode(null, e.Documents[0]);
                    TreeView.Create(newNode);
                    index = TreeView.Root.Children.Count;
                }

                if ((uint)index >= (uint)TreeView.Root.Children.Count)
                {
                    index = TreeView.Root.Children.Count;
                }
                TreeView.Root.Children.Insert(index, newNode.TreeNode);
                CallCollectionChanged(NotifyDocumentTreeViewCollectionChangedEventArgs.CreateAdd(newNode));
                break;

            case NotifyDocumentCollectionType.Remove:
                var dict  = new Dictionary <IDsDocumentNode, int>();
                var dict2 = new Dictionary <IDsDocument, IDsDocumentNode>();
                int i     = 0;
                foreach (var n in TopNodes)
                {
                    dict[n]           = i++;
                    dict2[n.Document] = n;
                }
                var list = new List <Tuple <IDsDocumentNode, int> >(e.Documents.Select(a => {
                    IDsDocumentNode node;
                    bool b = dict2.TryGetValue(a, out node);
                    Debug.Assert(b);
                    int j = -1;
                    b     = b && dict.TryGetValue(node, out j);
                    Debug.Assert(b);
                    return(Tuple.Create(node, b ? j : -1));
                }));
                list.Sort((a, b) => b.Item2.CompareTo(a.Item2));
                var removed = new List <IDsDocumentNode>();
                foreach (var t in list)
                {
                    if (t.Item2 < 0)
                    {
                        continue;
                    }
                    Debug.Assert((uint)t.Item2 < (uint)TreeView.Root.Children.Count);
                    Debug.Assert(TreeView.Root.Children[t.Item2].Data == t.Item1);
                    TreeView.Root.Children.RemoveAt(t.Item2);
                    removed.Add(t.Item1);
                }
                DisableMemoryMappedIO(list.Select(a => a.Item1).ToArray());
                CallCollectionChanged(NotifyDocumentTreeViewCollectionChangedEventArgs.CreateRemove(removed.ToArray()));
                break;

            case NotifyDocumentCollectionType.Clear:
                var oldNodes = TreeView.Root.Children.Select(a => (IDsDocumentNode)a.Data).ToArray();
                TreeView.Root.Children.Clear();
                DisableMemoryMappedIO(oldNodes);
                CallCollectionChanged(NotifyDocumentTreeViewCollectionChangedEventArgs.CreateClear(oldNodes));
                break;

            default:
                Debug.Fail(string.Format("Unknown event type: {0}", e.Type));
                break;
            }
        }
コード例 #16
0
 void DocumentService_CollectionChanged(object sender, NotifyDocumentCollectionChangedEventArgs e) => CallDocumentCollectionChanged(e);
コード例 #17
0
 void CallCollectionChanged2(NotifyDocumentCollectionChangedEventArgs eventArgs) =>
 CollectionChanged?.Invoke(this, eventArgs);