mirror of
https://github.com/MichaelGrafnetter/DSInternals
synced 2025-04-28 22:08:48 +00:00
96 lines
3.0 KiB
C#
96 lines
3.0 KiB
C#
namespace DSInternals.PowerShell.Commands
|
|
{
|
|
using System;
|
|
using System.Management.Automation;
|
|
using DSInternals.DataStore;
|
|
using Microsoft.PowerShell.Commands;
|
|
|
|
public abstract class ADDBCommandBase : PSCmdletEx, IDisposable
|
|
{
|
|
/// <summary>
|
|
/// Gets or sets the DIT database file path.
|
|
/// </summary>
|
|
/// <value>
|
|
/// Path to the DIT file on the local server.
|
|
/// </value>
|
|
/// <remarks>
|
|
/// The DIT must be in a consistent state, that is, the ESE logs must be replayed.
|
|
/// </remarks>
|
|
[Parameter(Mandatory = true, HelpMessage = "TODO")]
|
|
[ValidateNotNullOrEmpty]
|
|
[Alias("Database", "DatabasePath", "DatabaseFilePath", "DBFilePath")]
|
|
public string DBPath
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the ESE transaction log folder. If not specified, then database folder will be used.
|
|
/// </summary>
|
|
/// <value>
|
|
/// The log path.
|
|
/// </value>
|
|
[Parameter(Mandatory = false, HelpMessage = "TODO")]
|
|
[ValidateNotNullOrEmpty]
|
|
[Alias("Log", "TransactionLogPath")]
|
|
public string LogPath
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
protected virtual bool ReadOnly
|
|
{
|
|
get
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
protected DirectoryContext DirectoryContext
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
protected override void BeginProcessing()
|
|
{
|
|
// TODO: Debug output
|
|
this.WriteDebug("Opening the Active Directory database.");
|
|
try
|
|
{
|
|
// Resolve possibly relative paths to absolute paths:
|
|
string dbPathResolved = this.ResolveSinglePath(this.DBPath);
|
|
string logPathResolved = this.ResolveSinglePath(this.LogPath);
|
|
this.DirectoryContext = new DirectoryContext(dbPathResolved, this.ReadOnly, logPathResolved);
|
|
}
|
|
catch(SessionStateException ex)
|
|
{
|
|
// This may be DriveNotFoundException, ItemNotFoundException, ProviderNotFoundException, etc.
|
|
// Terminate on this error:
|
|
this.ThrowTerminatingError(new ErrorRecord(ex.ErrorRecord, ex));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorRecord error = new ErrorRecord(ex, "DBContextError", ErrorCategory.OpenError, null);
|
|
// Terminate on this error:
|
|
this.ThrowTerminatingError(error);
|
|
}
|
|
}
|
|
public void Dispose()
|
|
{
|
|
this.Dispose(true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
{
|
|
if (disposing && this.DirectoryContext != null)
|
|
{
|
|
this.DirectoryContext.Dispose();
|
|
this.DirectoryContext = null;
|
|
}
|
|
}
|
|
}
|
|
} |