/// <summary>
        ///     Returns the appropriate dynamic ObjectContext type.
        /// </summary>
        /// <typeparam name="T">
        ///     The ObjectContext type that the result type should derive from.
        /// </typeparam>
        /// <param name="entityConnectionString">
        ///     The entity connection string that references the metadata and identifies the
        ///     persistent database.
        /// </param>
        /// <param name="persistent">
        ///     if set to <c>true</c> the ObjectContext uses a persistent database, otherwise
        ///     transient.
        /// </param>
        /// <param name="dataLoader">
        ///     The data loader that initializes the state of the database.
        /// </param>
        /// <returns>
        ///     The ObjectContext type.
        /// </returns>
        private static Type CreateType <T>(
            string entityConnectionString,
            bool persistent,
            IDataLoader dataLoader)
            where T : ObjectContext
        {
            EffortConnectionStringBuilder ecsb = new EffortConnectionStringBuilder();

            if (dataLoader != null)
            {
                ecsb.DataLoaderType     = dataLoader.GetType();
                ecsb.DataLoaderArgument = dataLoader.Argument;
            }

            string effortConnectionString = ecsb.ConnectionString;

            return(ObjectContextTypeStore.GetObjectContextType(
                       entityConnectionString,
                       effortConnectionString,
                       typeof(T),
                       () =>
            {
                if (string.IsNullOrEmpty(entityConnectionString))
                {
                    entityConnectionString = GetDefaultConnectionString <T>();
                }

                return CreateType <T>(
                    entityConnectionString,
                    effortConnectionString,
                    persistent);
            }));
        }
Esempio n. 2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="DataLoaderConfigurationKey" />
        ///     class.
        /// </summary>
        /// <param name="loader"> The data loader. </param>
        public DataLoaderConfigurationKey(IDataLoader loader)
        {
            if (loader == null)
            {
                throw new ArgumentNullException("loader");
            }

            this.type     = loader.GetType();
            this.argument = loader.Argument ?? string.Empty;
        }
        /// <summary>
        ///     Creates an EffortConnection object with a connection string that represents the
        ///     specified parameter values.
        /// </summary>
        /// <param name="instanceId"> The instance id. </param>
        /// <param name="dataLoader"> The data loader. </param>
        /// <returns> The EffortConnection object. </returns>
        private static EffortConnection Create(string instanceId, IDataLoader dataLoader)
        {
            EffortProviderConfiguration.VerifyProvider();

            EffortConnectionStringBuilder connectionString =
                new EffortConnectionStringBuilder();

            connectionString.InstanceId = instanceId;

            if (dataLoader != null)
            {
                connectionString.DataLoaderType     = dataLoader.GetType();
                connectionString.DataLoaderArgument = dataLoader.Argument;
            }

            EffortConnection connection = new EffortConnection();

            connection.ConnectionString = connectionString.ConnectionString;

            return(connection);
        }
        /// <summary>
        ///     Creates an EffortConnection object with a connection string that represents the 
        ///     specified parameter values.
        /// </summary>
        /// <param name="instanceId"> The instance id. </param>
        /// <param name="dataLoader"> The data loader. </param>
        /// <returns> The EffortConnection object. </returns>
        private static EffortConnection Create(string instanceId, IDataLoader dataLoader)
        {
            EffortProviderConfiguration.VerifyProvider();

            EffortConnectionStringBuilder connectionString = 
                new EffortConnectionStringBuilder();

            connectionString.InstanceId = instanceId;

            if (dataLoader != null)
            {
                connectionString.DataLoaderType = dataLoader.GetType();
                connectionString.DataLoaderArgument = dataLoader.Argument;
            }

            EffortConnection connection = new EffortConnection();
            connection.ConnectionString = connectionString.ConnectionString;

            return connection;
        }
Esempio n. 5
0
        /// <summary>
        /// Priorities the specified loader.
        /// </summary>
        /// <param name="loader">The loader.</param>
        /// <returns></returns>
        public static int Priority(this IDataLoader loader)
        {
            var attr = loader.GetType().GetCustomAttribute <VersionedComponentExportAttribute>();

            return(attr == null ? 0 : attr.Priority);
        }