/// <summary> /// Reset the object state. This method will be called by the pool manager just before the /// object is being returned to the pool. /// </summary> internal bool ResetState() { if (!ValidateObject(PooledObjectValidationContext.Inbound(this))) { return(false); } if (OnResetState != null) { try { OnResetState(); } catch (Exception ex) { #if !NET35 if (Log.IsWarnEnabled()) { Log.WarnException("[ObjectPool] An unexpected error occurred while resetting state", ex); } #else System.Diagnostics.Debug.Assert(ex != null); // Placeholder to avoid warnings #endif return(false); } } return(true); }
/// <summary> /// Validates pooled object state. An invalid object will not get into the pool and it will /// not be returned to consumers. /// </summary> /// <param name="validationContext">The validation context.</param> /// <returns>True if current pooled object is valid, false otherwise.</returns> internal bool ValidateObject(PooledObjectValidationContext validationContext) { if (OnValidateObject != null) { try { return(OnValidateObject(validationContext)); } catch (Exception ex) { if (Log.IsWarnEnabled()) { Log.WarnException("[ObjectPool] An unexpected error occurred while validating an object", ex); } return(false); } } return(true); }
/// <summary> /// Validates pooled object state. An invalid object will not get into the pool and it will /// not be returned to consumers. /// </summary> /// <param name="validationContext">The validation context.</param> /// <returns>True if current pooled object is valid, false otherwise.</returns> internal bool ValidateObject(PooledObjectValidationContext validationContext) { if (OnValidateObject != null) { try { return(OnValidateObject.GetInvocationList() .Cast <Func <PooledObjectValidationContext, bool> >() .All(validationDelegate => validationDelegate(validationContext))); } catch (Exception ex) { if (Log.IsWarnEnabled()) { Log.WarnException("[ObjectPool] An unexpected error occurred while validating an object", ex); } return(false); } } return(true); }
/// <summary> /// Reset the object state. This method will be called by the pool manager just before the /// object is being returned to the pool. /// </summary> internal bool ResetState() { if (!ValidateObject(PooledObjectValidationContext.Inbound(this))) { return(false); } if (OnResetState != null) { try { OnResetState(); } catch (Exception ex) { if (Log.IsWarnEnabled()) { Log.WarnException("[ObjectPool] An unexpected error occurred while resetting state", ex); } return(false); } } return(true); }
/// <summary> /// Validates pooled object state. An invalid object will not get into the pool and it will /// not be returned to consumers. /// </summary> /// <param name="validationContext">The validation context.</param> /// <returns>True if current pooled object is valid, false otherwise.</returns> internal bool ValidateObject(PooledObjectValidationContext validationContext) { if (OnValidateObject != null) { try { return(OnValidateObject(validationContext)); } catch (Exception ex) { #if !NET35 if (Log.IsWarnEnabled()) { Log.WarnException("[ObjectPool] An unexpected error occurred while validating an object", ex); } #else System.Diagnostics.Debug.Assert(ex != null); // Placeholder to avoid warnings #endif return(false); } } return(true); }