Esempio n. 1
0
        public void TestThatDeliveryEngineCanExecute()
        {
            IDeliveryEngine deliveryEngine = _container.Resolve <IDeliveryEngine>();

            Assert.That(deliveryEngine, Is.Not.Null);
            Assert.That(deliveryEngine.ExceptionHandler, Is.Not.Null);

            deliveryEngine.ExceptionHandler.OnException += (s, e) =>
            {
                Assert.That(s, Is.Not.Null);
                Assert.That(e, Is.Not.Null);
                Assert.That(e.Message, Is.Not.Null);
                Assert.That(e.Message, Is.Not.Empty);
                Assert.That(e.Exception, Is.Not.Null);
                Debug.WriteLine(e.Message);
                e.CanContinue = false;

                Assert.Fail(e.Message);
            };

            IDeliveryEngineExecuteCommand command = new DeliveryEngineExecuteCommand
            {
                OverrideArchiveInformationPackageId = "AVID.SA.40330",
                ValidationOnly = false,
                RemoveMissingRelationshipsOnForeignKeys = false,
                NumberOfForeignTablesToCache            = 10,
                IncludeEmptyTables = _configurationRepository.IncludeEmptyTables
            };

            deliveryEngine.Execute(command);
        }
Esempio n. 2
0
        public void TestThatValidationOnlySetterChangeValue()
        {
            IDeliveryEngineExecuteCommand command = new DeliveryEngineExecuteCommand();

            Assert.That(command, Is.Not.Null);
            Assert.That(command.ValidationOnly, Is.False);

            command.ValidationOnly = true;
            Assert.That(command.ValidationOnly, Is.True);
        }
Esempio n. 3
0
        public void TestThatIncludeEmptyTablesSetterChangeValue()
        {
            IDeliveryEngineExecuteCommand command = new DeliveryEngineExecuteCommand();

            Assert.That(command, Is.Not.Null);
            Assert.That(command.IncludeEmptyTables, Is.False);

            command.IncludeEmptyTables = true;
            Assert.That(command.IncludeEmptyTables, Is.True);
        }
Esempio n. 4
0
        public void TestThatRemoveMissingRelationshipsOnForeignKeysSetterChangeValue()
        {
            IDeliveryEngineExecuteCommand command = new DeliveryEngineExecuteCommand();

            Assert.That(command, Is.Not.Null);
            Assert.That(command.RemoveMissingRelationshipsOnForeignKeys, Is.False);

            command.RemoveMissingRelationshipsOnForeignKeys = true;
            Assert.That(command.RemoveMissingRelationshipsOnForeignKeys, Is.True);
        }
Esempio n. 5
0
        public void TestThatNumberOfForeignTablesToCacheSetterChangeValue()
        {
            IDeliveryEngineExecuteCommand command = new DeliveryEngineExecuteCommand();

            Assert.That(command, Is.Not.Null);
            Assert.That(command.NumberOfForeignTablesToCache, Is.EqualTo(10));

            var newValue = command.NumberOfForeignTablesToCache + _fixture.CreateAnonymous <int>();

            command.NumberOfForeignTablesToCache = newValue;
            Assert.That(command.NumberOfForeignTablesToCache, Is.EqualTo(newValue));
        }
Esempio n. 6
0
        public void TestThatTablesHandledSimultaneitySetterChangeValue()
        {
            IDeliveryEngineExecuteCommand command = new DeliveryEngineExecuteCommand();

            Assert.That(command, Is.Not.Null);
            Assert.That(command.TablesHandledSimultaneity, Is.EqualTo(5));

            var newValue = command.TablesHandledSimultaneity + _fixture.CreateAnonymous <int>();

            command.TablesHandledSimultaneity = newValue;
            Assert.That(command.TablesHandledSimultaneity, Is.EqualTo(newValue));
        }
Esempio n. 7
0
        public void TestThatConstructorInitializeCommand()
        {
            IDeliveryEngineExecuteCommand command = new DeliveryEngineExecuteCommand();

            Assert.That(command, Is.Not.Null);
            Assert.That(command.OverrideArchiveInformationPackageId, Is.Null);
            Assert.That(command.ValidationOnly, Is.False);
            Assert.That(command.Table, Is.Null);
            Assert.That(command.TablesHandledSimultaneity, Is.EqualTo(5));
            Assert.That(command.RemoveMissingRelationshipsOnForeignKeys, Is.False);
            Assert.That(command.NumberOfForeignTablesToCache, Is.EqualTo(10));
            Assert.That(command.IncludeEmptyTables, Is.False);
        }
Esempio n. 8
0
        public void TestThatTableSetterChangeValue()
        {
            IDeliveryEngineExecuteCommand command = new DeliveryEngineExecuteCommand();

            Assert.That(command, Is.Not.Null);
            Assert.That(command.Table, Is.Null);

            string newValue = _fixture.CreateAnonymous <string>();

            command.Table = newValue;
            Assert.That(command.Table, Is.Not.Null);
            Assert.That(command.Table, Is.Not.Empty);
            Assert.That(command.Table, Is.EqualTo(newValue));
        }
Esempio n. 9
0
        public void TestThatOverrideArchiveInformationPackageIdSetterChangeValue()
        {
            IDeliveryEngineExecuteCommand command = new DeliveryEngineExecuteCommand();

            Assert.That(command, Is.Not.Null);
            Assert.That(command.OverrideArchiveInformationPackageId, Is.Null);

            string newValue = _fixture.CreateAnonymous <string>();

            command.OverrideArchiveInformationPackageId = newValue;
            Assert.That(command.OverrideArchiveInformationPackageId, Is.Not.Null);
            Assert.That(command.OverrideArchiveInformationPackageId, Is.Not.Empty);
            Assert.That(command.OverrideArchiveInformationPackageId, Is.EqualTo(newValue));
        }
        public void TestValidation()
        {
            int warnings = 0;
            IExceptionHandler exceptionHandlerMock = MockRepository.GenerateMock <IExceptionHandler>();

            exceptionHandlerMock.OnException += (sender, eventArgs) =>
            {
                Assert.That(sender, Is.Not.Null);
                Assert.That(eventArgs, Is.Not.Null);
                Assert.That(eventArgs.Exception, Is.Not.Null);
                throw eventArgs.Exception;
            };
            exceptionHandlerMock.Expect(m => m.HandleException(Arg <Exception> .Is.NotNull, out Arg <bool> .Out(true).Dummy))
            .WhenCalled(e =>
            {
                if (e.Arguments.ElementAt(0) is DeliveryEngineValidateException validationException)
                {
                    Debug.WriteLine("{0}: {1}", "WARNING", validationException.Message);
                    warnings++;
                    e.Arguments[1] = warnings < 25;
                    return;
                }

                if (e.Arguments.ElementAt(0) is DeliveryEngineMappingException mappingException)
                {
                    Debug.WriteLine("{0}: {1}", "WARNING", mappingException.Message);
                    warnings++;
                    e.Arguments[1] = warnings < 25;
                    return;
                }

                Exception exception = (Exception)e.Arguments.ElementAt(0);
                Debug.WriteLine(exception);
                e.Arguments[1] = false;
                exceptionHandlerMock.Raise(f => f.OnException += null, exceptionHandlerMock, new HandleExceptionEventArgs(exception));
            })
            .Repeat.Any();
            exceptionHandlerMock.Expect(m => m.HandleException(Arg <Exception> .Is.NotNull))
            .WhenCalled(e =>
            {
                Exception exception = (Exception)e.Arguments.ElementAt(0);
                Debug.WriteLine(exception.Message);
                Debug.WriteLine(exception.StackTrace);
                exceptionHandlerMock.Raise(f => f.OnException += null, exceptionHandlerMock, new HandleExceptionEventArgs(exception));
            })
            .Repeat.Any();

            IDeliveryEngine deliveryEngine = CreateSut(true, exceptionHandlerMock);

            Assert.That(deliveryEngine, Is.Not.Null);

            deliveryEngine.BeforeGetDataSource += (sender, eventArgs) =>
            {
                Assert.That(sender, Is.Not.Null);
                Assert.That(eventArgs, Is.Not.Null);
                Debug.WriteLine("Getting the data source. Please wait...");
            };
            deliveryEngine.BeforeGetDataForTargetTable += (sender, eventArgs) =>
            {
                Assert.That(sender, Is.Not.Null);
                Assert.That(eventArgs, Is.Not.Null);
                Assert.That(eventArgs.DataSource, Is.Not.Null);
                Assert.That(eventArgs.TargetTable, Is.Not.Null);
                Debug.WriteLine("Getting data for the table named '{0}' (reading data from block {1}). Please wait...", eventArgs.TargetTable.NameTarget, eventArgs.DataBlock);
            };
            deliveryEngine.BeforeValidateDataInTargetTable += (sender, eventArgs) =>
            {
                Assert.That(sender, Is.Not.Null);
                Assert.That(eventArgs, Is.Not.Null);
                Assert.That(eventArgs.DataSource, Is.Not.Null);
                Assert.That(eventArgs.TargetTable, Is.Not.Null);
                Debug.WriteLine("Validating data from table named '{0}' (validating data from block {1}). Please wait...", eventArgs.TargetTable.NameTarget, eventArgs.DataBlock);
            };

            IConfigurationRepository      configurationRepository = new ConfigurationRepository(ConfigurationManager.AppSettings);
            IDeliveryEngineExecuteCommand command = new DeliveryEngineExecuteCommand
            {
                OverrideArchiveInformationPackageId = "AVID.SA.12549",
                ValidationOnly            = true,
                TablesHandledSimultaneity = 3,
                IncludeEmptyTables        = configurationRepository.IncludeEmptyTables
            };

            deliveryEngine.Execute(command);
        }
Esempio n. 11
0
        /// <summary>
        /// Entry point.
        /// </summary>
        /// <param name="args">Arguments</param>
        static void Main(string[] args)
        {
            Console.WriteLine(Resource.GetText(Text.ArchiveMaker));
            Console.WriteLine();

            ValidationOnly = false;
            AcceptWarnings = 1024;
            string archiveInformationPackageId             = null;
            int    tablesHandledSimultaneity               = 5;
            bool   removeMissingRelationshipsOnForeignKeys = false;
            int    numberOfForeignTablesToCache            = 10;
            bool?  includeEmptyTables = null;

            try
            {
                if (args != null && args.Length > 0)
                {
                    archiveInformationPackageId = args.Single(m => string.IsNullOrEmpty(m) == false && m.Length > 29 && m.Substring(0, 29).Equals("/ArchiveInformationPackageID:")).Substring(29);

                    string optionalArg = args.SingleOrDefault(m => string.IsNullOrEmpty(m) == false && m.Length > 16 && m.Substring(0, 16).Equals("/ValidationOnly:"));
                    if (optionalArg != null)
                    {
                        ValidationOnly = bool.Parse(optionalArg.Substring(16));
                    }

                    optionalArg = args.SingleOrDefault(m => string.IsNullOrEmpty(m) == false && m.Length > 28 && m.Substring(0, 30).Equals("/TablesHandledSimultaneity:"));
                    if (optionalArg != null)
                    {
                        tablesHandledSimultaneity = int.Parse(optionalArg.Substring(28));
                    }

                    optionalArg = args.SingleOrDefault(m => string.IsNullOrEmpty(m) == false && m.Length > 16 && m.Substring(0, 16).Equals("/AcceptWarnings:"));
                    if (optionalArg != null)
                    {
                        AcceptWarnings = int.Parse(optionalArg.Substring(16));
                    }

                    optionalArg = args.SingleOrDefault(m => string.IsNullOrEmpty(m) == false && m.Length > 41 && m.Substring(0, 41).Equals("/RemoveMissingRelationshipsOnForeignKeys:"));
                    if (optionalArg != null)
                    {
                        removeMissingRelationshipsOnForeignKeys = bool.Parse(optionalArg.Substring(41));
                    }

                    optionalArg = args.SingleOrDefault(m => string.IsNullOrEmpty(m) == false && m.Length > 30 && m.Substring(0, 30).Equals("/NumberOfForeignTablesToCache:"));
                    if (optionalArg != null)
                    {
                        numberOfForeignTablesToCache = int.Parse(optionalArg.Substring(30));
                    }

                    optionalArg = args.SingleOrDefault(m => string.IsNullOrEmpty(m) == false && m.Length > 20 && m.Substring(0, 20).Equals("/IncludeEmptyTables:"));
                    if (optionalArg != null)
                    {
                        includeEmptyTables = Convert.ToBoolean(optionalArg.Substring(20));
                    }
                }

                if (string.IsNullOrEmpty(archiveInformationPackageId))
                {
                    Console.WriteLine(Resource.GetText(Text.UsageArchiveMaker, new FileInfo(Process.GetCurrentProcess().MainModule.FileName).Name));
                    Console.WriteLine();
                    return;
                }
            }
            catch
            {
                Console.WriteLine(Resource.GetText(Text.UsageArchiveMaker, new FileInfo(Process.GetCurrentProcess().MainModule.FileName).Name));
                Console.WriteLine();
                return;
            }

            try
            {
                IContainer container = ContainerFactory.Create();

                InformationLogger = container.Resolve <IInformationLogger>();

                IExceptionHandler exceptionHandler = container.Resolve <IExceptionHandler>();
                exceptionHandler.OnException += ExceptionEventHandler;

                IDeliveryEngine deliveryEngine = container.Resolve <IDeliveryEngine>();
                deliveryEngine.BeforeGetDataSource             += BeforeGetDataSourceEventHandler;
                deliveryEngine.BeforeArchiveMetadata           += BeforeArchiveMetadataEventHandler;
                deliveryEngine.BeforeGetDataForTargetTable     += BeforeGetDataForTargetTableEventHandler;
                deliveryEngine.BeforeValidateDataInTargetTable += BeforeValidatingDataInTargetTableEventHandler;
                deliveryEngine.BeforeArchiveDataForTargetTable += BeforeArchiveDataForTargetTableEventHandler;

                IConfigurationRepository      configurationRepository = container.Resolve <IConfigurationRepository>();
                IDeliveryEngineExecuteCommand command = new DeliveryEngineExecuteCommand
                {
                    OverrideArchiveInformationPackageId = archiveInformationPackageId,
                    ValidationOnly            = ValidationOnly,
                    TablesHandledSimultaneity = tablesHandledSimultaneity,
                    RemoveMissingRelationshipsOnForeignKeys = removeMissingRelationshipsOnForeignKeys,
                    NumberOfForeignTablesToCache            = numberOfForeignTablesToCache,
                    IncludeEmptyTables = includeEmptyTables ?? configurationRepository.IncludeEmptyTables
                };
                deliveryEngine.Execute(command);
            }
            catch (Exception ex)
            {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                Console.WriteLine(Resource.GetText(Text.ErrorMessage, ex.Message));
                Console.WriteLine();
            }
        }