Exemplo n.º 1
0
        /// <summary>
        /// Hydrates the properties from the registry asyncronously.
        /// </summary>
        public virtual async Task LoadAsync()
        {
            ShellSettingsManager manager = await _settingsManager.GetValueAsync();

            SettingsStore settingsStore = manager.GetReadOnlySettingsStore(SettingsScope.UserSettings);

            if (!settingsStore.CollectionExists(CollectionName))
            {
                return;
            }

            foreach (PropertyInfo property in GetOptionProperties())
            {
                try
                {
                    string serializedProp = settingsStore.GetString(CollectionName, property.Name);
                    object value          = DeserializeValue(serializedProp, property.PropertyType);
                    property.SetValue(this, value);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.Write(ex);
                }
            }
        }
        private static bool?GetOutOfProcessSettingFromSessionStore(AcuminatorVSPackage package)
        {
            const bool   defaultOutOfProcessValue           = true;
            const string settingsStoreOutOfProcessValuePath = @"Roslyn\Internal\OnOff\Features";
            const string OutOfProcessPropertyName           = "OOP64Bit";

            var           shellSettingsManager = new ShellSettingsManager(package);
            SettingsStore settingsStore        = shellSettingsManager.GetReadOnlySettingsStore(SettingsScope.UserSettings);

            if (settingsStore == null)
            {
                return(null);
            }
            else if (!settingsStore.CollectionExists(settingsStoreOutOfProcessValuePath))
            {
                return(defaultOutOfProcessValue);
            }

            var propertyNames = settingsStore.GetPropertyNames(settingsStoreOutOfProcessValuePath);

            if (!propertyNames.Contains(OutOfProcessPropertyName))
            {
                return(defaultOutOfProcessValue);
            }

            int?outOfProcessValue = settingsStore.GetInt32(settingsStoreOutOfProcessValuePath, OutOfProcessPropertyName) as int?;

            return(outOfProcessValue.HasValue
                                ? outOfProcessValue == 1
                                : defaultOutOfProcessValue);
        }
Exemplo n.º 3
0
        /// <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()
        {
            CompareDirectoriesCommand.Initialize(this);
            base.Initialize();

            using (ServiceProvider serviceProvider = new ServiceProvider((IServiceProvider)(Package.GetGlobalService(typeof(IServiceProvider)))))
            {
                SettingsManager settingsManager = new ShellSettingsManager(serviceProvider);
                SettingsStore   settingsStore   = settingsManager.GetReadOnlySettingsStore(SettingsScope.UserSettings);

                if (settingsStore.CollectionExists(FilterSettings))
                {
                    IEnumerable <string> propertyNames = settingsStore.GetPropertyNames(FilterSettings);

                    foreach (string propertyName in propertyNames)
                    {
                        var filter = settingsStore.GetString(FilterSettings, propertyName, null);
                        if (filter != null)
                        {
                            CommonFilters.Add(filter);
                        }
                    }
                }
            }

            if (CommonFilters.Count == 0)
            {
                CommonFilters.Add("-*.dll;-*.pdb;-*.obj;-*.exe;-*.vsix;-.vs\\*;-*obj\\*;-*bin\\*;-.git\\*;-packages\\*");
                CommonFilters.Add("*.cs;*.vb;*.c;*.cpp;*.h");
                CommonFilters.Add(string.Empty);
            }
        }
Exemplo n.º 4
0
        private void GeneralOptionLoad(SettingsStore settingsStore)
        {
            if (!settingsStore.CollectionExists(CollectionName))
            {
                return;
            }

            _generalOptionProvider.SortOptions              = ReadSetting <GeneralOptionPage.SortState>(settingsStore, nameof(_generalOptionProvider.SortOptions));
            _generalOptionProvider.AutoScroll               = ReadSetting <bool>(settingsStore, nameof(_generalOptionProvider.AutoScroll));
            _generalOptionProvider.IsEnabledIndentGuides    = ReadSetting <bool>(settingsStore, nameof(_generalOptionProvider.IsEnabledIndentGuides));
            _generalOptionProvider.IndentGuideThickness     = ReadSetting <double>(settingsStore, nameof(_generalOptionProvider.IndentGuideThickness));
            _generalOptionProvider.IndentGuideDashSize      = ReadSetting <double>(settingsStore, nameof(_generalOptionProvider.IndentGuideDashSize));
            _generalOptionProvider.IndentGuideSpaceSize     = ReadSetting <double>(settingsStore, nameof(_generalOptionProvider.IndentGuideSpaceSize));
            _generalOptionProvider.IndentGuideOffsetY       = ReadSetting <double>(settingsStore, nameof(_generalOptionProvider.IndentGuideOffsetY));
            _generalOptionProvider.IndentGuideOffsetX       = ReadSetting <double>(settingsStore, nameof(_generalOptionProvider.IndentGuideOffsetX));
            _generalOptionProvider.Asm1FileExtensions       = ReadSetting <IReadOnlyList <string> >(settingsStore, nameof(_generalOptionProvider.Asm1FileExtensions));
            _generalOptionProvider.Asm2FileExtensions       = ReadSetting <IReadOnlyList <string> >(settingsStore, nameof(_generalOptionProvider.Asm2FileExtensions));
            _generalOptionProvider.Asm1SelectedSet          = ReadSetting <string>(settingsStore, nameof(_generalOptionProvider.Asm1SelectedSet));
            _generalOptionProvider.Asm2SelectedSet          = ReadSetting <string>(settingsStore, nameof(_generalOptionProvider.Asm2SelectedSet));
            _generalOptionProvider.AutocompleteInstructions = ReadSetting <bool>(settingsStore, nameof(_generalOptionProvider.AutocompleteInstructions));
            _generalOptionProvider.AutocompleteFunctions    = ReadSetting <bool>(settingsStore, nameof(_generalOptionProvider.AutocompleteFunctions));
            _generalOptionProvider.AutocompleteLabels       = ReadSetting <bool>(settingsStore, nameof(_generalOptionProvider.AutocompleteLabels));
            _generalOptionProvider.AutocompleteVariables    = ReadSetting <bool>(settingsStore, nameof(_generalOptionProvider.AutocompleteVariables));
            _generalOptionProvider.SignatureHelp            = ReadSetting <bool>(settingsStore, nameof(_generalOptionProvider.SignatureHelp));
        }
Exemplo n.º 5
0
        public string ReadStringData(string key)
        {
            try
            {
                if (!_readOnlySettingsStore.CollectionExists(tasCollectionPath))
                {
                    _logger.Error($"Attempted to read user settings store value under \"{tasCollectionPath}\" but no such collection path exists");

                    return(null);
                }

                if (_readOnlySettingsStore.PropertyExists(tasCollectionPath, key))
                {
                    return(_readOnlySettingsStore.GetString(tasCollectionPath, key));
                }
                else
                {
                    _logger.Error($"Attempted to read user settings store value for \"{key}\" but no such property exists");

                    return(null);
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);

                return(null);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Hydrates the properties from the registry asyncronously.
        /// </summary>
        public virtual async Task LoadAsync()
        {
            ShellSettingsManager manager = await _settingsManager.GetValueAsync();

            SettingsStore settingsStore = manager.GetReadOnlySettingsStore(SettingsScope.UserSettings);

            if (!settingsStore.CollectionExists(CollectionName))
            {
                return;
            }

            foreach (PropertyInfo property in GetOptionProperties())
            {
                try
                {
                    var serializedProp = settingsStore.GetString(CollectionName, property.Name, default);
                    var value          = DeserializeValue(serializedProp, property.PropertyType);
                    property.SetValue(this, value);
                }
                catch
                {
                    // Do nothing here
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Hydrates the properties from the registry asyncronously.
        /// </summary>
        public virtual async Task LoadAsync()
        {
            ShellSettingsManager manager = await _settingsManager.GetValueAsync();

            SettingsStore    settingsStore     = manager.GetReadOnlySettingsStore(SettingsScope.UserSettings);
            HashSet <string> testedCollections = new HashSet <string>();

            bool DoesCollectionExist(string collectionName)
            {
                if (testedCollections.Contains(collectionName))
                {
                    return(true);
                }
                if (settingsStore.CollectionExists(collectionName))
                {
                    testedCollections.Add(collectionName);
                    return(true);
                }
                return(false);
            }

            foreach (PropertyInfo property in GetOptionProperties())
            {
                try
                {
                    var collectionNameAttribute = property.GetCustomAttribute <OverrideCollectionNameAttribute>();
                    var collectionName          = collectionNameAttribute?.CollectionName ?? this.CollectionName;
                    if (!DoesCollectionExist(collectionName))
                    {
                        continue;
                    }

                    var overrideDataTypeAttribute = property.GetCustomAttribute <OverrideDataTypeAttribute>();
                    var dataType = overrideDataTypeAttribute?.SettingDataType ?? SettingDataType.Serialized;

                    switch (dataType)
                    {
                    case SettingDataType.Serialized:
                        var serializedProp = settingsStore.GetString(collectionName, property.Name, default);
                        var value          = DeserializeValue(serializedProp, property.PropertyType);
                        property.SetValue(this, value);
                        break;

                    case SettingDataType.Bool:
                        var boolValue = settingsStore.GetBoolean(collectionName, property.Name, false);
                        property.SetValue(this, boolValue);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                catch
                {
                    // Do nothing here
                }
            }
        }
Exemplo n.º 8
0
        internal static bool TryGetInt(this SettingsStore settingsStore, string collectionName, string propertyName, out int value)
        {
            if (settingsStore.CollectionExists(collectionName))
            {
                value = settingsStore.GetInt32(collectionName, propertyName);
                return(true);
            }

            value = default;
            return(false);
        }
Exemplo n.º 9
0
        public ServerParameters()
        {
            SettingsManager settingsManager            = new ShellSettingsManager(VMSTPSettingsStore.ServiceProvider);
            SettingsStore   configurationSettingsStore = settingsManager.GetReadOnlySettingsStore(SettingsScope.UserSettings);

            if (configurationSettingsStore.CollectionExists(VMSTPSettingsStore.Collection))
            {
                disableESMTP = configurationSettingsStore.GetBoolean(VMSTPSettingsStore.Collection, "DisableESMTP", DisableESMTP);
                port         = configurationSettingsStore.GetInt32(VMSTPSettingsStore.Collection, "Port", Port);
            }
        }
Exemplo n.º 10
0
        private static string GetStringOption(SettingsStore store, string catelogName, string optionName)
        {
            if (store == null ||
                !store.CollectionExists(COLLECTION_PATH) ||
                !store.PropertyExists(COLLECTION_PATH, CombineCatelogAndOptionName(catelogName, optionName)))
            {
                return(null);
            }

            return(store.GetString(COLLECTION_PATH, CombineCatelogAndOptionName(catelogName, optionName)));
        }
Exemplo n.º 11
0
        private void InstructionOptionLoad(SettingsStore settingsStore)
        {
            if (!settingsStore.CollectionExists(InstructionCollectionName))
            {
                return;
            }

            _generalOptionProvider.InstructionsPaths = ReadSetting <IReadOnlyList <string> >(
                settingsStore, InstructionCollectionName,
                nameof(_generalOptionProvider.InstructionsPaths));
        }
Exemplo n.º 12
0
        private static Color?GetColorOption(SettingsStore store, string catelogName, string optionName)
        {
            if (store == null ||
                !store.CollectionExists(COLLECTION_PATH) ||
                !store.PropertyExists(COLLECTION_PATH, CombineCatelogAndOptionName(catelogName, optionName)))
            {
                return(null);
            }

            var rgb = store.GetString(COLLECTION_PATH, CombineCatelogAndOptionName(catelogName, optionName)).Split(',').Select(x => Int32.Parse(x)).ToList();

            return(Color.FromArgb(rgb[0], rgb[1], rgb[2]));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Hydrates the properties from the registry asyncronously.
        /// </summary>
        public virtual async Task LoadAsync()
        {
            ShellSettingsManager manager = await _settingsManager.GetValueAsync().ConfigureAwait(true);

            SettingsStore settingsStore = manager.GetReadOnlySettingsStore(SettingsScope.UserSettings);

            if (!settingsStore.CollectionExists(CollectionName))
            {
                return;
            }

#if DEBUG_OPTION_VALUES_LOAD_SAVE
            Debug.WriteLine($"LoadAsync<{typeof(T).Name}>()");
            Debug.WriteLine($"GetPropertyCount = {settingsStore.GetPropertyCount(CollectionName)}");
            Debug.WriteLine($"GetPropertyCount = {settingsStore.GetPropertyCount(CollectionName)}");
            //var pnv = settingsStore.GetPropertyNamesAndValues(CollectionName);
            var pn = settingsStore.GetPropertyNames(CollectionName);
            foreach (var n in pn)
            {
                Debug.WriteLine($"Property: Name={n} Type = {settingsStore.GetPropertyType(CollectionName, n).ToString()}");
            }
#endif
            var propertiesToSerialize = GetOptionProperties();
            foreach (PropertyInfo property in propertiesToSerialize)
            {
                if (!settingsStore.PropertyExists(CollectionName, property.Name))
                {
#if DEBUG_OPTION_VALUES_LOAD_SAVE
                    Debug.WriteLine($"Skipping property {property.Name}. Not found in settings store");
#endif
                    property.SetValue(this, property.GetValue(this));
                    continue;
                }
                try
                {
                    string serializedProp = settingsStore.GetString(CollectionName, property.Name);
                    object value          = DeserializeValue(serializedProp, property.PropertyType);
                    property.SetValue(this, value);
#if DEBUG_OPTION_VALUES_LOAD_SAVE
                    Debug.WriteLine($"{property.Name} = {property.GetValue(this)} | value = {value}");
#endif
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex);
                }
            }
#if DEBUG_OPTION_VALUES_LOAD_SAVE
            Debug.WriteLine($"LoadAsync<{typeof(T).Name}>() finished ===================================");
#endif
        }
Exemplo n.º 14
0
        public AutoLoadPackage(Guid packageGuid, Guid contextGuid, string contextName, bool isRuleBasedUIContext, string contextTerms, SettingsStore configurationStore)
        {
            PackageGuid          = packageGuid;
            AutoLoadContextGuid  = contextGuid;
            AutoLoadContextName  = contextName;
            IsRuleBasedUIContext = isRuleBasedUIContext;
            UIContextTerms       = contextTerms;

            string packageInfoPath           = Path.Combine(_packagesPath, packageGuid.ToString("B"));
            string autoLoadConfigurationPath = Path.Combine(_autoLoadPackagesPath, contextGuid.ToString("B"));

            if (configurationStore.CollectionExists(packageInfoPath))
            {
                PackageName = configurationStore.GetString(packageInfoPath, string.Empty, "Unknown").Split(',')[0];
                string moduleName = configurationStore.GetString(packageInfoPath, "Class", null) ?? Path.GetFileName(configurationStore.GetString(packageInfoPath, "InProcServer32", string.Empty));
                ModuleName     = moduleName.Split(',')[0];
                IsAsyncPackage = configurationStore.GetBoolean(packageInfoPath, "AllowsBackgroundLoad", false);
            }

            if (configurationStore.CollectionExists(autoLoadConfigurationPath))
            {
                uint autoLoadFlags = (uint)PackageAutoLoadFlags.None;
                try
                {
                    autoLoadFlags = configurationStore.GetUInt32(autoLoadConfigurationPath, packageGuid.ToString("B"), 0);
                }
                catch (Exception)
                {
                    //Do not do anyting. Use none as flag
                    // Apparently user feed package "bb4bf712-fcf7-4d17-83bb-93e6478b4e5d" specified a string in the pkgdef..
                }

                bool backgroundLoad = ((autoLoadFlags & (uint)PackageAutoLoadFlags.BackgroundLoad) == (uint)PackageAutoLoadFlags.BackgroundLoad);

                IsAsyncForUIContext = IsAsyncPackage && backgroundLoad;
            }
        }
Exemplo n.º 15
0
        public void WriteInt32(string name, int value)
        {
            if (_serviceProvider == null)
            {
                return;
            }
            int exists;

            SettingsStore.CollectionExists(SettingsRoot, out exists);
            if (exists != 1)
            {
                SettingsStore.CreateCollection(SettingsRoot);
            }
            SettingsStore.SetInt(SettingsRoot, name, value);
        }
        private void SetSettings(string container, string vsdbg)
        {
            const string collectionPath = nameof(AttachToDockerContainerDialog);

            ThreadHelper.ThrowIfNotOnUIThread();

            SettingsStore.CollectionExists(collectionPath, out int exists);
            if (exists != 1)
            {
                SettingsStore.CreateCollection(collectionPath);
            }

            SettingsStore.SetString(collectionPath, "container", container);
            SettingsStore.SetString(collectionPath, "vsdbg", vsdbg);
        }
Exemplo n.º 17
0
        //=====================================================================

        /// <summary>
        /// This is used to load the MEF provider configuration settings
        /// </summary>
        /// <returns>True if loaded successfully or false if the settings collection does not exist</returns>
        /// <remarks>The settings are loaded using the <see cref="ShellSettingsManager"/> from the
        /// <see cref="CollectionPath"/> collection.</remarks>
        private bool LoadConfiguration()
        {
            ShellSettingsManager settingsManager = new ShellSettingsManager(_serviceProvider);
            SettingsStore        settingsStore   = settingsManager.GetReadOnlySettingsStore(SettingsScope.UserSettings);

            if (!settingsStore.CollectionExists(CollectionPath))
            {
                return(false);
            }

            EnableExtendedXmlCommentsCompletion = settingsStore.GetBoolean(CollectionPath, "EnableExtendedXmlCommentsCompletion", true);
            EnableGoToDefinition       = settingsStore.GetBoolean(CollectionPath, "EnableGoToDefinition", true);
            EnableGoToDefinitionInCRef = settingsStore.GetBoolean(CollectionPath, "EnableGoToDefinitionInCRef", DefaultEnableGoToDefinitionInCRef);
            return(true);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Hydrates the properties from the registry asyncronously.
        /// </summary>
        public virtual async Task LoadAsync()
        {
            ShellSettingsManager manager = await s_settings_manager.GetValueAsync();

            if (manager == null)
            {
                return;
            }
            SettingsStore settingsStore = manager.GetReadOnlySettingsStore(SettingsScope.UserSettings);

            if (settingsStore == null)
            {
                return;
            }
            if (!settingsStore.CollectionExists(CollectionName))
            {
                return;
            }

            LoadProperty(settingsStore);
        }
        private PythonInterpreterFactoryWithDatabase LoadUserDefinedInterpreter(SettingsStore store, string guid)
        {
            // PythonInterpreters\
            //      Id\
            //          Description
            //          InterpreterPath
            //          WindowsInterpreterPath
            //          Architecture
            //          Version
            //          PathEnvironmentVariable

            Guid   id;
            string collection;

            if (Guid.TryParse(guid, out id) && store.CollectionExists((collection = PythonInterpreterKey + "\\" + id.ToString("B"))))
            {
                var path        = store.GetString(collection, PathKey, string.Empty);
                var winPath     = store.GetString(collection, WindowsPathKey, string.Empty);
                var libPath     = store.GetString(collection, LibraryPathKey, string.Empty);
                var arch        = store.GetString(collection, ArchitectureKey, string.Empty);
                var version     = store.GetString(collection, VersionKey, string.Empty);
                var pathEnvVar  = store.GetString(collection, PathEnvVarKey, string.Empty);
                var description = store.GetString(collection, DescriptionKey, string.Empty);

                return(InterpreterFactoryCreator.CreateInterpreterFactory(
                           new InterpreterFactoryCreationOptions {
                    LanguageVersionString = version,
                    Id = id,
                    Description = description,
                    InterpreterPath = path,
                    WindowInterpreterPath = winPath,
                    LibraryPath = libPath,
                    PathEnvironmentVariableName = pathEnvVar,
                    ArchitectureString = arch,
                    WatchLibraryForNewModules = true
                }
                           ));
            }
            return(null);
        }
        private PythonInterpreterFactoryWithDatabase LoadUserDefinedInterpreter(SettingsStore store, string guid) {
            // PythonInterpreters\
            //      Id\
            //          Description
            //          InterpreterPath
            //          WindowsInterpreterPath
            //          Architecture
            //          Version
            //          PathEnvironmentVariable

            Guid id;
            string collection;
            if (Guid.TryParse(guid, out id) && store.CollectionExists((collection = PythonInterpreterKey + "\\" + id.ToString("B")))) {
                var path = store.GetString(collection, PathKey, string.Empty);
                var winPath = store.GetString(collection, WindowsPathKey, string.Empty);
                var libPath = store.GetString(collection, LibraryPathKey, string.Empty);
                var arch = store.GetString(collection, ArchitectureKey, string.Empty);
                var version = store.GetString(collection, VersionKey, string.Empty);
                var pathEnvVar = store.GetString(collection, PathEnvVarKey, string.Empty);
                var description = store.GetString(collection, DescriptionKey, string.Empty);

                return InterpreterFactoryCreator.CreateInterpreterFactory(
                    new InterpreterFactoryCreationOptions {
                        LanguageVersionString = version,
                        Id = id,
                        Description = description,
                        InterpreterPath = path,
                        WindowInterpreterPath = winPath,
                        LibraryPath = libPath,
                        PathEnvironmentVariableName = pathEnvVar,
                        ArchitectureString = arch,
                        WatchLibraryForNewModules = true
                    }
                );
            }
            return null;
        }
Exemplo n.º 21
0
        public override void LoadSettingsFromStorage()
        {
            SettingsManager settingsManager = new ShellSettingsManager(ServiceProvider.GlobalProvider);
            SettingsStore   settingsStore   = settingsManager.GetReadOnlySettingsStore(SettingsScope.UserSettings);

            if (!settingsStore.CollectionExists(CollectionName))
            {
                return;
            }

            foreach (PropertyInfo property in GetOptionProperties())
            {
                try
                {
                    string serializedProp = settingsStore.GetString(CollectionName, property.Name);
                    object value          = DeserializeValue(serializedProp, property.PropertyType);
                    property.SetValue(this, value);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.Write(ex);
                }
            }
        }
Exemplo n.º 22
0
        private IPythonInterpreterFactoryProvider[] LoadProviders(
            SettingsStore store,
            IServiceProvider serviceProvider
            )
        {
            var seen    = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            var catalog = new List <ComposablePartCatalog>();

            if (store.CollectionExists(SuppressFactoryProvidersCollection))
            {
                return(new IPythonInterpreterFactoryProvider[0]);
            }

            if (store.CollectionExists(FactoryProvidersCollection))
            {
                foreach (var idStr in store.GetSubCollectionNames(FactoryProvidersCollection))
                {
                    var key = FactoryProvidersCollection + "\\" + idStr;
                    LoadOneProvider(
                        store.GetString(key, FactoryProviderCodeBaseSetting, ""),
                        seen,
                        catalog,
                        _activityLog
                        );
                }
            }

            foreach (var baseKey in new[] { Registry.CurrentUser, Registry.LocalMachine })
            {
                using (var key = baseKey.OpenSubKey(FactoryProvidersRegKey)) {
                    if (key != null)
                    {
                        foreach (var idStr in key.GetSubKeyNames())
                        {
                            using (var subkey = key.OpenSubKey(idStr)) {
                                if (subkey != null)
                                {
                                    LoadOneProvider(
                                        subkey.GetValue(FactoryProviderCodeBaseSetting, "") as string,
                                        seen,
                                        catalog,
                                        _activityLog
                                        );
                                }
                            }
                        }
                    }
                }
            }

            if (!catalog.Any())
            {
                LoadOneProvider(
                    typeof(CPythonInterpreterFactoryConstants).Assembly.Location,
                    seen,
                    catalog,
                    _activityLog
                    );
            }

            const string FailedToImportMessage   = "Failed to import factory providers";
            var          providers               = new List <IPythonInterpreterFactoryProvider>();
            var          serviceProviderProvider = new MockExportProvider();

            if (serviceProvider != null)
            {
                serviceProviderProvider.SetExport(typeof(SVsServiceProvider), () => serviceProvider);
            }

            foreach (var part in catalog)
            {
                var container = new CompositionContainer(part, serviceProviderProvider);
                try {
                    foreach (var provider in container.GetExports <IPythonInterpreterFactoryProvider>())
                    {
                        if (provider.Value != null)
                        {
                            providers.Add(provider.Value);
                        }
                    }
                } catch (CompositionException ex) {
                    LogException(_activityLog, FailedToImportMessage, null, ex, ex.Errors);
                } catch (ReflectionTypeLoadException ex) {
                    LogException(_activityLog, FailedToImportMessage, null, ex, ex.LoaderExceptions);
                } catch (Exception ex) {
                    LogException(_activityLog, FailedToImportMessage, null, ex);
                }
            }

            return(providers.ToArray());
        }
Exemplo n.º 23
0
 public int CollectionExists([ComAliasName("OLE.LPCOLESTR")] string collectionPath, [ComAliasName("OLE.BOOL")] out int pfExists)
 {
     pfExists = inner.CollectionExists(collectionPath) ? 1 : 0;
     return(0);
 }
        /// <summary>
        /// Populates the maps that map from name -> scope info and GUID -> scope info
        /// </summary>
        private void PopulateScopeMaps()
        {
            ShellSettingsManager settingsManager = new ShellSettingsManager(this.serviceProvider);
            SettingsStore        settingsStore   = settingsManager.GetReadOnlySettingsStore(SettingsScope.Configuration);

            // First build map of all registered scopes
            if (settingsStore.CollectionExists(KeyBindingTableRegKeyName))
            {
                int itemCount = settingsStore.GetSubCollectionCount(KeyBindingTableRegKeyName);

                foreach (string str in settingsStore.GetSubCollectionNames(KeyBindingTableRegKeyName))
                {
                    string collectionName = Path.Combine(KeyBindingTableRegKeyName, str);

                    Guid scopeId;
                    if (!Guid.TryParse(str, out scopeId))
                    {
                        continue;
                    }

                    Guid owningPackage;
                    uint resourceId;
                    bool allowNavKeyBinding = false;

                    if (scopeId == VSConstants.GUID_VSStandardCommandSet97)
                    {
                        owningPackage = CLSID_VsEnvironmentPackage;
                        resourceId    = ID_Intl_Base + 18;
                    }
                    else
                    {
                        if (!settingsStore.PropertyExists(collectionName, PackageRegPropertyName))
                        {
                            continue;
                        }

                        if (!Guid.TryParse(settingsStore.GetString(collectionName, PackageRegPropertyName), out owningPackage))
                        {
                            continue;
                        }

                        string resIdString = settingsStore.GetString(collectionName, string.Empty);
                        if (resIdString.StartsWith("#"))
                        {
                            resIdString = resIdString.Substring(1);
                        }

                        if (!uint.TryParse(resIdString, out resourceId))
                        {
                            continue;
                        }

                        if (settingsStore.PropertyExists(collectionName, AllowNavKeyBindingPropertyName))
                        {
                            allowNavKeyBinding = settingsStore.GetUInt32(collectionName, AllowNavKeyBindingPropertyName) == 0 ? false : true;
                        }
                    }

                    string scopeName;
                    if (!ErrorHandler.Succeeded(Shell.LoadPackageString(ref owningPackage, resourceId, out scopeName)))
                    {
                        continue;
                    }

                    KeybindingScope scopeInfo = new KeybindingScope(scopeName, scopeId, allowNavKeyBinding);

                    this.scopeGuidToScopeInfoMap[scopeId]   = scopeInfo;
                    this.scopeNameToScopeInfoMap[scopeName] = scopeInfo;
                }
            }

            IVsEnumGuids scopeEnum = UIShell.EnumKeyBindingScopes();

            // Random GUID the shell also skips ("Source Code Text Editor" scope)
            Guid toSkip = new Guid("{72F42A10-B1C5-11d0-A8CD-00A0C921A4D2}");

            Guid[] scopes  = new Guid[1];
            uint   fetched = 0;

            while (scopeEnum.Next((uint)scopes.Length, scopes, out fetched) == VSConstants.S_OK && fetched != 0)
            {
                // We already have info for this scope
                if (scopeGuidToScopeInfoMap.ContainsKey(scopes[0]))
                {
                    continue;
                }

                // The shell skips this as a possible binding scope
                if (scopes[0] == toSkip)
                {
                    continue;
                }

                string path = Path.Combine("Editors", scopes[0].ToString("B"));

                // If it isn't a registered scope, see if it is an editor factory
                if (!settingsStore.CollectionExists(path))
                {
                    continue;
                }

                if (!settingsStore.PropertyExists(path, PackageRegPropertyName))
                {
                    continue;
                }

                Guid packageGuid;
                if (!Guid.TryParse(settingsStore.GetString(path, PackageRegPropertyName), out packageGuid))
                {
                    continue;
                }

                if (!settingsStore.PropertyExists(path, DisplayNameRegPropertyName))
                {
                    continue;
                }

                string displayNameResIdStr = settingsStore.GetString(path, DisplayNameRegPropertyName);
                if (displayNameResIdStr.StartsWith("#"))
                {
                    displayNameResIdStr = displayNameResIdStr.Substring(1);
                }

                uint displayNameResId;
                if (!uint.TryParse(displayNameResIdStr, out displayNameResId))
                {
                    continue;
                }

                string displayName;
                if (!ErrorHandler.Succeeded(shell.LoadPackageString(ref packageGuid, displayNameResId, out displayName)))
                {
                    continue;
                }

                // NOTE: Is false the right default value?
                KeybindingScope scopeInfo = new KeybindingScope(displayName, scopes[0], allowNavKeyBinding: false);

                this.scopeGuidToScopeInfoMap[scopes[0]]   = scopeInfo;
                this.scopeNameToScopeInfoMap[displayName] = scopeInfo;
            }
        }
Exemplo n.º 25
0
        private IPythonInterpreterFactoryProvider[] LoadProviders(
            SettingsStore store,
            IServiceProvider serviceProvider
        ) {
            var seen = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
            var catalog = new List<ComposablePartCatalog>();

            if (store.CollectionExists(SuppressFactoryProvidersCollection)) {
                return new IPythonInterpreterFactoryProvider[0];
            }

            if (store.CollectionExists(FactoryProvidersCollection)) {
                foreach (var idStr in store.GetSubCollectionNames(FactoryProvidersCollection)) {
                    var key = FactoryProvidersCollection + "\\" + idStr;
                    LoadOneProvider(
                        store.GetString(key, FactoryProviderCodeBaseSetting, ""),
                        seen,
                        catalog,
                        _activityLog
                    );
                }
            }

            foreach (var baseKey in new[] { Registry.CurrentUser, Registry.LocalMachine }) {
                using (var key = baseKey.OpenSubKey(FactoryProvidersRegKey)) {
                    if (key != null) {
                        foreach (var idStr in key.GetSubKeyNames()) {
                            using (var subkey = key.OpenSubKey(idStr)) {
                                if (subkey != null) {
                                    LoadOneProvider(
                                        subkey.GetValue(FactoryProviderCodeBaseSetting, "") as string,
                                        seen,
                                        catalog,
                                        _activityLog
                                    );
                                }
                            }
                        }
                    }
                }
            }

            if (!catalog.Any()) {
                LoadOneProvider(
                    typeof(CPythonInterpreterFactoryConstants).Assembly.Location,
                    seen,
                    catalog,
                    _activityLog
                );
            }

            const string FailedToImportMessage = "Failed to import factory providers";
            var providers = new List<IPythonInterpreterFactoryProvider>();
            var serviceProviderProvider = new MockExportProvider();
            if (serviceProvider != null) {
                serviceProviderProvider.SetExport(typeof(SVsServiceProvider), () => serviceProvider);
            }

            foreach (var part in catalog) {
                var container = new CompositionContainer(part, serviceProviderProvider);
                try {
                    foreach (var provider in container.GetExports<IPythonInterpreterFactoryProvider>()) {
                        if (provider.Value != null) {
                            providers.Add(provider.Value);
                        }
                    }
                } catch (CompositionException ex) {
                    LogException(_activityLog, FailedToImportMessage, null, ex, ex.Errors);
                } catch (ReflectionTypeLoadException ex) {
                    LogException(_activityLog, FailedToImportMessage, null, ex, ex.LoaderExceptions);
                } catch (Exception ex) {
                    LogException(_activityLog, FailedToImportMessage, null, ex);
                }
            }

            return providers.ToArray();
        }
Exemplo n.º 26
0
 private bool IsRuleBasedUIContext(string uiContextString)
 {
     return(_configurationStore.CollectionExists(Path.Combine(_uIContextRulesPath, uiContextString)));
 }