Exemplo n.º 1
0
        /// <summary>
        /// Runs commands queue
        /// </summary>
        public void Save()
        {
            if (_actions.IsRunning)
            {
                throw new Exception(".SaveChanges cannot be called within post-save action");
            }
            if (_finallyActions.IsRunning)
            {
                throw new Exception(".SaveChanges cannot be called within finally action");
            }


            Exception thrown = null;

            try
            {
                _serviceManager.OnSave();

                CommandsDispatcher dispatcher = new CommandsDispatcher(_mx, _aux.TraceCollector, _tranManager);
                dispatcher.Dispatch(_pipeline, _actions);

                _serviceManager.OnFinally();
                _finallyActions.Run();
                dispatcher.Dispatch(_pipeline, _actions);
            }
            catch (Exception ex)
            {
                if (_exceptionHandler == null || !_exceptionHandler(ex))
                {
                    throw;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Runs commands queue
        /// </summary>
        public void Save(OuterTransactionMode transaction     = OuterTransactionMode.None,
                         OuterTransactionIsolationLevel level = OuterTransactionIsolationLevel.Chaos)
        {
            if (_actions.IsRunning)
            {
                throw new Exception(".SaveChanges cannot be called within post-save action");
            }
            if (_finallyActions.IsRunning)
            {
                throw new Exception(".SaveChanges cannot be called within finally action");
            }
            IOuterTransaction tran = ObtainTransaction(transaction, level);

            Exception thrown = null;

            try
            {
                _serviceManager.OnSave();

                CommandsDispatcher dispatcher = new CommandsDispatcher(_mx, _aux.TraceCollector);
                dispatcher.Dispatch(_pipeline, _actions);

                _serviceManager.OnFinally();
                _finallyActions.Run();
                dispatcher.Dispatch(_pipeline, _actions);

                tran?.Commit();
            }
            catch (Exception ex)
            {
                _exceptionHandler?.Invoke(ex);
                thrown = ex;
            }
            finally
            {
                try
                {
                    tran?.Dispose();
                }
                catch (Exception)
                {
                    if (thrown == null)
                    {
                        throw;
                    }
                }
                if (thrown != null)
                {
                    throw thrown;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Runs commands queue
        /// </summary>
        public void Save()
        {
            if (_actions.IsRunning)
            {
                throw new Exception(".SaveChanges cannot be called within post-save action");
            }
            if (_finallyActions.IsRunning)
            {
                throw new Exception(".SaveChanges cannot be called within finally action");
            }

            Exception          thrown     = null;
            CommandsDispatcher dispatcher = new CommandsDispatcher(_mx, _aux.TraceCollector, _tranManager);

            try
            {
                _serviceManager.OnSave();
                dispatcher.Dispatch(_pipeline, _actions);
            }
            catch (Exception ex)
            {
                thrown = ex;
            }
            finally
            {
                Exception thrown2 = null;
                try
                {
                    if (_tc != null)
                    {
                        _tc.Command(new Comment()
                        {
                            Annotation = "<<< Finally block >>>",
                            Channel    = typeof(NoChannel),
                            IsExecuted = true
                        });
                    }

                    _serviceManager.OnFinally(thrown);
                    _finallyActions.Run();
                    if (_pipeline.HasEffects)
                    {
                        dispatcher.Dispatch(_pipeline, null);
                    }
                }
                catch (Exception finException)
                {
                    thrown2 = finException;
                }
                finally
                {
                    _tc?.Command(new Comment()
                    {
                        Annotation = "<<< End of Finally block >>>",
                        Channel    = typeof(NoChannel),
                        IsExecuted = true
                    });
                }

                if (thrown2 != null)
                {
                    if (thrown == null)
                    {
                        thrown = thrown2;
                    }
                    else
                    {
                        thrown = new AggregateException(thrown, thrown2);
                    }
                }

                if (thrown != null)
                {
                    if (_exceptionHandler == null || !_exceptionHandler(thrown))
                    {
                        throw thrown;
                    }
                }
            }
        }