예제 #1
0
        /// <summary>
        /// import file and write import-log.
        /// throws AxisImportCancelledException.
        /// </summary>
        /// <param name="filename"></param>
        ///
        public void RunImport(string filename, DateTime SenderTimestamp)
        {
            int impNr;

            using (var transactionScope = transactionScopeFactory.CreateReadOnly())
            {
                impNr = GetNextImpNR(transactionScope.Session, SenderTimestamp);
            }

            if (impNr == 1)
            {
                try
                {
                    // initial full imports use multiple transactions (performance and memory)
                    using (MultiTransactionCommitter transactionCommitter = new MultiTransactionCommitter(transactionScopeFactory))
                    {
                        CreateImpLogRecord(transactionCommitter.Session, impNr, filename, SenderTimestamp);
                        transactionCommitter.ForceNext();

                        RunInitialFullImport(transactionCommitter, filename);
                        transactionCommitter.ForceNext();

                        UpdateImportLogRecord(transactionCommitter.Session, impNr, AchsenImportLog.SUCCESS, Statistics);
                        transactionCommitter.Finish();
                    }
                }
                catch (Exception)
                {
                    using (var transactionScope = transactionScopeFactory.CreateReadWrite())
                    {
                        try
                        {
                            UpdateImportLogRecord(transactionScope.Session, impNr, AchsenImportLog.FAILED, Statistics);
                            transactionScope.Commit();
                        }
                        catch (Exception)
                        {
                        }
                    }
                    throw;
                }
            }
            else
            {
                using (var transactionScope = transactionScopeFactory.CreateReadWrite())
                {
                    // incremental imports run in a single transaction
                    SingleTransactionCommitter transactionCommitter = new SingleTransactionCommitter(transactionScope);

                    CreateImpLogRecord(transactionCommitter.Session, impNr, filename, SenderTimestamp);
                    RunIncrementalImport(transactionCommitter, filename, impNr);
                    UpdateImportLogRecord(transactionCommitter.Session, impNr, AchsenImportLog.SUCCESS, Statistics);
                    transactionScope.Commit();
                }
            }
        }