Example #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;
                }
            }
        }
Example #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;
                }
            }
        }
        public void Dispatch(Pipeline queue, ActionsQueue postSave)
        {
            do
            {
                HashSet <string> usedChannels = new HashSet <string>();

                if (queue.HasEffects)
                {
                    DispatchInternal(queue.GetEffects(), usedChannels);
                    Save(usedChannels);
                    postSave.Run();
                }
            } while (queue.HasEffects);
        }
        public void Dispatch(Pipeline queue, ActionsQueue postSave)
        {
            do
            {
                HashSet <string> usedChannels = new HashSet <string>();
                if (queue.HasEffects)
                {
                    RunCommands(queue.GetEffects(), usedChannels);
                    Stopwatch sw     = null;
                    Exception thrown = null;

                    try
                    {
                        if (_traceCollector != null && _traceCollector.Profiling)
                        {
                            sw = new Stopwatch();
                            sw.Start();
                        }

                        Save(usedChannels);
                    }
                    catch (Exception ex)
                    {
                        thrown = ex;
                        throw new TectureSaveException(ex);
                    }
                    finally
                    {
                        if (sw != null)
                        {
                            sw.Stop();
                        }
                        _traceCollector?.Save(sw?.Elapsed ?? TimeSpan.Zero, thrown);
                    }
                }
                else
                {
                    _traceCollector?.Save(TimeSpan.Zero, null);
                }

                postSave?.Run();
            } while (queue.HasEffects);
        }
Example #5
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;
                    }
                }
            }
        }