//-----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation.
//
//-----------------------------------------------------------------------
namespace Microsoft.Isam.Esent.Interop
{
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;
///
/// The native version of the JET_SNPROG structure.
///
[StructLayout(LayoutKind.Sequential)]
[SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules",
"SA1305:FieldNamesMustNotUseHungarianNotation",
Justification = "This should match the unmanaged API, which isn't capitalized.")]
[SuppressMessage(
"Microsoft.StyleCop.CSharp.NamingRules",
"SA1307:AccessibleFieldsMustBeginWithUpperCaseLetter",
Justification = "This should match the unmanaged API, which isn't capitalized.")]
internal struct NATIVE_SNPROG
{
///
/// Size of this structure.
///
public static readonly int Size = Marshal.SizeOf(typeof(NATIVE_SNPROG));
///
/// Size of the structure.
///
public uint cbStruct;
///
/// The number of work units that are already completed during the long
/// running operation.
///
public uint cunitDone;
///
/// The number of work units that need to be completed. This value will
/// always be bigger than or equal to cunitDone.
///
public uint cunitTotal;
}
///
/// Contains information about the progress of a long-running operation.
///
[SuppressMessage(
"Microsoft.StyleCop.CSharp.NamingRules",
"SA1300:ElementMustBeginWithUpperCaseLetter",
Justification = "This should match the unmanaged API, which isn't capitalized.")]
[Serializable]
public class JET_SNPROG : IEquatable
{
///
/// Number of units of work that have completed.
///
private int completedUnits;
///
/// Total number of units of work to be done.
///
private int totalUnits;
///
/// Gets the number of work units that are already completed during the long
/// running operation.
///
public int cunitDone
{
[DebuggerStepThrough]
get { return this.completedUnits; }
internal set { this.completedUnits = value; }
}
///
/// Gets the number of work units that need to be completed. This value will
/// always be bigger than or equal to cunitDone.
///
public int cunitTotal
{
[DebuggerStepThrough]
get { return this.totalUnits; }
internal set { this.totalUnits = value; }
}
///
/// Returns a value indicating whether this instance is equal
/// to another instance.
///
/// An object to compare with this instance.
/// True if the two instances are equal.
public override bool Equals(object obj)
{
if (obj == null || this.GetType() != obj.GetType())
{
return false;
}
return this.Equals((JET_SNPROG)obj);
}
///
/// Generate a string representation of the instance.
///
/// The structure as a string.
public override string ToString()
{
return string.Format(CultureInfo.InvariantCulture, "JET_SNPROG({0}/{1})", this.cunitDone, this.cunitTotal);
}
///
/// Returns the hash code for this instance.
///
/// The hash code for this instance.
public override int GetHashCode()
{
return unchecked(this.cunitDone * 31) ^ this.cunitTotal;
}
///
/// Returns a value indicating whether this instance is equal
/// to another instance.
///
/// An instance to compare with this instance.
/// True if the two instances are equal.
public bool Equals(JET_SNPROG other)
{
if (null == other)
{
return false;
}
return this.cunitDone == other.cunitDone && this.cunitTotal == other.cunitTotal;
}
///
/// Set the members of this class from a .
///
/// The native struct.
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);
}
}
}