private static async Task <IRelationalDatabase> SnapshotAsyncCore(IRelationalDatabase database, IIdentifierResolutionStrategy identifierResolver, CancellationToken cancellationToken) { var tablesTask = database.GetAllTables(cancellationToken).ToListAsync(cancellationToken).AsTask(); var viewsTask = database.GetAllViews(cancellationToken).ToListAsync(cancellationToken).AsTask(); var sequencesTask = database.GetAllSequences(cancellationToken).ToListAsync(cancellationToken).AsTask(); var synonymsTask = database.GetAllSynonyms(cancellationToken).ToListAsync(cancellationToken).AsTask(); var routinesTask = database.GetAllRoutines(cancellationToken).ToListAsync(cancellationToken).AsTask(); await Task.WhenAll(new Task[] { tablesTask, viewsTask, sequencesTask, synonymsTask, routinesTask }).ConfigureAwait(false); var tables = await tablesTask.ConfigureAwait(false); var views = await viewsTask.ConfigureAwait(false); var sequences = await sequencesTask.ConfigureAwait(false); var synonyms = await synonymsTask.ConfigureAwait(false); var routines = await routinesTask.ConfigureAwait(false); return(new RelationalDatabase( database.IdentifierDefaults, identifierResolver, tables, views, sequences, synonyms, routines )); }
/// <summary> /// Initialize the application /// </summary> /// <param name="initializationInformation"></param> private void Initialize(IInitializationInformation initializationInformation) { Application = new Application(initializationInformation); InternalTransaction = new InternalTransaction(initializationInformation); ExternalTransaction = new ExternalTransaction(initializationInformation); RelationalDatabase = new RelationalDatabase(initializationInformation); }
/// <summary> /// Analyses a relational database. /// </summary> /// <param name="database">A relational database. Analysis will be performed on objects retrieved from the database.</param> /// <param name="cancellationToken">A cancellation token used to interrupt analysis.</param> /// <returns>A set of linting messages used for reporting. An empty set indicates no issues discovered.</returns> /// <exception cref="ArgumentNullException"><paramref name="database"/> is <c>null</c>.</exception> public IAsyncEnumerable <IRuleMessage> AnalyseDatabase(IRelationalDatabase database, CancellationToken cancellationToken = default) { if (database == null) { throw new ArgumentNullException(nameof(database)); } return(AnalyseDatabaseCore(database, cancellationToken)); }
public Task <string> SerializeAsync(IRelationalDatabase obj, CancellationToken cancellationToken = default) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } return(SerializeAsyncCore(obj, cancellationToken)); }
/// <summary> /// Initializes a new instance of the <see cref="PocoDataAccessGenerator"/> class. /// </summary> /// <param name="fileSystem">A file system to export to.</param> /// <param name="database">A relational database object provider.</param> /// <param name="commentProvider">A database comment provider.</param> /// <param name="nameTranslator">The name translator to use when generating C# object names.</param> /// <exception cref="ArgumentNullException">Thrown when any of <paramref name="fileSystem"/>, <paramref name="database"/>, <paramref name="commentProvider"/>, <paramref name="nameTranslator"/> are <c>null</c>.</exception> public PocoDataAccessGenerator( IFileSystem fileSystem, IRelationalDatabase database, IRelationalDatabaseCommentProvider commentProvider, INameTranslator nameTranslator) { FileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem)); Database = database ?? throw new ArgumentNullException(nameof(database)); CommentProvider = commentProvider ?? throw new ArgumentNullException(nameof(commentProvider)); NameTranslator = nameTranslator ?? throw new ArgumentNullException(nameof(nameTranslator)); }
/// <summary> /// Initializes a new instance of the <see cref="RelationalDatabaseBuilder"/> class. /// </summary> /// <param name="database">A base relational database.</param> /// <exception cref="ArgumentNullException"><paramref name="database"/> is <c>null</c>.</exception> public RelationalDatabaseBuilder(IRelationalDatabase database) { if (database == null) { throw new ArgumentNullException(nameof(database)); } _databases = new List <IRelationalDatabase> { database }; }
public ReflectionSequence(IRelationalDatabase database, IDatabaseDialect dialect, Type sequenceType) { if (database == null) { throw new ArgumentNullException(nameof(database)); } if (dialect == null) { throw new ArgumentNullException(nameof(dialect)); } if (sequenceType == null) { throw new ArgumentNullException(nameof(sequenceType)); } var typeInfo = sequenceType.GetTypeInfo(); if (!typeInfo.ImplementedInterfaces.Contains(ISequenceType)) { throw new ArgumentException($"The sequence type { typeInfo.FullName } must implement the { ISequenceType.FullName } interface.", nameof(sequenceType)); } var ctor = sequenceType.GetDefaultConstructor(); if (ctor == null) { throw new ArgumentException($"The sequence type { typeInfo.FullName } does not contain a default constructor.", nameof(sequenceType)); } var instance = ctor.Invoke(Array.Empty <object>()) as ISequence; var sequenceName = dialect.GetQualifiedNameOrDefault(database, sequenceType); var minValue = instance !.MinValue.ToOption(); var maxValue = instance !.MaxValue.ToOption(); // create an inner sequence, which will perform validation var sequence = new DatabaseSequence( sequenceName, instance !.Start, instance !.Increment, minValue, maxValue, instance !.Cycle, instance !.Cache ); Cache = sequence.Cache; Cycle = sequence.Cycle; Increment = sequence.Increment; MaxValue = maxValue; MinValue = minValue; Name = sequenceName; Start = sequence.Start; }
private async IAsyncEnumerable <IRuleMessage> AnalyseDatabaseCore(IRelationalDatabase database, [EnumeratorCancellation] CancellationToken cancellationToken) { var tables = await database.GetAllTables(cancellationToken).ToListAsync(cancellationToken).ConfigureAwait(false); foreach (var tableRule in TableRules) { await foreach (var message in tableRule.AnalyseTables(tables, cancellationToken).ConfigureAwait(false)) { yield return(message); } } var views = await database.GetAllViews(cancellationToken).ToListAsync(cancellationToken).ConfigureAwait(false); foreach (var viewRule in ViewRules) { await foreach (var message in viewRule.AnalyseViews(views, cancellationToken).ConfigureAwait(false)) { yield return(message); } } var sequences = await database.GetAllSequences(cancellationToken).ToListAsync(cancellationToken).ConfigureAwait(false); foreach (var sequenceRule in SequenceRules) { await foreach (var message in sequenceRule.AnalyseSequences(sequences, cancellationToken).ConfigureAwait(false)) { yield return(message); } } var synonyms = await database.GetAllSynonyms(cancellationToken).ToListAsync(cancellationToken).ConfigureAwait(false); foreach (var synonymRule in SynonymRules) { await foreach (var message in synonymRule.AnalyseSynonyms(synonyms, cancellationToken).ConfigureAwait(false)) { yield return(message); } } var routines = await database.GetAllRoutines(cancellationToken).ToListAsync(cancellationToken).ConfigureAwait(false); foreach (var routineRule in RoutineRules) { await foreach (var message in routineRule.AnalyseRoutines(routines, cancellationToken).ConfigureAwait(false)) { yield return(message); } } }
/// <summary> /// Snapshots a relational database. Preserves the same behaviour, but enables querying in-memory, avoiding further database calls. /// </summary> /// <param name="database">A relational database.</param> /// <param name="identifierResolver">An identifier resolver to use when an object cannot be found using the given name.</param> /// <param name="cancellationToken">A cancellation token.</param> /// <returns>A relational database with the same data as <paramref name="database"/>, but serialized into an in-memory copy.</returns> /// <exception cref="ArgumentNullException"><paramref name="database"/> or <paramref name="identifierResolver"/> is <c>null</c>.</exception> public static Task <IRelationalDatabase> SnapshotAsync(IRelationalDatabase database, IIdentifierResolutionStrategy identifierResolver, CancellationToken cancellationToken = default) { if (database == null) { throw new ArgumentNullException(nameof(database)); } if (identifierResolver == null) { throw new ArgumentNullException(nameof(identifierResolver)); } return(SnapshotAsyncCore(database, identifierResolver, cancellationToken)); }
public static Task <Dto.RelationalDatabase> ToDtoAsync(this IMapper mapper, IRelationalDatabase database, CancellationToken cancellationToken = default) { if (mapper == null) { throw new ArgumentNullException(nameof(mapper)); } if (database == null) { throw new ArgumentNullException(nameof(database)); } return(ToDtoAsyncCore(mapper, database, cancellationToken)); }
public ReflectionRoutine(IRelationalDatabase database, IDatabaseDialect dialect, Type routineType) { if (database == null) { throw new ArgumentNullException(nameof(database)); } if (dialect == null) { throw new ArgumentNullException(nameof(dialect)); } RoutineType = routineType ?? throw new ArgumentNullException(nameof(routineType)); Name = dialect.GetQualifiedNameOrDefault(database, RoutineType); }
public ReflectionView(IRelationalDatabase database, IDatabaseDialect dialect, Type viewType) { if (database == null) { throw new ArgumentNullException(nameof(database)); } if (dialect == null) { throw new ArgumentNullException(nameof(dialect)); } ViewType = viewType ?? throw new ArgumentNullException(nameof(viewType)); Name = dialect.GetQualifiedNameOrDefault(database, ViewType); }
/// <summary> /// Overrides any existing database objects with a provided database. /// </summary> /// <param name="database">The database.</param> /// <returns>A relational database builder with the given relational database applied.</returns> /// <exception cref="ArgumentNullException"><paramref name="database"/> is <c>null</c>.</exception> public IRelationalDatabaseBuilder OverrideWith(IRelationalDatabase database) { if (database == null) { throw new ArgumentNullException(nameof(database)); } var appendedDatabases = new List <IRelationalDatabase>(_databases) { database }; return(new RelationalDatabaseBuilder(appendedDatabases)); }
public ReflectionTable(IRelationalDatabase database, IDatabaseDialect dialect, Type tableType) { Database = database ?? throw new ArgumentNullException(nameof(database)); Dialect = dialect ?? throw new ArgumentNullException(nameof(dialect)); InstanceType = tableType ?? throw new ArgumentNullException(nameof(tableType)); Name = Dialect.GetQualifiedNameOrDefault(database, InstanceType); TypeProvider = new ReflectionTableTypeProvider(Dialect, InstanceType); _columns = new Lazy <IReadOnlyList <IDatabaseColumn> >(LoadColumnList); _checkLookup = new Lazy <IReadOnlyDictionary <Identifier, IDatabaseCheckConstraint> >(LoadChecks); _uniqueKeyLookup = new Lazy <IReadOnlyDictionary <Identifier, IDatabaseKey> >(LoadUniqueKeys); _indexLookup = new Lazy <IReadOnlyDictionary <Identifier, IDatabaseIndex> >(LoadIndexes); _parentKeyLookup = new Lazy <IReadOnlyDictionary <Identifier, IDatabaseRelationalKey> >(LoadParentKeys); _childKeys = new Lazy <IReadOnlyCollection <IDatabaseRelationalKey> >(LoadChildKeys); _primaryKey = new Lazy <Option <IDatabaseKey> >(LoadPrimaryKey); }
public MainRenderer( IRelationalDatabase database, IHtmlFormatter formatter, IReadOnlyCollection <IRelationalDatabaseTable> tables, IReadOnlyCollection <IDatabaseView> views, IReadOnlyCollection <IDatabaseSequence> sequences, IReadOnlyCollection <IDatabaseSynonym> synonyms, IReadOnlyCollection <IDatabaseRoutine> routines, IReadOnlyDictionary <Identifier, ulong> rowCounts, string dbVersion, DirectoryInfo exportDirectory) { if (tables == null || tables.AnyNull()) { throw new ArgumentNullException(nameof(tables)); } if (views == null || views.AnyNull()) { throw new ArgumentNullException(nameof(views)); } if (sequences == null || sequences.AnyNull()) { throw new ArgumentNullException(nameof(sequences)); } if (synonyms == null || synonyms.AnyNull()) { throw new ArgumentNullException(nameof(synonyms)); } if (routines == null || routines.AnyNull()) { throw new ArgumentNullException(nameof(routines)); } Tables = tables; Views = views; Sequences = sequences; Synonyms = synonyms; Routines = routines; Database = database ?? throw new ArgumentNullException(nameof(database)); Formatter = formatter ?? throw new ArgumentNullException(nameof(formatter)); RowCounts = rowCounts ?? throw new ArgumentNullException(nameof(rowCounts)); DatabaseDisplayVersion = dbVersion; ExportDirectory = exportDirectory ?? throw new ArgumentNullException(nameof(exportDirectory)); }
public ReflectionSynonym(IRelationalDatabase database, IDatabaseDialect dialect, Type synonymType) { if (database == null) { throw new ArgumentException(nameof(database)); } if (dialect == null) { throw new ArgumentNullException(nameof(dialect)); } if (synonymType == null) { throw new ArgumentNullException(nameof(synonymType)); } Name = dialect.GetQualifiedNameOrDefault(database, synonymType); var targetType = GetBaseGenericTypeArg(synonymType); Target = dialect.GetQualifiedNameOrDefault(database, targetType); }
public SimpleLoggingTests() { Mock <IQueueMessenger> queueMessenger = new Mock <IQueueMessenger>(); queueMessenger.Setup(x => x.SendMessage(It.IsAny <byte[]>())); _queueMessenger = queueMessenger.Object; _initializationInformation = new InitialilizationInformation(MessageQueueType.RabbitMQ); _initializationInformation.RabbitMq.ExchangeName = "Testing"; _initializationInformation.RabbitMq.HostName = "localHost"; _initializationInformation.RabbitMq.Password = "******"; _initializationInformation.RabbitMq.UserName = "******"; _initializationInformation.RabbitMq.PortNumber = 5672; _initializationInformation.RabbitMq.QueueName = "SimpleLoggingClientTest"; _initializationInformation.RabbitMq.RoutingKey = "key"; _initializationInformation.ApplicationName = APPLICATION_NAME; _logicHelper = new LogicHelper(_initializationInformation); _internalTransaction = new InternalTransaction(_initializationInformation); _externalTransaction = new ExternalTransaction(_initializationInformation); _application = new Application(_initializationInformation); _messageQueue = new MessageQueue(_initializationInformation); _relationalDatabase = new RelationalDatabase(_initializationInformation); }
internal static void AssertMockClassE(MockClassE item, MockClassE orig, IRelationalDatabase<int, MockClassD> repo) { if (item == null && orig == null) return; Assert.IsNotNull(item); Assert.IsNotNull(orig); orig.SetRepository(repo); Assert.AreEqual(item.Id, orig.Id); Assert.AreEqual(item.Name, orig.Name); Assert.AreEqual(item.GetSomeCheckSum[0], orig.GetSomeCheckSum[0]); Assert.AreEqual(item.NamesOfStuff[0], orig.NamesOfStuff[0]); Assert.AreEqual(item.Location.X, orig.Location.X); Assert.AreEqual(item.Location.Y, orig.Location.Y); Assert.AreEqual(item.Location.Z, orig.Location.Z); Assert.AreEqual(item.Location.W, orig.Location.W); Assert.AreEqual(item.ReferenceCode, orig.ReferenceCode); Assert.AreEqual(item.ReplicationID, orig.ReplicationID); Assert.AreEqual(item.CatalogName, orig.CatalogName); Assert.AreEqual(item.CatalogNameNull, orig.CatalogNameNull); AssertMockClassE(item.HiC as MockClassE, orig.HiC as MockClassE, repo); AssertMockClassE(item.Parent, orig.Parent, repo); for (var i = 0; i < item.LowBall.Count(); i++) AssertMockClassE(item.LowBall.ToArray()[i] as MockClassE, orig.LowBall.ToArray()[i] as MockClassE, repo); }
private async Task <string> SerializeAsyncCore(IRelationalDatabase obj, CancellationToken cancellationToken) { var dto = await Mapper.ToDtoAsync(obj, cancellationToken).ConfigureAwait(false); return(JsonSerializer.Serialize(dto, _settings.Value)); }
public ReportGenerator(ISchematicConnection connection, IRelationalDatabase database, DirectoryInfo directory) { Connection = connection ?? throw new ArgumentNullException(nameof(connection)); Database = database ?? throw new ArgumentNullException(nameof(database)); ExportDirectory = directory ?? throw new ArgumentNullException(nameof(directory)); }
public ReportGenerator(ISchematicConnection connection, IRelationalDatabase database, string directory) : this(connection, database, new DirectoryInfo(directory)) { }
private static async Task <Dto.RelationalDatabase> ToDtoAsyncCore(IMapper mapper, IRelationalDatabase database, CancellationToken cancellationToken) { var tablesTask = database.GetAllTables(cancellationToken).ToListAsync(cancellationToken).AsTask(); var viewsTask = database.GetAllViews(cancellationToken).ToListAsync(cancellationToken).AsTask(); var sequencesTask = database.GetAllSequences(cancellationToken).ToListAsync(cancellationToken).AsTask(); var synonymsTask = database.GetAllSynonyms(cancellationToken).ToListAsync(cancellationToken).AsTask(); var routinesTask = database.GetAllRoutines(cancellationToken).ToListAsync(cancellationToken).AsTask(); await Task.WhenAll(tablesTask, viewsTask, sequencesTask, synonymsTask, routinesTask).ConfigureAwait(false); var tables = await tablesTask.ConfigureAwait(false); var views = await viewsTask.ConfigureAwait(false); var sequences = await sequencesTask.ConfigureAwait(false); var synonyms = await synonymsTask.ConfigureAwait(false); var routines = await routinesTask.ConfigureAwait(false); var dtoIdentifierDefaults = mapper.Map <IIdentifierDefaults, Dto.IdentifierDefaults>(database.IdentifierDefaults); var dtoTables = mapper.Map <IEnumerable <IRelationalDatabaseTable>, IEnumerable <Dto.RelationalDatabaseTable> >(tables); var dtoViews = mapper.Map <IEnumerable <IDatabaseView>, IEnumerable <Dto.DatabaseView> >(views); var dtoSequences = mapper.Map <IEnumerable <IDatabaseSequence>, IEnumerable <Dto.DatabaseSequence> >(sequences); var dtoSynonyms = mapper.Map <IEnumerable <IDatabaseSynonym>, IEnumerable <Dto.DatabaseSynonym> >(synonyms); var dtoRoutines = mapper.Map <IEnumerable <IDatabaseRoutine>, IEnumerable <Dto.DatabaseRoutine> >(routines); return(new Dto.RelationalDatabase { IdentifierDefaults = dtoIdentifierDefaults, Tables = dtoTables, Views = dtoViews, Sequences = dtoSequences, Synonyms = dtoSynonyms, Routines = dtoRoutines }); }
internal static MockClassE CreateRandomRelation(IRelationalDatabase<int, MockClassD> repo) { return new MockClassE(repo) { Name = "Class " + random.Next(), Location = new MockStruct() { X = (float)random.NextDouble(), Y = (float)random.NextDouble(), Z = (float)random.NextDouble(), W = (float)random.NextDouble() }, GetSomeCheckSum = new double[] { random.NextDouble(), random.NextDouble() }, ReferenceCode = "R " + random.Next(), ReplicationID = Guid.NewGuid(), NamesOfStuff = new string[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }, TPSCoverSheet = Guid.NewGuid().ToString(), HiC = null, LowBall = null, Parent = null }; }
public ReflectionSequence(IRelationalDatabase database, IDatabaseDialect dialect) : base(database, dialect, typeof(T)) { }
internal static IList<MockClassE> GetMockClassDObjects(int count, IRelationalDatabase<int, MockClassD> repo) { var mocks = new List<MockClassE>(); Enumerable.Range(0, count) .ToList() .ForEach(i => mocks.Add(CreateRandomRelation(repo))); foreach (var m in mocks) { m.HiC = CreateRandomRelation(repo); m.LowBall = new List<MockClassD> { CreateRandomRelation(repo), CreateRandomRelation(repo) }; m.Parent = CreateRandomRelation(repo) as MockClassE; } return mocks.ToList(); }
public MockClassE(IRelationalDatabase<int, MockClassD> repo) : base(repo) { }
/// <summary> /// Retrieves the resolved schema-qualified name for an object type. /// </summary> /// <param name="dialect">A dialect that the name should be qualified for.</param> /// <param name="database">The database that an object should be qualified for.</param> /// <param name="type">The type of object that the attribute is applied to.</param> /// <returns>A schema-qualified name for a database object.</returns> /// <exception cref="ArgumentNullException"><paramref name="dialect"/>, <paramref name="database"/>, or <paramref name="type"/> is <c>null</c></exception> public static Identifier GetQualifiedNameOrDefault(this IDatabaseDialect dialect, IRelationalDatabase database, Type type) { if (dialect == null) { throw new ArgumentNullException(nameof(dialect)); } if (database == null) { throw new ArgumentNullException(nameof(dialect)); } if (type == null) { throw new ArgumentNullException(nameof(type)); } var schemaName = dialect.GetSchemaOverride(type); if (schemaName.IsNullOrWhiteSpace()) { schemaName = database.IdentifierDefaults.Schema; } var localName = dialect.GetAliasOrDefault(type); return(Identifier.CreateQualifiedIdentifier(schemaName, localName)); }