/// <summary>
 /// Free the durable commit session.
 /// We do not try to set the instance parameter to null, since the callback is disposed after JetTerm and
 /// the callback cannot be set after JetTerm.
 /// </summary>
 protected override void ReleaseResource()
 {
     this.instance        = JET_INSTANCE.Nil;
     this.wrappedCallback = null;
     this.wrapperCallback = null;
     this.ResourceWasReleased();
 }
        /// <summary>
        /// Gets the callback for log flush.
        /// </summary>
        /// <returns>The delegate that's called for log flush.</returns>
        internal NATIVE_JET_PFNDURABLECOMMITCALLBACK GetDurableCommitCallback()
        {
            NATIVE_JET_PFNDURABLECOMMITCALLBACK pfndurablecommit = null;

            IntPtr rawValue = this.GetIntPtrParameter(Windows8Param.DurableCommitCallback);

            if (rawValue != IntPtr.Zero)
            {
                pfndurablecommit = (NATIVE_JET_PFNDURABLECOMMITCALLBACK)Marshal.GetDelegateForFunctionPointer(rawValue, typeof(NATIVE_JET_PFNDURABLECOMMITCALLBACK));
            }

            return(pfndurablecommit);
        }
        /// <summary>
        /// Sets the callback for log flush.
        /// It is the caller's responsibility to hold a reference to the delegate
        /// so that it doesn't get GC'ed.
        /// </summary>
        /// <param name="callback">
        /// The callback.
        /// </param>
        internal void SetDurableCommitCallback(
            NATIVE_JET_PFNDURABLECOMMITCALLBACK callback)
        {
            IntPtr nativeDelegate;

            if (callback != null)
            {
                nativeDelegate = Marshal.GetFunctionPointerForDelegate(callback);
            }
            else
            {
                nativeDelegate = IntPtr.Zero;
            }

            this.SetIntPtrParameter(Windows8Param.DurableCommitCallback, nativeDelegate);
        }
        public void VerifyGetAndSetNullDurableCommitCallback()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            NATIVE_JET_PFNDURABLECOMMITCALLBACK savedCallback = this.instanceParameters.GetDurableCommitCallback();

            try
            {
                this.instanceParameters.SetDurableCommitCallback(null);
                Assert.AreEqual(null, this.instanceParameters.GetDurableCommitCallback());
            }
            finally
            {
                this.instanceParameters.SetDurableCommitCallback(savedCallback);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DurableCommitCallback"/> class. 
        /// The constructor.
        /// </summary>
        /// <param name="instance">
        /// The instance with which to associate the callback.
        /// </param>
        /// <param name="wrappedCallback">
        /// The managed code callback to call.
        /// </param>
        public DurableCommitCallback(
            JET_INSTANCE instance,
            JET_PFNDURABLECOMMITCALLBACK wrappedCallback)
        {
            this.instance = instance;
            this.wrappedCallback = wrappedCallback;
            this.wrapperCallback = this.NativeDurableCommitCallback;

            #if !MANAGEDESENT_ON_WSA // RuntimeHelpers works differently in Windows Store Apps.
            if (this.wrappedCallback != null)
            {
                RuntimeHelpers.PrepareMethod(this.wrappedCallback.Method.MethodHandle);
            }

            RuntimeHelpers.PrepareMethod(typeof(DurableCommitCallback).GetMethod("NativeDurableCommitCallback", BindingFlags.NonPublic | BindingFlags.Instance).MethodHandle);
            #endif

            InstanceParameters instanceParameters = new InstanceParameters(this.instance);

            // This might be null.
            instanceParameters.SetDurableCommitCallback(this.wrapperCallback);

            this.ResourceWasAllocated();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DurableCommitCallback"/> class.
        /// The constructor.
        /// </summary>
        /// <param name="instance">
        /// The instance with which to associate the callback.
        /// </param>
        /// <param name="wrappedCallback">
        /// The managed code callback to call.
        /// </param>
        public DurableCommitCallback(
            JET_INSTANCE instance,
            JET_PFNDURABLECOMMITCALLBACK wrappedCallback)
        {
            this.instance        = instance;
            this.wrappedCallback = wrappedCallback;
            this.wrapperCallback = this.NativeDurableCommitCallback;

#if !MANAGEDESENT_ON_WSA // RuntimeHelpers works differently in Windows Store Apps.
            if (this.wrappedCallback != null)
            {
                RuntimeHelpers.PrepareMethod(this.wrappedCallback.Method.MethodHandle);
            }

            RuntimeHelpers.PrepareMethod(typeof(DurableCommitCallback).GetMethod("NativeDurableCommitCallback", BindingFlags.NonPublic | BindingFlags.Instance).MethodHandle);
#endif

            InstanceParameters instanceParameters = new InstanceParameters(this.instance);

            // This might be null.
            instanceParameters.SetDurableCommitCallback(this.wrapperCallback);

            this.ResourceWasAllocated();
        }
 /// <summary>
 /// Free the durable commit session.
 /// We do not try to set the instance parameter to null, since the callback is disposed after JetTerm and
 /// the callback cannot be set after JetTerm.
 /// </summary>
 protected override void ReleaseResource()
 {
     this.instance = JET_INSTANCE.Nil;
     this.wrappedCallback = null;
     this.wrapperCallback = null;
     this.ResourceWasReleased();
 }
        /// <summary>
        /// Sets the callback for log flush.
        /// It is the caller's responsibility to hold a reference to the delegate
        /// so that it doesn't get GC'ed.
        /// </summary>
        /// <param name="callback">
        /// The callback.
        /// </param>
        internal void SetDurableCommitCallback(
            NATIVE_JET_PFNDURABLECOMMITCALLBACK callback)
        {
            IntPtr nativeDelegate;
            if (callback != null)
            {
                nativeDelegate = Marshal.GetFunctionPointerForDelegate(callback);
            }
            else
            {
                nativeDelegate = IntPtr.Zero;
            }

            this.SetIntPtrParameter(Windows8Param.DurableCommitCallback, nativeDelegate);
        }