OLD | NEW |
| (Empty) |
1 /// Copyright (c) Microsoft Corporation. All rights reserved. | |
2 | |
3 using System; | |
4 using System.Diagnostics; | |
5 using Microsoft.VisualStudio; | |
6 using Microsoft.VisualStudio.Shell; | |
7 using Microsoft.VisualStudio.Shell.Interop; | |
8 using ShellConstants = Microsoft.VisualStudio.Shell.Interop.Constants; | |
9 using System.Diagnostics.CodeAnalysis; | |
10 | |
11 namespace Microsoft.VisualStudio.Project | |
12 { | |
13 | |
14 [CLSCompliant(false)] | |
15 public abstract class ProjectDocumentsListener : IVsTrackProjectDocument
sEvents2, IDisposable | |
16 { | |
17 #region fields | |
18 private uint eventsCookie; | |
19 private IVsTrackProjectDocuments2 projectDocTracker; | |
20 private ServiceProvider serviceProvider; | |
21 private bool isDisposed; | |
22 /// <summary> | |
23 /// Defines an object that will be a mutex for this object for s
ynchronizing thread calls. | |
24 /// </summary> | |
25 private static volatile object Mutex = new object(); | |
26 #endregion | |
27 | |
28 #region ctors | |
29 protected ProjectDocumentsListener(ServiceProvider serviceProvid
er) | |
30 { | |
31 | |
32 this.serviceProvider = serviceProvider; | |
33 this.projectDocTracker = serviceProvider.GetService(type
of(SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2; | |
34 | |
35 Debug.Assert(this.projectDocTracker != null, "Could not
get the IVsTrackProjectDocuments2 object from the services exposed by this proje
ct"); | |
36 | |
37 if(this.projectDocTracker == null) | |
38 { | |
39 throw new InvalidOperationException(); | |
40 } | |
41 } | |
42 #endregion | |
43 | |
44 #region properties | |
45 protected uint EventsCookie | |
46 { | |
47 get | |
48 { | |
49 return this.eventsCookie; | |
50 } | |
51 } | |
52 | |
53 protected IVsTrackProjectDocuments2 ProjectDocumentTracker2 | |
54 { | |
55 get | |
56 { | |
57 return this.projectDocTracker; | |
58 } | |
59 } | |
60 | |
61 protected ServiceProvider ServiceProvider | |
62 { | |
63 get | |
64 { | |
65 return this.serviceProvider; | |
66 } | |
67 } | |
68 #endregion | |
69 | |
70 #region IVsTrackProjectDocumentsEvents2 Members | |
71 | |
72 public virtual int OnAfterAddDirectoriesEx(int cProjects, int cD
irectories, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgpszMkDocu
ments, VSADDDIRECTORYFLAGS[] rgFlags) | |
73 { | |
74 return VSConstants.E_NOTIMPL; | |
75 } | |
76 | |
77 public virtual int OnAfterAddFilesEx(int cProjects, int cFiles,
IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgpszMkDocuments, VSADD
FILEFLAGS[] rgFlags) | |
78 { | |
79 return VSConstants.E_NOTIMPL; | |
80 } | |
81 | |
82 public virtual int OnAfterRemoveDirectories(int cProjects, int c
Directories, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgpszMkDoc
uments, VSREMOVEDIRECTORYFLAGS[] rgFlags) | |
83 { | |
84 return VSConstants.E_NOTIMPL; | |
85 } | |
86 | |
87 public virtual int OnAfterRemoveFiles(int cProjects, int cFiles,
IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgpszMkDocuments, VSRE
MOVEFILEFLAGS[] rgFlags) | |
88 { | |
89 return VSConstants.E_NOTIMPL; | |
90 } | |
91 | |
92 public virtual int OnAfterRenameDirectories(int cProjects, int c
Dirs, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgszMkOldNames, s
tring[] rgszMkNewNames, VSRENAMEDIRECTORYFLAGS[] rgFlags) | |
93 { | |
94 return VSConstants.E_NOTIMPL; | |
95 } | |
96 | |
97 public virtual int OnAfterRenameFiles(int cProjects, int cFiles,
IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgszMkOldNames, string
[] rgszMkNewNames, VSRENAMEFILEFLAGS[] rgFlags) | |
98 { | |
99 return VSConstants.E_NOTIMPL; | |
100 } | |
101 | |
102 public virtual int OnAfterSccStatusChanged(int cProjects, int cF
iles, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgpszMkDocuments,
uint[] rgdwSccStatus) | |
103 { | |
104 return VSConstants.E_NOTIMPL; | |
105 } | |
106 | |
107 public virtual int OnQueryAddDirectories(IVsProject pProject, in
t cDirectories, string[] rgpszMkDocuments, VSQUERYADDDIRECTORYFLAGS[] rgFlags, V
SQUERYADDDIRECTORYRESULTS[] pSummaryResult, VSQUERYADDDIRECTORYRESULTS[] rgResul
ts) | |
108 { | |
109 return VSConstants.E_NOTIMPL; | |
110 } | |
111 | |
112 public virtual int OnQueryAddFiles(IVsProject pProject, int cFil
es, string[] rgpszMkDocuments, VSQUERYADDFILEFLAGS[] rgFlags, VSQUERYADDFILERESU
LTS[] pSummaryResult, VSQUERYADDFILERESULTS[] rgResults) | |
113 { | |
114 return VSConstants.E_NOTIMPL; | |
115 } | |
116 | |
117 public virtual int OnQueryRemoveDirectories(IVsProject pProject,
int cDirectories, string[] rgpszMkDocuments, VSQUERYREMOVEDIRECTORYFLAGS[] rgFl
ags, VSQUERYREMOVEDIRECTORYRESULTS[] pSummaryResult, VSQUERYREMOVEDIRECTORYRESUL
TS[] rgResults) | |
118 { | |
119 return VSConstants.E_NOTIMPL; | |
120 } | |
121 | |
122 public virtual int OnQueryRemoveFiles(IVsProject pProject, int c
Files, string[] rgpszMkDocuments, VSQUERYREMOVEFILEFLAGS[] rgFlags, VSQUERYREMOV
EFILERESULTS[] pSummaryResult, VSQUERYREMOVEFILERESULTS[] rgResults) | |
123 { | |
124 return VSConstants.E_NOTIMPL; | |
125 } | |
126 | |
127 public virtual int OnQueryRenameDirectories(IVsProject pProject,
int cDirs, string[] rgszMkOldNames, string[] rgszMkNewNames, VSQUERYRENAMEDIREC
TORYFLAGS[] rgFlags, VSQUERYRENAMEDIRECTORYRESULTS[] pSummaryResult, VSQUERYRENA
MEDIRECTORYRESULTS[] rgResults) | |
128 { | |
129 return VSConstants.E_NOTIMPL; | |
130 } | |
131 | |
132 public virtual int OnQueryRenameFiles(IVsProject pProject, int c
Files, string[] rgszMkOldNames, string[] rgszMkNewNames, VSQUERYRENAMEFILEFLAGS[
] rgFlags, VSQUERYRENAMEFILERESULTS[] pSummaryResult, VSQUERYRENAMEFILERESULTS[]
rgResults) | |
133 { | |
134 return VSConstants.E_NOTIMPL; | |
135 } | |
136 | |
137 #endregion | |
138 | |
139 #region IDisposable Members | |
140 /// <summary> | |
141 /// The IDispose interface Dispose method for disposing the obje
ct determinastically. | |
142 /// </summary> | |
143 public void Dispose() | |
144 { | |
145 this.Dispose(true); | |
146 GC.SuppressFinalize(this); | |
147 } | |
148 #endregion | |
149 | |
150 #region methods | |
151 public void Init() | |
152 { | |
153 if(this.ProjectDocumentTracker2 != null) | |
154 { | |
155 ErrorHandler.ThrowOnFailure(this.ProjectDocument
Tracker2.AdviseTrackProjectDocumentsEvents(this, out this.eventsCookie)); | |
156 } | |
157 } | |
158 | |
159 /// <summary> | |
160 /// The method that does the cleanup. | |
161 /// </summary> | |
162 /// <param name="disposing"></param> | |
163 [SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodRes
ults", MessageId = "Microsoft.VisualStudio.Shell.Interop.IVsTrackProjectDocument
s2.UnadviseTrackProjectDocumentsEvents(System.UInt32)")] | |
164 protected virtual void Dispose(bool disposing) | |
165 { | |
166 // Everybody can go here. | |
167 if(!this.isDisposed) | |
168 { | |
169 // Synchronize calls to the Dispose simultenious
ly. | |
170 lock(Mutex) | |
171 { | |
172 if(disposing && this.eventsCookie != (ui
nt)ShellConstants.VSCOOKIE_NIL && this.ProjectDocumentTracker2 != null) | |
173 { | |
174 this.ProjectDocumentTracker2.Una
dviseTrackProjectDocumentsEvents((uint)this.eventsCookie); | |
175 this.eventsCookie = (uint)ShellC
onstants.VSCOOKIE_NIL; | |
176 } | |
177 | |
178 this.isDisposed = true; | |
179 } | |
180 } | |
181 } | |
182 #endregion | |
183 } | |
184 } | |
OLD | NEW |