internal ConfigurationService() { var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); _configPath = Path.Combine(appData, AppFolderName); _configFileName = Path.Combine(_configPath, ConfigFileName); if(!Directory.Exists(_configPath)) { try { Directory.CreateDirectory(_configPath); } catch(Exception exc) { if(exc.IsCritical()) { throw; } LoggingService.Global.Error(exc); } } _configuration = LoadConfig(ConfigFileName, "Configuration"); _rootSection = _configuration.RootSection; _guiSection = _rootSection.GetCreateSection("Gui"); _globalSection = _rootSection.GetCreateSection("Global"); _viewsSection = _rootSection.GetCreateSection("Tools"); _providersSection = _rootSection.GetCreateSection("Providers"); _repositoryManagerSection = _rootSection.GetCreateSection("RepositoryManager"); }
/// <summary>Create <see cref="Repository"/>.</summary> /// <param name="gitAccessor">Git repository access provider.</param> /// <param name="workingDirectory">Repository working directory.</param> /// <param name="load"><c>true</c> to load repository; <c>false</c> otherwise.</param> private Repository(IGitAccessor gitAccessor, string workingDirectory, bool load) { Verify.Argument.IsNotNull(gitAccessor, "gitAccessor"); Verify.Argument.IsNotNull(workingDirectory, "workingDirectory"); _workingDirectory = GetWorkingDirectory(workingDirectory); _gitDirectory = GetGitDirectory(_workingDirectory); _configurationManager = GetConfigurationManager(_gitDirectory); _accessor = gitAccessor.CreateRepositoryAccessor(this); _revisionCache = new RevisionCache(this); _configuration = new ConfigParametersCollection(this); _status = new Status(this); _stash = new StashedStatesCollection(this); _refs = new RefsCollection(this); _notes = new NotesCollection(this); _remotes = new RemotesCollection(this); _submodules = new SubmodulesCollection(this); _users = new UsersCollection(this); _hooks = new HooksCollection(this); if(load) { try { LoadCore(this, null, CancellationToken.None); } catch { Dispose(); throw; } } }
private void SaveConfig(string configFile, ConfigurationManager config) { try { using(var stream = CreateFile(configFile)) using(var adapter = new XmlAdapter(stream)) { config.Save(adapter); } } catch(Exception exc) { if(exc.IsCritical()) { throw; } LoggingService.Global.Error(exc); } }
private ConfigurationManager LoadConfig(string configFile, string configName) { ConfigurationManager config = null; if(FileExists(configFile)) { try { using(var stream = OpenFile(configFile)) { if(stream.Length != 0) { using(var adapter = new XmlAdapter(stream)) { try { config = new ConfigurationManager(adapter); } catch(Exception exc) { if(exc.IsCritical()) { throw; } LoggingService.Global.Error(exc); } } } } } catch(Exception exc) { if(exc.IsCritical()) { throw; } LoggingService.Global.Error(exc); } } if(config == null) { config = new ConfigurationManager(configName); } return config; }
private static ConfigurationManager GetConfigurationManager(string gitDirectory) { ConfigurationManager configurationManager = null; var cfgFileName = Path.Combine(gitDirectory, "gitter-config"); try { if(File.Exists(cfgFileName)) { using(var fs = new FileStream(cfgFileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { configurationManager = new ConfigurationManager(new XmlAdapter(fs)); } } } catch(Exception exc) { if(exc.IsCritical()) { throw; } } if(configurationManager == null) { configurationManager = new ConfigurationManager("Gitter"); } return configurationManager; }