Exemple #1
0
        private void EnsureLoaded()
        {
            if (_isLoaded)
            {
                return;
            }

            string userSettings = null;

            using (Timing.Over("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("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(this, _userSettings);
            using (Timing.Over("Init Mount Point manager"))
                _mountPointManager = new MountPointManager(_environmentSettings, _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;
        }
Exemple #2
0
        public bool TryMount(IMountPointManager manager, MountPointInfo info, out IMountPoint mountPoint)
        {
            if (info.ParentMountPointId != Guid.Empty || !Directory.Exists(info.Place))
            {
                mountPoint = null;
                return(false);
            }

            mountPoint = new FileSystemMountPoint(manager.EnvironmentSettings, info);
            return(true);
        }
Exemple #3
0
        public bool TryMount(IMountPointManager manager, MountPointInfo info, out IMountPoint mountPoint)
        {
            IMountPoint parent = null;

            if (info.ParentMountPointId != Guid.Empty)
            {
                if (!manager.TryDemandMountPoint(info.ParentMountPointId, out parent))
                {
                    mountPoint = null;
                    return(false);
                }
            }

            return(TryMount(manager.EnvironmentSettings, parent, info.MountPointId, info.Place, out mountPoint));
        }
        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;
        }
Exemple #5
0
 internal SettingsLoader(IEngineEnvironmentSettings environmentSettings, IMountPointManager mountPointManager) : this(environmentSettings)
 {
     _mountPointManager = mountPointManager;
 }
        private void EnsureLoaded()
        {
            if (!_isLoaded)
            {
                string json = null;
                using (Timing.Over(EnvironmentSettings.Host, "Read settings"))
                {
                    var num = 0;
                    while (true)
                    {
                        if (num < 20)
                        {
                            try
                            {
                                json = _paths.ReadAllText(_paths.User.SettingsFile, "{}");
                            }
                            catch (IOException)
                            {
                                if (num == 19)
                                {
                                    throw;
                                }

                                Task.Delay(2).Wait();
                                goto IL_005e;
                            }
                        }

                        break;
IL_005e:
                        num++;
                    }
                }

                JObject obj;
                using (Timing.Over(EnvironmentSettings.Host, "Parse settings"))
                {
                    try
                    {
                        obj = JObject.Parse(json);
                    }
                    catch (Exception innerException)
                    {
                        throw new EngineInitializationException("Error parsing the user settings file", "Settings File", innerException);
                    }
                }

                using (Timing.Over(EnvironmentSettings.Host, "Deserialize user settings"))
                {
                    _userSettings = new SettingsStore(obj);
                }

                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 (var mountPoint in _userSettings.MountPoints)
                    {
                        _mountPoints[mountPoint.MountPointId] = mountPoint;
                    }
                }

                using (Timing.Over(EnvironmentSettings.Host, "Init Component manager"))
                {
                    _componentManager = new TemplateComponentManager(this, _userSettings);
                }

                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;
            }
        }