wsp-10323 Step 9

This commit is contained in:
me 2015-03-23 19:13:25 +04:00
parent 4bd3dbc9fe
commit 1b967de004
9 changed files with 298 additions and 20 deletions

View file

@ -315,7 +315,7 @@ namespace WebsitePanel.Providers.Virtualization
cmdNew.Parameters.Add("Name", vm.Name);
cmdNew.Parameters.Add("Generation", vm.Generation > 1 ? vm.Generation : 1);
cmdNew.Parameters.Add("VHDPath", vm.VirtualHardDrivePath);
PowerShell.Execute(cmdNew, true);
PowerShell.Execute(cmdNew, true, true);
// Set VM
Command cmdSet = new Command("Set-VM");
@ -512,14 +512,10 @@ namespace WebsitePanel.Providers.Virtualization
DeleteSwitch(networkAdapter.SwitchName);
}
object[] errors;
Command cmdSet = new Command("Remove-VM");
cmdSet.Parameters.Add("Name", vm.Name);
cmdSet.Parameters.Add("Force");
PowerShell.Execute(cmdSet, false, out errors);
PowerShellManager.ExceptionIfErrors(errors);
PowerShell.Execute(cmdSet, false, true);
return JobHelper.CreateSuccessResult(ReturnCode.JobStarted);
}
@ -788,9 +784,7 @@ namespace WebsitePanel.Providers.Virtualization
if (!string.IsNullOrEmpty(computerName)) cmd.Parameters.Add("ComputerName", computerName);
if (!string.IsNullOrEmpty(type)) cmd.Parameters.Add("SwitchType", type);
object[] errors;
Collection<PSObject> result = PowerShell.Execute(cmd, false, out errors);
PowerShellManager.ExceptionIfErrors(errors);
Collection<PSObject> result = PowerShell.Execute(cmd, false, true);
foreach (PSObject current in result)
{

View file

@ -66,12 +66,13 @@ namespace WebsitePanel.Providers.Virtualization
public Collection<PSObject> Execute(Command cmd, bool addComputerNameParameter)
{
object[] errors;
return Execute(cmd, addComputerNameParameter, out errors);
return Execute(cmd, addComputerNameParameter, false);
}
public Collection<PSObject> Execute(Command cmd, bool addComputerNameParameter, out object[] errors)
public Collection<PSObject> Execute(Command cmd, bool addComputerNameParameter, bool withExceptions)
{
HostedSolutionLog.LogStart("Execute");
List<object> errorList = new List<object>();
HostedSolutionLog.DebugCommand(cmd);
@ -110,14 +111,17 @@ namespace WebsitePanel.Providers.Virtualization
}
}
pipeLine = null;
errors = errorList.ToArray();
if (withExceptions)
ExceptionIfErrors(errorList);
HostedSolutionLog.LogEnd("Execute");
return results;
}
public static void ExceptionIfErrors(object[] errors)
private static void ExceptionIfErrors(List<object> errors)
{
if (errors != null && errors.Length > 0)
if (errors != null && errors.Count > 0)
throw new Exception("Invoke error: " + string.Join("; ", errors.Select(e => e.ToString())));
}
}