本文整理汇总了C#中Microsoft.VisualStudio.Shell.ServiceProvider类的典型用法代码示例。如果您正苦于以下问题:C# ServiceProvider类的具体用法?C# ServiceProvider怎么用?C# ServiceProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServiceProvider类属于Microsoft.VisualStudio.Shell命名空间,在下文中一共展示了ServiceProvider类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:XewTurquish,项目名称:vsminecraft,代码行数:27,代码来源:VSHelpers.cs
示例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;
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:31,代码来源:EFModelErrorTaskFactory.cs
示例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));
}
}
开发者ID:dishiyicijinqiu,项目名称:VSIXProject1,代码行数:30,代码来源:MyCmdPackage.cs
示例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();
}
}
开发者ID:Galad,项目名称:SpecFlow,代码行数:32,代码来源:VsContextMenuManager.cs
示例5: GetTextManager
private IVsTextManager GetTextManager(DTE2 application)
{
using (ServiceProvider wrapperSP = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)application))
{
return (IVsTextManager)wrapperSP.GetService(typeof(SVsTextManager));
}
}
开发者ID:hxhlb,项目名称:wordlight,代码行数:7,代码来源:WindowWatcher.cs
示例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));
}
}
开发者ID:NuPattern,项目名称:NuPattern,代码行数:28,代码来源:CoordinatorTemplateWizard.cs
示例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));
}
开发者ID:t4generators,项目名称:t4-SolutionManager,代码行数:37,代码来源:VsShellHelper.cs
示例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);
}
开发者ID:IcodeNet,项目名称:cleansolution,代码行数:34,代码来源:RemoveToolboxTabCmdlet.cs
示例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();
}
开发者ID:itowlson,项目名称:torment-roslyn,代码行数:28,代码来源:RoslyniserSingleFileGenerator.cs
示例10: SqlEditorPane
public SqlEditorPane(ServiceProvider sp, SqlEditorFactory factory)
: base(sp)
{
Factory = factory;
DocumentPath = factory.LastDocumentPath;
editor = new SqlEditor(sp, this);
}
开发者ID:jimmy00784,项目名称:mysql-connector-net,代码行数:7,代码来源:SqlEditorPane.cs
示例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 );
}
}
开发者ID:yakostya,项目名称:TargetFrameworkMigrator,代码行数:41,代码来源:TargetFrameworkMigratorPackage.cs
示例12: PropertiesEditorLauncher
public PropertiesEditorLauncher(ServiceProvider serviceProvider)
{
if(serviceProvider == null)
throw new ArgumentNullException("serviceProvider");
this.serviceProvider = serviceProvider;
}
开发者ID:ashumeow,项目名称:android-plus-plus,代码行数:7,代码来源:PropertiesEditorLauncher.cs
示例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");
}
开发者ID:noizefloor,项目名称:cppcheck-vs-add-in,代码行数:7,代码来源:ErrorHandler.cs
示例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);
}
开发者ID:xuhdev,项目名称:editorconfig-visualstudio,代码行数:32,代码来源:PluginFactory.cs
示例15: SqlEditor
internal SqlEditor(ServiceProvider sp, SqlEditorPane pane )
: this()
{
Pane = pane;
serviceProvider = sp;
codeEditor.Init(sp, this);
}
开发者ID:Top-Cat,项目名称:SteamBot,代码行数:7,代码来源:SqlEditor.cs
示例16: Context
public Context(object automationObject, IDictionary<string, string> values)
{
_replacementValues = values;
_environment = (DTE)automationObject;
ServiceProvider = new ServiceProvider(_environment as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
TemplateService = new TemplateService(this);
}
开发者ID:mikeobrien,项目名称:VisualStudioWizardAndTemplateExploration,代码行数:7,代码来源:Context.cs
示例17: RunFinished
// Add Silverlight app to the Web project and create test web pages
public void RunFinished()
{
Project silverlightProject = GetSilverlightProject();
Project webProject = GetWebProject();
if (webProject != null)
{
_dte2.Solution.SolutionBuild.StartupProjects = webProject.UniqueName;
Properties properties = webProject.Properties;
ProjectItem aspxTestPage = this.GetAspxTestPage(webProject);
if (aspxTestPage != null)
{
properties.Item("WebApplication.StartPageUrl").Value = aspxTestPage.Name;
properties.Item("WebApplication.DebugStartAction").Value = 1;
}
if (silverlightProject != null)
{
IVsHierarchy hierarchy;
IVsHierarchy hierarchy2;
silverlightProject.Properties.Item("SilverlightProject.LinkedServerProject").Value = webProject.FullName;
var sp = _dte2 as Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
IVsSolution service = null;
using (var provider2 = new ServiceProvider(sp))
{
service = provider2.GetService(typeof(IVsSolution)) as IVsSolution;
}
if (((service.GetProjectOfUniqueName(webProject.UniqueName, out hierarchy) == 0) && (hierarchy != null)) && (service.GetProjectOfUniqueName(silverlightProject.UniqueName, out hierarchy2) == 0))
{
((IVsSilverlightProjectConsumer)hierarchy).LinkToSilverlightProject("ClientBin", true, false, hierarchy2 as IVsSilverlightProject);
}
}
}
}
开发者ID:ruisebastiao,项目名称:simplemvvmtoolkit,代码行数:33,代码来源:RootWizard.cs
示例18: GetWpfTextView
public static IWpfTextView GetWpfTextView(EnvDTE.DTE dte, IVsTextView viewAdapter)
{
using (ServiceProvider sp = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte))
{
var svc = (IVsEditorAdaptersFactoryService)sp.GetService(typeof(IVsEditorAdaptersFactoryService));
return svc.GetWpfTextView(viewAdapter);
}
}
开发者ID:pgourlain,项目名称:CodeWeaver,代码行数:8,代码来源:VSTools.cs
示例19: ErrorListHelper
public ErrorListHelper(object dte2)
{
_serviceProvider = new ServiceProvider(dte2 as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
_errorProvider = new ErrorListProvider(_serviceProvider);//this implementing IServiceProvider
_errorProvider.ProviderName = "JS Lint";
_errorProvider.ProviderGuid = new Guid(); // should be package guid
_errorProvider.Show();
}
开发者ID:michalliu,项目名称:jslint4vs2012,代码行数:8,代码来源:ErrorListHelper.cs
示例20: VsDesignerControl
/// <summary>
/// Overloaded Constructor
/// </summary>
/// <param name="viewModel"></param>
public VsDesignerControl(ServiceProvider serviceProvider, IViewModel viewModel)
{
_serviceProvider = serviceProvider;
DataContext = viewModel;
InitializeComponent();
// wait until we're initialized to handle events
viewModel.ViewModelChanged += new EventHandler(ViewModelChanged);
}
开发者ID:blackberry,项目名称:VSPlugin,代码行数:12,代码来源:VsDesignerControl.xaml.cs
注:本文中的Microsoft.VisualStudio.Shell.ServiceProvider类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论