Ejemplo n.º 1
0
        /// <summary>
        /// Loads the specified command.
        /// </summary>
        /// <param name="set">The set.</param>
        /// <param name="command">The command.</param>
        /// <param name="mappings">The mappings.</param>
        /// <param name="invariantProviderName">Name of the invariant provider.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">
        /// set;The expected set of data is not here.
        /// or
        /// command;The expected command is not here.
        /// or
        /// mappings;The expected table mappings are not here.
        /// or
        /// mappings;The expected table mappings are not here.
        /// </exception>
        public static DataSet Load(this DataSet set, DbCommand command, IEnumerable <DataTableMapping> mappings, string invariantProviderName)
        {
            if (set == null)
            {
                throw new ArgumentNullException("set", "The expected set of data is not here.");
            }
            if (command == null)
            {
                throw new ArgumentNullException("command", "The expected command is not here.");
            }
            if ((mappings == null) || (!mappings.Any()))
            {
                throw new ArgumentNullException("mappings", "The expected table mappings are not here.");
            }
            if (string.IsNullOrEmpty(invariantProviderName))
            {
                throw new ArgumentNullException("invariantProviderName", "The expected invariant provider name.");
            }

            using (var adapter = CommonDbmsUtility.GetAdapter(invariantProviderName))
            {
                adapter.TableMappings.AddRange(mappings.ToArray());
                adapter.SelectCommand = command;
                adapter.Fill(set);
            }

            return(set);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommonDbms"/> class.
        /// </summary>
        /// <param name="invariantProviderName">Name of the invariant provider.</param>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="connectionStringKey">The connection string key.</param>
        /// <param name="encryptionMetaJson">The encryption meta json.</param>
        /// <exception cref="System.ArgumentNullException">
        /// invariantProviderName;The expected provider name is not here.
        /// or
        /// connectionString;The expected connection string is not here.
        /// </exception>
        public CommonDbms(string invariantProviderName, string connectionString, string connectionStringKey, string encryptionMetaJson)
        {
            if (string.IsNullOrEmpty(invariantProviderName))
            {
                throw new ArgumentNullException("invariantProviderName", "The expected provider name is not here.");
            }
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentNullException("connectionString", "The expected connection string is not here.");
            }

            this._invariantProviderName = invariantProviderName;
            this._factory = CommonDbmsUtility.GetProviderFactory(this._invariantProviderName);

            if (!string.IsNullOrEmpty(encryptionMetaJson))
            {
                if (File.Exists(encryptionMetaJson))
                {
                    encryptionMetaJson = File.ReadAllText(encryptionMetaJson);
                }
                var encryptionMeta = JsonConvert.DeserializeObject <EncryptionMetadata>(encryptionMetaJson);
                connectionString = (!string.IsNullOrEmpty(connectionStringKey)) ?
                                   encryptionMeta.GetConnectionStringWithDecryptedValue(connectionString, connectionStringKey)
                    :
                                   encryptionMeta.Decrypt(connectionString);
            }

            this._connection = CommonDbmsUtility.GetConnection(this._factory, connectionString);
            this._connection.Open();
            this.OnConnectionOpen(this._connection);
        }
Ejemplo n.º 3
0
        public static void ShouldOpenConnection(this TestContext context, string dbFolder)
        {
            var invariantProviderName = context.Properties["invariantProviderName"].ToString();

            var connectionString = context.ShouldGetConnectionString(dbFolder);

            using (var connection = CommonDbmsUtility.GetConnection(invariantProviderName, connectionString))
            {
                connection.Open();
                Assert.AreEqual(connection.State, ConnectionState.Open, "The expected Open Connection State is not here.");
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public virtual void Dispose()
 {
     CommonDbmsUtility.Close(this._connection);
 }