コード例 #1
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);
 }
コード例 #2
0
        /// <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;
        }
コード例 #3
0
        /// <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
ファイル: ToStringTests.cs プロジェクト: 925coder/ravendb
 public void JetSnprogToString()
 {
     var snprog = new JET_SNPROG { cunitDone = 5, cunitTotal = 10 };
     Assert.AreEqual("JET_SNPROG(5/10)", snprog.ToString());
 }
コード例 #6
0
ファイル: jet_pfnstatus.cs プロジェクト: ayende/managed-esent
        /// <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.
        }