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());
            }
        }
示例#2
0
        private static void EnsureLoaded()
        {
            if (_isLoaded)
            {
                return;
            }

            string userSettings;

            using (Timing.Over("Read settings"))
                userSettings = Paths.User.SettingsFile.ReadAllText("{}");
            JObject parsed;

            using (Timing.Over("Parse settings"))
                parsed = JObject.Parse(userSettings);
            using (Timing.Over("Deserialize user settings"))
                _userSettings = new SettingsStore(parsed);

            using (Timing.Over("Init probing paths"))
                if (_userSettings.ProbingPaths.Count == 0)
                {
                    _userSettings.ProbingPaths.Add(Paths.User.Content);
                }

            using (Timing.Over("Init Component manager"))
                _componentManager = new ComponentManager(_userSettings);
            using (Timing.Over("Init Mount Point manager"))
                _mountPointManager = new MountPointManager(_componentManager);

            using (Timing.Over("Demand template load"))
                EnsureTemplatesLoaded();

            _mountPoints = new Dictionary <Guid, MountPointInfo>();

            using (Timing.Over("Load mount points"))
                foreach (MountPointInfo info in _userSettings.MountPoints)
                {
                    _mountPoints[info.MountPointId] = info;
                }

            _isLoaded = true;
        }
示例#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);
            }
        }
示例#4
0
        private void EnsureLoaded()
        {
            if (_isLoaded)
            {
                return;
            }

            string userSettings = null;

            using (Timing.Over(_environmentSettings.Host, "Read settings"))
                for (int i = 0; i < MaxLoadAttempts; ++i)
                {
                    try
                    {
                        userSettings = _paths.ReadAllText(_paths.User.SettingsFile, "{}");
                        break;
                    }
                    catch (IOException)
                    {
                        if (i == MaxLoadAttempts - 1)
                        {
                            throw;
                        }

                        Task.Delay(2).Wait();
                    }
                }
            JObject parsed;

            using (Timing.Over(_environmentSettings.Host, "Parse settings"))
                try
                {
                    parsed = JObject.Parse(userSettings);
                }
                catch (Exception ex)
                {
                    throw new EngineInitializationException("Error parsing the user settings file", "Settings File", ex);
                }
            using (Timing.Over(_environmentSettings.Host, "Deserialize user settings"))
                _userSettings = new SettingsStore(parsed);

            using (Timing.Over(_environmentSettings.Host, "Init probing paths"))
                if (_userSettings.ProbingPaths.Count == 0)
                {
                    _userSettings.ProbingPaths.Add(_paths.User.Content);
                }

            _mountPoints = new Dictionary <Guid, MountPointInfo>();
            using (Timing.Over(_environmentSettings.Host, "Load mount points"))
                foreach (MountPointInfo info in _userSettings.MountPoints)
                {
                    _mountPoints[info.MountPointId] = info;
                }

            using (Timing.Over(_environmentSettings.Host, "Init Component manager"))
                _componentManager = new ComponentManager(this, _userSettings);

            if (_mountPointManager == null)
            {
                using (Timing.Over(_environmentSettings.Host, "Init Mount Point manager"))
                    _mountPointManager = new MountPointManager(_environmentSettings, _componentManager);
            }

            using (Timing.Over(_environmentSettings.Host, "Demand template load"))
                EnsureTemplatesLoaded();

            _isLoaded = true;
        }
        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 (!_componentIdsByType.TryGetValue(typeof(IMountPointFactory), out HashSet <Guid> ids))
            {
                _componentIdsByType[typeof(IMountPointFactory)] = ids = new HashSet <Guid>();
            }

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

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

            if (!ids.Contains(DefaultInstallUnitDescriptorFactory.FactoryId))
            {
                if (ids.Add(DefaultInstallUnitDescriptorFactory.FactoryId))
                {
                    RegisterType(typeof(DefaultInstallUnitDescriptorFactory));
                }
            }

            if (!ids.Contains(NupkgInstallUnitDescriptorFactory.FactoryId))
            {
                if (ids.Add(NupkgInstallUnitDescriptorFactory.FactoryId))
                {
                    RegisterType(typeof(NupkgInstallUnitDescriptorFactory));
                }
            }

            foreach (KeyValuePair <Guid, Func <Type> > components in _loader.EnvironmentSettings.Host.BuiltInComponents)
            {
                if (ids.Add(components.Key))
                {
                    RegisterType(components.Value());
                }
            }
        }
示例#6
0
        public static void Save(this SettingsStore store)
        {
            JObject serialized = JObject.FromObject(store);

            Paths.User.SettingsFile.WriteAllText(serialized.ToString());
        }