Ejemplo n.º 1
0
        public void AddConfiguration(string configurationName, string fileName, bool createNew)
        {
            _package.EnableConfigurations = true;

            string configFilePath = ExpressionPathBuilder.PathCleaner(Settings.Default.DetegoPackageConfigurationRoot
                                                                      + Path.DirectorySeparatorChar
                                                                      + fileName);

            Message.Trace(Severity.Debug, "Adding Configuration File {0}", configFilePath);

            if (createNew)
            {
                Message.Trace(Severity.Debug, "XML Says CreateNew: Creating Configuration File {0}", configFilePath);
                _package.ExportConfigurationFile(configFilePath + Resources.ExtensionTempFile);

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(configFilePath + Resources.ExtensionTempFile);

                XmlTextWriter xmlPrettyPrinter = new XmlTextWriter(configFilePath, null);
                xmlPrettyPrinter.Formatting = Formatting.Indented;

                xmlDoc.Save(xmlPrettyPrinter);

                xmlPrettyPrinter.Flush();
                xmlPrettyPrinter.Close();
                File.Delete(configFilePath + Resources.ExtensionTempFile);
            }

            DTS.Configuration config = _package.Configurations.Add();
            config.ConfigurationType = DTS.DTSConfigurationType.ConfigFile;
            config.Name                = configurationName;
            config.Description         = configurationName;
            config.ConfigurationString = configFilePath;
        }