/// <summary> /// Indicates whether the data manipulator is manipulating a given field. /// </summary> /// <param name="fieldName">Name of the field on which to exam for use in the data manipulator.</param> /// <returns>True if the data manipulator use the field otherwise false.</returns> protected override bool ManipulatingField(string fieldName) { lock (SyncRoot) { if (_currentDataSource == null) { _currentDataSource = MetadataRepository.DataSourceGet(); } try { ITable dataManipulatorTable; try { dataManipulatorTable = _currentDataSource.Tables.Single(table => String.Compare(TableName, table.NameSource, StringComparison.OrdinalIgnoreCase) == 0); } catch (InvalidOperationException) { dataManipulatorTable = _currentDataSource.Tables.SingleOrDefault(table => String.Compare(TableName, table.NameTarget, StringComparison.OrdinalIgnoreCase) == 0); } if (dataManipulatorTable == null) { throw new DeliveryEngineSystemException(Resource.GetExceptionMessage(ExceptionMessage.TableNotFound, TableName)); } try { return(_worker.IsManipulatingField(fieldName, dataManipulatorTable)); } finally { dataManipulatorTable = null; Debug.Assert(dataManipulatorTable == null); } } finally { GC.Collect(); } } }
/// <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(); } } }