Fix archiving

This commit is contained in:
dev_amdtel 2014-05-15 20:52:56 +04:00
parent 2170367f8f
commit 56cf823559
19 changed files with 371 additions and 179 deletions

View file

@ -1224,7 +1224,8 @@ namespace WebsitePanel.EnterpriseServer
DataProvider.UpdateExchangeAccount(account.AccountId, account.AccountName, account.AccountType, account.DisplayName,
account.PrimaryEmailAddress, account.MailEnabledPublicFolder,
account.MailboxManagerActions.ToString(), account.SamAccountName, account.AccountPassword, account.MailboxPlanId, account.ArchivingMailboxPlanId,
(string.IsNullOrEmpty(account.SubscriberNumber) ? null : account.SubscriberNumber.Trim()));
(string.IsNullOrEmpty(account.SubscriberNumber) ? null : account.SubscriberNumber.Trim()),
account.EnableArchiving);
}
private static void DeleteAccount(int itemId, int accountId)
@ -1598,7 +1599,8 @@ namespace WebsitePanel.EnterpriseServer
private static void UpdateExchangeAccount(int accountId, string accountName, ExchangeAccountType accountType,
string displayName, string primaryEmailAddress, bool mailEnabledPublicFolder,
string mailboxManagerActions, string samAccountName, string accountPassword, int mailboxPlanId, int archivePlanId, string subscriberNumber)
string mailboxManagerActions, string samAccountName, string accountPassword, int mailboxPlanId, int archivePlanId, string subscriberNumber,
bool EnableArchiving)
{
DataProvider.UpdateExchangeAccount(accountId,
accountName,
@ -1609,13 +1611,13 @@ namespace WebsitePanel.EnterpriseServer
mailboxManagerActions,
samAccountName,
CryptoUtils.Encrypt(accountPassword),
mailboxPlanId, archivePlanId,
(string.IsNullOrEmpty(subscriberNumber) ? null : subscriberNumber.Trim()));
mailboxPlanId, archivePlanId,
(string.IsNullOrEmpty(subscriberNumber) ? null : subscriberNumber.Trim()), EnableArchiving);
}
public static int CreateMailbox(int itemId, int accountId, ExchangeAccountType accountType, string accountName,
string displayName, string name, string domain, string password, bool sendSetupInstructions, string setupInstructionMailAddress, int mailboxPlanId, int archivedPlanId, string subscriberNumber)
string displayName, string name, string domain, string password, bool sendSetupInstructions, string setupInstructionMailAddress, int mailboxPlanId, int archivedPlanId, string subscriberNumber, bool EnableArchiving)
{
// check account
int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
@ -1724,6 +1726,24 @@ namespace WebsitePanel.EnterpriseServer
return BusinessErrorCodes.ERROR_EXCHANGE_STORAGE_QUOTAS_EXCEED_HOST_VALUES;
}
int maxArchivingStorage = -1;
int quotaArchivingStorageUsed = 0;
if (cntx.Quotas.ContainsKey(Quotas.EXCHANGE2013_ARCHIVINGSTORAGE)
&& cntx.Quotas[Quotas.EXCHANGE2013_ARCHIVINGSTORAGE].QuotaAllocatedValue > 0)
{
maxArchivingStorage = cntx.Quotas[Quotas.EXCHANGE2013_ARCHIVINGSTORAGE].QuotaAllocatedValue;
quotaArchivingStorageUsed = cntx.Quotas[Quotas.EXCHANGE2013_ARCHIVINGSTORAGE].QuotaUsedValue;
}
if (maxArchivingStorage != -1)
{
if (plan.MailboxSizeMB == -1)
return BusinessErrorCodes.ERROR_EXCHANGE_STORAGE_QUOTAS_EXCEED_HOST_VALUES;
if ((quotaArchivingStorageUsed + plan.MailboxSizeMB) > (maxArchivingStorage))
return BusinessErrorCodes.ERROR_EXCHANGE_STORAGE_QUOTAS_EXCEED_HOST_VALUES;
}
//GetServiceSettings
StringDictionary primSettings = ServerController.GetServiceSettings(exchangeServiceId);
@ -1756,10 +1776,10 @@ namespace WebsitePanel.EnterpriseServer
| MailboxManagerActions.EmailAddresses;
UpdateExchangeAccount(accountId, accountName, accountType, displayName, email, false, pmmActions.ToString(), samAccount, password, mailboxPlanId, archivedPlanId, subscriberNumber);
UpdateExchangeAccount(accountId, accountName, accountType, displayName, email, false, pmmActions.ToString(), samAccount, password, mailboxPlanId, archivedPlanId, subscriberNumber, EnableArchiving);
ResultObject resPolicy = new ResultObject() { IsSuccess = true };
SetMailBoxRetentionPolicy(itemId, archivedPlanId, accountName, exchange, org.OrganizationId, resPolicy);
SetMailBoxRetentionPolicyAndArchiving(itemId, mailboxPlanId, archivedPlanId, accountName, exchange, org.OrganizationId, resPolicy, EnableArchiving);
if (!resPolicy.IsSuccess)
{
TaskManager.WriteError("Error SetMailBoxRetentionPolicy", resPolicy.ErrorCodes.ToArray());
@ -2605,7 +2625,7 @@ namespace WebsitePanel.EnterpriseServer
#region Mailbox plan
public static int SetExchangeMailboxPlan(int itemId, int accountId, int mailboxPlanId, int archivePlanId)
public static int SetExchangeMailboxPlan(int itemId, int accountId, int mailboxPlanId, int archivePlanId, bool EnableArchiving)
{
// check account
int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
@ -2707,13 +2727,13 @@ namespace WebsitePanel.EnterpriseServer
plan.LitigationHoldMsg);
ResultObject resPolicy = new ResultObject() { IsSuccess = true };
SetMailBoxRetentionPolicy(itemId, archivePlanId, account.UserPrincipalName, exchange, org.OrganizationId, resPolicy);
SetMailBoxRetentionPolicyAndArchiving(itemId, mailboxPlanId, archivePlanId, account.UserPrincipalName, exchange, org.OrganizationId, resPolicy, EnableArchiving);
if (!resPolicy.IsSuccess)
{
TaskManager.WriteError("Error SetMailBoxRetentionPolicy", resPolicy.ErrorCodes.ToArray());
}
DataProvider.SetExchangeAccountMailboxPlan(accountId, mailboxPlanId, archivePlanId);
DataProvider.SetExchangeAccountMailboxPlan(accountId, mailboxPlanId, archivePlanId, EnableArchiving);
return 0;
}
@ -2893,7 +2913,8 @@ namespace WebsitePanel.EnterpriseServer
mailboxPlan.IsDefault, mailboxPlan.IssueWarningPct, mailboxPlan.KeepDeletedItemsDays, mailboxPlan.MailboxSizeMB, mailboxPlan.MaxReceiveMessageSizeKB, mailboxPlan.MaxRecipients,
mailboxPlan.MaxSendMessageSizeKB, mailboxPlan.ProhibitSendPct, mailboxPlan.ProhibitSendReceivePct, mailboxPlan.HideFromAddressBook, mailboxPlan.MailboxPlanType,
mailboxPlan.AllowLitigationHold, mailboxPlan.RecoverableItemsSpace, mailboxPlan.RecoverableItemsWarningPct,
mailboxPlan.LitigationHoldUrl, mailboxPlan.LitigationHoldMsg, mailboxPlan.Archiving, mailboxPlan.EnableArchiving);
mailboxPlan.LitigationHoldUrl, mailboxPlan.LitigationHoldMsg, mailboxPlan.Archiving, mailboxPlan.EnableArchiving,
mailboxPlan.ArchiveSizeMB, mailboxPlan.ArchiveWarningPct);
}
catch (Exception ex)
{
@ -2964,7 +2985,8 @@ namespace WebsitePanel.EnterpriseServer
mailboxPlan.MaxSendMessageSizeKB, mailboxPlan.ProhibitSendPct, mailboxPlan.ProhibitSendReceivePct, mailboxPlan.HideFromAddressBook, mailboxPlan.MailboxPlanType,
mailboxPlan.AllowLitigationHold, mailboxPlan.RecoverableItemsSpace, mailboxPlan.RecoverableItemsWarningPct,
mailboxPlan.LitigationHoldUrl, mailboxPlan.LitigationHoldMsg,
mailboxPlan.Archiving, mailboxPlan.EnableArchiving);
mailboxPlan.Archiving, mailboxPlan.EnableArchiving,
mailboxPlan.ArchiveSizeMB, mailboxPlan.ArchiveWarningPct);
}
catch (Exception ex)
{
@ -3027,22 +3049,25 @@ namespace WebsitePanel.EnterpriseServer
#region Exchange Retention Policy Tags
private static void SetMailBoxRetentionPolicy(int itemId, int retentionPolicyId, string accountName, ExchangeServer exchange, string orgId, ResultObject result)
private static void SetMailBoxRetentionPolicyAndArchiving(int itemId, int mailboxPlanId, int retentionPolicyId, string accountName, ExchangeServer exchange, string orgId, ResultObject result, bool EnableArchiving)
{
bool archive = false;
long archiveQuotaKB = 0;
long archiveWarningQuotaKB = 0;
string RetentionPolicy = "";
if (retentionPolicyId > 0)
{
ExchangeMailboxPlan mailboxPlan = GetExchangeMailboxPlan(itemId, mailboxPlanId);
if ( mailboxPlan != null)
{
archiveQuotaKB = mailboxPlan.ArchiveSizeMB != -1 ? ((long)mailboxPlan.ArchiveSizeMB * 1024) : -1;
archiveWarningQuotaKB = mailboxPlan.ArchiveSizeMB != -1 ? (((long)mailboxPlan.ArchiveWarningPct * (long) mailboxPlan.ArchiveSizeMB * 1024) / 100) : -1;
}
ExchangeMailboxPlan retentionPolicy = GetExchangeMailboxPlan(itemId, retentionPolicyId);
if (retentionPolicy != null)
{
archive = retentionPolicy.EnableArchiving;
archiveQuotaKB = retentionPolicy.MailboxSizeMB != -1 ? ((long)retentionPolicy.MailboxSizeMB * 1024) : -1;
archiveWarningQuotaKB = retentionPolicy.MailboxSizeMB != -1 ? (((long)retentionPolicy.IssueWarningPct * (long)retentionPolicy.MailboxSizeMB * 1024) / 100) : -1;
// update PlanRetentionPolicy and Tags
List<ExchangeMailboxPlanRetentionPolicyTag> listtags = GetExchangeMailboxPlanRetentionPolicyTags(retentionPolicyId);
foreach(ExchangeMailboxPlanRetentionPolicyTag listtag in listtags)
@ -3056,7 +3081,7 @@ namespace WebsitePanel.EnterpriseServer
}
}
ResultObject res = exchange.SetMailBoxArchiving(orgId, accountName, archive, archiveQuotaKB, archiveWarningQuotaKB, RetentionPolicy);
ResultObject res = exchange.SetMailBoxArchiving(orgId, accountName, EnableArchiving, archiveQuotaKB, archiveWarningQuotaKB, RetentionPolicy);
result.ErrorCodes.AddRange(res.ErrorCodes);
result.IsSuccess = result.IsSuccess && res.IsSuccess;
}