Ejemplo n.º 1
0
        private JET_err RestoreStatusCallback(JET_SESID sesid, JET_SNP snp, JET_SNT snt, object data)
        {
            output(string.Format("Esent Restore: {0} {1} {2}", snp, snt, data));
            Console.WriteLine("Esent Restore: {0} {1} {2}", snp, snt, data);

            return(JET_err.Success);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Callback function for native code. We don't want to throw an exception through
        /// unmanaged ESENT because that will corrupt ESENT's internal state. Instead we
        /// catch all exceptions and return an error instead. We use a CER to make catching
        /// the exceptions as reliable as possible.
        /// </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="nativeData">Optional <see cref="NATIVE_SNPROG"/>.</param>
        /// <returns>An error code.</returns>
        private JET_err CallbackImpl(IntPtr nativeSesid, uint nativeSnp, uint nativeSnt, IntPtr nativeData)
        {
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                var sesid = new JET_SESID {
                    Value = nativeSesid
                };
                JET_SNP snp  = (JET_SNP)nativeSnp;
                JET_SNT snt  = (JET_SNT)nativeSnt;
                object  data = CallbackDataConverter.GetManagedData(nativeData, snp, snt);
                return(this.wrappedCallback(sesid, snp, snt, data));
            }
            catch (ThreadAbortException)
            {
                Trace.WriteLineIf(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(
                    TraceSwitch.TraceWarning,
                    String.Format(CultureInfo.InvariantCulture, "Caught Exception {0}", ex));
                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.
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Progress reporting callback.
        /// </summary>
        /// <param name="sesid">The session performing the operation.</param>
        /// <param name="snp">The operation type.</param>
        /// <param name="snt">The type of the progress report.</param>
        /// <param name="data">Progress info.</param>
        /// <returns>An error code.</returns>
        private JET_err StatusCallback(JET_SESID sesid, JET_SNP snp, JET_SNT snt, object data)
        {
            this.statusCallbackWasCalled = true;

            if (JET_SNT.Progress == snt)
            {
                if (data as JET_SNPROG == null)
                {
                    Assert.Inconclusive(
                        "Not all cases in CallbackDataConverter.GetManagedData() have been implemented. snp={0},snt={1}",
                        snp,
                        snt);
                }

                var snprog = data as JET_SNPROG;
                Assert.IsNotNull(snprog, "Expected an snprog in a progress callback");
                Assert.IsTrue(snprog.cunitDone <= snprog.cunitTotal, "done > total in the snprog");
            }

            // On Windows Store Apps, the functions that reference this variable are compiled out, so this
            // prevents a warning-as-error.
            Assert.IsTrue(this.statusCallbackWasCalled, "This will always be true.");

            return(JET_err.Success);
        }
Ejemplo n.º 4
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;
        }
        /// <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);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Progress reporting callback.
        /// </summary>
        /// <param name="sesid">The session performing the operation.</param>
        /// <param name="snp">The operation type.</param>
        /// <param name="snt">The type of the progress report.</param>
        /// <param name="data">Progress info.</param>
        /// <returns>An error code.</returns>
        private JET_err StatusCallback(JET_SESID sesid, JET_SNP snp, JET_SNT snt, object data)
        {
            this.statusCallbackWasCalled = true;
            Assert.IsTrue(
                JET_SNP.Backup == snp ||
                JET_SNP.Restore == snp ||
                JET_SNP.Compact == snp,
                "Unexpected snp (progress type)");
            if (JET_SNT.Progress == snt)
            {
                var snprog = data as JET_SNPROG;
                Assert.IsNotNull(snprog, "Expected an snprog in a progress callback");
                Assert.IsTrue(snprog.cunitDone <= snprog.cunitTotal, "done > total in the snprog");
            }

            return(JET_err.Success);
        }
Ejemplo n.º 7
0
        private JET_err CompactStatusCallback(JET_SESID sesid, JET_SNP snp, JET_SNT snt, object data)
        {
            Console.WriteLine("Esent Compact: {0} {1} {2}", snp, snt, data);

            if (snt == JET_SNT.Progress)
            {
                if (SystemTime.UtcNow - lastCompactionProgressStatusUpdate < TimeSpan.FromMilliseconds(100))
                {
                    return(JET_err.Success);
                }

                lastCompactionProgressStatusUpdate = SystemTime.UtcNow;
            }

            output(string.Format("Esent Compact: {0} {1} {2}", snp, snt, data));

            return(JET_err.Success);
        }
Ejemplo n.º 8
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.
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Progress reporting callback.
        /// </summary>
        /// <param name="sesid">The session performing the operation.</param>
        /// <param name="snp">The operation type.</param>
        /// <param name="snt">The type of the progress report.</param>
        /// <param name="data">Progress info.</param>
        /// <returns>An error code.</returns>
        private JET_err StatusCallback(JET_SESID sesid, JET_SNP snp, JET_SNT snt, object data)
        {
            this.statusCallbackWasCalled = true;

            if (JET_SNT.Progress == snt)
            {
                if (data as JET_SNPROG == null)
                {
                    Assert.Inconclusive(
                        "Not all cases in CallbackDataConverter.GetManagedData() have been implemented. snp={0},snt={1}",
                        snp,
                        snt);
                }

                var snprog = data as JET_SNPROG;
                Assert.IsNotNull(snprog, "Expected an snprog in a progress callback");
                Assert.IsTrue(snprog.cunitDone <= snprog.cunitTotal, "done > total in the snprog");
            }

            return(JET_err.Success);
        }
Ejemplo n.º 10
0
 private JET_err StatusCallback(JET_SESID sesid, JET_SNP snp, JET_SNT snt, object data)
 {
     Console.WriteLine("Esent Restore: {0} {1} {2}", snp, snt, data);
     return(JET_err.Success);
 }
Ejemplo n.º 11
0
		private JET_err StatusCallback(JET_SESID sesid, JET_SNP snp, JET_SNT snt, object data)
		{
			Console.WriteLine("Esent Restore: {0} {1} {2}", snp, snt, data);
			return JET_err.Success;
		}
Ejemplo n.º 12
0
		private JET_err RestoreStatusCallback(JET_SESID sesid, JET_SNP snp, JET_SNT snt, object data)
		{
			output(string.Format("Esent Restore: {0} {1} {2}", snp, snt, data));
			Console.WriteLine("Esent Restore: {0} {1} {2}", snp, snt, data);

			return JET_err.Success;
		}
Ejemplo n.º 13
0
 static JET_err progress(JET_SESID sesid, JET_SNP snp, JET_SNT snt, object data)
 {
     return(JET_err.Success);
 }
Ejemplo n.º 14
0
		private JET_err StatusCallback(JET_SESID sesid, JET_SNP snp, JET_SNT snt, object data)
		{
			Notify(string.Format("Esent {0} {1} {2}", snp, snt, data).Trim(), BackupStatus.BackupMessageSeverity.Informational);
			return JET_err.Success;
		}
Ejemplo n.º 15
0
		private JET_err StatusCallback(JET_SESID sesid, JET_SNP snp, JET_SNT snt, object data)
		{
			Notify(string.Format("Esent {0} {1} {2}", snp, snt, data).Trim());
			return JET_err.Success;
		}
Ejemplo n.º 16
0
 private JET_err StatusCallback(JET_SESID sesid, JET_SNP snp, JET_SNT snt, object data)
 {
     Notify(string.Format("Esent {0} {1} {2}", snp, snt, data).Trim(), BackupStatus.BackupMessageSeverity.Informational);
     return(JET_err.Success);
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Progress reporting callback.
        /// </summary>
        /// <param name="sesid">The session performing the operation.</param>
        /// <param name="snp">The operation type.</param>
        /// <param name="snt">The type of the progress report.</param>
        /// <param name="data">Progress info.</param>
        /// <returns>An error code.</returns>
        private JET_err StatusCallback(JET_SESID sesid, JET_SNP snp, JET_SNT snt, object data)
        {
            this.statusCallbackWasCalled = true;

            if (JET_SNT.Progress == snt)
            {
                if (data as JET_SNPROG == null)
                {
                    Assert.Inconclusive(
                    "Not all cases in CallbackDataConverter.GetManagedData() have been implemented. snp={0},snt={1}",
                    snp,
                    snt);
                }

                var snprog = data as JET_SNPROG;
                Assert.IsNotNull(snprog, "Expected an snprog in a progress callback");
                Assert.IsTrue(snprog.cunitDone <= snprog.cunitTotal, "done > total in the snprog");
            }

            return JET_err.Success;
        }
Ejemplo n.º 18
0
 private JET_err StatusCallback(JET_SESID sesid, JET_SNP snp, JET_SNT snt, object data)
 {
     Notify(string.Format("Esent {0} {1} {2}", snp, snt, data).Trim());
     return(JET_err.Success);
 }
Ejemplo n.º 19
0
		private JET_err CompactStatusCallback(JET_SESID sesid, JET_SNP snp, JET_SNT snt, object data)
		{
			Console.WriteLine("Esent Compact: {0} {1} {2}", snp, snt, data);

			if (snt == JET_SNT.Progress)
			{
				if(SystemTime.UtcNow - lastCompactionProgressStatusUpdate < TimeSpan.FromMilliseconds(100))
					return JET_err.Success;

				lastCompactionProgressStatusUpdate = SystemTime.UtcNow;
			}

			output(string.Format("Esent Compact: {0} {1} {2}", snp, snt, data));
			
			return JET_err.Success;
		}
Ejemplo n.º 20
0
        /// <summary>
        /// Progress reporting callback.
        /// </summary>
        /// <param name="sesid">The session performing the operation.</param>
        /// <param name="snp">The operation type.</param>
        /// <param name="snt">The type of the progress report.</param>
        /// <param name="data">Progress info.</param>
        /// <returns>An error code.</returns>
        private JET_err StatusCallback(JET_SESID sesid, JET_SNP snp, JET_SNT snt, object data)
        {
            this.statusCallbackWasCalled = true;
            Assert.IsTrue(
                JET_SNP.Backup == snp
                || JET_SNP.Restore == snp
                || JET_SNP.Compact == snp,
                "Unexpected snp (progress type)");
            if (JET_SNT.Progress == snt)
            {
                var snprog = data as JET_SNPROG;
                Assert.IsNotNull(snprog, "Expected an snprog in a progress callback");
                Assert.IsTrue(snprog.cunitDone <= snprog.cunitTotal, "done > total in the snprog");
            }

            return JET_err.Success;
        }