Example #1
0
        /// <summary>
        /// Begins a new, nested, isolation scope
        /// </summary>
        /// <param name="isolationScopeName">The name of the new isolation scope</param>
        /// <param name="initialize">A delegate to an action that is performed on initialization. If an exception occurs inside this
        /// method, then the scope is automatically destroyed, calling any cleanup actions that were added during this method</param>
        public IDisposable BeginIsolationScope(string isolationScopeName, Action <IIsolationScope> initialize)
        {
            if (initialize == null)
            {
                initialize = Functions.EmptyAction <IIsolationScope>();
            }

            _currentState = State.Initialize;
            var lastIsolationLevel = _currentIsolationLevel;

            _currentIsolationLevel = new IsolationLevel(isolationScopeName);

            Logger.WriteLine("***************************** Initializing " + isolationScopeName + " *****************************");
            try
            {
                initialize(this);
                Logger.WriteLine("***************************** Initializing " + isolationScopeName + " Completed succesfully *****************************");
            }
            catch
            {
                _currentIsolationLevel.Cleanup();
                _currentIsolationLevel = lastIsolationLevel;
                throw;
            }

            _isolationLevels.Push(lastIsolationLevel);

            _currentState = State.Normal;

            return(new IsolationScopeDisposer(this));
        }
Example #2
0
        private void CleanupCurrentLevel()
        {
            _currentState = State.Cleanup;
            Logger.WriteLine("***************************** Cleanup " + _currentIsolationLevel.Name +
                             " *****************************");

            _currentIsolationLevel.Cleanup();

            _currentState = State.Normal;
        }
        /// <summary>
        /// Begins a new, nested, isolation scope
        /// </summary>
        /// <param name="isolationScopeName">The name of the new isolation scope</param>
        /// <param name="initialize">A delegate to an action that is performed on initialization. If an exception occurs inside this 
        /// method, then the scope is automatically destroyed, calling any cleanup actions that were added during this method</param>
        public IDisposable BeginIsolationScope(string isolationScopeName, Action<IIsolationScope> initialize)
        {
            if (initialize == null)
                initialize = Functions.EmptyAction<IIsolationScope>();

            _currentState = State.Initialize;
            var lastIsolationLevel = _currentIsolationLevel;
            _currentIsolationLevel = new IsolationLevel(isolationScopeName);

            Logger.WriteLine("***************************** Initializing " + isolationScopeName + " *****************************");
            try
            {
                initialize(this);
                Logger.WriteLine("***************************** Initializing " + isolationScopeName + " Completed succesfully *****************************");
            }
            catch
            {
                _currentIsolationLevel.Cleanup();
                _currentIsolationLevel = lastIsolationLevel;
                throw;
            }

            _isolationLevels.Push(lastIsolationLevel);

            _currentState = State.Normal;

            return new IsolationScopeDisposer(this);
        }