Fixed bugs with adding new mapped drive and when rename folder. Added new functionality - change folder path for mapped drive, when rename folder.

This commit is contained in:
vfedosevich 2014-06-17 05:53:15 +03:00
parent 5f412a78d3
commit 34f2d2bb4f
6 changed files with 175 additions and 33 deletions

View file

@ -1317,8 +1317,6 @@ namespace WebsitePanel.Providers.HostedSolution
{
runSpace = OpenRunspace();
//ImportGroupPolicyMolude(runSpace);
string gpoName = string.Format("{0}-mapped-drives", organizationId);
//create new gpo
@ -1330,6 +1328,8 @@ namespace WebsitePanel.Providers.HostedSolution
catch (Exception ex)
{
CloseRunspace(runSpace);
throw;
}
finally
{
@ -1362,9 +1362,6 @@ namespace WebsitePanel.Providers.HostedSolution
{
runSpace = OpenRunspace();
//import grouppolicy module
//ImportGroupPolicyMolude(runSpace);
Dictionary<string, ExchangeAccount> sidAccountPairs = new Dictionary<string, ExchangeAccount>();
Command cmd;
@ -1445,7 +1442,9 @@ namespace WebsitePanel.Providers.HostedSolution
}
catch (Exception ex)
{
CloseRunspace(runSpace);
throw;
}
finally
{
@ -1453,7 +1452,71 @@ namespace WebsitePanel.Providers.HostedSolution
HostedSolutionLog.LogEnd("SetDriveMapsTargetingFilterInternal");
}
}
}
public void ChangeDriveMapFolderPath(string organizationId, string oldFolder, string newFolder)
{
ChangeDriveMapFolderPathInternal(organizationId, oldFolder, newFolder);
}
internal void ChangeDriveMapFolderPathInternal(string organizationId, string oldFolder, string newFolder)
{
HostedSolutionLog.LogStart("ChangeDriveMapFolderPathInternal");
HostedSolutionLog.DebugInfo("organizationId : {0}", organizationId);
if (string.IsNullOrEmpty(organizationId))
throw new ArgumentNullException("organizationId");
Runspace runSpace = null;
try
{
runSpace = OpenRunspace();
string gpoId;
if (!CheckMappedDriveGpoExists(organizationId, out gpoId))
{
CreateAndLinkMappedDrivesGPO(organizationId, out gpoId);
}
if (!string.IsNullOrEmpty(gpoId))
{
string drivesXmlPath = string.Format("{0}\\{1}",
string.Format(GROUP_POLICY_MAPPED_DRIVES_FILE_PATH_TEMPLATE, RootDomain, gpoId),
"Drives.xml");
// open xml document
XmlDocument xml = new XmlDocument();
xml.Load(drivesXmlPath);
XmlNodeList drives = xml.SelectNodes(string.Format("./Drives/Drive[contains(Properties/@path,'{0}')]", oldFolder));
foreach (XmlNode driveNode in drives)
{
if (driveNode.ChildNodes.Count > 1)
{
string oldPath = driveNode.FirstChild.Attributes["path"].Value;
driveNode.FirstChild.Attributes["path"].Value = oldPath.Replace(oldFolder, newFolder);
}
}
xml.Save(drivesXmlPath);
}
}
catch (Exception ex)
{
CloseRunspace(runSpace);
throw;
}
finally
{
CloseRunspace(runSpace);
HostedSolutionLog.LogEnd("ChangeDriveMapFolderPathInternal");
}
}
private void CreateAndLinkMappedDrivesGPO(string organizationId, out string gpoId)
{
@ -1463,8 +1526,6 @@ namespace WebsitePanel.Providers.HostedSolution
{
runSpace = OpenRunspace();
//ImportGroupPolicyMolude(runSpace);
string gpoName = string.Format("{0}-mapped-drives", organizationId);
string pathOU = GetOrganizationTargetPath(organizationId);
@ -1498,6 +1559,8 @@ namespace WebsitePanel.Providers.HostedSolution
{
gpoId = null;
CloseRunspace(runSpace);
throw;
}
finally
{
@ -1513,8 +1576,6 @@ namespace WebsitePanel.Providers.HostedSolution
{
runSpace = OpenRunspace();
//ImportGroupPolicyMolude(runSpace);
string gpoName = string.Format("{0}-mapped-drives", organizationId);
Command cmd = new Command("Get-GPO");
@ -1530,6 +1591,13 @@ namespace WebsitePanel.Providers.HostedSolution
gpoId = ((Guid)GetPSObjectProperty(gpo, "Id")).ToString("B");
}
}
catch (Exception ex)
{
gpoId = null;
CloseRunspace(runSpace);
throw;
}
finally
{
CloseRunspace(runSpace);
@ -1558,22 +1626,6 @@ namespace WebsitePanel.Providers.HostedSolution
#region Drive Mapping Helpers
private void ImportGroupPolicyMolude(Runspace runSpace)
{
Command cmd = new Command("Import-Module");
cmd.Parameters.Add("Name", "grouppolicy");
ExecuteShellCommand(runSpace, cmd);
}
private void ImportActiveDirectoryMolude(Runspace runSpace)
{
Command cmd = new Command("Import-Module");
cmd.Parameters.Add("Name", "ActiveDirectory");
ExecuteShellCommand(runSpace, cmd);
}
private void CreateDrivesXmlEmpty(string path, string fileName)
{
DirectoryInfo drivesDirectory = new DirectoryInfo(path);
@ -1747,6 +1799,22 @@ namespace WebsitePanel.Providers.HostedSolution
#region PowerShell integration
internal void ImportGroupPolicyMolude(Runspace runSpace)
{
Command cmd = new Command("Import-Module");
cmd.Parameters.Add("Name", "grouppolicy");
ExecuteShellCommand(runSpace, cmd);
}
internal void ImportActiveDirectoryMolude(Runspace runSpace)
{
Command cmd = new Command("Import-Module");
cmd.Parameters.Add("Name", "ActiveDirectory");
ExecuteShellCommand(runSpace, cmd);
}
private static RunspaceConfiguration runspaceConfiguration = null;
internal virtual Runspace OpenRunspace()