Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: obsolete/Microsoft.VisualStudio.Project/Automation/AutomationScope.cs

Issue 10928195: First round of dead file removal (Closed) Base URL: https://github.com/samclegg/nativeclient-sdk.git@master
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /// Copyright (c) Microsoft Corporation. All rights reserved.
2
3 using System;
4 using Microsoft.VisualStudio.Shell.Interop;
5 using ErrorHandler = Microsoft.VisualStudio.ErrorHandler;
6
7 namespace Microsoft.VisualStudio.Project.Automation
8 {
9 /// <summary>
10 /// Helper class that handle the scope of an automation function.
11 /// It should be used inside a "using" directive to define the scope of the
12 /// automation function and make sure that the ExitAutomation method is called.
13 /// </summary>
14 internal class AutomationScope : IDisposable
15 {
16 private IVsExtensibility3 extensibility;
17 private bool inAutomation;
18 private static volatile object Mutex;
19 private bool isDisposed;
20
21 /// <summary>
22 /// Initializes the <see cref="AutomationScope"/> class.
23 /// </summary>
24 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Perf ormance", "CA1810:InitializeReferenceTypeStaticFieldsInline")]
25 static AutomationScope()
26 {
27 Mutex = new object();
28 }
29
30 /// <summary>
31 /// Defines the beginning of the scope of an automation function . This constuctor
32 /// calls EnterAutomationFunction to signal the Shell that the c urrent function is
33 /// changing the status of the automation objects.
34 /// </summary>
35 public AutomationScope(IServiceProvider provider)
36 {
37 if(null == provider)
38 {
39 throw new ArgumentNullException("provider");
40 }
41 extensibility = provider.GetService(typeof(EnvDTE.IVsExt ensibility)) as IVsExtensibility3;
42 if(null == extensibility)
43 {
44 throw new InvalidOperationException();
45 }
46 ErrorHandler.ThrowOnFailure(extensibility.EnterAutomatio nFunction());
47 inAutomation = true;
48 }
49
50 /// <summary>
51 /// Ends the scope of the automation function. This function is also called by the
52 /// Dispose method.
53 /// </summary>
54 public void ExitAutomation()
55 {
56 if(inAutomation)
57 {
58 ErrorHandler.ThrowOnFailure(extensibility.ExitAu tomationFunction());
59 inAutomation = false;
60 }
61 }
62
63 /// <summary>
64 /// Gets the IVsExtensibility3 interface used in the automation function.
65 /// </summary>
66 public IVsExtensibility3 Extensibility
67 {
68 get { return extensibility; }
69 }
70
71 /// <summary>
72 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
73 /// </summary>
74 public void Dispose()
75 {
76 this.Dispose(true);
77 GC.SuppressFinalize(this);
78 }
79
80 #region IDisposable Members
81 private void Dispose(bool disposing)
82 {
83 if(!this.isDisposed)
84 {
85 lock(Mutex)
86 {
87 if(disposing)
88 {
89 ExitAutomation();
90 }
91
92 this.isDisposed = true;
93 }
94 }
95 }
96 #endregion
97 }
98 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698