Here are the examples of the csharp api System.IServiceProvider.GetService(bool) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
19
Source : ShellEventsService.cs
with GNU General Public License v3.0
from sergey-visual-studio
with GNU General Public License v3.0
from sergey-visual-studio
public void Dispose()
{
ThreadHelper.ThrowIfNotOnUIThread();
if (_solutionEvents != null)
{
_solutionEvents.Renamed -= SolutionEvents_Renamed;
_solutionEvents = null;
}
if (_doreplacedentEvents != null)
{
_doreplacedentEvents.DoreplacedentOpened -= DoreplacedentEvents_DoreplacedentOpened;
_doreplacedentEvents.DoreplacedentClosing -= DoreplacedentEvents_DoreplacedentClosing;
_doreplacedentEvents.DoreplacedentSaved -= DoreplacedentEvents_DoreplacedentSaved;
_doreplacedentEvents = null;
}
if (_codeModelEvents != null)
{
_codeModelEvents.ElementAdded -= CodeModelEvents_ElementAdded;
_codeModelEvents.ElementChanged -= CodeModelEvents_ElementChanged;
_codeModelEvents.ElementDeleted -= CodeModelEvents_ElementDeleted;
_codeModelEvents = null;
}
if (_solutionCookie != 0)
{
var solution = _serviceProvider.GetService<IVsSolution, SVsSolution>(false);
if (solution != null)
solution.UnadviseSolutionEvents(_solutionCookie);
}
if (_docEventsCookie != 0)
{
var docEvents = _serviceProvider.GetService<IVsTrackProjectDoreplacedents2, SVsTrackProjectDoreplacedents>(false);
if (docEvents != null)
docEvents.UnadviseTrackProjectDoreplacedentsEvents(_docEventsCookie);
}
if (_windowEventsCookie != 0)
{
var windowEvents = _serviceProvider.GetService<IVsRunningDoreplacedentTable, SVsRunningDoreplacedentTable>(false);
if (windowEvents != null)
windowEvents.UnadviseRunningDocTableEvents(_windowEventsCookie);
}
}
19
Source : ShellEventsService.cs
with GNU General Public License v3.0
from sergey-visual-studio
with GNU General Public License v3.0
from sergey-visual-studio
public int OnAfterSave(uint docCookie)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (!IsSolutionOpen())
return VSConstants.S_OK;
var dte = _shellProjectService.GetDTE() as DTE;
var fileName = dte.Solution.FileName;
if (string.IsNullOrEmpty(fileName))
return VSConstants.S_OK;
var rdt = _serviceProvider.GetService<IVsRunningDoreplacedentTable, SVsRunningDoreplacedentTable>(false);
if (rdt == null)
return VSConstants.S_OK;
var itemid = VSConstants.VSITEMID_NIL;
var result = rdt.GetDoreplacedentInfo(docCookie, out _, out _, out _, out string docFileName, out _, out itemid, out IntPtr ppunkDocData);
if (ppunkDocData != IntPtr.Zero)
Marshal.Release(ppunkDocData);
if (result != VSConstants.S_OK)
return VSConstants.S_OK;
// Check if it's a solution's item
if (string.Compare(fileName, docFileName, StringComparison.OrdinalIgnoreCase) == 0)
_solutionEventSubscribers.For(s => s.SolutionSaved());
return VSConstants.S_OK;
}
19
Source : ShellEventsService.cs
with GNU General Public License v3.0
from sergey-visual-studio
with GNU General Public License v3.0
from sergey-visual-studio
private void Initialize()
{
if (_initialized)
return;
ThreadHelper.ThrowIfNotOnUIThread();
try
{
var dte = _shellProjectService.GetDTE() as DTE2;
if (dte != null)
{
var events = dte.Events as Events2;
_solutionEvents = events?.SolutionEvents;
if (_solutionEvents != null)
_solutionEvents.Renamed += SolutionEvents_Renamed;
_doreplacedentEvents = events?.get_DoreplacedentEvents(null);
if (_doreplacedentEvents != null)
{
_doreplacedentEvents.DoreplacedentOpened += DoreplacedentEvents_DoreplacedentOpened;
_doreplacedentEvents.DoreplacedentClosing += DoreplacedentEvents_DoreplacedentClosing;
_doreplacedentEvents.DoreplacedentSaved += DoreplacedentEvents_DoreplacedentSaved;
}
_codeModelEvents = events?.get_CodeModelEvents(null);
if (_codeModelEvents != null)
{
_codeModelEvents.ElementAdded += CodeModelEvents_ElementAdded;
_codeModelEvents.ElementChanged += CodeModelEvents_ElementChanged;
_codeModelEvents.ElementDeleted += CodeModelEvents_ElementDeleted;
}
}
var solution = _serviceProvider.GetService<IVsSolution, SVsSolution>(false);
if (solution != null)
solution.AdviseSolutionEvents(this, out _solutionCookie);
var docEvents = _serviceProvider.GetService<IVsTrackProjectDoreplacedents2, SVsTrackProjectDoreplacedents>(false);
if (docEvents != null)
docEvents.AdviseTrackProjectDoreplacedentsEvents(this, out _docEventsCookie);
var windowEvents = _serviceProvider.GetService<IVsRunningDoreplacedentTable, SVsRunningDoreplacedentTable>(false);
if (windowEvents != null)
windowEvents.AdviseRunningDocTableEvents(this, out _windowEventsCookie);
}
finally
{
_initialized = true;
}
}