public void VerifyStatusCallbackWrapperConvertsArguments()
        {
            var wrapper = new StatusCallbackWrapper(
                (session, snp, snt, obj) =>
                {
                    Assert.IsInstanceOfType(obj, typeof(JET_SNPROG));
                    var snprog = obj as JET_SNPROG;
                    Assert.AreEqual(this.sesid, session);
                    Assert.AreEqual(JET_SNP.Restore, snp);
                    Assert.AreEqual(JET_SNT.Progress, snt);
                    Assert.IsNotNull(snprog);
                    Assert.AreEqual(1, snprog.cunitDone);
                    Assert.AreEqual(100, snprog.cunitTotal);
                    return JET_err.Success;
                });

            var native = new NATIVE_SNPROG
            {
                cbStruct = checked((uint)NATIVE_SNPROG.Size),
                cunitDone = 1,
                cunitTotal = 100,
            };

            unsafe
            {
                wrapper.NativeCallback(
                    this.sesid.Value,
                    (uint)JET_SNP.Restore,
                    (uint)JET_SNT.Progress,
                    new IntPtr(&native));
            }

            wrapper.ThrowSavedException();
        }
示例#2
0
 public void Setup()
 {
     this.native = new NATIVE_SNPROG
     {
         cbStruct = checked((uint)NATIVE_SNPROG.Size),
         cunitDone = 2,
         cunitTotal = 7,
     };
     this.managed = new JET_SNPROG();
     this.managed.SetFromNative(this.native);
 }
        /// <summary>
        /// Get the managed data object from the unmanaged data.
        /// </summary>
        /// <param name="nativeData">The native data.</param>
        /// <param name="snp">The SNP (used to determine the type of object).</param>
        /// <param name="snt">The SNT (used to determine the type of object).</param>
        /// <returns>The managed data object.</returns>
        public static object GetManagedData(IntPtr nativeData, JET_SNP snp, JET_SNT snt)
        {
            if (IntPtr.Zero != nativeData && JET_SNT.Progress == snt)
            {
                NATIVE_SNPROG native  = (NATIVE_SNPROG)Marshal.PtrToStructure(nativeData, typeof(NATIVE_SNPROG));
                JET_SNPROG    managed = new JET_SNPROG();
                managed.SetFromNative(native);
                return(managed);
            }

            return(null);
        }
示例#4
0
        /// <summary>
        /// Callback function for native code.
        /// </summary>
        /// <param name="nativeSesid">
        /// The session with which the long running operation was called.
        /// </param>
        /// <param name="nativeSnp">The type of operation.</param>
        /// <param name="nativeSnt">The status of the operation.</param>
        /// <param name="nativeSnprog">Optional <see cref="NATIVE_SNPROG"/>.</param>
        /// <returns>An error code.</returns>
        private JET_err CallbackImpl(IntPtr nativeSesid, uint nativeSnp, uint nativeSnt, IntPtr nativeSnprog)
        {
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                var sesid = new JET_SESID {
                    Value = nativeSesid
                };
                JET_SNP    snp    = (JET_SNP)nativeSnp;
                JET_SNT    snt    = (JET_SNT)nativeSnt;
                JET_SNPROG snprog = null;

                // Other callback types can have pointers to different structures.
                if (IntPtr.Zero != nativeSnprog && JET_SNT.Progress == snt)
                {
                    NATIVE_SNPROG native = (NATIVE_SNPROG)Marshal.PtrToStructure(nativeSnprog, typeof(NATIVE_SNPROG));
                    snprog = new JET_SNPROG();
                    snprog.SetFromNative(native);
                }

                return(this.wrappedCallback(sesid, snp, snt, snprog));
            }
            catch (ThreadAbortException)
            {
                Trace.WriteLineIf(this.traceSwitch.TraceWarning, "Caught ThreadAbortException");

                // Stop the thread abort and let the unmanaged ESENT code finish.
                // ThrowSavedException will call Thread.Abort() again.
                this.ThreadWasAborted = true;
                Thread.ResetAbort();
                return(JET_err.CallbackFailed);
            }
            catch (Exception ex)
            {
                Trace.WriteLineIf(this.traceSwitch.TraceWarning, "Caught Exception");
                this.SavedException = ex;
                return(JET_err.CallbackFailed);
            }

            // What happens if the thread is aborted here, outside of the CER?
            // We probably throw the exception through ESENT, which isn't good.
        }
示例#5
0
 /// <summary>
 /// Set the members of this class from a <see cref="NATIVE_SNPROG"/>.
 /// </summary>
 /// <param name="native">The native struct.</param>
 internal void SetFromNative(NATIVE_SNPROG native)
 {
     Debug.Assert(native.cbStruct == NATIVE_SNPROG.Size, "NATIVE_SNPROG is the wrong size");
     this.cunitDone  = checked ((int)native.cunitDone);
     this.cunitTotal = checked ((int)native.cunitTotal);
 }
示例#6
0
 /// <summary>
 /// Set the members of this class from a <see cref="NATIVE_SNPROG"/>.
 /// </summary>
 /// <param name="native">The native struct.</param>
 internal void SetFromNative(NATIVE_SNPROG native)
 {
     Debug.Assert(native.cbStruct == NATIVE_SNPROG.Size, "NATIVE_SNPROG is the wrong size");
     this.cunitDone = checked((int) native.cunitDone);
     this.cunitTotal = checked((int) native.cunitTotal);
 }