public IProvider GetProvider(string providerName, out IProviderMetadata metadata)
        {
            Lazy <IProvider, IProviderMetadata> exportedProvider = GetExportedProvider(providerName);

            metadata = exportedProvider.Metadata;
            return(exportedProvider.Value);
        }
Exemple #2
0
 public RuntimeContext(IDbConnection connection, IDbTransaction transaction, IDbCommandExecutor executor, IProviderMetadata providerMetadata, IMigrationStepMetadata stepMetadata)
     : base(providerMetadata, stepMetadata)
 {
     _connection = connection;
     _transaction = transaction;
     _executor = executor;
 }
Exemple #3
0
        public ProviderInfo(IProvider provider, IProviderMetadata metadata)
        {
            if (provider == null) throw new ArgumentNullException("provider");
            if (metadata == null) throw new ArgumentNullException("metadata");

            Provider = provider;
            Metadata = metadata;
        }
 public MigrationStep(IMigration migration, IScheduledMigrationMetadata metadata, ConnectionInfo connectionInfo, IProvider provider, IProviderMetadata providerMetadata, IDbConnectionFactory connectionFactory, ISqlDispatcher sqlDispatcher)
     : base(migration, provider, providerMetadata)
 {
     _metadata = metadata;
     _connectionInfo = connectionInfo;
     _connectionFactory = connectionFactory;
     _sqlDispatcher = sqlDispatcher;
 }
        public ProviderInfo GetLatest(DbPlatform dbPlatform)
        {
            IProviderMetadata providerMetadata = FindLatest(dbPlatform);

            if (providerMetadata == null)
            {
                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Could not find a provider for '{0}'.", dbPlatform));
            }
            return(ToProviderInfo(providerMetadata));
        }
        public SqlDispatcher(ScriptingOptions scriptingOptions, IProvider provider, IProviderMetadata providerMetadata)
        {
            if (scriptingOptions == null)
            {
                throw new ArgumentNullException("scriptingOptions");
            }

            _scriptingOptions = scriptingOptions;
            _provider         = provider;
            _providerMetadata = providerMetadata;
        }
        internal IProvider GetProvider(string providerName, out IProviderMetadata metadata)
        {
            ProviderInfo info;

            if (!_providers.TryGetValue(providerName, out info))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "The provider '{0}' is not enlisted in the supported providers.", providerName));
            }
            metadata = info.Metadata;
            return(info.Provider);
        }
Exemple #8
0
        public FileScripter(DirectoryInfo targetDirectory, string stepName, IProvider provider, IProviderMetadata providerMetadata)
        {
            if (!targetDirectory.Exists)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "The directory '{0}' does not exist.", targetDirectory.FullName), "targetDirectory");
            }

            _targetDirectory  = targetDirectory;
            _provider         = provider;
            _providerMetadata = providerMetadata;
            _writer           = CreateWriter(stepName);
        }
Exemple #9
0
        public ProviderInfo(IProvider provider, IProviderMetadata metadata)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (metadata == null)
            {
                throw new ArgumentNullException("metadata");
            }

            Provider = provider;
            Metadata = metadata;
        }
        public static string GetParameterSpecifier(this IProviderMetadata metadata, IDataParameter parameter)
        {
            if (parameter == null)
            {
                throw new ArgumentNullException("parameter");
            }
            if (!parameter.ParameterName.StartsWith("@", StringComparison.Ordinal))
            {
                throw new ArgumentException("Parameter names must start with an '@'.");
            }

            string name = parameter.ParameterName.Substring(1); // the name itself starts after the @

            return(metadata.ParameterExpression.Replace("p", name));
        }
Exemple #11
0
        private static MigrationOptions GetOptions(out IEnumerable <ProviderInfo> providerInfos)
        {
            IProviderMetadata metadata = A.Fake <IProviderMetadata>();

            A.CallTo(() => metadata.MaximumDbObjectNameLength).Returns(MaximumSupportedLength);
            A.CallTo(() => metadata.MajorVersion).Returns(Platform.MajorVersion);
            A.CallTo(() => metadata.InvariantName).Returns("System.Data.Odbc"); // for the Odbc specific tests

            IProvider provider = new ProviderStub();

            IProviderRegistry providerRegistry = A.Fake <IProviderRegistry>();

            A.CallTo(() => providerRegistry.GetProvider(metadata)).Returns(provider);
            providerInfos = new[] { new ProviderInfo(provider, metadata) };

            var options = new MigrationOptions();

            options.SupportedPlatforms.AddOrReplaceMinimumRequirement(Platform);
            return(options);
        }
        public void SaveLocalizedValue(IProviderMetadata metadata, int languageId, string propertyName, string value)
        {
            Guard.NotNull(metadata, nameof(metadata));
            Guard.IsPositive(languageId, nameof(languageId));
            Guard.NotEmpty(propertyName, nameof(propertyName));

            var resourceName = metadata.ResourceKeyPattern.FormatInvariant(metadata.SystemName, propertyName);
            var resource     = _services.Localization.GetLocaleStringResourceByName(resourceName, languageId, false);

            if (resource != null)
            {
                if (value.IsEmpty())
                {
                    // delete
                    _services.Localization.DeleteLocaleStringResource(resource);
                }
                else
                {
                    // update
                    resource.ResourceValue = value;
                    _services.Localization.UpdateLocaleStringResource(resource);
                }
            }
            else
            {
                if (value.HasValue())
                {
                    // insert
                    resource = new LocaleStringResource
                    {
                        LanguageId    = languageId,
                        ResourceName  = resourceName,
                        ResourceValue = value,
                    };
                    _services.Localization.InsertLocaleStringResource(resource);
                }
            }
        }
Exemple #13
0
        internal Versioning(ConnectionInfo connectionInfo, IDbConnectionFactory connectionFactory, IProvider provider, IProviderMetadata providerMetadata, string versioningTableName, ISqlDispatcher sqlDispatcher)
        {
            _connectionInfo = connectionInfo;
            _connectionFactory = connectionFactory;
            _provider = provider;
            _providerMetadata = providerMetadata;
            _versioningTableName = versioningTableName;
            _sqlDispatcher = sqlDispatcher;

            _versioningTableExists = new Lazy<bool>(() =>
                {
                    int exists;
                    using (IDbConnection connection = connectionFactory.OpenConnection(connectionInfo))
                    {
                        IDbCommand command = connection.CreateCommand();
                        command.CommandTimeout = 0; // do not timeout; the client is responsible for not causing lock-outs
                        command.CommandText = provider.ExistsTable(connection.Database, _versioningTableName);
                        Log.Verbose(LogCategory.Sql, command.CommandText);
                        exists = Convert.ToInt32(command.ExecuteScalar(), CultureInfo.InvariantCulture);
                    }
                    return exists != 0;
                });
        }
Exemple #14
0
        internal Versioning(ConnectionInfo connectionInfo, IDbConnectionFactory connectionFactory, IProvider provider, IProviderMetadata providerMetadata, string versioningTableName, ISqlDispatcher sqlDispatcher)
        {
            _connectionInfo      = connectionInfo;
            _connectionFactory   = connectionFactory;
            _provider            = provider;
            _providerMetadata    = providerMetadata;
            _versioningTableName = versioningTableName;
            _sqlDispatcher       = sqlDispatcher;

            _versioningTableExists = new Lazy <bool>(() =>
            {
                int exists;
                using (IDbConnection connection = connectionFactory.OpenConnection(connectionInfo))
                {
                    IDbCommand command     = connection.CreateCommand();
                    command.CommandTimeout = 0;     // do not timeout; the client is responsible for not causing lock-outs
                    command.CommandText    = provider.ExistsTable(connection.Database, _versioningTableName);
                    Log.Verbose(LogCategory.Sql, command.CommandText);
                    exists = Convert.ToInt32(command.ExecuteScalar(), CultureInfo.InvariantCulture);
                }
                return(exists != 0);
            });
        }
Exemple #15
0
        private static MigrationOptions GetOptions()
        {
            IProviderMetadata returnedMetadata = MockRepository.GenerateStub <IProviderMetadata>();

            returnedMetadata.Expect(m => m.MaximumDbObjectNameLength).Return(MaximumSupportedLength);
            returnedMetadata.Expect(m => m.Name).Return(ProviderName);
            returnedMetadata.Expect(m => m.InvariantName).Return("System.Data.Odbc"); // for the Odbc specific tests

            IProvider provider = new ProviderStub();

            IProviderFactory  providerFactory = MockRepository.GenerateStub <IProviderFactory>();
            IProviderMetadata passedMetadata;

            providerFactory.Expect(f => f.GetProvider(ProviderName, out passedMetadata)).OutRef(returnedMetadata).Return(provider);

            var supportedProviders = new SupportedProviders(providerFactory);

            supportedProviders.Add(ProviderName);

            var options = new MigrationOptions();

            options.SupportedProviders = supportedProviders;
            return(options);
        }
 public MigrationContext(IProviderMetadata providerMetadata)
 {
     _providerMetadata = providerMetadata;
 }
 private ProviderInfo ToProviderInfo(IProviderMetadata providerMetadata)
 {
     return(new ProviderInfo(_providerRegistry.GetProvider(providerMetadata), providerMetadata));
 }
 public MigrationContext(IProviderMetadata providerMetadata, IMigrationStepMetadata stepMetadata)
 {
     _providerMetadata = providerMetadata;
     _stepMetadata     = stepMetadata;
 }
Exemple #19
0
        public void TestScriptingAllMigrations()
        {
            DirectoryInfo targetDirectory = PrepareScriptingDirectory();

            _options.VersioningTableName = "My Versioning Table"; // test overriding the default versioning table name
            _options.OnlyScriptSqlTo(targetDirectory);
            Migrator migrator = CreateMigrator();

            migrator.MigrateAll(typeof(Migration1).Assembly);

            // assert that all script files were generated
            List <FileInfo> scriptFiles = targetDirectory.GetFiles(string.Format(CultureInfo.InvariantCulture, "Migration.*.*.sql"))
                                          .OrderBy(f => int.Parse(Regex.Match(f.Name, @"Migration\..*\.(\d+)\.sql").Groups[1].Value, CultureInfo.InvariantCulture))
                                          .ToList();

            Assert.AreEqual(Migrations.Count, scriptFiles.Count);
            Assert.AreEqual("Migration." + MigrationExportAttribute.DefaultModuleName + ".1.sql", scriptFiles[0].Name);
            Assert.AreEqual("Migration." + Migration2.Module + ".2.sql", scriptFiles[1].Name);

            // assert Versioning table was *not* created as we are scripting only
            DataTable versioningTable = GetTable(_options.VersioningTable);

            Assert.IsNull(versioningTable, string.Format(CultureInfo.CurrentCulture, "The '{0}' table was created altough ScriptingMode was ScriptOnly.", _options.VersioningTableName));

            // assert Customer table was *not* created as we are scripting only
            var       migration1    = new Migration1();
            DataTable customerTable = GetTable(migration1.Tables[0].FullName);

            Assert.IsNull(customerTable, string.Format(CultureInfo.CurrentCulture, "The '{0}' table was created altough ScriptingMode was ScriptOnly.", migration1.Tables[0].FullName));

            // execute generated script files against database and recheck results
            IProviderMetadata metadata = IntegrationTestContext.ProviderMetadata;
            var info = new ConnectionInfo(ConnectionString, metadata.InvariantName, metadata.SupportsTransactions, metadata.EnableAnsiQuotesCommand);

            using (IDbConnection connection = migrator.Configuration.ConnectionFactory.OpenConnection(info))
            {
                foreach (FileInfo scriptFile in scriptFiles)
                {
                    Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Reading script '{0}':", scriptFile.FullName));
                    string[] scriptLines = File.ReadAllLines(scriptFile.FullName);
                    foreach (string line in scriptLines)
                    {
                        Trace.WriteLine(line);
                    }

                    // group all lines between empty lines into one command (some database platforms require DDL operations to
                    // be executed in separated commands)
                    Trace.WriteLine(Environment.NewLine + string.Format(CultureInfo.CurrentCulture, "Executing script '{0}':", scriptFile.FullName));
                    string commandText = string.Empty;
                    foreach (string line in scriptLines)
                    {
                        if (line.Trim().Length != 0)
                        {
                            commandText += line;
                        }
                        else
                        {
                            ExecuteCommand(commandText, connection);
                            commandText = string.Empty;
                        }
                    }
                    Assert.IsEmpty(commandText, "The script should end with an empty line.");
                }
            }
            VerifyResultsOfAllMigrations();

            // delete script files
            targetDirectory.Delete(true);
        }
Exemple #20
0
 public IProvider GetProvider(IProviderMetadata metadata)
 {
     return _providers.Single(p => p.Metadata == metadata).Value;
 }
 public string GetLocalizedDescription(IProviderMetadata metadata, int languageId = 0, bool returnDefaultValue = true)
 {
     return(GetLocalizedValue(metadata, "Description", x => x.Description, languageId, returnDefaultValue));
 }
Exemple #22
0
 public IProvider GetProvider(IProviderMetadata metadata)
 {
     return(_providers.Single(p => p.Metadata == metadata).Value);
 }
Exemple #23
0
 public IProvider GetProvider(IProviderMetadata metadata)
 {
     return(Providers.Value.Single(p => p.Metadata == metadata).CreateExport().Value);
 }
Exemple #24
0
 public History(string tableName, IProviderMetadata providerMetadata)
 {
     _tableName = tableName;
     _providerMetadata = providerMetadata;
 }
 public IProvider GetProvider(string providerName, out IProviderMetadata metadata)
 {
     Lazy<IProvider, IProviderMetadata> exportedProvider = GetExportedProvider(providerName);
     metadata = exportedProvider.Metadata;
     return exportedProvider.Value;
 }
 public ProviderInfo(IProvider provider, IProviderMetadata metadata)
 {
     _provider = provider;
     _metadata = metadata;
 }
 internal IProvider GetProvider(string providerName, out IProviderMetadata metadata)
 {
     ProviderInfo info;
     if (!_providers.TryGetValue(providerName, out info))
     {
         throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "The provider '{0}' is not enlisted in the supported providers.", providerName));
     }
     metadata = info.Metadata;
     return info.Provider;
 }
Exemple #28
0
        private void Validate(IProviderMetadata providerMetadata, IEnumerable <SupportsAttribute> supportsAttributes, IEnumerable <UnsupportedMethod> unsupportedMethods, IMigrationReport report, List <ValidationWarning> warningMessages, List <string> errorMessages)
        {
            if (!string.IsNullOrEmpty(report.Error))
            {
                errorMessages.Add(string.Format(CultureInfo.InvariantCulture, "Error in migration '{0}': {1}", report.MigrationName, report.Error));
            }

            // check created object name lengths
            if (providerMetadata.MaximumDbObjectNameLength > 0 && !string.IsNullOrEmpty(report.LongestName) &&
                providerMetadata.MaximumDbObjectNameLength < report.LongestName.Length)
            {
                errorMessages.Add(string.Format(CultureInfo.CurrentCulture,
                                                "Migration '{0}' contains object names that are longer than what is supported by '{1}' ('{2}': {3}, supported: {4}).",
                                                report.MigrationName,
                                                providerMetadata.GetPlatform(),
                                                report.LongestName,
                                                report.LongestName.Length,
                                                providerMetadata.MaximumDbObjectNameLength));
            }

            // check used data types
            foreach (DataType dataType in report.DataTypes)
            {
                DbType dbType = dataType.DbType;
                List <SupportsAttribute> attributes = supportsAttributes.Where(a => a.DbType == dbType).ToList();
                if (attributes.Count == 0)
                {
                    errorMessages.Add(string.Format(CultureInfo.CurrentCulture,
                                                    "Migration '{0}' uses the data type '{1}' which is not supported by '{2}'.",
                                                    report.MigrationName,
                                                    dataType,
                                                    providerMetadata.GetPlatform()));
                    continue;
                }
                // post-condition: the data type is supported

                // check if OfSize was specified correctly
                SupportsAttribute attribute = attributes.Find(a => !(a.MaximumSize > 0 ^ dataType.Size.HasValue) && !(a.MaximumScale > 0 ^ dataType.Scale.HasValue));
                if (attribute == null)
                {
                    errorMessages.Add(string.Format(CultureInfo.CurrentCulture,
                                                    "Migration '{0}' uses the data type '{1}' which is not supported by '{2}'.",
                                                    report.MigrationName,
                                                    dataType,
                                                    providerMetadata.GetPlatform()));
                    continue;
                }
                // post-condition: the data type is supported and OfSize was specified with the correct number of parameters

                // check other properties
                if (report.PrimaryKeyDataTypes.Contains(dataType) && !attribute.CanBeUsedAsPrimaryKey)
                {
                    errorMessages.Add(string.Format(CultureInfo.CurrentCulture,
                                                    "Migration '{0}' uses the data type '{1}' for a primary key which is not supported by '{2}'.",
                                                    report.MigrationName,
                                                    dataType,
                                                    providerMetadata.GetPlatform()));
                }
                if (report.IdentityDataTypes.Contains(dataType) && !attribute.CanBeUsedAsIdentity)
                {
                    errorMessages.Add(string.Format(CultureInfo.CurrentCulture,
                                                    "Migration '{0}' uses the data type '{1}' for an identity column which is not supported by '{2}'.",
                                                    report.MigrationName,
                                                    dataType,
                                                    providerMetadata.GetPlatform()));
                }
                if (attribute.MaximumSize > 0 && dataType.Size > attribute.MaximumSize)
                {
                    errorMessages.Add(string.Format(CultureInfo.CurrentCulture,
                                                    "Migration '{0}' uses the data type '{1}' which exceeds the maximum size of {2} supported by '{3}'.",
                                                    report.MigrationName,
                                                    dataType,
                                                    attribute.MaximumSize,
                                                    providerMetadata.GetPlatform()));
                }
                if (attribute.MaximumScale > 0 && dataType.Scale > attribute.MaximumScale)
                {
                    errorMessages.Add(string.Format(CultureInfo.CurrentCulture,
                                                    "Migration '{0}' uses the data type '{1}' which exceeds the maximum scale of {2} supported by '{3}'.",
                                                    report.MigrationName,
                                                    dataType,
                                                    attribute.MaximumScale,
                                                    providerMetadata.GetPlatform()));
                }
                if (!string.IsNullOrEmpty(attribute.Warning))
                {
                    warningMessages.Add(new ValidationWarning(report.MigrationName, dataType, providerMetadata.GetPlatform(), attribute.Warning));
                }
                if (providerMetadata.InvariantName == "System.Data.Odbc") // ODBC specific warnings
                {
                    if (dataType.DbType == DbType.Int64)
                    {
                        warningMessages.Add(new ValidationWarning(report.MigrationName, dataType, providerMetadata.GetPlatform(), "Int64 is not supported for DbParameters with ODBC; requires calling ToString to directly inline the value in the CommandText."));
                    }
                }
            }

            // check used methods
            foreach (UnsupportedMethod method in unsupportedMethods
                     .Join(report.Methods, um => um.Name, m => m, (um, m) => um))
            {
                errorMessages.Add(string.Format(CultureInfo.CurrentCulture,
                                                "Migration '{0}' calls the '{1}' method which is not supported by '{2}': {3}",
                                                report.MigrationName,
                                                method.Name,
                                                providerMetadata.GetPlatform(),
                                                method.Message));
            }

            // filter suppressed warnings
            warningMessages.RemoveAll(WarningIsSuppressed);
        }
 public BootstrapMigrationStep(IMigration migration, IProvider provider, IProviderMetadata providerMetadata)
 {
     _migration = migration;
     _provider = provider;
     _providerMetadata = providerMetadata;
 }
 public MigrationStep(IMigration migration, IScheduledMigrationMetadata metadata, ConnectionInfo connectionInfo, IProvider provider, IProviderMetadata providerMetadata, IDbConnectionFactory connectionFactory, ISqlDispatcher sqlDispatcher)
     : base(migration, provider, providerMetadata)
 {
     _metadata          = metadata;
     _connectionInfo    = connectionInfo;
     _connectionFactory = connectionFactory;
     _sqlDispatcher     = sqlDispatcher;
 }
 public string GetLocalizedFriendlyName(IProviderMetadata metadata, int languageId = 0, bool returnDefaultValue = true)
 {
     return(GetLocalizedValue(metadata, "FriendlyName", x => x.FriendlyName, languageId, returnDefaultValue));
 }
 public MigrationContext(IProviderMetadata providerMetadata)
 {
     _providerMetadata = providerMetadata;
 }
        /// <summary>
        /// Populates the member metadata for the given type
        /// </summary>
        /// <param name="resourceTypeCacheItem">Instance of ResourceTypeCacheItem containing the ResourceType and its metadata.</param>
        /// <param name="workspace">workspace containing the metadata information</param>
        /// <param name="metadataCacheItem">Instance of ProviderMetadataCacheItem.</param>
        /// <param name="primitiveResourceTypeMap">Map of primitive types to use when building member metadata.</param>
        internal static void PopulateMemberMetadata(
            ResourceTypeCacheItem resourceTypeCacheItem,
            IProviderMetadata workspace,
            ProviderMetadataCacheItem metadataCacheItem,
            PrimitiveResourceTypeMap primitiveResourceTypeMap)
        {
            Debug.Assert(resourceTypeCacheItem != null, "resourceTypeCacheItem != null");
            Debug.Assert(workspace != null, "workspace != null");

            var resourceType = resourceTypeCacheItem.ResourceType;

            // Find the type from the OSpace
            IProviderType edmType = workspace.GetProviderType(resourceType.FullName);
            foreach (IProviderMember member in edmType.Members)
            {
                ResourcePropertyKind kind = (ResourcePropertyKind)(-1);

                // ObjectContextServiceProvider fails with NullReferenceException when an entity property is not public.
                // If the property on the CLR type which is representing the EDM type has non-public properties but those properties are part of the
                // conceptual model, the server will try to load CLR metadata for these properties.
                // The Type.GetProperty(propertyName) method used BindingFlags.Instance | BindingFlags.Public by default if no binding flags are specified.
                // Since the property was not found with these binding flags, the GetProperty method returns null, which we didn't check for in v1 and v2 and threw an NRE.
                // We now check for null return values from this function and throw if we find that the model property declared on the CLR type is not public.
                PropertyInfo propertyInfo = resourceType.InstanceType.GetProperty(member.Name, BindingFlags.Instance | BindingFlags.Public);
                if (propertyInfo == null)
                {
                    throw new DataServiceException((int)HttpStatusCode.InternalServerError, Strings.ObjectContext_PublicPropertyNotDefinedOnType(edmType.Name, member.Name));
                }

                ResourceType propertyType = null;
                switch (member.EdmTypeKind)
                {
                    case BuiltInTypeKind.PrimitiveType:
#if !INTERNAL_DROP && !EFRTM
                        Type propertyClrType = ObjectContextSpatialUtil.IsDbGeography(propertyInfo.PropertyType) ? typeof(Geography) : propertyInfo.PropertyType;
#else
                        Type propertyClrType = propertyInfo.PropertyType;
#endif
                        propertyType = primitiveResourceTypeMap.GetPrimitive(propertyClrType);

                        if (propertyType == null)
                        {
                            throw new NotSupportedException(Strings.ObjectContext_PrimitiveTypeNotSupported(member.Name, edmType.Name, member.EdmTypeName));
                        }

                        if (member.IsKey)
                        {
                            kind = ResourcePropertyKind.Key | ResourcePropertyKind.Primitive;
                        }
                        else
                        {
                            kind = ResourcePropertyKind.Primitive;
                        }

                        break;
                    case BuiltInTypeKind.ComplexType:
                        kind = ResourcePropertyKind.ComplexType;
                        propertyType = metadataCacheItem.TryGetResourceType(propertyInfo.PropertyType);
                        break;
                    case BuiltInTypeKind.EntityType:
                        kind = ResourcePropertyKind.ResourceReference;
                        propertyType = metadataCacheItem.TryGetResourceType(propertyInfo.PropertyType);
                        break;
                    case BuiltInTypeKind.CollectionType:
                        kind = ResourcePropertyKind.ResourceSetReference;
                        Type collectionItemClrType = workspace.GetClrType(member.CollectionItemType);
                        Debug.Assert(!WebUtil.IsPrimitiveType(collectionItemClrType), "We don't support collections of primitives, we shouldn't see one here");
                        propertyType = metadataCacheItem.TryGetResourceType(collectionItemClrType);
                        break;
                    default:
                        throw new NotSupportedException(Strings.ObjectContext_PrimitiveTypeNotSupported(member.Name, edmType.Name, member.EdmTypeName));
                }

                Debug.Assert(propertyType != null, "propertyType != null");
                ResourceProperty resourceProperty = new ResourceProperty(propertyInfo.Name, kind, propertyType);
                SetMimeTypeForMappedMember(resourceProperty, member);
                resourceType.AddProperty(resourceProperty);
#if !EF6Provider
                ObjectContextServiceProvider.PopulateFacets(resourceProperty, member.Facets, resourceProperty.ResourceType.ResourceTypeKind == ResourceTypeKind.EntityType /*ignoreNullableAnnotation*/);
                ObjectContextServiceProvider.PopulateAnnotations(member.MetadataProperties, resourceProperty.AddCustomAnnotation);
#endif
                resourceTypeCacheItem.AddResourcePropertyCacheItem(resourceProperty, new ObjectContextResourcePropertyCacheItem(propertyInfo, member));
            }
        }
 public ProviderInfo(IProvider provider, IProviderMetadata metadata)
 {
     _provider = provider;
     _metadata = metadata;
 }
Exemple #35
0
 public RuntimeContext(IDbConnection connection, IDbTransaction transaction, IDbCommandExecutor executor, IProviderMetadata providerMetadata)
     : base(providerMetadata)
 {
     _connection  = connection;
     _transaction = transaction;
     _executor    = executor;
 }
Exemple #36
0
 private ProviderInfo ToProviderInfo(IProviderMetadata providerMetadata)
 {
     return new ProviderInfo(_providerFactory.GetProvider(providerMetadata), providerMetadata);
 }
Exemple #37
0
 public History(string tableName, IProviderMetadata providerMetadata)
 {
     _tableName        = tableName;
     _providerMetadata = providerMetadata;
 }
        public ProviderInfo GetExactly(DbPlatform dbPlatform)
        {
            IProviderMetadata metadata = _providerRegistry.GetProviderMetadatas().Single(m => m.Platform == dbPlatform.Platform && m.MajorVersion == dbPlatform.MajorVersion && m.Driver == dbPlatform.Driver);

            return(new ProviderInfo(_providerRegistry.GetProvider(metadata), metadata));
        }
Exemple #39
0
        private void Validate(IProviderMetadata providerMetadata, IEnumerable<SupportsAttribute> supportsAttributes, IEnumerable<UnsupportedMethod> unsupportedMethods, IMigrationReport report, List<ValidationWarning> warningMessages, List<string> errorMessages)
        {
            if (!string.IsNullOrEmpty(report.Error))
            {
                errorMessages.Add(string.Format(CultureInfo.InvariantCulture, "Error in migration '{0}': {1}", report.MigrationName, report.Error));
            }

            // check created object name lengths
            if (providerMetadata.MaximumDbObjectNameLength > 0 && !string.IsNullOrEmpty(report.LongestName) &&
                providerMetadata.MaximumDbObjectNameLength < report.LongestName.Length)
            {
                errorMessages.Add(string.Format(CultureInfo.CurrentCulture,
                    "Migration '{0}' contains object names that are longer than what is supported by '{1}' ('{2}': {3}, supported: {4}).",
                    report.MigrationName,
                    providerMetadata.Name,
                    report.LongestName,
                    report.LongestName.Length,
                    providerMetadata.MaximumDbObjectNameLength));
            }

            // check used data types
            foreach (DataType dataType in report.DataTypes)
            {
                DbType dbType = dataType.DbType;
                List<SupportsAttribute> attributes = supportsAttributes.Where(a => a.DbType == dbType).ToList();
                if (attributes.Count == 0)
                {
                    errorMessages.Add(string.Format(CultureInfo.CurrentCulture,
                        "Migration '{0}' uses the data type '{1}' which is not supported by '{2}'.",
                        report.MigrationName,
                        dataType,
                        providerMetadata.Name));
                    continue;
                }
                // post-condition: the data type is supported

                // check if OfSize was specified correctly
                SupportsAttribute attribute = attributes.Find(a => !(a.MaximumSize > 0 ^ dataType.Size.HasValue) && !(a.MaximumScale > 0 ^ dataType.Scale.HasValue));
                if (attribute == null)
                {
                    errorMessages.Add(string.Format(CultureInfo.CurrentCulture,
                        "Migration '{0}' uses the data type '{1}' which is not supported by '{2}'.",
                        report.MigrationName,
                        dataType,
                        providerMetadata.Name));
                    continue;
                }
                // post-condition: the data type is supported and OfSize was specified with the correct number of parameters

                // check other properties
                if (report.PrimaryKeyDataTypes.Contains(dataType) && !attribute.CanBeUsedAsPrimaryKey)
                {
                    errorMessages.Add(string.Format(CultureInfo.CurrentCulture,
                        "Migration '{0}' uses the data type '{1}' for a primary key which is not supported by '{2}'.",
                        report.MigrationName,
                        dataType,
                        providerMetadata.Name));
                }
                if (report.IdentityDataTypes.Contains(dataType) && !attribute.CanBeUsedAsIdentity)
                {
                    errorMessages.Add(string.Format(CultureInfo.CurrentCulture,
                        "Migration '{0}' uses the data type '{1}' for an identity column which is not supported by '{2}'.",
                        report.MigrationName,
                        dataType,
                        providerMetadata.Name));
                }
                if (attribute.MaximumSize > 0 && dataType.Size > attribute.MaximumSize)
                {
                    errorMessages.Add(string.Format(CultureInfo.CurrentCulture,
                        "Migration '{0}' uses the data type '{1}' which exceeds the maximum size of {2} supported by '{3}'.",
                        report.MigrationName,
                        dataType,
                        attribute.MaximumSize,
                        providerMetadata.Name));
                }
                if (attribute.MaximumScale > 0 && dataType.Scale > attribute.MaximumScale)
                {
                    errorMessages.Add(string.Format(CultureInfo.CurrentCulture,
                        "Migration '{0}' uses the data type '{1}' which exceeds the maximum scale of {2} supported by '{3}'.",
                        report.MigrationName,
                        dataType,
                        attribute.MaximumScale,
                        providerMetadata.Name));
                }
                if (!string.IsNullOrEmpty(attribute.Warning))
                {
                    warningMessages.Add(new ValidationWarning(report.MigrationName, dataType, providerMetadata.Name, attribute.Warning));
                }
                if (providerMetadata.InvariantName == "System.Data.Odbc") // ODBC specific warnings
                {
                    if (dataType.DbType == DbType.Int64)
                    {
                        warningMessages.Add(new ValidationWarning(report.MigrationName, dataType, providerMetadata.Name, "Int64 is not supported for DbParameters with ODBC; requires calling ToString to directly inline the value in the CommandText."));
                    }
                }
            }

            // check used methods
            foreach (UnsupportedMethod method in unsupportedMethods
                .Join(report.Methods, um => um.Name, m => m, (um, m) => um))
            {
                errorMessages.Add(string.Format(CultureInfo.CurrentCulture,
                    "Migration '{0}' calls the '{1}' method which is not supported by '{2}': {3}",
                    report.MigrationName,
                    method.Name,
                    providerMetadata.Name,
                    method.Message));
            }

            // filter suppressed warnings
            warningMessages.RemoveAll(WarningIsSuppressed);
        }
Exemple #40
0
        protected override bool PrepareResult(IConnectionFilter result, IAppServer appServer, IProviderMetadata metadata)
        {
            if (!result.Initialize(metadata.Name, appServer))
            {
                appServer.Logger.ErrorFormat("Failed to initialize the ConnectionFilter '{0}'", metadata.Name);
                return(false);
            }

            return(true);
        }
 public static bool UsesPositionalParameters(this IProviderMetadata metadata)
 {
     return(!metadata.ParameterExpression.Contains("p"));
 }
 public BootstrapMigrationStep(IMigration migration, IProvider provider, IProviderMetadata providerMetadata)
 {
     _migration        = migration;
     _provider         = provider;
     _providerMetadata = providerMetadata;
 }
 public static DbPlatform GetPlatform(this IProviderMetadata metadata)
 {
     return(new DbPlatform(metadata.Platform, metadata.MajorVersion, metadata.Driver));
 }
Exemple #44
0
 public MigrationContext(IProviderMetadata providerMetadata, IMigrationStepMetadata stepMetadata)
 {
     _providerMetadata = providerMetadata;
     _stepMetadata = stepMetadata;
 }