当前位置: 首页>>代码示例>>C#>>正文


C# IServiceProvider.GetComponentModel方法代码示例

本文整理汇总了C#中IServiceProvider.GetComponentModel方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceProvider.GetComponentModel方法的具体用法?C# IServiceProvider.GetComponentModel怎么用?C# IServiceProvider.GetComponentModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IServiceProvider的用法示例。


在下文中一共展示了IServiceProvider.GetComponentModel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StandaloneTargetView

        public StandaloneTargetView(IServiceProvider serviceProvider) {
            var componentService = serviceProvider.GetComponentModel();
            
            var interpreterProviders = componentService.DefaultExportProvider.GetExports<IPythonInterpreterFactoryProvider, Dictionary<string, object>>();
            var interpreterOptions = componentService.GetService<IInterpreterOptionsService>();
            var registry = componentService.GetService<IInterpreterRegistryService>();
            var pythonService = serviceProvider.GetPythonToolsService();

            var availableInterpreters = registry.Configurations.Select(
                config => new PythonInterpreterView(
                    config.Description, 
                    config.Id, 
                    config.InterpreterPath
                )
            ).ToList();

            _customInterpreter = new PythonInterpreterView("Other...", "", null);
            availableInterpreters.Add(_customInterpreter);
            _availableInterpreters = new ReadOnlyCollection<PythonInterpreterView>(availableInterpreters);

            _interpreterPath = null;
            _canSpecifyInterpreterPath = false;
            _scriptPath = null;
            _workingDirectory = null;
            _arguments = null;

            _isValid = false;

            PropertyChanged += new PropertyChangedEventHandler(StandaloneTargetView_PropertyChanged);

            if (IsAnyAvailableInterpreters) {
                var defaultId = interpreterOptions.DefaultInterpreterId;
                Interpreter = AvailableInterpreters.FirstOrDefault(v => v.Id == defaultId);
            }
        }
开发者ID:jsschultz,项目名称:PTVS,代码行数:35,代码来源:StandaloneTargetView.cs

示例2: EnsureReplWindow

        internal static IVsInteractiveWindow/*!*/ EnsureReplWindow(IServiceProvider serviceProvider, IPythonInterpreterFactory factory, PythonProjectNode project) {
            var compModel = serviceProvider.GetComponentModel();
            var provider = compModel.GetService<InteractiveWindowProvider>();

            string replId = PythonReplEvaluatorProvider.GetReplId(factory, project);
            var window = provider.FindReplWindow(replId);
            if (window == null) {
                window = provider.CreateInteractiveWindow(
                    serviceProvider.GetPythonContentType(),
                    factory.Description + " Interactive",
                    typeof(PythonLanguageInfo).GUID,
                    replId
                );

                var toolWindow = window as ToolWindowPane;
                if (toolWindow != null) {
                    toolWindow.BitmapImageMoniker = KnownMonikers.PYInteractiveWindow;
                }

                var pyService = serviceProvider.GetPythonToolsService();
                window.InteractiveWindow.SetSmartUpDown(pyService.GetInteractiveOptions(factory).ReplSmartHistory);
            }

            if (project != null && project.Interpreters.IsProjectSpecific(factory)) {
                project.AddActionOnClose(window, BasePythonReplEvaluator.CloseReplWindow);
            }

            return window;
        }
开发者ID:omnimark,项目名称:PTVS,代码行数:29,代码来源:ExecuteInReplCommand.cs

示例3: ImportWizard

        public ImportWizard(IServiceProvider serviceProvider, string sourcePath, string projectPath) {
            var interpreterService = serviceProvider.GetComponentModel().GetService<IInterpreterOptionsService>();
            _site = serviceProvider;
            ImportSettings = new ImportSettings(serviceProvider, interpreterService);

            _pageSequence = new CollectionViewSource {
                Source = new ObservableCollection<Page>(new Page[] {
                    new FileSourcePage { DataContext = ImportSettings },
                    new InterpreterPage { DataContext = ImportSettings },
                    new SaveProjectPage { DataContext = ImportSettings }
                })
            };
            PageCount = _pageSequence.View.OfType<object>().Count();

            PageSequence = _pageSequence.View;
            PageSequence.CurrentChanged += PageSequence_CurrentChanged;
            PageSequence.MoveCurrentToFirst();

            if (!string.IsNullOrEmpty(sourcePath)) {
                ImportSettings.SetInitialSourcePath(sourcePath);
                Loaded += ImportWizard_Loaded;
            }
            if (!string.IsNullOrEmpty(projectPath)) {
                ImportSettings.SetInitialProjectPath(projectPath);
            }
            ImportSettings.UpdateIsValid();

            DataContext = this;

            InitializeComponent();
        }
开发者ID:smallwave,项目名称:PTVS,代码行数:31,代码来源:ImportWizard.xaml.cs

示例4: PythonInterpreterOptionsControl

        public PythonInterpreterOptionsControl(IServiceProvider serviceProvider) {
            _serviceProvider = serviceProvider;
            InitializeComponent();

            _service = serviceProvider.GetComponentModel().GetService<IInterpreterOptionsService>();
            UpdateInterpreters();
        }
开发者ID:wenh123,项目名称:PTVS,代码行数:7,代码来源:PythonInterpreterOptionsControl.cs

示例5: OnCreate

        protected override void OnCreate() {
            base.OnCreate();

            _site = (IServiceProvider)this;

            _pyService = _site.GetPythonToolsService();

#if DEV14_OR_LATER
            // TODO: Get PYEnvironment added to image list
            BitmapImageMoniker = KnownMonikers.DockPanel;
#else
            BitmapResourceID = PythonConstants.ResourceIdForReplImages;
            BitmapIndex = 0;
#endif
            Caption = SR.GetString(SR.Environments);

            _service = _site.GetComponentModel().GetService<IInterpreterOptionsService>();
            
            _outputWindow = OutputWindowRedirector.GetGeneral(_site);
            Debug.Assert(_outputWindow != null);
            _statusBar = _site.GetService(typeof(SVsStatusbar)) as IVsStatusbar;
            
            var list = new ToolWindow();
            list.ViewCreated += List_ViewCreated;

            list.CommandBindings.Add(new CommandBinding(
                EnvironmentView.OpenInteractiveWindow,
                OpenInteractiveWindow_Executed,
                OpenInteractiveWindow_CanExecute
            ));
            list.CommandBindings.Add(new CommandBinding(
                EnvironmentView.OpenInteractiveOptions,
                OpenInteractiveOptions_Executed,
                OpenInteractiveOptions_CanExecute
            ));
            list.CommandBindings.Add(new CommandBinding(
                EnvironmentPathsExtension.StartInterpreter,
                StartInterpreter_Executed,
                StartInterpreter_CanExecute
            ));
            list.CommandBindings.Add(new CommandBinding(
                EnvironmentPathsExtension.StartWindowsInterpreter,
                StartInterpreter_Executed,
                StartInterpreter_CanExecute
            ));
            list.CommandBindings.Add(new CommandBinding(
                ApplicationCommands.Help,
                OnlineHelp_Executed,
                OnlineHelp_CanExecute
            ));
            list.CommandBindings.Add(new CommandBinding(
                ToolWindow.UnhandledException,
                UnhandledException_Executed,
                UnhandledException_CanExecute
            ));

            list.Service = _service;

            Content = list;
        }
开发者ID:munyirik,项目名称:PTVS,代码行数:60,代码来源:InterpreterListToolWindow.cs

示例6: LaunchDebugTarget

        public void LaunchDebugTarget(IServiceProvider serviceProvider, DebugLaunchActionContext debugLaunchActionContext) {
            var registry = serviceProvider.GetComponentModel().GetService<IInterpreterRegistryService>();

            var settings = debugLaunchActionContext.LaunchConfiguration;
            var debug = !settings.GetValue("noDebug", false);
            var path = settings.GetValue(InterpreterKey, string.Empty);
            InterpreterConfiguration config = null;

            if (!string.IsNullOrEmpty(path)) {
                if (PathUtils.IsValidPath(path) && !Path.IsPathRooted(path)) {
                    // TODO: Find location of launch.json
                }

                if (File.Exists(path)) {
                    config = registry.Configurations.FirstOrDefault(c => c.InterpreterPath.Equals(path, StringComparison.OrdinalIgnoreCase)) ??
                        new InterpreterConfiguration("Custom", path, PathUtils.GetParent(path), path);
                } else {
                    config = registry.FindConfiguration(path);
                }
            } else {
                var service = serviceProvider.GetComponentModel().GetService<IInterpreterOptionsService>();
                service.DefaultInterpreter.ThrowIfNotRunnable();
                config = service.DefaultInterpreter.Configuration;
                path = config.InterpreterPath;
            }

            if (!File.Exists(path)) {
                throw new InvalidOperationException(Strings.DebugLaunchInterpreterMissing_Path.FormatUI(path));
            }

            IProjectLauncher launcher = null;
            var launchConfig = new LaunchConfiguration(config) {
                InterpreterPath = config == null ? path : null,
                InterpreterArguments = settings.GetValue(InterpreterArgumentsKey, string.Empty),
                ScriptName = settings.GetValue(ScriptNameKey, string.Empty),
                ScriptArguments = settings.GetValue(ScriptArgumentsKey, string.Empty),
                WorkingDirectory = settings.GetValue(WorkingDirectoryKey, string.Empty),
                // TODO: Support search paths
                SearchPaths = null,
                // TODO: Support env variables
                Environment = null,
            };
            launchConfig.LaunchOptions[PythonConstants.EnableNativeCodeDebugging] = settings.GetValue(NativeDebuggingKey, false).ToString();


            var browserUrl = settings.GetValue(WebBrowserUrlKey, string.Empty);
            if (!string.IsNullOrEmpty(browserUrl)) {
                launchConfig.LaunchOptions[PythonConstants.WebBrowserUrlSetting] = browserUrl;
                launcher = new PythonWebLauncher(serviceProvider, launchConfig, launchConfig, launchConfig);
            }

            (launcher ?? new DefaultPythonLauncher(serviceProvider, launchConfig)).LaunchProject(debug);
        }
开发者ID:jsschultz,项目名称:PTVS,代码行数:53,代码来源:PythonLaunchDebugTargetProvider.cs

示例7: EnsureReplWindow

        internal static IVsInteractiveWindow/*!*/ EnsureReplWindow(IServiceProvider serviceProvider, InterpreterConfiguration config, PythonProjectNode project) {
            var compModel = serviceProvider.GetComponentModel();
            var provider = compModel.GetService<InteractiveWindowProvider>();
            var vsProjectContext = compModel.GetService<VsProjectContextProvider>();

            string replId = config != null ?
                PythonReplEvaluatorProvider.GetEvaluatorId(config) :
                PythonReplEvaluatorProvider.GetEvaluatorId(project);
            var window = provider.OpenOrCreate(replId);
            project?.AddActionOnClose(window, InteractiveWindowProvider.Close);

            return window;
        }
开发者ID:jsschultz,项目名称:PTVS,代码行数:13,代码来源:ExecuteInReplCommand.cs

示例8: EnsureReplWindow

        internal static IVsInteractiveWindow/*!*/ EnsureReplWindow(IServiceProvider serviceProvider) {
            var compModel = serviceProvider.GetComponentModel();
            var provider = compModel.GetService<InteractiveWindowProvider>();

            string replId = PythonDebugReplEvaluatorProvider.GetDebugReplId();
            var window = provider.FindReplWindow(replId);
            if (window == null) {
                window = provider.CreateInteractiveWindow(serviceProvider.GetPythonContentType(), "Python Debug Interactive", typeof(PythonLanguageInfo).GUID, replId);

                var pyService = serviceProvider.GetPythonToolsService();
                window.InteractiveWindow.SetSmartUpDown(pyService.DebugInteractiveOptions.ReplSmartHistory);
            }
            return window;
        }
开发者ID:omnimark,项目名称:PTVS,代码行数:14,代码来源:OpenDebugReplCommand.cs

示例9: PythonInteractiveOptionsControl

        public PythonInteractiveOptionsControl(IServiceProvider serviceProvider) {
            _serviceProvider = serviceProvider;
            InitializeComponent();

            _executionModes = ExecutionMode.GetRegisteredModes(_serviceProvider.GetComponentModel().GetService<SVsServiceProvider>());

            foreach (var mode in _executionModes) {
                // TODO: Support localizing these names...
                _executionMode.Items.Add(mode.FriendlyName);
            }

            UpdateInterpreters();

            AddToolTips();
        }
开发者ID:omnimark,项目名称:PTVS,代码行数:15,代码来源:PythonInteractiveOptionsControl.cs

示例10: EnsureReplWindow

        internal static IVsInteractiveWindow/*!*/ EnsureReplWindow(IServiceProvider serviceProvider, InterpreterConfiguration config, PythonProjectNode project) {
            var compModel = serviceProvider.GetComponentModel();
            var provider = compModel.GetService<InteractiveWindowProvider>();
            var vsProjectContext = compModel.GetService<VsProjectContextProvider>();

            var projectId = project != null ? PythonReplEvaluatorProvider.GetEvaluatorId(project) : null;
            var configId = config != null ? PythonReplEvaluatorProvider.GetEvaluatorId(config) : null;

            IVsInteractiveWindow window;

            // If we find an open window for the project, prefer that to a per-config one
            if (!string.IsNullOrEmpty(projectId)) {
                window = provider.Open(projectId);
                if (window != null) {
                    if (window.InteractiveWindow.GetPythonEvaluator()?.AssociatedProjectHasChanged == true) {
                        // We have an existing window, but it needs to be reset.
                        // Let's create a new one
                        window = provider.Create(projectId);
                        project.AddActionOnClose(window, InteractiveWindowProvider.Close);
                    }

                    return window;
                }
            }

            // If we find an open window for the configuration, return that
            if (!string.IsNullOrEmpty(configId)) {
                window = provider.Open(configId);
                if (window != null) {
                    return window;
                }
            }

            // No window found, so let's create one
            if (!string.IsNullOrEmpty(projectId)) {
                window = provider.Create(projectId);
                project.AddActionOnClose(window, InteractiveWindowProvider.Close);
            } else if (!string.IsNullOrEmpty(configId)) {
                window = provider.Create(configId);
            } else {
                var interpService = compModel.GetService<IInterpreterOptionsService>();
                window = provider.Create(PythonReplEvaluatorProvider.GetEvaluatorId(interpService.DefaultInterpreter.Configuration));
            }

            return window;
        }
开发者ID:zooba,项目名称:PTVS,代码行数:46,代码来源:ExecuteInReplCommand.cs

示例11: PythonFormattingOptionsControl

        public PythonFormattingOptionsControl(IServiceProvider serviceProvider) {
            _serviceProvider = serviceProvider;
            InitializeComponent();

            _optionsTree.AfterSelect += AfterSelectOrCheckNode;
            _optionsTree.AfterCheck += AfterSelectOrCheckNode;

            var compModel = _serviceProvider.GetComponentModel();
            var editorFactory = compModel.GetService<ITextEditorFactoryService>();
            var bufferFactory = compModel.GetService<ITextBufferFactoryService>();
            var contentTypeRegistry = compModel.GetService<IContentTypeRegistryService>();
            var textContentType = contentTypeRegistry.GetContentType("Python");

            _buffer = bufferFactory.CreateTextBuffer(textContentType);
            var editor = editorFactory.CreateTextView(_buffer, CreateRoleSet());
            
            _editorHost.Child = (UIElement)editor;
            _buffer.Replace(new Span(0, 0), DefaultText);
        }
开发者ID:wenh123,项目名称:PTVS,代码行数:19,代码来源:PythonFormattingOptionsControl.cs

示例12: PythonInteractiveOptionsControl

        public PythonInteractiveOptionsControl(IServiceProvider serviceProvider) {
            _serviceProvider = serviceProvider;
            InitializeComponent();

            _executionModes = ExecutionMode.GetRegisteredModes(_serviceProvider.GetComponentModel().GetService<SVsServiceProvider>());

            foreach (var mode in _executionModes) {
                // TODO: Support localizing these names...
                _executionMode.Items.Add(mode.FriendlyName);
            }

#if DEV14_OR_LATER
            // This isn't supported in the Dev14 interactive window
            _inlinePrompts.Visible = false;
#endif
            UpdateInterpreters();

            AddToolTips();
        }
开发者ID:wenh123,项目名称:PTVS,代码行数:19,代码来源:PythonInteractiveOptionsControl.cs

示例13: Create

        public static IPythonProjectLaunchProperties Create(
            IPythonProject project,
            IServiceProvider site,
            IProjectLaunchProperties properties
        ) {
            var res = properties as IPythonProjectLaunchProperties;
            if (res != null) {
                return res;
            }
            
            res = project as IPythonProjectLaunchProperties;
            if (res != null) {
                // This should be the common case, as we implement
                // IPythonProjectLaunchProperties on our project.
                return res;
            }

            // Backwards compatibility shim to handle project implementations
            // that omit IPythonProjectLaunchProperties.

            string arguments, workingDir;
            Dictionary<string, string> environment, environmentWithPaths;
            properties = properties ?? (project as IProjectLaunchProperties);
            if (properties != null) {
                arguments = properties.GetArguments();
                workingDir = properties.GetWorkingDirectory();
                environment = new Dictionary<string, string>(properties.GetEnvironment(false));
                environmentWithPaths = new Dictionary<string, string>(properties.GetEnvironment(true));
            } else {
                arguments = project.GetProperty(CommonConstants.CommandLineArguments);
                workingDir = project.GetWorkingDirectory();

                environment = ParseEnvironment(project.GetProperty(PythonConstants.EnvironmentSetting));
                environmentWithPaths = new Dictionary<string, string>(environment);
                AddSearchPaths(environmentWithPaths, project, site);
            }

            string strValue;
            bool boolValue;
            bool? isWindowsApplication = null;
            strValue = project.GetProperty(PythonConstants.IsWindowsApplicationSetting);
            if (bool.TryParse(strValue, out boolValue)) {
                isWindowsApplication = boolValue;
            }

            IPythonInterpreterFactory interpreter;

            var ipp3 = project as IPythonProject3;
            if (ipp3 != null) {
                interpreter = ipp3.GetInterpreterFactoryOrThrow();
            } else {
                interpreter = project.GetInterpreterFactory();
                var service = site.GetComponentModel().GetService<IInterpreterOptionsService>();
                if (service == null || interpreter == service.NoInterpretersValue) {
                    throw new NoInterpretersException();
                }
            }

            var interpreterPath = (isWindowsApplication ?? false) ?
                interpreter.Configuration.WindowsInterpreterPath :
                interpreter.Configuration.InterpreterPath;

            var interpreterArguments = project.GetProperty(PythonConstants.InterpreterArgumentsSetting);

            bool? isNativeDebugging = null;
            strValue = project.GetProperty(PythonConstants.EnableNativeCodeDebugging);
            if (bool.TryParse(strValue, out boolValue)) {
                isNativeDebugging = boolValue;
            }

            return new PythonProjectLaunchProperties(
                arguments,
                workingDir,
                environment,
                environmentWithPaths,
                interpreterPath,
                interpreterArguments,
                isWindowsApplication,
                isNativeDebugging
            );
        }
开发者ID:omnimark,项目名称:PTVS,代码行数:81,代码来源:PythonProjectLaunchProperties.cs

示例14: GetInteractiveCommands

        internal static IInteractiveWindowCommands GetInteractiveCommands(
            IServiceProvider serviceProvider,
            IInteractiveWindow window,
            IInteractiveEvaluator eval
        ) {
            var model = serviceProvider.GetComponentModel();
            var cmdFactory = model.GetService<IInteractiveWindowCommandsFactory>();
            var cmds = model.GetExtensions<IInteractiveWindowCommand>();
            var roles = eval.GetType()
                .GetCustomAttributes(typeof(InteractiveWindowRoleAttribute), true)
                .Select(r => ((InteractiveWindowRoleAttribute)r).Name)
                .ToArray();

            var contentTypeRegistry = model.GetService<IContentTypeRegistryService>();
            var contentTypes = eval.GetType()
                .GetCustomAttributes(typeof(ContentTypeAttribute), true)
                .Select(r => contentTypeRegistry.GetContentType(((ContentTypeAttribute)r).ContentTypes))
                .ToArray();

            return cmdFactory.CreateInteractiveCommands(
                window,
                "$",
                cmds.Where(x => IsCommandApplicable(x, roles, contentTypes))
            );
        }
开发者ID:,项目名称:,代码行数:25,代码来源:

示例15: GetLauncher

        internal static IProjectLauncher GetLauncher(IServiceProvider serviceProvider, IPythonProject project) {
            var launchProvider = serviceProvider.GetUIThread().Invoke<string>(() => project.GetProperty(PythonConstants.LaunchProvider));

            IPythonLauncherProvider defaultLaunchProvider = null;
            foreach (var launcher in serviceProvider.GetComponentModel().GetExtensions<IPythonLauncherProvider>()) {
                if (launcher.Name == launchProvider) {
                    return serviceProvider.GetUIThread().Invoke<IProjectLauncher>(() => launcher.CreateLauncher(project));
                }

                if (launcher.Name == DefaultLauncherProvider.DefaultLauncherName) {
                    defaultLaunchProvider = launcher;
                }
            }

            // no launcher configured, use the default one.
            Debug.Assert(defaultLaunchProvider != null);
            return (defaultLaunchProvider != null) ?
                serviceProvider.GetUIThread().Invoke<IProjectLauncher>(() => defaultLaunchProvider.CreateLauncher(project)) :
                null;
        }
开发者ID:wenh123,项目名称:PTVS,代码行数:20,代码来源:PythonToolsPackage.cs


注:本文中的IServiceProvider.GetComponentModel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。