Exemplo n.º 1
0
        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
                       ));
        }
Exemplo n.º 2
0
 /// <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);
 }
Exemplo n.º 3
0
        /// <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));
        }
Exemplo n.º 4
0
        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));
 }
Exemplo n.º 6
0
        /// <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
            };
        }
Exemplo n.º 7
0
        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;
        }
Exemplo n.º 8
0
        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);
                }
            }
        }
Exemplo n.º 9
0
        /// <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));
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        /// <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));
        }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
0
        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));
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
        private async Task <string> SerializeAsyncCore(IRelationalDatabase obj, CancellationToken cancellationToken)
        {
            var dto = await Mapper.ToDtoAsync(obj, cancellationToken).ConfigureAwait(false);

            return(JsonSerializer.Serialize(dto, _settings.Value));
        }
Exemplo n.º 20
0
 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));
 }
Exemplo n.º 21
0
 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
            });
        }
Exemplo n.º 23
0
 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
     };
 }
Exemplo n.º 24
0
 public ReflectionSequence(IRelationalDatabase database, IDatabaseDialect dialect)
     : base(database, dialect, typeof(T))
 {
 }
Exemplo n.º 25
0
        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();
        }
Exemplo n.º 26
0
 public MockClassE(IRelationalDatabase<int, MockClassD> repo)
     : base(repo)
 {
 }
Exemplo n.º 27
0
        /// <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));
        }