示例#1
0
        protected override void InnerCleanup()
        {
            AggregateExceptionBuilder builder = new AggregateExceptionBuilder("Some Datareaders might be open");

            while (_stk.Count > 0)
            {
                var rd = _stk.Pop();

                try
                {
                    if (!rd.IsClosed)
                    {
                        rd.Close();
                        rd.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    builder.Add(ex);
                }
            }
            if (builder.HasErrors)
            {
                throw builder.ToAggregateException();
            }
        }
示例#2
0
        void IDisposable.Dispose()
        {
            var contexts = _map.Clear();
            var builder  = new AggregateExceptionBuilder("Errors encountered while disposing DbContext objects");

            foreach (var it in contexts)
            {
                try
                {
                    (it as IDisposable).Dispose();
                }
                catch (Exception ex)
                {
                    builder.Add(ex);
                }
            }

            if (builder.HasErrors)
            {
                throw builder.ToAggregateException();
            }
        }
示例#3
0
        void IDisposable.Dispose()
        {
            var builder = new AggregateExceptionBuilder("Error while disposing the DbContext objects");

            _timer.Stop();
            var keys = _map.Keys;

            for (var i = 0; i < keys.Length; i++)
            {
                var key   = keys[i];
                var count = (_map[key].Provider as ContextProviderBase).ConsumerCount;
                if (count > 0)
                {
                    builder.Add(new Exception($"Provider for thread {key} has {count} consumer(s)"));
                }
                (_map.Remove(key) as IDisposable).Dispose();
            }
            _timer.Dispose();

            if (KPolicy.FinalDisposalBehaviour == ManagerDisposalStrategy.DisposeButThrowIfInUse && builder.HasErrors)
            {
                throw builder.ToAggregateException();
            }
        }