From 34f2d2bb4f13c2849d3d4c7d1442d096b41e2ac0 Mon Sep 17 00:00:00 2001 From: vfedosevich Date: Tue, 17 Jun 2014 05:53:15 +0300 Subject: [PATCH] Fixed bugs with adding new mapped drive and when rename folder. Added new functionality - change folder path for mapped drive, when rename folder. --- .../EnterpriseStorageController.cs | 15 ++- .../HostedSolution/IOrganization.cs | 2 + .../OrganizationProvider.cs | 120 ++++++++++++++---- .../OrganizationProxy.cs | 63 +++++++++ .../WebsitePanel.Server/Organizations.asmx.cs | 6 + .../EnterpriseStoragePermissions.ascx.cs | 2 - 6 files changed, 175 insertions(+), 33 deletions(-) diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/EnterpriseStorage/EnterpriseStorageController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/EnterpriseStorage/EnterpriseStorageController.cs index 058461da..dbab4f3a 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/EnterpriseStorage/EnterpriseStorageController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/EnterpriseStorage/EnterpriseStorageController.cs @@ -403,14 +403,20 @@ namespace WebsitePanel.EnterpriseServer EnterpriseStorage es = GetEnterpriseStorage(GetEnterpriseStorageServiceID(org.PackageId)); var webDavSetting = ObjectUtils.FillObjectFromDataReader( - DataProvider.GetEnterpriseFolder(itemId, oldFolder)); + DataProvider.GetEnterpriseFolder(itemId, newFolder)); - if (webDavSetting == null) + bool folderExists = es.GetFolder(org.OrganizationId, newFolder, webDavSetting) != null; + + if (!folderExists) { SystemFile folder = es.RenameFolder(org.OrganizationId, oldFolder, newFolder, webDavSetting); DataProvider.UpdateEnterpriseFolder(itemId, oldFolder, newFolder, folder.FRSMQuotaGB); + Organizations orgProxy = OrganizationController.GetOrganizationProxy(org.ServiceId); + + orgProxy.ChangeDriveMapFolderPath(org.OrganizationId, oldFolder, newFolder); + return folder; } @@ -1247,10 +1253,9 @@ namespace WebsitePanel.EnterpriseServer if (esServiceId != 0) { - var webDavSetting = ObjectUtils.FillObjectFromDataReader( - DataProvider.GetEnterpriseFolder(itemId, folderName)); + StringDictionary esSesstings = ServerController.GetServiceSettings(esServiceId); - string path = string.Format(@"\\{0}@SSL\{1}\{2}", webDavSetting.Domain.Split('.')[0], org.OrganizationId, folderName); + string path = string.Format(@"\\{0}@SSL\{1}\{2}", esSesstings["UsersDomain"].Split('.')[0], org.OrganizationId, folderName); Organizations orgProxy = OrganizationController.GetOrganizationProxy(org.ServiceId); diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/IOrganization.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/IOrganization.cs index 829684c2..9aae68e1 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/IOrganization.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/IOrganization.cs @@ -91,5 +91,7 @@ namespace WebsitePanel.Providers.HostedSolution void DeleteMappedDrivesGPO(string organizationId); void SetDriveMapsTargetingFilter(string organizationId, ExchangeAccount[] accounts, string folderName); + + void ChangeDriveMapFolderPath(string organizationId, string oldFolder, string newFolder); } } diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/OrganizationProvider.cs b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/OrganizationProvider.cs index e0e9fbc6..b23d05bf 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/OrganizationProvider.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/OrganizationProvider.cs @@ -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 sidAccountPairs = new Dictionary(); 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() diff --git a/WebsitePanel/Sources/WebsitePanel.Server.Client/OrganizationProxy.cs b/WebsitePanel/Sources/WebsitePanel.Server.Client/OrganizationProxy.cs index 75847ebd..2b4b05b7 100644 --- a/WebsitePanel/Sources/WebsitePanel.Server.Client/OrganizationProxy.cs +++ b/WebsitePanel/Sources/WebsitePanel.Server.Client/OrganizationProxy.cs @@ -118,6 +118,8 @@ namespace WebsitePanel.Providers.HostedSolution private System.Threading.SendOrPostCallback SetDriveMapsTargetingFilterOperationCompleted; + private System.Threading.SendOrPostCallback ChangeDriveMapFolderPathOperationCompleted; + /// public Organizations() { @@ -202,6 +204,9 @@ namespace WebsitePanel.Providers.HostedSolution /// public event SetDriveMapsTargetingFilterCompletedEventHandler SetDriveMapsTargetingFilterCompleted; + /// + public event ChangeDriveMapFolderPathCompletedEventHandler ChangeDriveMapFolderPathCompleted; + /// [System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")] [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/OrganizationExists", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] @@ -1758,6 +1763,60 @@ namespace WebsitePanel.Providers.HostedSolution } } + /// + [System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")] + [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/ChangeDriveMapFolderPath", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] + public void ChangeDriveMapFolderPath(string organizationId, string oldFolder, string newFolder) + { + this.Invoke("ChangeDriveMapFolderPath", new object[] { + organizationId, + oldFolder, + newFolder}); + } + + /// + public System.IAsyncResult BeginChangeDriveMapFolderPath(string organizationId, string oldFolder, string newFolder, System.AsyncCallback callback, object asyncState) + { + return this.BeginInvoke("ChangeDriveMapFolderPath", new object[] { + organizationId, + oldFolder, + newFolder}, callback, asyncState); + } + + /// + public void EndChangeDriveMapFolderPath(System.IAsyncResult asyncResult) + { + this.EndInvoke(asyncResult); + } + + /// + public void ChangeDriveMapFolderPathAsync(string organizationId, string oldFolder, string newFolder) + { + this.ChangeDriveMapFolderPathAsync(organizationId, oldFolder, newFolder, null); + } + + /// + public void ChangeDriveMapFolderPathAsync(string organizationId, string oldFolder, string newFolder, object userState) + { + if ((this.ChangeDriveMapFolderPathOperationCompleted == null)) + { + this.ChangeDriveMapFolderPathOperationCompleted = new System.Threading.SendOrPostCallback(this.OnChangeDriveMapFolderPathOperationCompleted); + } + this.InvokeAsync("ChangeDriveMapFolderPath", new object[] { + organizationId, + oldFolder, + newFolder}, this.ChangeDriveMapFolderPathOperationCompleted, userState); + } + + private void OnChangeDriveMapFolderPathOperationCompleted(object arg) + { + if ((this.ChangeDriveMapFolderPathCompleted != null)) + { + System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg)); + this.ChangeDriveMapFolderPathCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState)); + } + } + /// public new void CancelAsync(object userState) { @@ -2154,4 +2213,8 @@ namespace WebsitePanel.Providers.HostedSolution /// [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")] public delegate void SetDriveMapsTargetingFilterCompletedEventHandler(object sender, System.ComponentModel.AsyncCompletedEventArgs e); + + /// + [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")] + public delegate void ChangeDriveMapFolderPathCompletedEventHandler(object sender, System.ComponentModel.AsyncCompletedEventArgs e); } diff --git a/WebsitePanel/Sources/WebsitePanel.Server/Organizations.asmx.cs b/WebsitePanel/Sources/WebsitePanel.Server/Organizations.asmx.cs index 7fa769bd..4d22d608 100644 --- a/WebsitePanel/Sources/WebsitePanel.Server/Organizations.asmx.cs +++ b/WebsitePanel/Sources/WebsitePanel.Server/Organizations.asmx.cs @@ -241,5 +241,11 @@ namespace WebsitePanel.Server { Organization.SetDriveMapsTargetingFilter(organizationId, accounts, folderName); } + + [WebMethod, SoapHeader("settings")] + public void ChangeDriveMapFolderPath(string organizationId, string oldFolder, string newFolder) + { + Organization.ChangeDriveMapFolderPath(organizationId, oldFolder, newFolder); + } } } diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/EnterpriseStoragePermissions.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/EnterpriseStoragePermissions.ascx.cs index 323d26c1..120d1d75 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/EnterpriseStoragePermissions.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/EnterpriseStoragePermissions.ascx.cs @@ -143,8 +143,6 @@ namespace WebsitePanel.Portal.ExchangeServer.UserControls ExchangeAccount[] accounts = ES.Services.EnterpriseStorage.SearchESAccounts(PanelRequest.ItemID, ddlSearchColumn.SelectedValue, txtSearchValue.Text + "%", ""); - //List newAccounts = new List(); - accounts = accounts.Where(x => !GetPemissions().Select(p => p.Account).Contains(x.AccountName)).ToArray(); Array.Sort(accounts, CompareAccount); if (Direction == SortDirection.Ascending)