コード例 #1
0
ファイル: TableIndex.cs プロジェクト: MrGottham/789fe44a87d4
        public void AddTable(ITable table, string tableFolder, int rowCount)
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }
            if (tableFolder == null)
            {
                throw new ArgumentNullException(nameof(tableFolder));
            }
            if (rowCount < 0)
            {
                throw new DeliveryEngineRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.IllegalValue, rowCount, "rowCount"));
            }

            ReadOnlyObservableCollection <IFilter> fieldFilters = table.FieldFilters;

            var namespaceManager = new XmlNamespaceManager(Document.NameTable);

            namespaceManager.AddNamespace("ns", Namespace);
            var rowsElement = (XmlElement)TableElement.SelectSingleNode($"ns:table[ns:name = '{table.NameTarget}']/ns:rows", namespaceManager);

            if (rowsElement != null)
            {
                var rows = int.Parse(rowsElement.InnerText);
                rowsElement.InnerText = Convert.ToString(rows + rowCount);
                return;
            }
            var tableElement = AddElement(TableElement, "table");

            AddElement(tableElement, "name", MakeSqlIdentifier(table.NameTarget));
            AddElement(tableElement, "folder", tableFolder);
            AddElement(tableElement, "description", table.Description);
            var columnsElement = AddElement(tableElement, "columns");

            foreach (var field in table.Fields.Where(m => ArchiveVersionRepository.ExcludeField(m, fieldFilters) == false))
            {
                var columnElement = AddElement(columnsElement, "column");
                AddElement(columnElement, "name", MakeSqlIdentifier(field.NameTarget));
                AddElement(columnElement, "columnID", field.ColumnId);
                AddElement(columnElement, "type", Sql1999DataType(field.DatatypeOfTarget, field.LengthOfTarget));
                AddElement(columnElement, "typeOriginal", field.OriginalDatatype, true);
                AddElement(columnElement, "defaultValue", field.DefaultValue, true);
                AddBooleanElement(columnElement, "nullable", field.Nullable);
                AddElement(columnElement, "description", field.Description);
                foreach (var function in field.Functionality)
                {
                    AddElement(columnElement, "functionalDescription", function.XmlValue);
                }
            }
            AddPrimaryKey(tableElement, table.PrimaryKey);
            if (table.ForeignKeys.Count > 0)
            {
                AddForeignKeys(tableElement, table.ForeignKeys);
            }
            AddElement(tableElement, "rows", rowCount.ToString(CultureInfo.InvariantCulture));
        }
        /// <summary>
        /// Adding configuration to the container for Inversion of Control.
        /// </summary>
        /// <param name="container">Container for Inversion of Control.</param>
        public void AddConfiguration(IWindsorContainer container)
        {
            var archivePath = ConfigurationManager.AppSettings["ArchivePath"];

            if (string.IsNullOrEmpty(archivePath))
            {
                throw new DeliveryEngineSystemException(Resource.GetExceptionMessage(ExceptionMessage.ApplicationSettingMissing, "ArchivePath"));
            }

            var archiveVersionRepository = new ArchiveVersionRepository(new DirectoryInfo(Environment.ExpandEnvironmentVariables(archivePath)));

            container.Register(Component.For <IArchiveVersionRepository>().Instance(archiveVersionRepository).LifeStyle.PerThread);
        }
コード例 #3
0
        public void TestThatConstructorInitializeOldToArchiveVersionRepository()
        {
            var archivePath = ConfigurationManager.AppSettings["ArchivePath"];

            if (string.IsNullOrEmpty(archivePath))
            {
                throw new DeliveryEngineSystemException(Resource.GetExceptionMessage(ExceptionMessage.ApplicationSettingMissing, "SourcePath"));
            }

            var archiveVersionRepository = new ArchiveVersionRepository(new DirectoryInfo(archivePath));

            Assert.That(archiveVersionRepository, Is.Not.Null);
        }
コード例 #4
0
        /// <summary>
        /// Event handler for handling data on a given target table.
        /// </summary>
        /// <param name="sender">Object which raises the event.</param>
        /// <param name="eventArgs">Arguments to the event.</param>
        private void HandleDataForTargetTable(object sender, IHandleDataEventArgs eventArgs)
        {
            if (sender == null)
            {
                throw new ArgumentNullException("sender");
            }
            if (eventArgs == null)
            {
                throw new ArgumentNullException("eventArgs");
            }
            var table     = eventArgs.Table;
            var tableData = new Dictionary <ITable, IEnumerable <IEnumerable <IDataObjectBase> > >
            {
                { table, eventArgs.Data }
            };
            var tuple       = _tableInformations[table];
            var dataSource  = tuple.Item1;
            var command     = tuple.Item2;
            var tableWorker = tuple.Item3;

            if (tableWorker.CancellationPending)
            {
                throw new ThreadInterruptedException();
            }

            // Validate received data for the target table.
            if (DataValidators.Any())
            {
                IValidateDataInTargetTableEventArgs validateDataInTargetTableEventArgs;
                lock (_syncRoot)
                {
                    validateDataInTargetTableEventArgs = new ValidateDataInTargetTableEventArgs(dataSource, table, _tableDataBlock[table], tableData.Select(m => m.Value).Sum(m => m.Count()));
                }
                RaiseEvent(BeforeValidateDataInTargetTable, validateDataInTargetTableEventArgs);
                var validationWorkers = new Collection <BackgroundWorker>();
                try
                {
                    foreach (var dataValidator in DataValidators)
                    {
                        if (tableWorker.CancellationPending)
                        {
                            throw new ThreadInterruptedException();
                        }
                        var validationWorker = new BackgroundWorker
                        {
                            WorkerReportsProgress      = false,
                            WorkerSupportsCancellation = true
                        };
                        validationWorker.DoWork             += ValidationDoWork;
                        validationWorker.RunWorkerCompleted += WorkerCompleted;
                        validationWorker.Disposed           += (s, e) => validationWorkers.Remove((BackgroundWorker)s);
                        validationWorkers.Add(validationWorker);
                        validationWorker.RunWorkerAsync(new Tuple <IDataValidator, ITable, IDictionary <ITable, IEnumerable <IEnumerable <IDataObjectBase> > >, bool, IDeliveryEngineExecuteCommand>(dataValidator, table, tableData, eventArgs.EndOfData, command));
                    }
                    while (validationWorkers.Any(m => m.IsBusy))
                    {
                        if (tableWorker.CancellationPending)
                        {
                            throw new ThreadInterruptedException();
                        }
                        Thread.Sleep(250);
                    }
                }
                finally
                {
                    foreach (var validationWorker in validationWorkers.Where(m => m.IsBusy))
                    {
                        validationWorker.CancelAsync();
                    }
                    while (validationWorkers.Any(m => m.IsBusy))
                    {
                        Thread.Sleep(250);
                    }
                    while (validationWorkers.Count > 0)
                    {
                        var validationWorker = validationWorkers.ElementAt(0);
                        validationWorker.Dispose();
                        validationWorkers.Remove(validationWorker);
                    }
                }
            }
            if (tableWorker.CancellationPending)
            {
                throw new ThreadInterruptedException();
            }

            // Archive the received data for the target table.
            if (command.ValidationOnly == false)
            {
                IArchiveDataForTargetTableEventArgs archiveDataForTargetTableEventArgs;
                lock (_syncRoot)
                {
                    archiveDataForTargetTableEventArgs = new ArchiveDataForTargetTableEventArgs(dataSource, table, _tableDataBlock[table], tableData.Select(m => m.Value).Sum(m => m.Count()));
                }
                RaiseEvent(BeforeArchiveDataForTargetTable, archiveDataForTargetTableEventArgs);
                ArchiveVersionRepository.ArchiveTableData(tableData, command.IncludeEmptyTables, _syncRoot);
            }
            if (tableWorker.CancellationPending)
            {
                throw new ThreadInterruptedException();
            }
            if (eventArgs.EndOfData)
            {
                return;
            }
            IGetDataForTargetTableEventArgs getDataForTargetTableEventArgs;

            lock (_syncRoot)
            {
                _tableDataBlock[table]        += 1;
                getDataForTargetTableEventArgs = new GetDataForTargetTableEventArgs(dataSource, table, _tableDataBlock[table]);
            }
            RaiseEvent(BeforeGetDataForTargetTable, getDataForTargetTableEventArgs);
        }
コード例 #5
0
        /// <summary>
        /// Execute the delivery engine to create and write the delivery format.
        /// </summary>
        /// <param name="command">Command for executing the delivery engine.</param>
        public virtual void Execute(IDeliveryEngineExecuteCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }
            try
            {
                // Get the data source.
                RaiseEvent(BeforeGetDataSource, new GetDataSourceEventArgs());
                var dataSource = MetadataRepository.DataSourceGet();
                if (!string.IsNullOrEmpty(command.OverrideArchiveInformationPackageId))
                {
                    dataSource.ArchiveInformationPackageId = command.OverrideArchiveInformationPackageId;
                }
                ArchiveVersionRepository.DataSource = dataSource;

                // Archive the metadata for the data source.
                if (command.ValidationOnly == false)
                {
                    RaiseEvent(BeforeArchiveMetadata, new ArchiveMetadataEventArgs(dataSource));
                    ArchiveVersionRepository.ArchiveMetaData();
                }

                // Handle and archive any target tables included in the data source.
                DataRepository.OnHandleData += HandleDataForTargetTable;
                DataRepository.OnClone      += DataRepositoryCloned;
                var tableWorkers = new Collection <BackgroundWorker>();
                try
                {
                    var namedObjectComparer = new NameTargetComparer();
                    var targetTables        = dataSource.Tables
                                              .Where(m => string.IsNullOrEmpty(m.NameTarget) == false && (string.IsNullOrEmpty(command.Table) || Regex.IsMatch(m.NameTarget, command.Table, RegexOptions.Compiled)))
                                              .Distinct(namedObjectComparer)
                                              .OfType <ITable>()
                                              .ToList();
                    foreach (var targetTable in targetTables)
                    {
                        while (tableWorkers.Count(m => m.IsBusy) >= (command.TablesHandledSimultaneity <= 0 ? 1 : command.TablesHandledSimultaneity) && _errors.Any() == false)
                        {
                            Thread.Sleep(250);
                        }
                        if (_errors.Any())
                        {
                            throw _errors.ElementAt(0);
                        }
                        var tableWorker = new BackgroundWorker
                        {
                            WorkerReportsProgress      = false,
                            WorkerSupportsCancellation = true
                        };
                        tableWorker.DoWork             += HandleTargetTableDoWork;
                        tableWorker.RunWorkerCompleted += WorkerCompleted;
                        tableWorker.Disposed           += (sender, eventArgs) => tableWorkers.Remove((BackgroundWorker)sender);
                        tableWorkers.Add(tableWorker);
                        tableWorker.RunWorkerAsync(new Tuple <ITable, IDataSource, IDeliveryEngineExecuteCommand>(targetTable, dataSource, command));
                    }
                    while (tableWorkers.Any(m => m.IsBusy))
                    {
                        if (_errors.Any())
                        {
                            throw _errors.ElementAt(0);
                        }
                        Thread.Sleep(250);
                    }
                }
                finally
                {
                    foreach (var tableWorker in tableWorkers.Where(m => m.IsBusy))
                    {
                        tableWorker.CancelAsync();
                    }
                    while (tableWorkers.Any(m => m.IsBusy))
                    {
                        Thread.Sleep(250);
                    }
                    while (tableWorkers.Count > 0)
                    {
                        var tableWorker = tableWorkers.ElementAt(0);
                        tableWorker.Dispose();
                        tableWorkers.Remove(tableWorker);
                    }
                }
            }
            catch (DeliveryEngineAlreadyHandledException)
            {
            }
            catch (Exception ex)
            {
                lock (_syncRoot)
                {
                    ExceptionHandler.HandleException(ex);
                }
            }
            finally
            {
                lock (_syncRoot)
                {
                    while (_tableInformations.Count > 0)
                    {
                        _tableInformations.Clear();
                    }
                }
                while (_errors.Count > 0)
                {
                    _errors.Clear();
                }
            }
        }
        private IDeliveryEngine CreateSut(bool useDataValidators, IExceptionHandler exceptionHandler)
        {
            if (exceptionHandler == null)
            {
                throw new ArgumentNullException(nameof(exceptionHandler));
            }

            IContainer containerMock = MockRepository.GenerateMock <IContainer>();

            IInformationLogger informationLoggerMock = MockRepository.GenerateMock <IInformationLogger>();

            informationLoggerMock.Expect(m => m.LogInformation(Arg <string> .Is.NotNull))
            .WhenCalled(e => Debug.WriteLine(e.Arguments.ElementAt(0)))
            .Repeat.Any();
            informationLoggerMock.Expect(m => m.LogWarning(Arg <string> .Is.NotNull))
            .WhenCalled(e => Debug.WriteLine(e.Arguments.ElementAt(0)))
            .Repeat.Any();

            IConfigurationRepository configurationRepositoryMock = MockRepository.GenerateMock <IConfigurationRepository>();
            IMetadataRepository      metadataRepository          = new OldToNewMetadataRepository(RepositoryTestHelper.GetSourcePathForOracleTest(), new ConfigurationValues());

            containerMock.Expect(m => m.Resolve <IMetadataRepository>())
            .Return(metadataRepository)
            .Repeat.Any();

            ICollection <IDataManipulator> dataManipulatorCollection;

            using (var windsorContainer = new WindsorContainer())
            {
                windsorContainer.Register(Component.For <IContainer>().Instance(containerMock).LifeStyle.Transient);
                windsorContainer.Register(Component.For <IInformationLogger>().Instance(informationLoggerMock).LifeStyle.Transient);
                windsorContainer.Register(Component.For <IMetadataRepository>().Instance(metadataRepository).LifeStyle.Transient);

                IConfigurationProvider dataManipulatorsConfigurationProvider = new DataManipulatorsConfigurationProvider();
                dataManipulatorsConfigurationProvider.AddConfiguration(windsorContainer);

                dataManipulatorCollection = windsorContainer.ResolveAll <IDataManipulator>();
                windsorContainer.Dispose();
            }
            containerMock.Expect(m => m.ResolveAll <IDataManipulator>())
            .Return(dataManipulatorCollection.ToArray())
            .Repeat.Any();
            IDataRepository dataRepository = new OracleDataRepository(new OracleClientFactory(), new DataManipulators(containerMock));

            containerMock.Expect(m => m.Resolve <IDataRepository>())
            .Return(dataRepository)
            .Repeat.Any();
            IDocumentRepository       documentRepositoryMock = MockRepository.GenerateMock <IDocumentRepository>();
            IArchiveVersionRepository archiveRepository      = new ArchiveVersionRepository(new DirectoryInfo(ConfigurationManager.AppSettings["ArchivePath"]));

            ICollection <IDataValidator> dataValidatorCollection = useDataValidators ? new Collection <IDataValidator> {
                new PrimaryKeyDataValidator(dataRepository), new ForeignKeysDataValidator(dataRepository), new MappingDataValidator()
            } : new Collection <IDataValidator>();

            containerMock.Expect(m => m.ResolveAll <IDataValidator>())
            .Return(dataValidatorCollection.ToArray())
            .Repeat.Any();
            IDataValidators dataValidators = new DataValidators(containerMock);

            return(new DeliveryEngine.BusinessLogic.DeliveryEngine(configurationRepositoryMock, metadataRepository, dataRepository, documentRepositoryMock, dataValidators, archiveRepository, exceptionHandler));
        }