fix: resolve Exchange runspace and PowerShell invoke API mismatches
This commit is contained in:
@@ -62,11 +62,8 @@ namespace C4IT.LIAM
|
|||||||
var runspace = RunspaceFactory.CreateRunspace(connectionInfo);
|
var runspace = RunspaceFactory.CreateRunspace(connectionInfo);
|
||||||
LogEntry($"Opening Exchange runspace (timeout: {RunspaceOpenTimeout.TotalSeconds:0}s) for endpoint '{_exchangeUri}'", LogLevels.Debug);
|
LogEntry($"Opening Exchange runspace (timeout: {RunspaceOpenTimeout.TotalSeconds:0}s) for endpoint '{_exchangeUri}'", LogLevels.Debug);
|
||||||
|
|
||||||
IAsyncResult openResult = null;
|
var openTask = Task.Run(() => runspace.Open());
|
||||||
try
|
if (!openTask.Wait(RunspaceOpenTimeout))
|
||||||
{
|
|
||||||
openResult = runspace.BeginOpen(null, null);
|
|
||||||
if (!openResult.AsyncWaitHandle.WaitOne(RunspaceOpenTimeout))
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -81,12 +78,7 @@ namespace C4IT.LIAM
|
|||||||
$"Timeout while opening Exchange runspace after {RunspaceOpenTimeout.TotalSeconds:0} seconds.");
|
$"Timeout while opening Exchange runspace after {RunspaceOpenTimeout.TotalSeconds:0} seconds.");
|
||||||
}
|
}
|
||||||
|
|
||||||
runspace.EndOpen(openResult);
|
openTask.GetAwaiter().GetResult();
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
openResult?.AsyncWaitHandle?.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
LogEntry("Exchange runspace opened successfully", LogLevels.Debug);
|
LogEntry("Exchange runspace opened successfully", LogLevels.Debug);
|
||||||
return runspace;
|
return runspace;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace C4IT.LIAM
|
|||||||
{
|
{
|
||||||
private static readonly TimeSpan PowerShellInvokeTimeout = TimeSpan.FromSeconds(120);
|
private static readonly TimeSpan PowerShellInvokeTimeout = TimeSpan.FromSeconds(120);
|
||||||
|
|
||||||
private static Collection<PSObject> InvokePowerShellWithTimeout(PowerShell ps, TimeSpan timeout, string operationName)
|
private static PSDataCollection<PSObject> InvokePowerShellWithTimeout(PowerShell ps, TimeSpan timeout, string operationName)
|
||||||
{
|
{
|
||||||
IAsyncResult asyncResult = null;
|
IAsyncResult asyncResult = null;
|
||||||
try
|
try
|
||||||
|
|||||||
Reference in New Issue
Block a user