From 3aac8aa9d95e3ce484bd9796bb39b9321466424b Mon Sep 17 00:00:00 2001 From: dev_amdtel Date: Fri, 7 Nov 2014 01:01:10 +0300 Subject: [PATCH] wsp-10263: Deleting account doesn't delete Exchange address list --- .../ExchangeServerController.cs | 22 ++++++++----------- .../Exchange2013.cs | 11 +++++++--- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/ExchangeServer/ExchangeServerController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/ExchangeServer/ExchangeServerController.cs index 3c6d1c9d..d0e48fee 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/ExchangeServer/ExchangeServerController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/ExchangeServer/ExchangeServerController.cs @@ -589,6 +589,15 @@ namespace WebsitePanel.EnterpriseServer ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId); + // delete public folders + List folders = GetAccounts(itemId, ExchangeAccountType.PublicFolder); + folders.Sort(delegate(ExchangeAccount f1, ExchangeAccount f2) { return f2.AccountId.CompareTo(f1.AccountId); }); + + foreach (ExchangeAccount folder in folders) + DeletePublicFolder(itemId, folder.AccountId); + + exchange.DeletePublicFolder(org.OrganizationId, "\\" + org.OrganizationId); + bool successful = exchange.DeleteOrganization( org.OrganizationId, org.DistinguishedName, @@ -600,19 +609,6 @@ namespace WebsitePanel.EnterpriseServer org.AddressBookPolicy, acceptedDomains.ToArray()); - // delete public folders - if (successful) - { - List folders = GetAccounts(itemId, ExchangeAccountType.PublicFolder); - folders.Sort(delegate(ExchangeAccount f1, ExchangeAccount f2) { return f2.AccountId.CompareTo(f1.AccountId);}); - - foreach(ExchangeAccount folder in folders) - DeletePublicFolder(itemId, folder.AccountId); - - exchange.DeletePublicFolder(org.OrganizationId, "\\" + org.OrganizationId); - } - - return successful ? 0 : BusinessErrorCodes.ERROR_EXCHANGE_DELETE_SOME_PROBLEMS; } catch (Exception ex) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution.Exchange2013/Exchange2013.cs b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution.Exchange2013/Exchange2013.cs index d39d2748..fa411b12 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution.Exchange2013/Exchange2013.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution.Exchange2013/Exchange2013.cs @@ -1004,7 +1004,10 @@ namespace WebsitePanel.Providers.HostedSolution - if (!DeleteOrganizationMailboxes(runSpace, ou)) + if (!DeleteOrganizationMailboxes(runSpace, ou, false)) + ret = false; + + if (!DeleteOrganizationMailboxes(runSpace, ou, true)) ret = false; if (!DeleteOrganizationContacts(runSpace, ou)) @@ -1159,13 +1162,15 @@ namespace WebsitePanel.Providers.HostedSolution return ret; } - internal bool DeleteOrganizationMailboxes(Runspace runSpace, string ou) + internal bool DeleteOrganizationMailboxes(Runspace runSpace, string ou, bool publicFolder) { ExchangeLog.LogStart("DeleteOrganizationMailboxes"); bool ret = true; Command cmd = new Command("Get-Mailbox"); cmd.Parameters.Add("OrganizationalUnit", ou); + if (publicFolder) cmd.Parameters.Add("PublicFolder"); + Collection result = ExecuteShellCommand(runSpace, cmd); if (result != null && result.Count > 0) { @@ -1177,7 +1182,7 @@ namespace WebsitePanel.Providers.HostedSolution id = ObjToString(GetPSObjectProperty(obj, "Identity")); RemoveDevicesInternal(runSpace, id); - RemoveMailbox(runSpace, id, false); + RemoveMailbox(runSpace, id, publicFolder); } catch (Exception ex) {