Files
git.stella-ops.org/Mongo2Go-4.1.0/src/Mongo2Go/MongoDbRunner.IDisposable.cs

55 lines
1.3 KiB
C#

using System;
namespace Mongo2Go
{
// IDisposable and friends
public partial class MongoDbRunner
{
~MongoDbRunner()
{
Dispose(false);
}
public bool Disposed { get; private set; }
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (Disposed)
{
return;
}
if (State != State.Running)
{
return;
}
if (disposing)
{
// we have no "managed resources" - but we leave this switch to avoid an FxCop CA1801 warnig
}
if (_mongoDbProcess != null)
{
_mongoDbProcess.Dispose();
}
// will be null if we are working in debugging mode (single instance)
if (_dataDirectoryWithPort != null)
{
// finally clean up the data directory we created previously
_fileSystem.DeleteFolder(_dataDirectoryWithPort);
}
Disposed = true;
State = State.Stopped;
}
}
}