Пример #1
0
        private Configuration BuildConfiguration()
        {
            Logger.Debug("Building configuration");
            var parameters = GetSessionFactoryParameters();

            var config = _sessionConfigurationCache.GetConfiguration(() =>
                                                                     _dataServicesProviderFactory
                                                                     .CreateProvider(parameters)
                                                                     .BuildConfiguration(parameters));

            #region NH-2.1.2 specific optimization
            // cannot be done in fluent config
            // the IsSelectable = false prevents unused ContentPartRecord proxies from being created
            // for each ContentItemRecord or ContentItemVersionRecord.
            // done for perf reasons - has no other side-effect

            foreach (var persistentClass in config.ClassMappings)
            {
                if (persistentClass.EntityName.StartsWith("Orchard.ContentManagement.Records."))
                {
                    foreach (var property in persistentClass.PropertyIterator)
                    {
                        if (property.Name.EndsWith("Record") && !property.IsBasicPropertyAccessor)
                        {
                            property.IsSelectable = false;
                        }
                    }
                }
            }
            #endregion

            Logger.Debug("Done Building configuration");
            return(config);
        }
Пример #2
0
        private NHibernate.Cfg.Configuration BuildConfiguration()
        {
            var parameters = GetDataServicesParameters();

            return(_dataServicesProviderFactory
                   .CreateProvider(parameters)
                   .BuildConfiguration(parameters));
        }
Пример #3
0
        private NHibernate.Cfg.Configuration BuildConfiguration(IDbProviderConfig config)
        {
            Logger.Debug("Building configuration");
            //TODO 缓存配置实现
            var providerService = _dataServicesProviderFactory.CreateProvider(config);
            var result          = providerService.BuildConfiguration(config);

            Logger.Debug("Done Building configuration");
            return(result);
        }
Пример #4
0
        public void Configure(DbContextOptionsBuilder optionsBuilders)
        {
            var shellPath = _appDataFolder.Combine("Sites", _shellSettings.Name);

            _appDataFolder.CreateDirectory(shellPath);

            var shellFolder = _appDataFolder.MapPath(shellPath);

            _dataServicesProviderFactory.CreateProvider(
                new DataServiceParameters {
                Provider         = _shellSettings.DataProvider,
                ConnectionString = _shellSettings.DataConnectionString,
                DataFolder       = shellFolder
            })
            .ConfigureContextOptions(optionsBuilders, _shellSettings.DataConnectionString);
        }
        public DbContextOptions BuildConfiguration()
        {
            lock (this)
            {
                if (_dbContextOptions == null)
                {
                    var shellPath = _appDataFolder.Combine("Sites", _shellSettings.Name);
                    _appDataFolder.CreateDirectory(shellPath);

                    var shellFolder = _appDataFolder.MapPath(shellPath);

                    _dbContextOptions = _dataServicesProviderFactory.CreateProvider(
                        new DataServiceParameters
                    {
                        Provider         = _shellSettings.DataProvider,
                        ConnectionString = _shellSettings.DataConnectionString,
                        DataFolder       = shellFolder
                    })
                                        .BuildContextOptions();
                }
            }
            return(_dbContextOptions);
        }
Пример #6
0
        /// <summary>
        /// Generates SchemaCommand instances in order to create the schema for a specific feature
        /// </summary>
        public IEnumerable <SchemaCommand> GetCreateFeatureCommands(string feature, bool drop)
        {
            var dependencies = _extensionManager.AvailableFeatures()
                               .Where(f => String.Equals(f.Id, feature, StringComparison.OrdinalIgnoreCase))
                               .Where(f => f.Dependencies != null)
                               .SelectMany(f => f.Dependencies)
                               .ToList();

            var shellDescriptor = new ShellDescriptor {
                Features = dependencies.Select(id => new ShellFeature {
                    Name = id
                }).Union(new[] { new ShellFeature {
                                     Name = feature
                                 }, new ShellFeature {
                                     Name = "Orchard.Framework"
                                 } })
            };

            var shellBlueprint = _compositionStrategy.Compose(_shellSettings, shellDescriptor);

            if (!shellBlueprint.Records.Any())
            {
                yield break;
            }

            //var features = dependencies.Select(name => new ShellFeature {Name = name}).Union(new[] {new ShellFeature {Name = feature}, new ShellFeature {Name = "Orchard.Framework"}});

            var parameters = _sessionFactoryHolder.GetSessionFactoryParameters();

            parameters.RecordDescriptors = shellBlueprint.Records;

            var configuration = _dataServicesProviderFactory
                                .CreateProvider(parameters)
                                .BuildConfiguration(parameters);

            Dialect.GetDialect(configuration.Properties);
            var mapping = configuration.BuildMapping();

            // get the table mappings using reflection
            var tablesField = typeof(Configuration).GetField("tables", BindingFlags.Instance | BindingFlags.NonPublic);
            var tables      = ((IDictionary <string, Table>)tablesField.GetValue(configuration)).Values;

            string prefix = feature.Replace(".", "_") + "_";

            foreach (var table in tables.Where(t => parameters.RecordDescriptors.Any(rd => rd.Feature.Descriptor.Id == feature && rd.TableName == t.Name)))
            {
                string tableName     = table.Name;
                var    recordType    = parameters.RecordDescriptors.First(rd => rd.Feature.Descriptor.Id == feature && rd.TableName == tableName).Type;
                var    isContentPart = typeof(ContentPartRecord).IsAssignableFrom(recordType);

                if (tableName.StartsWith(prefix))
                {
                    tableName = tableName.Substring(prefix.Length);
                }

                if (drop)
                {
                    yield return(new DropTableCommand(tableName));
                }

                var command = new CreateTableCommand(tableName);

                foreach (var column in table.ColumnIterator)
                {
                    // create copies for local variables to be evaluated at the time the loop is called, and not lately when the la;bda is executed
                    var tableCopy  = table;
                    var columnCopy = column;

                    var sqlType = columnCopy.GetSqlTypeCode(mapping);
                    command.Column(column.Name, sqlType.DbType,
                                   action => {
                        if (tableCopy.PrimaryKey.Columns.Any(c => c.Name == columnCopy.Name))
                        {
                            action.PrimaryKey();

                            if (!isContentPart)
                            {
                                action.Identity();
                            }
                        }


                        if (columnCopy.IsLengthDefined() &&
                            new[] { DbType.StringFixedLength, DbType.String, DbType.AnsiString, DbType.AnsiStringFixedLength }.Contains(sqlType.DbType) &&
                            columnCopy.Length != Column.DefaultLength)
                        {
                            action.WithLength(columnCopy.Length);
                        }

                        if (columnCopy.IsPrecisionDefined())
                        {
                            action.WithPrecision((byte)columnCopy.Precision);
                            action.WithScale((byte)columnCopy.Scale);
                        }
                        if (columnCopy.IsNullable)
                        {
                            action.Nullable();
                        }

                        if (columnCopy.IsUnique)
                        {
                            action.Unique();
                        }

                        if (columnCopy.DefaultValue != null)
                        {
                            action.WithDefault(columnCopy.DefaultValue);
                        }
                    });
                }

                yield return(command);
            }
        }