本文整理汇总了C#中Microsoft.VisualStudio.Shell.ServiceProvider类的典型用法代码示例。如果您正苦于以下问题:C# ServiceProvider类的具体用法?C# ServiceProvider怎么用?C# ServiceProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServiceProvider类属于Microsoft.VisualStudio.Shell命名空间,在下文中一共展示了ServiceProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpenDocument
public static IVsWindowFrame OpenDocument(string filePath, Action<IVsWindowFrame> creationCallback)
{
if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
return null;
var dte2 = (EnvDTE80.DTE2)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2;
Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp = (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte2;
Microsoft.VisualStudio.Shell.ServiceProvider serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(sp);
IVsUIHierarchy hierarchy;
uint itemId;
IVsWindowFrame frame = null;
if (!VsShellUtilities.IsDocumentOpen(serviceProvider, filePath,
VSConstants.LOGVIEWID_Primary, out hierarchy, out itemId, out frame))
{
VsShellUtilities.OpenDocument(serviceProvider, filePath,
VSConstants.LOGVIEWID_Primary, out hierarchy, out itemId, out frame);
if (creationCallback != null)
creationCallback(frame);
}
if (frame != null)
frame.Show();
return frame;
}
示例2: CreateErrorTask
internal static ErrorTask CreateErrorTask(
string document, string errorMessage, TextSpan textSpan, TaskErrorCategory taskErrorCategory, IVsHierarchy hierarchy,
uint itemID, MARKERTYPE markerType)
{
ErrorTask errorTask = null;
IOleServiceProvider oleSp = null;
hierarchy.GetSite(out oleSp);
IServiceProvider sp = new ServiceProvider(oleSp);
// see if Document is open
IVsTextLines buffer = null;
var docData = VSHelpers.GetDocData(sp, document);
if (docData != null)
{
buffer = VSHelpers.GetVsTextLinesFromDocData(docData);
}
if (buffer != null)
{
errorTask = new EFModelDocumentTask(sp, buffer, markerType, textSpan, document, itemID, errorMessage, hierarchy);
errorTask.ErrorCategory = taskErrorCategory;
}
else
{
errorTask = new EFModelErrorTask(
document, errorMessage, textSpan.iStartLine, textSpan.iEndLine, taskErrorCategory, hierarchy, itemID);
}
return errorTask;
}
示例3: CommandInvoke
private void CommandInvoke(object sender, EventArgs e)
{
OleMenuCmdEventArgs oOleMenuCmdEventArgs = (OleMenuCmdEventArgs)e;
DTE2 Application = (DTE2)GetService(typeof(DTE));
ProjectItem oProjectItem = Application.SelectedItems.Item(1).ProjectItem;
IServiceProvider oServiceProvider = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)Application);
Microsoft.Build.Evaluation.Project oBuildProject = Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection.GetLoadedProjects(oProjectItem.ContainingProject.FullName).SingleOrDefault();
Microsoft.Build.Evaluation.ProjectProperty oGUID = oBuildProject.AllEvaluatedProperties.SingleOrDefault(oProperty => oProperty.Name == "ProjectGuid");
Microsoft.VisualStudio.Shell.Interop.IVsHierarchy oVsHierarchy = VsShellUtilities.GetHierarchy(oServiceProvider, new Guid(oGUID.EvaluatedValue));
Microsoft.VisualStudio.Shell.Interop.IVsBuildPropertyStorage oVsBuildPropertyStorage = (Microsoft.VisualStudio.Shell.Interop.IVsBuildPropertyStorage)oVsHierarchy;
string szItemPath = (string)oProjectItem.Properties.Item("FullPath").Value;
uint nItemId;
oVsHierarchy.ParseCanonicalName(szItemPath, out nItemId);
if (oOleMenuCmdEventArgs.OutValue != IntPtr.Zero)
{
string szOut;
oVsBuildPropertyStorage.GetItemAttribute(nItemId, "ItemColor", out szOut);
Marshal.GetNativeVariantForObject(szOut, oOleMenuCmdEventArgs.OutValue);
}
else if (oOleMenuCmdEventArgs.InValue != null)
{
oVsBuildPropertyStorage.SetItemAttribute(nItemId, "ItemColor", Convert.ToString(oOleMenuCmdEventArgs.InValue));
}
}
示例4: ShowContextMenu
public static void ShowContextMenu(ContextMenuStrip contextMenu, DTE dte)
{
try
{
var serviceProvider = new ServiceProvider(dte as IServiceProvider);
IVsUIShellOpenDocument sod = (IVsUIShellOpenDocument)serviceProvider.GetService(typeof(SVsUIShellOpenDocument));
IVsUIHierarchy targetHier;
uint[] targetId = new uint[1];
IVsWindowFrame targetFrame;
int isOpen;
Guid viewId = new Guid(LogicalViewID.Primary);
sod.IsDocumentOpen(null, 0, dte.ActiveWindow.Document.FullName,
ref viewId, 0, out targetHier, targetId,
out targetFrame, out isOpen);
IVsTextView textView = VsShellUtilities.GetTextView(targetFrame);
TextSelection selection = (TextSelection)dte.ActiveWindow.Document.Selection;
Microsoft.VisualStudio.OLE.Interop.POINT[] interopPoint = new Microsoft.VisualStudio.OLE.Interop.POINT[1];
textView.GetPointOfLineColumn(selection.ActivePoint.Line, selection.ActivePoint.LineCharOffset, interopPoint);
POINT p = new POINT(interopPoint[0].x, interopPoint[0].y);
ClientToScreen(textView.GetWindowHandle(), p);
contextMenu.Show(new Point(p.x, p.y));
}
catch (Exception)
{
contextMenu.Show();
}
}
示例5: GetTextManager
private IVsTextManager GetTextManager(DTE2 application)
{
using (ServiceProvider wrapperSP = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)application))
{
return (IVsTextManager)wrapperSP.GetService(typeof(SVsTextManager));
}
}
示例6: RunStarted
/// <summary>
/// Executes when the wizard starts.
/// </summary>
public override void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, Microsoft.VisualStudio.TemplateWizard.WizardRunKind runKind, object[] customParams)
{
base.RunStarted(automationObject, replacementsDictionary, runKind, customParams);
var wizardData = this.TemplateSchema.WizardData.FirstOrDefault();
if (wizardData != null)
{
LoadWizards(wizardData);
using (var services = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)automationObject))
{
var components = services.GetService<SComponentModel, IComponentModel>();
foreach (var wizard in wizards)
{
TryOrDispose(() => AttributedModelServices.SatisfyImportsOnce(components.DefaultCompositionService, wizard));
}
}
}
foreach (var wizard in wizards)
{
TryOrDispose(() => wizard.RunStarted(automationObject, replacementsDictionary, runKind, customParams));
}
}
示例7: ToHierarchy
/// <summary>
/// Get the hierarchy corresponding to a Project
/// </summary>
/// <param name="project"></param>
/// <returns></returns>
public static IVsHierarchy ToHierarchy(EnvDTE.Project project)
{
if (project == null) throw new ArgumentNullException("project");
string projectGuid = null;
// DTE does not expose the project GUID that exists at in the msbuild project file.
// Cannot use MSBuild object model because it uses a static instance of the Engine,
// and using the Project will cause it to be unloaded from the engine when the
// GC collects the variable that we declare.
using (XmlReader projectReader = XmlReader.Create(project.FileName))
{
projectReader.MoveToContent();
object nodeName = projectReader.NameTable.Add("ProjectGuid");
while (projectReader.Read())
{
if (Object.Equals(projectReader.LocalName, nodeName))
{
// projectGuid = projectReader.ReadContentAsString();
projectGuid = projectReader.ReadElementContentAsString();
break;
}
}
}
Debug.Assert(!String.IsNullOrEmpty(projectGuid));
System.IServiceProvider serviceProvider = new ServiceProvider(project.DTE as
Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
return VsShellUtilities.GetHierarchy(serviceProvider, new Guid(projectGuid));
}
示例8: ProcessRecord
/// <summary>
/// The process record.
/// </summary>
/// <exception cref="PSInvalidOperationException">
/// An error occured
/// </exception>
protected override void ProcessRecord()
{
var project = this.Project as VSProject;
if (project == null)
{
throw new PSInvalidOperationException("Cannot cast the Project object to a VSProject");
}
var sp = new ServiceProvider((IOleServiceProvider)project.DTE);
// Get the toolbox
var svsToolbox = sp.GetService(typeof(SVsToolbox));
if (svsToolbox == null)
{
throw new PSInvalidOperationException("Cannot get global Toolbox Service (SVsToolbox)");
}
var toolbox = svsToolbox as IVsToolbox;
if (toolbox == null)
{
throw new PSInvalidOperationException("Cannot cast Toolbox Service to IVsToolbox");
}
toolbox.RemoveTab(this.Category);
}
示例9: Transform
private string Transform(string fileName, string source)
{
var sp = new ServiceProvider(_site as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
var vsproj = ((EnvDTE.ProjectItem)(sp.GetService(typeof(EnvDTE.ProjectItem)))).ContainingProject;
var cm = (IComponentModel)(Package.GetGlobalService(typeof(SComponentModel)));
var workspace = cm.GetService<VisualStudioWorkspace>();
var solution = workspace.CurrentSolution;
var project = solution.Projects.FirstOrDefault(p => p.FilePath == vsproj.FileName);
var syntaxTrees = Enumerable.Empty<SyntaxTree>();
if (project != null)
{
var c = project.GetCompilationAsync().Result;
syntaxTrees = c.SyntaxTrees;
}
var syntaxTree = CSharpSyntaxTree.ParseText(source);
var compilation = CSharpCompilation.Create("temp", syntaxTrees.Concat(new[] { syntaxTree }));
var rewriter = new NotifyPropertyChangedRewriter(fileName, compilation.GetSemanticModel(syntaxTree, true));
var result = rewriter.Visit(syntaxTree.GetRoot());
return result.ToFullString();
}
示例10: SqlEditorPane
public SqlEditorPane(ServiceProvider sp, SqlEditorFactory factory)
: base(sp)
{
Factory = factory;
DocumentPath = factory.LastDocumentPath;
editor = new SqlEditor(sp, this);
}
示例11: Initialize
/////////////////////////////////////////////////////////////////////////////
// Overridden Package Implementation
#region Package Members
/// <summary>
/// Initialization of the package; this method is called right after the package is sited, so this is the place
/// where you can put all the initialization code that rely on services provided by VisualStudio.
/// </summary>
protected override void Initialize()
{
Debug.WriteLine (string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
base.Initialize();
// Add our command handlers for menu (commands must exist in the .vsct file)
OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if ( null != mcs )
{
DTE dte = (DTE)GetService(typeof(DTE));
migrator = new Migrator(dte);
var serviceProvider = new ServiceProvider((IServiceProvider)dte);
solutionLoadEvents = new SolutionLoadEvents(serviceProvider);
synchronizationContext = SynchronizationContext.Current;
solutionLoadEvents.BeforeSolutionLoaded += () =>
{
synchronizationContext.Post(_ => migrator.OnBeforeSolutionLoaded(), null);
};
solutionLoadEvents.AfterSolutionLoaded += () =>
{
synchronizationContext.Post(_ => migrator.OnAfterSolutionLoaded(), null);
};
// Create the command for the menu item.
CommandID menuCommandID = new CommandID(GuidList.guidTargetFrameworkMigratorCmdSet, (int)PkgCmdIDList.cmdidTargetFrameworkMigrator);
MenuCommand menuItem = new MenuCommand(MenuItemCallback, menuCommandID );
mcs.AddCommand( menuItem );
}
}
示例12: PropertiesEditorLauncher
public PropertiesEditorLauncher(ServiceProvider serviceProvider)
{
if(serviceProvider == null)
throw new ArgumentNullException("serviceProvider");
this.serviceProvider = serviceProvider;
}
示例13: CreateErrorListProvider
private void CreateErrorListProvider()
{
IServiceProvider serviceProvider = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)mApplication);
mErrorListProvider = new ErrorListProvider(serviceProvider);
mErrorListProvider.ProviderName = "CppCheck Errors";
mErrorListProvider.ProviderGuid = new Guid("5A10E43F-8D1D-4026-98C0-E6B502058901");
}
示例14: VsTextViewCreated
/// <summary>
/// Creates a plugin instance when a new text editor is opened
/// </summary>
public void VsTextViewCreated(IVsTextView adapter)
{
IWpfTextView view = adapterFactory.GetWpfTextView(adapter);
if (view == null)
return;
ITextDocument document;
if (!docFactory.TryGetTextDocument(view.TextDataModel.DocumentBuffer, out document))
return;
IObjectWithSite iows = adapter as IObjectWithSite;
if (iows == null)
return;
System.IntPtr p;
iows.GetSite(typeof(IServiceProvider).GUID, out p);
if (p == System.IntPtr.Zero)
return;
IServiceProvider isp = Marshal.GetObjectForIUnknown(p) as IServiceProvider;
if (isp == null)
return;
ServiceProvider sp = new ServiceProvider(isp);
DTE dte = sp.GetService(typeof(DTE)) as DTE;
sp.Dispose();
new Plugin(view, document, dte);
}
示例15: SqlEditor
internal SqlEditor(ServiceProvider sp, SqlEditorPane pane )
: this()
{
Pane = pane;
serviceProvider = sp;
codeEditor.Init(sp, this);
}