/// <summary>
        /// Build this instance.
        /// </summary>
        /// <returns>The build.</returns>
        public DataContextOptions <TContext> Build()
        {
            var options = new DataContextOptions <TContext>();

            BuildOptions(options);
            return(options);
        }
        /// <summary>
        /// Builds the options.
        /// </summary>
        /// <param name="options">Options.</param>
        protected void BuildOptions(DataContextOptions options)
        {
            if (_func == null)
            {
                throw new LightDataException(SR.DataContextOptionsError);
            }
            var paramSet = new ConfigParamSet();

            foreach (var item in _dict)
            {
                if (item.Value != null)
                {
                    paramSet.SetParamValue(item.Key, item.Value);
                }
            }
            var database = _func(Guid.NewGuid().ToString("N"), paramSet);

            if (database == null)
            {
                throw new LightDataException(SR.DataContextOptionsError);
            }
            options.Connection    = _connection;
            options.Database      = database;
            options.CommandOutput = _commandOutput;
        }
        /// <summary>
        /// Create the specified configuration.
        /// </summary>
        /// <returns>The create.</returns>
        /// <param name="configuration">Configuration.</param>
        public DataContextOptions <TContext> Create(DataContextConfiguration configuration)
        {
            var options = new DataContextOptions <TContext>();

            BuildOptions(options, configuration);
            return(options);
        }
Esempio n. 4
0
 private void Internal_DataContextConfiguration(LightDataOptions optionList)
 {
     if (optionList != null && optionList.Connections != null && optionList.Connections.Length > 0)
     {
         foreach (var connection in optionList.Connections)
         {
             var setting = new ConnectionSetting()
             {
                 Name             = connection.Name,
                 ConnectionString = connection.ConnectionString,
                 ProviderName     = connection.ProviderName
             };
             var configParam = new ConfigParamSet();
             if (connection.ConfigParams != null && connection.ConfigParams.Count > 0)
             {
                 foreach (var param in connection.ConfigParams)
                 {
                     configParam.SetParamValue(param.Key, param.Value);
                 }
             }
             setting.ConfigParam = configParam;
             var options = DataContextOptions.CreateOptions(setting);
             if (options != null)
             {
                 if (defaultOptions == null)
                 {
                     defaultOptions = options;
                 }
                 optionsDict.Add(setting.Name, options);
             }
         }
     }
 }
Esempio n. 5
0
        internal static DataContextOptions CreateOptions(IConnectionSetting setting)
        {
            if (setting == null)
            {
                throw new ArgumentNullException(nameof(setting));
            }
            Type   type;
            string connection = setting.ConnectionString;

            type = Type.GetType(setting.ProviderName, true);

            if (type == null)
            {
                return(null);
            }

            DatabaseProvider dataBase = (DatabaseProvider)Activator.CreateInstance(type, setting.Name, setting.ConfigParam) as DatabaseProvider;

            if (dataBase == null)
            {
                throw new LightDataException(string.Format(SR.TypeIsNotDatabaseType, type.FullName));
            }
            DataContextOptions contextOptions = new DataContextOptions()
            {
                Connection = connection,
                Database   = dataBase
            };

            return(contextOptions);
        }
        void BuildOptions(DataContextOptions options, DataContextConfiguration configuration)
        {
            DataContextOptions baseOptions = null;

            if (_configName == null)
            {
                baseOptions = configuration.DefaultOptions;
            }
            else
            {
                baseOptions = configuration.GetOptions(_configName);
            }
            options.Database      = baseOptions.Database;
            options.Connection    = baseOptions.Connection;
            options.CommandOutput = _commandOutput;
        }
Esempio n. 7
0
 internal LCollection(DataContext context, object owner, QueryExpression query, string[] fieldPaths)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     if (owner == null)
     {
         throw new ArgumentNullException(nameof(owner));
     }
     if (query == null)
     {
         throw new ArgumentNullException(nameof(query));
     }
     options         = context.Options;
     output          = context.Output;
     this.owner      = owner;
     this.query      = query;
     this.fieldPaths = fieldPaths;
 }
Esempio n. 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="options"></param>
 public LightDataContextFactory(DataContextOptions <DataContext> options) : base(options)
 {
 }
Esempio n. 9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="options"></param>
 public DataContextFactory(DataContextOptions <TContxt> options)
 {
     this.options = options;
 }