wsp-10263: Deleting account doesn't delete Exchange address list

This commit is contained in:
dev_amdtel 2014-11-07 01:01:10 +03:00
parent 5c87808411
commit 3aac8aa9d9
2 changed files with 17 additions and 16 deletions

View file

@ -589,6 +589,15 @@ namespace WebsitePanel.EnterpriseServer
ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId); ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
// delete public folders
List<ExchangeAccount> 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( bool successful = exchange.DeleteOrganization(
org.OrganizationId, org.OrganizationId,
org.DistinguishedName, org.DistinguishedName,
@ -600,19 +609,6 @@ namespace WebsitePanel.EnterpriseServer
org.AddressBookPolicy, org.AddressBookPolicy,
acceptedDomains.ToArray()); acceptedDomains.ToArray());
// delete public folders
if (successful)
{
List<ExchangeAccount> 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; return successful ? 0 : BusinessErrorCodes.ERROR_EXCHANGE_DELETE_SOME_PROBLEMS;
} }
catch (Exception ex) catch (Exception ex)

View file

@ -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; ret = false;
if (!DeleteOrganizationContacts(runSpace, ou)) if (!DeleteOrganizationContacts(runSpace, ou))
@ -1159,13 +1162,15 @@ namespace WebsitePanel.Providers.HostedSolution
return ret; return ret;
} }
internal bool DeleteOrganizationMailboxes(Runspace runSpace, string ou) internal bool DeleteOrganizationMailboxes(Runspace runSpace, string ou, bool publicFolder)
{ {
ExchangeLog.LogStart("DeleteOrganizationMailboxes"); ExchangeLog.LogStart("DeleteOrganizationMailboxes");
bool ret = true; bool ret = true;
Command cmd = new Command("Get-Mailbox"); Command cmd = new Command("Get-Mailbox");
cmd.Parameters.Add("OrganizationalUnit", ou); cmd.Parameters.Add("OrganizationalUnit", ou);
if (publicFolder) cmd.Parameters.Add("PublicFolder");
Collection<PSObject> result = ExecuteShellCommand(runSpace, cmd); Collection<PSObject> result = ExecuteShellCommand(runSpace, cmd);
if (result != null && result.Count > 0) if (result != null && result.Count > 0)
{ {
@ -1177,7 +1182,7 @@ namespace WebsitePanel.Providers.HostedSolution
id = ObjToString(GetPSObjectProperty(obj, "Identity")); id = ObjToString(GetPSObjectProperty(obj, "Identity"));
RemoveDevicesInternal(runSpace, id); RemoveDevicesInternal(runSpace, id);
RemoveMailbox(runSpace, id, false); RemoveMailbox(runSpace, id, publicFolder);
} }
catch (Exception ex) catch (Exception ex)
{ {