public InitializrComponentManager(ISettingsLoader loader, SettingsStore userSettings)
        {
            _loader   = loader;
            _settings = userSettings;
            _loadLocations.AddRange(userSettings.ProbingPaths);

            ReflectionLoadProbingPath.Reset();
            foreach (string loadLocation in _loadLocations)
            {
                ReflectionLoadProbingPath.Add(loadLocation);
            }

            _componentIdsByType = new Dictionary <Type, HashSet <Guid> >();
            HashSet <Guid> allowedIds = new HashSet <Guid>();

            foreach (KeyValuePair <string, HashSet <Guid> > bucket in userSettings.ComponentTypeToGuidList)
            {
                allowedIds.UnionWith(bucket.Value);

                Type interfaceType = Type.GetType(bucket.Key);
                if (interfaceType != null)
                {
                    _componentIdsByType[interfaceType] = bucket.Value;
                }
            }

            foreach (KeyValuePair <string, string> entry in userSettings.ComponentGuidToAssemblyQualifiedName)
            {
                if (Guid.TryParse(entry.Key, out Guid componentId) && allowedIds.Contains(componentId))
                {
                    _componentIdToAssemblyQualifiedTypeName[componentId] = entry.Value;
                }
            }

            if (!_componentIdsByType.TryGetValue(typeof(IMountPointFactory), out HashSet <Guid> ids))
            {
                _componentIdsByType[typeof(IMountPointFactory)] = ids = new HashSet <Guid>();
            }

            if (!ids.Contains(InitializrSettingsLoader.FactoryId))
            {
                ids.Add(InitializrSettingsLoader.FactoryId);

                Cache <IMountPointFactory> .Instance.AddPart(new FileSystemMountPointFactory());
            }

            if (!ids.Contains(InitializrSettingsLoader.ZipFactoryId))
            {
                ids.Add(InitializrSettingsLoader.ZipFactoryId);
                Cache <IMountPointFactory> .Instance.AddPart(new ZipFileMountPointFactory());
            }

            foreach (KeyValuePair <Guid, Func <Type> > components in _loader.EnvironmentSettings.Host.BuiltInComponents)
            {
                if (ids.Add(components.Key))
                {
                    RegisterType(components.Value());
                }
            }
        }
        public ComponentManager(SettingsStore userSettings)
        {
            _settings = userSettings;
            _loadLocations.AddRange(userSettings.ProbingPaths);

            ReflectionLoadProbingPath.Reset();
            foreach (string loadLocation in _loadLocations)
            {
                ReflectionLoadProbingPath.Add(loadLocation);
            }

            _componentIdsByType = new Dictionary <Type, List <Guid> >();
            HashSet <Guid> allowedIds = new HashSet <Guid>();

            foreach (KeyValuePair <string, List <Guid> > bucket in userSettings.ComponentTypeToGuidList)
            {
                allowedIds.UnionWith(bucket.Value);
            }

            foreach (KeyValuePair <string, string> entry in userSettings.ComponentGuidToAssemblyQualifiedName)
            {
                Guid componentId;
                if (Guid.TryParse(entry.Key, out componentId) && allowedIds.Contains(componentId))
                {
                    _componentIdToAssemblyQualifiedTypeName[componentId] = entry.Value;
                }
            }

            List <Guid> ids;

            if (!_componentIdsByType.TryGetValue(typeof(IMountPointFactory), out ids))
            {
                _componentIdsByType[typeof(IMountPointFactory)] = ids = new List <Guid>();
            }

            if (!ids.Contains(FileSystemMountPointFactory.FactoryId))
            {
                ids.Add(FileSystemMountPointFactory.FactoryId);
                Cache <IMountPointFactory> .Instance.AddPart(new FileSystemMountPointFactory());
            }

            if (!ids.Contains(ZipFileMountPointFactory.FactoryId))
            {
                ids.Add(ZipFileMountPointFactory.FactoryId);
                Cache <IMountPointFactory> .Instance.AddPart(new ZipFileMountPointFactory());
            }
        }
Beispiel #3
0
        public ComponentManager(IEngineEnvironmentSettings engineEnvironmentSettings)
        {
            _engineEnvironmentSettings = engineEnvironmentSettings;
            _paths    = new SettingsFilePaths(engineEnvironmentSettings);
            _settings = SettingsStore.Load(engineEnvironmentSettings, _paths);
            _loadLocations.AddRange(_settings.ProbingPaths);

            ReflectionLoadProbingPath.Reset();
            foreach (string loadLocation in _loadLocations)
            {
                ReflectionLoadProbingPath.Add(loadLocation);
            }

            _componentIdsByType = new Dictionary <Type, HashSet <Guid> >();

            foreach (KeyValuePair <string, HashSet <Guid> > bucket in _settings.ComponentTypeToGuidList)
            {
                Type interfaceType = Type.GetType(bucket.Key);
                if (interfaceType != null)
                {
                    _componentIdsByType[interfaceType] = bucket.Value;
                }
            }

            foreach (KeyValuePair <string, string> entry in _settings.ComponentGuidToAssemblyQualifiedName)
            {
                if (Guid.TryParse(entry.Key, out Guid componentId))
                {
                    _componentIdToAssemblyQualifiedTypeName[componentId] = entry.Value;
                }
            }

            foreach (var(interfaceType, instance) in engineEnvironmentSettings.Host.BuiltInComponents)
            {
                AddComponent(interfaceType, instance);
            }
        }
        public ComponentManager(ISettingsLoader loader, SettingsStore userSettings)
        {
            _loader   = loader;
            _settings = userSettings;
            _loadLocations.AddRange(userSettings.ProbingPaths);

            ReflectionLoadProbingPath.Reset();
            foreach (string loadLocation in _loadLocations)
            {
                ReflectionLoadProbingPath.Add(loadLocation);
            }

            _componentIdsByType = new Dictionary <Type, HashSet <Guid> >();
            HashSet <Guid> allowedIds = new HashSet <Guid>();

            foreach (KeyValuePair <string, HashSet <Guid> > bucket in userSettings.ComponentTypeToGuidList)
            {
                allowedIds.UnionWith(bucket.Value);

                Type interfaceType = Type.GetType(bucket.Key);
                if (interfaceType != null)
                {
                    _componentIdsByType[interfaceType] = bucket.Value;
                }
            }

            foreach (KeyValuePair <string, string> entry in userSettings.ComponentGuidToAssemblyQualifiedName)
            {
                if (Guid.TryParse(entry.Key, out Guid componentId) && allowedIds.Contains(componentId))
                {
                    _componentIdToAssemblyQualifiedTypeName[componentId] = entry.Value;
                }
            }

            if (!allowedIds.Contains(FileSystemMountPointFactory.FactoryId))
            {
                allowedIds.Add(FileSystemMountPointFactory.FactoryId);
                AddComponent(typeof(IMountPointFactory), new FileSystemMountPointFactory());
            }

            if (!allowedIds.Contains(ZipFileMountPointFactory.FactoryId))
            {
                allowedIds.Add(ZipFileMountPointFactory.FactoryId);
                AddComponent(typeof(IMountPointFactory), new ZipFileMountPointFactory());
            }

            if (!allowedIds.Contains(GlobalSettingsTemplatePackageProviderFactory.FactoryId))
            {
                allowedIds.Add(GlobalSettingsTemplatePackageProviderFactory.FactoryId);
                AddComponent(typeof(ITemplatePackageProviderFactory), new GlobalSettingsTemplatePackageProviderFactory());
            }

            if (!allowedIds.Contains(NuGetInstallerFactory.FactoryId))
            {
                allowedIds.Add(NuGetInstallerFactory.FactoryId);
                AddComponent(typeof(IInstallerFactory), new NuGetInstallerFactory());
            }

            if (!allowedIds.Contains(FolderInstallerFactory.FactoryId))
            {
                allowedIds.Add(FolderInstallerFactory.FactoryId);
                AddComponent(typeof(IInstallerFactory), new FolderInstallerFactory());
            }

            foreach (KeyValuePair <Guid, Func <Type> > components in _loader.EnvironmentSettings.Host.BuiltInComponents)
            {
                if (allowedIds.Add(components.Key))
                {
                    RegisterType(components.Value());
                }
            }
        }
        public TemplateComponentManager(ISettingsLoader loader, SettingsStore userSettings)
        {
            _loader   = loader;
            _settings = userSettings;
            _loadLocations.AddRange(userSettings.ProbingPaths);
            ReflectionLoadProbingPath.Reset();
            foreach (var loadLocation in _loadLocations)
            {
                ReflectionLoadProbingPath.Add(loadLocation);
            }

            _componentIdsByType = new Dictionary <Type, HashSet <Guid> >();
            var hashSet = new HashSet <Guid>();

            foreach (var componentTypeToGuid in userSettings.ComponentTypeToGuidList)
            {
                hashSet.UnionWith(componentTypeToGuid.Value);
                try
                {
                    var type = Type.GetType(componentTypeToGuid.Key);
                    if (type != null)
                    {
                        _componentIdsByType[type] = componentTypeToGuid.Value;
                    }
                }
                catch (Exception e)
                {
                    Debug.Print(e.Message);
                }
            }

            foreach (var item in userSettings.ComponentGuidToAssemblyQualifiedName)
            {
                if (Guid.TryParse(item.Key, out var result) && hashSet.Contains(result))
                {
                    _componentIdToAssemblyQualifiedTypeName[result] = item.Value;
                }
            }

            if (!_componentIdsByType.TryGetValue(typeof(IMountPointFactory), out var value))
            {
                value = _componentIdsByType[typeof(IMountPointFactory)] = new HashSet <Guid>();
            }

            if (!value.Contains(Identifiers.FactoryId))
            {
                value.Add(Identifiers.FactoryId);
                Cache <IMountPointFactory> .Instance.AddPart(new FileSystemMountPointFactory());
            }

            if (!value.Contains(Identifiers.FactoryId))
            {
                value.Add(Identifiers.FactoryId);
                Cache <IMountPointFactory> .Instance.AddPart(new ZipFileMountPointFactory());
            }

            foreach (var builtInComponent in _loader.EnvironmentSettings.Host.BuiltInComponents)
            {
                if (value.Add(builtInComponent.Key))
                {
                    RegisterType(builtInComponent.Value());
                }
            }
        }