/// <summary>
        /// Gets the configuration.
        /// </summary>
        /// <param name="environment">The connection string.</param>
        /// <param name="configKey">The connection string.</param>
        /// <returns></returns>

        public static T LoadApplicationsConfiguration <T>(this EnvironmentsSection environment, string configKey)
            where T : class
        {
            T apps = null;

            using (var connection = new DB2Connection(environment.ConnectionString))
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    command.CommandType = CommandType.Text;
                    command.CommandText = "SELECT XMLVALUE FROM EUREKA_TOOLS.CONFIGURATION WHERE KEY = ?";
                    command.Parameters.Add(new DB2Parameter {
                        Value = configKey
                    });

                    var xmlConfiguration = command.ExecuteScalar();
                    if (xmlConfiguration == null)
                    {
                        return(null);
                    }

                    var stringConfiguration = xmlConfiguration.ToString();

                    var deserializer = new XmlSerializer(typeof(T));
                    var reader       = new StringReader(stringConfiguration);
                    apps = (T)deserializer.Deserialize(reader);
                }
            }

            return(apps);
        }
        /// <summary>
        /// Creates a copy of this instance.
        /// </summary>
        /// <returns>A shallow copy of this instance</returns>
        public EnvironmentsSection Copy()
        {
            var copy = new EnvironmentsSection();

            copy.ConnectionString = this.ConnectionString;
            copy.environments     = this.environments;
            copy.applications     = this.applications;

            return(copy);
        }
Beispiel #3
0
        /// <summary>
        /// Initializes the <see cref="EnvironmentManager"/> class.
        /// </summary>
        static EnvironmentManager()
        {
            var configurationSection = (EnvironmentsSection)ConfigurationManager.GetSection("environments");

            if (configurationSection == null)
            {
                environments = new EnvironmentElementCollection();
            }
            else
            {
                section            = configurationSection;
                environments       = configurationSection.Environments;
                applications       = configurationSection.Applications;
                currentEnvironment = configurationSection.Current;
            }
        }
        /// <summary>
        /// Saves the configuration to the target database.
        /// </summary>
        public static void SaveConfigurationSection(this EnvironmentsSection environment)
        {
            using (var connection = new DB2Connection(environment.ConnectionString))
            {
                connection.Open();
                using (var transaction = connection.BeginTransaction())
                {
                    Update(connection, "Applications", environment.Environments, transaction);
                    Update(connection, "Applications", environment.Applications, transaction);
                    transaction.Commit();
                }
            }

            using (var connection = new DB2Connection(environment.ConnectionString))
            {
                connection.Open();
                Update(connection, "Applications", environment.Applications);
            }
        }