Exemple #1
0
        internal void SaveInterpreterOptions()
        {
            _interpreterOptionsService.BeginSuppressInterpretersChangedEvent();
            try {
                var configurable = _interpreterOptionsService.KnownProviders.OfType <ConfigurablePythonInterpreterFactoryProvider>().FirstOrDefault();
                Debug.Assert(configurable != null);

                if (configurable != null)
                {
                    // Remove any items
                    foreach (var option in InterpreterOptions.Select(kv => kv.Value).Where(o => o.Removed).ToList())
                    {
                        configurable.RemoveInterpreter(option.Id);
                        RemoveInteractiveOptions(option.Factory);
                        RemoveInterpreterOptions(option.Factory);
                    }

                    // Add or update any items that weren't removed
                    foreach (var option in InterpreterOptions.Select(x => x.Value))
                    {
                        if (option.Added)
                        {
                            if (option.Id == Guid.Empty)
                            {
                                option.Id = Guid.NewGuid();
                            }
                            option.Added = false;
                        }

                        if (option.IsConfigurable)
                        {
                            // save configurable interpreter options
                            var actualFactory = configurable.SetOptions(
                                new InterpreterFactoryCreationOptions {
                                Id = option.Id,
                                InterpreterPath             = option.InterpreterPath ?? "",
                                WindowInterpreterPath       = option.WindowsInterpreterPath ?? "",
                                LibraryPath                 = option.LibraryPath ?? "",
                                PathEnvironmentVariableName = option.PathEnvironmentVariable ?? "",
                                ArchitectureString          = option.Architecture ?? "x86",
                                LanguageVersionString       = option.Version ?? "2.7",
                                Description                 = option.Display,
                            }
                                );
                            if (option.InteractiveOptions != null)
                            {
                                option.InteractiveOptions._id = GetInteractivePath(actualFactory);
                                option.InteractiveOptions.Save(actualFactory);
                            }
                        }
                    }
                }

                foreach (var factory in InterpreterOptions.Select(x => x.Key).OfType <InterpreterPlaceholder>().ToArray())
                {
                    RemoveInterpreterOptions(factory);
                }
            } finally {
                _interpreterOptionsService.EndSuppressInterpretersChangedEvent();
            }
        }