OLD | NEW |
| (Empty) |
1 /// Copyright (c) Microsoft Corporation. All rights reserved. | |
2 | |
3 using System; | |
4 using System.Diagnostics; | |
5 using System.Runtime.InteropServices; | |
6 using Microsoft.VisualStudio; | |
7 using Microsoft.VisualStudio.Shell.Interop; | |
8 using IServiceProvider = System.IServiceProvider; | |
9 using ShellConstants = Microsoft.VisualStudio.Shell.Interop.Constants; | |
10 | |
11 namespace Microsoft.VisualStudio.Project | |
12 { | |
13 /// <summary> | |
14 /// helper to make the editor ignore external changes | |
15 /// </summary> | |
16 internal class SuspendFileChanges | |
17 { | |
18 private string documentFileName; | |
19 | |
20 private bool isSuspending; | |
21 | |
22 private IServiceProvider site; | |
23 | |
24 private IVsDocDataFileChangeControl fileChangeControl; | |
25 | |
26 public SuspendFileChanges(IServiceProvider site, string document
) | |
27 { | |
28 this.site = site; | |
29 this.documentFileName = document; | |
30 } | |
31 | |
32 | |
33 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Perf
ormance", "CA1800:DoNotCastUnnecessarily")] | |
34 public void Suspend() | |
35 { | |
36 if(this.isSuspending) | |
37 return; | |
38 | |
39 IntPtr docData = IntPtr.Zero; | |
40 try | |
41 { | |
42 IVsRunningDocumentTable rdt = this.site.GetServi
ce(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; | |
43 | |
44 IVsHierarchy hierarchy; | |
45 uint itemId; | |
46 uint docCookie; | |
47 IVsFileChangeEx fileChange; | |
48 | |
49 | |
50 if(rdt == null) return; | |
51 | |
52 ErrorHandler.ThrowOnFailure(rdt.FindAndLockDocum
ent((uint)_VSRDTFLAGS.RDT_NoLock, this.documentFileName, out hierarchy, out item
Id, out docData, out docCookie)); | |
53 | |
54 if((docCookie == (uint)ShellConstants.VSDOCCOOKI
E_NIL) || docData == IntPtr.Zero) | |
55 return; | |
56 | |
57 fileChange = this.site.GetService(typeof(SVsFile
ChangeEx)) as IVsFileChangeEx; | |
58 | |
59 if(fileChange != null) | |
60 { | |
61 this.isSuspending = true; | |
62 ErrorHandler.ThrowOnFailure(fileChange.I
gnoreFile(0, this.documentFileName, 1)); | |
63 if(docData != IntPtr.Zero) | |
64 { | |
65 IVsPersistDocData persistDocData
= null; | |
66 | |
67 // if interface is not supported
, return null | |
68 object unknown = Marshal.GetObje
ctForIUnknown(docData); | |
69 if(unknown is IVsPersistDocData) | |
70 { | |
71 persistDocData = (IVsPer
sistDocData)unknown; | |
72 if(persistDocData is IVs
DocDataFileChangeControl) | |
73 { | |
74 this.fileChangeC
ontrol = (IVsDocDataFileChangeControl)persistDocData; | |
75 if(this.fileChan
geControl != null) | |
76 { | |
77 ErrorHan
dler.ThrowOnFailure(this.fileChangeControl.IgnoreFileChanges(1)); | |
78 } | |
79 } | |
80 } | |
81 } | |
82 } | |
83 } | |
84 catch(InvalidCastException e) | |
85 { | |
86 Trace.WriteLine("Exception" + e.Message); | |
87 } | |
88 finally | |
89 { | |
90 if(docData != IntPtr.Zero) | |
91 { | |
92 Marshal.Release(docData); | |
93 } | |
94 } | |
95 return; | |
96 } | |
97 | |
98 public void Resume() | |
99 { | |
100 if(!this.isSuspending) | |
101 return; | |
102 IVsFileChangeEx fileChange; | |
103 fileChange = this.site.GetService(typeof(SVsFileChangeEx
)) as IVsFileChangeEx; | |
104 if(fileChange != null) | |
105 { | |
106 this.isSuspending = false; | |
107 ErrorHandler.ThrowOnFailure(fileChange.IgnoreFil
e(0, this.documentFileName, 0)); | |
108 if(this.fileChangeControl != null) | |
109 { | |
110 ErrorHandler.ThrowOnFailure(this.fileCha
ngeControl.IgnoreFileChanges(0)); | |
111 } | |
112 } | |
113 } | |
114 } | |
115 } | |
OLD | NEW |