Ejemplo n.º 1
0
        public Repository Init(IAbsoluteDirectoryPath folder, IReadOnlyCollection<Uri> hosts,
            Dictionary<string, object> opts = null) {
            Contract.Requires<ArgumentNullException>(folder != null);
            Contract.Requires<ArgumentNullException>(hosts != null);

            if (opts == null)
                opts = new Dictionary<string, object>();

            var rsyncFolder = folder.GetChildDirectoryWithName(Repository.RepoFolderName);
            if (rsyncFolder.Exists)
                throw new Exception("Already appears to be a repository");

            var packFolder = Path.Combine(opts.ContainsKey("pack_path")
                ? ((string) opts["pack_path"])
                : rsyncFolder.ToString(),
                Repository.PackFolderName).ToAbsoluteDirectoryPath();

            var configFile = rsyncFolder.GetChildFileWithName(Repository.ConfigFileName);
            var wdVersionFile = rsyncFolder.GetChildFileWithName(Repository.VersionFileName);
            var packVersionFile = packFolder.GetChildFileWithName(Repository.VersionFileName);

            this.Logger().Info("Initializing {0}", folder);
            rsyncFolder.MakeSurePathExists();
            packFolder.MakeSurePathExists();

            var config = new RepoConfig {Hosts = hosts.ToArray()};

            if (opts.ContainsKey("pack_path"))
                config.PackPath = (string) opts["pack_path"];

            if (opts.ContainsKey("include"))
                config.Include = (string[]) opts["include"];

            if (opts.ContainsKey("exclude"))
                config.Exclude = (string[]) opts["exclude"];

            var guid = opts.ContainsKey("required_guid")
                ? (string) opts["required_guid"]
                : Guid.NewGuid().ToString();

            var packVersion = new RepoVersion {Guid = guid};
            if (opts.ContainsKey("archive_format"))
                packVersion.ArchiveFormat = (string) opts["archive_format"];

            var wdVersion = YamlExtensions.NewFromYaml<RepoVersion>(packVersion.ToYaml());

            config.SaveYaml(configFile);
            packVersion.SaveYaml(packVersionFile);
            wdVersion.SaveYaml(wdVersionFile);

            return TryGetRepository(folder.ToString(), opts, rsyncFolder.ToString());
        }
Ejemplo n.º 2
0
 void TryLoadConfig(bool fallback) {
     try {
         Config = YamlExtensions.NewFromYamlFile<RepoConfig>(ConfigFile);
     } catch (FileNotFoundException) {
         Config = new RepoConfig();
     } catch (Exception e) {
         var msg = String.Format("An error has occurred during processing the config file [{0}]", RepoName);
         this.Logger().FormattedWarnException(e);
         if (!fallback)
             throw new ConfigException(msg);
         Config = new RepoConfig();
     }
 }