/// <summary> /// Reads the configuration. /// </summary> /// <param name="xmlFile">The XML file text reader.</param> /// <param name="rootPath">The root path to resolve relative paths to.</param> /// <returns> /// Configuration set. /// </returns> public DbDeploymentsConfig ReadConfiguration(TextReader xmlFile, string rootPath) { var doc = XDocument.Load(xmlFile); var deploymentsConfig = new DbDeploymentsConfig(); deploymentsConfig.Deployments = doc.Root.Descendants("dbdeploy").Select(e => ReadConfigElement(e, rootPath)).ToList(); return(deploymentsConfig); }
/// <summary> /// Parses the specified args into a deployments configuration. /// </summary> /// <param name="args">The args.</param> /// <returns> /// Configuration set. /// </returns> /// <exception cref="UsageException">Throws when unknown or invalid parameters are found.</exception> public static DbDeploymentsConfig ParseOptions(string[] args) { // Initialize configuration with a single deployment. var deploymentsConfig = new DbDeploymentsConfig(); try { var configFile = new ConfigFileInfo(); var config = new DbDeployConfig(); OptionSet options = Initialize(config, configFile); deploymentsConfig.Deployments.Add(config); List<string> unknown = options.Parse(args); if (unknown != null && unknown.Count != 0) { foreach (var s in unknown) { // empty "unkown" parameters are allowed if (s != null && !string.IsNullOrEmpty(s.Trim())) { throw new UsageException("Unkown parameter(s): " + string.Join(", ", unknown.ToArray())); } } } // If a configuration file was specified in the command, use that instead of options. if (configFile.FileInfo != null) { var configurationManager = new DbDeployConfigurationManager(); deploymentsConfig = configurationManager.ReadConfiguration(configFile.FileInfo.FullName); } } catch (OptionException e) { throw new UsageException(e.Message, e); } return deploymentsConfig; }