mirror of
https://github.com/soukoku/ntwain.git
synced 2026-02-25 13:04:07 +08:00
Road to v1 begins!
This commit is contained in:
42
NTwain/Internals/TentativeStateCommitable.cs
Normal file
42
NTwain/Internals/TentativeStateCommitable.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
namespace NTwain.Internals
|
||||
{
|
||||
class TentativeStateCommitable : ICommittable
|
||||
{
|
||||
bool _commit;
|
||||
ITwainStateInternal _session;
|
||||
int _origState;
|
||||
int _newState;
|
||||
public TentativeStateCommitable(ITwainStateInternal session, int newState)
|
||||
{
|
||||
_session = session;
|
||||
_origState = session.State;
|
||||
_newState = newState;
|
||||
_session.ChangeState(newState, false);
|
||||
}
|
||||
|
||||
#region ICommitable Members
|
||||
|
||||
public void Commit()
|
||||
{
|
||||
if (_session.State == _newState)
|
||||
{
|
||||
_session.ChangeState(_newState, true);
|
||||
}
|
||||
_commit = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!_commit && _session.State == _newState)
|
||||
{
|
||||
_session.ChangeState(_origState, false);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user