コード例 #1
0
        /// <summary>
        /// Initialize the setting for profiling of database accessing with ADO.NET.
        /// </summary>
        /// <param name="profilerType">The type to implement <see cref="IAdoNetProfiler"/>.</param>
        public static void Initialize(Type profilerType)
        {
            if (profilerType == null)
            {
                throw new ArgumentNullException(nameof(profilerType));
            }

            if (profilerType.GetInterfaces().All(x => x != typeof(IAdoNetProfiler)))
            {
                throw new ArgumentException($"The type must be {typeof(IAdoNetProfiler).FullName}.", nameof(profilerType));
            }

            _readerWriterLockSlim.ExecuteWithReadLock(() =>
            {
                if (_initialized)
                {
                    throw new InvalidOperationException("This factory class has already initialized.");
                }

                // Overwrite DbProviderFactories.
                Utility.InitialzeDbProviderFactory();

                var constructor = profilerType.GetConstructor(Type.EmptyTypes);

                if (constructor == null)
                {
                    throw new InvalidOperationException("There is no default constructor. The profiler must have it.");
                }

                _constructor = constructor;
                _initialized = true;
            });
        }
コード例 #2
0
        public static TResult ExecuteWithReadLock <TResult>(this ReaderWriterLockSlim rwlock, Func <TResult> func)
        {
            TResult result = default(TResult);

            rwlock.ExecuteWithReadLock(delegate {
                result = func();
            });
            return(result);
        }
コード例 #3
0
 //--- Methods ---
 public void Enqueue(XDoc doc)
 {
     _disposalLock.ExecuteWithReadLock(() => {
         EnsureInstanceNotDisposed();
         _queue.Enqueue(doc);
     });
 }