本文整理汇总了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);
}
}
示例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;
}
示例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();
}
示例4: PythonInterpreterOptionsControl
public PythonInterpreterOptionsControl(IServiceProvider serviceProvider) {
_serviceProvider = serviceProvider;
InitializeComponent();
_service = serviceProvider.GetComponentModel().GetService<IInterpreterOptionsService>();
UpdateInterpreters();
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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);
}
示例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();
}
示例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
);
}
示例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))
);
}
示例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;
}