當前位置: 首頁>>代碼示例>>C#>>正文


C# Shell.ServiceProvider類代碼示例

本文整理匯總了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;
        }
開發者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


注:本文中的Microsoft.VisualStudio.Shell.ServiceProvider類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。