deleted users archiving

This commit is contained in:
vfedosevich 2015-01-16 04:01:35 -08:00
parent 45462971d2
commit 26a050a3e5
78 changed files with 13755 additions and 9774 deletions

View file

@ -2070,7 +2070,8 @@ namespace WebsitePanel.EnterpriseServer
return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
ObjectQualifier + "GetSchedules",
new SqlParameter("@actorId", actorId),
new SqlParameter("@packageId", packageId));
new SqlParameter("@packageId", packageId),
new SqlParameter("@recursive", true));
}
public static DataSet GetSchedulesPaged(int actorId, int packageId, bool recursive,
@ -2364,7 +2365,6 @@ namespace WebsitePanel.EnterpriseServer
#region Exchange Server
public static int AddExchangeAccount(int itemId, int accountType, string accountName,
string displayName, string primaryEmailAddress, bool mailEnabledPublicFolder,
string mailboxManagerActions, string samAccountName, string accountPassword, int mailboxPlanId, string subscriberNumber)
@ -2393,7 +2393,6 @@ namespace WebsitePanel.EnterpriseServer
return Convert.ToInt32(outParam.Value);
}
public static void AddExchangeAccountEmailAddress(int accountId, string emailAddress)
{
SqlHelper.ExecuteNonQuery(
@ -2800,7 +2799,7 @@ namespace WebsitePanel.EnterpriseServer
bool isDefault, int issueWarningPct, int keepDeletedItemsDays, int mailboxSizeMB, int maxReceiveMessageSizeKB, int maxRecipients,
int maxSendMessageSizeKB, int prohibitSendPct, int prohibitSendReceivePct, bool hideFromAddressBook, int mailboxPlanType,
bool enabledLitigationHold, long recoverabelItemsSpace, long recoverabelItemsWarning, string litigationHoldUrl, string litigationHoldMsg,
bool archiving, bool EnableArchiving, int ArchiveSizeMB, int ArchiveWarningPct)
bool archiving, bool EnableArchiving, int ArchiveSizeMB, int ArchiveWarningPct, bool enableForceArchiveDeletion)
{
SqlParameter outParam = new SqlParameter("@MailboxPlanId", SqlDbType.Int);
outParam.Direction = ParameterDirection.Output;
@ -2836,7 +2835,8 @@ namespace WebsitePanel.EnterpriseServer
new SqlParameter("@Archiving", archiving),
new SqlParameter("@EnableArchiving", EnableArchiving),
new SqlParameter("@ArchiveSizeMB", ArchiveSizeMB),
new SqlParameter("@ArchiveWarningPct", ArchiveWarningPct)
new SqlParameter("@ArchiveWarningPct", ArchiveWarningPct),
new SqlParameter("@EnableForceArchiveDeletion", enableForceArchiveDeletion)
);
return Convert.ToInt32(outParam.Value);
@ -2847,8 +2847,8 @@ namespace WebsitePanel.EnterpriseServer
public static void UpdateExchangeMailboxPlan(int mailboxPlanID, string mailboxPlan, bool enableActiveSync, bool enableIMAP, bool enableMAPI, bool enableOWA, bool enablePOP,
bool isDefault, int issueWarningPct, int keepDeletedItemsDays, int mailboxSizeMB, int maxReceiveMessageSizeKB, int maxRecipients,
int maxSendMessageSizeKB, int prohibitSendPct, int prohibitSendReceivePct, bool hideFromAddressBook, int mailboxPlanType,
bool enabledLitigationHold, long recoverabelItemsSpace, long recoverabelItemsWarning, string litigationHoldUrl, string litigationHoldMsg,
bool Archiving, bool EnableArchiving, int ArchiveSizeMB, int ArchiveWarningPct)
bool enabledLitigationHold, long recoverabelItemsSpace, long recoverabelItemsWarning, string litigationHoldUrl, string litigationHoldMsg,
bool Archiving, bool EnableArchiving, int ArchiveSizeMB, int ArchiveWarningPct, bool enableForceArchiveDeletion)
{
SqlHelper.ExecuteNonQuery(
ConnectionString,
@ -2880,7 +2880,8 @@ namespace WebsitePanel.EnterpriseServer
new SqlParameter("@Archiving", Archiving),
new SqlParameter("@EnableArchiving", EnableArchiving),
new SqlParameter("@ArchiveSizeMB", ArchiveSizeMB),
new SqlParameter("@ArchiveWarningPct", ArchiveWarningPct)
new SqlParameter("@ArchiveWarningPct", ArchiveWarningPct),
new SqlParameter("@EnableForceArchiveDeletion", enableForceArchiveDeletion)
);
}
@ -3156,6 +3157,45 @@ namespace WebsitePanel.EnterpriseServer
#region Organizations
public static int AddOrganizationDeletedUser(int accountId, int originAT, string storagePath, string folderName, string fileName, DateTime expirationDate)
{
SqlParameter outParam = new SqlParameter("@ID", SqlDbType.Int);
outParam.Direction = ParameterDirection.Output;
SqlHelper.ExecuteNonQuery(
ConnectionString,
CommandType.StoredProcedure,
"AddOrganizationDeletedUser",
outParam,
new SqlParameter("@AccountID", accountId),
new SqlParameter("@OriginAT", originAT),
new SqlParameter("@StoragePath", storagePath),
new SqlParameter("@FolderName", folderName),
new SqlParameter("@FileName", fileName),
new SqlParameter("@ExpirationDate", expirationDate)
);
return Convert.ToInt32(outParam.Value);
}
public static void DeleteOrganizationDeletedUser(int id)
{
SqlHelper.ExecuteNonQuery(ConnectionString,
CommandType.StoredProcedure,
"DeleteOrganizationDeletedUser",
new SqlParameter("@ID", id));
}
public static IDataReader GetOrganizationDeletedUser(int accountId)
{
return SqlHelper.ExecuteReader(
ConnectionString,
CommandType.StoredProcedure,
"GetOrganizationDeletedUser",
new SqlParameter("@AccountID", accountId)
);
}
public static IDataReader GetAdditionalGroups(int userId)
{
return SqlHelper.ExecuteReader(

View file

@ -1953,6 +1953,86 @@ namespace WebsitePanel.EnterpriseServer
}
}
public static int ExportMailBox(int itemId, int accountId, string path)
{
// check account
int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
if (accountCheck < 0)
{
return accountCheck;
}
// place log record
TaskManager.StartTask("EXCHANGE", "EXPORT_MAILBOX", itemId);
try
{
// load organization
Organization org = GetOrganization(itemId);
if (org == null)
return -1;
// load account
ExchangeAccount account = GetAccount(itemId, accountId);
// export mailbox
int serviceExchangeId = GetExchangeServiceID(org.PackageId);
ExchangeServer exchange = GetExchangeServer(serviceExchangeId, org.ServiceId);
exchange.ExportMailBox(org.OrganizationId, account.UserPrincipalName, path);
return 0;
}
catch (Exception ex)
{
throw TaskManager.WriteError(ex);
}
finally
{
TaskManager.CompleteTask();
}
}
public static int SetDeletedMailbox(int itemId, int accountId)
{
// check account
int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
if (accountCheck < 0) return accountCheck;
// place log record
TaskManager.StartTask("EXCHANGE", "SET_DELETED_MAILBOX", itemId);
try
{
// load organization
Organization org = GetOrganization(itemId);
if (org == null)
return -1;
// load account
ExchangeAccount account = GetAccount(itemId, accountId);
if (BlackBerryController.CheckBlackBerryUserExists(accountId))
{
BlackBerryController.DeleteBlackBerryUser(itemId, accountId);
}
// delete mailbox
int serviceExchangeId = GetExchangeServiceID(org.PackageId);
ExchangeServer exchange = GetExchangeServer(serviceExchangeId, org.ServiceId);
exchange.DisableMailbox(account.UserPrincipalName);
return 0;
}
catch (Exception ex)
{
throw TaskManager.WriteError(ex);
}
finally
{
TaskManager.CompleteTask();
}
}
public static int DeleteMailbox(int itemId, int accountId)
{
@ -2984,7 +3064,7 @@ 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.ArchiveSizeMB, mailboxPlan.ArchiveWarningPct);
mailboxPlan.ArchiveSizeMB, mailboxPlan.ArchiveWarningPct, mailboxPlan.EnableForceArchiveDeletion);
}
catch (Exception ex)
{
@ -3054,9 +3134,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.ArchiveSizeMB, mailboxPlan.ArchiveWarningPct);
mailboxPlan.LitigationHoldUrl, mailboxPlan.LitigationHoldMsg, mailboxPlan.Archiving, mailboxPlan.EnableArchiving,
mailboxPlan.ArchiveSizeMB, mailboxPlan.ArchiveWarningPct, mailboxPlan.EnableForceArchiveDeletion);
}
catch (Exception ex)
{

View file

@ -49,6 +49,8 @@ using System.Xml;
using System.Xml.Serialization;
using WebsitePanel.EnterpriseServer.Base.HostedSolution;
using WebsitePanel.Providers.OS;
using System.Text.RegularExpressions;
using WebsitePanel.Server.Client;
namespace WebsitePanel.EnterpriseServer
{
@ -71,6 +73,21 @@ namespace WebsitePanel.EnterpriseServer
return true;
}
private static bool CheckDeletedUserQuota(int orgId, out int errorCode)
{
errorCode = 0;
OrganizationStatistics stats = GetOrganizationStatistics(orgId);
if (stats.AllocatedDeletedUsers != -1 && (stats.DeletedUsers >= stats.AllocatedDeletedUsers))
{
errorCode = BusinessErrorCodes.ERROR_DELETED_USERS_RESOURCE_QUOTA_LIMIT;
return false;
}
return true;
}
private static string EvaluateMailboxTemplate(int itemId, int accountId,
bool pmm, bool emailMode, bool signup, string template)
{
@ -933,6 +950,7 @@ namespace WebsitePanel.EnterpriseServer
stats.CreatedUsers = tempStats.CreatedUsers;
stats.CreatedDomains = tempStats.CreatedDomains;
stats.CreatedGroups = tempStats.CreatedGroups;
stats.DeletedUsers = tempStats.DeletedUsers;
PackageContext cntxTmp = PackageController.GetPackageContext(org.PackageId);
@ -1067,6 +1085,7 @@ namespace WebsitePanel.EnterpriseServer
// allocated quotas
PackageContext cntx = PackageController.GetPackageContext(org.PackageId);
stats.AllocatedUsers = cntx.Quotas[Quotas.ORGANIZATION_USERS].QuotaAllocatedValue;
stats.AllocatedDeletedUsers = cntx.Quotas[Quotas.ORGANIZATION_DELETED_USERS].QuotaAllocatedValue;
stats.AllocatedDomains = cntx.Quotas[Quotas.ORGANIZATION_DOMAINS].QuotaAllocatedValue;
stats.AllocatedGroups = cntx.Quotas[Quotas.ORGANIZATION_SECURITYGROUPS].QuotaAllocatedValue;
@ -1327,8 +1346,64 @@ namespace WebsitePanel.EnterpriseServer
#region Users
public static List<OrganizationDeletedUser> GetOrganizationDeletedUsers(int itemId)
{
var result = new List<OrganizationDeletedUser>();
var orgDeletedUsers = ObjectUtils.CreateListFromDataReader<OrganizationUser>(
DataProvider.GetExchangeAccounts(itemId, (int)ExchangeAccountType.DeletedUser));
foreach (var orgDeletedUser in orgDeletedUsers)
{
OrganizationDeletedUser deletedUser = GetDeletedUser(orgDeletedUser.AccountId);
if (deletedUser == null)
continue;
deletedUser.User = orgDeletedUser;
result.Add(deletedUser);
}
return result;
}
public static OrganizationDeletedUsersPaged GetOrganizationDeletedUsersPaged(int itemId, string filterColumn, string filterValue, string sortColumn,
int startRow, int maximumRows)
{
DataSet ds =
DataProvider.GetExchangeAccountsPaged(SecurityContext.User.UserId, itemId, ((int)ExchangeAccountType.DeletedUser).ToString(),
filterColumn, filterValue, sortColumn, startRow, maximumRows, false);
OrganizationDeletedUsersPaged result = new OrganizationDeletedUsersPaged();
result.RecordsCount = (int)ds.Tables[0].Rows[0][0];
List<OrganizationUser> Tmpaccounts = new List<OrganizationUser>();
ObjectUtils.FillCollectionFromDataView(Tmpaccounts, ds.Tables[1].DefaultView);
List<OrganizationDeletedUser> deletedUsers = new List<OrganizationDeletedUser>();
foreach (OrganizationUser user in Tmpaccounts.ToArray())
{
OrganizationDeletedUser deletedUser = GetDeletedUser(user.AccountId);
if (deletedUser == null)
continue;
OrganizationUser tmpUser = GetUserGeneralSettings(itemId, user.AccountId);
if (tmpUser != null)
{
deletedUser.User = tmpUser;
deletedUsers.Add(deletedUser);
}
}
result.PageDeletedUsers = deletedUsers.ToArray();
return result;
}
public static OrganizationUsersPaged GetOrganizationUsersPaged(int itemId, string filterColumn, string filterValue, string sortColumn,
int startRow, int maximumRows)
@ -1722,10 +1797,256 @@ namespace WebsitePanel.EnterpriseServer
}
else
return true;
}
#region Deleted Users
public static int SetDeletedUser(int itemId, int accountId, bool enableForceArchive)
{
// check account
int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
if (accountCheck < 0) return accountCheck;
// place log record
TaskManager.StartTask("ORGANIZATION", "SET_DELETED_USER", itemId);
try
{
Guid crmUserId = CRMController.GetCrmUserId(accountId);
if (crmUserId != Guid.Empty)
{
return BusinessErrorCodes.CURRENT_USER_IS_CRM_USER;
}
if (DataProvider.CheckOCSUserExists(accountId))
{
return BusinessErrorCodes.CURRENT_USER_IS_OCS_USER;
}
if (DataProvider.CheckLyncUserExists(accountId))
{
return BusinessErrorCodes.CURRENT_USER_IS_LYNC_USER;
}
// load organization
Organization org = GetOrganization(itemId);
if (org == null)
return -1;
int errorCode;
if (!CheckDeletedUserQuota(org.Id, out errorCode))
return errorCode;
// load account
ExchangeAccount account = ExchangeServerController.GetAccount(itemId, accountId);
string accountName = GetAccountName(account.AccountName);
var deletedUser = new OrganizationDeletedUser
{
AccountId = account.AccountId,
OriginAT = account.AccountType,
ExpirationDate = DateTime.UtcNow.AddHours(1)
};
if (account.AccountType == ExchangeAccountType.User)
{
Organizations orgProxy = GetOrganizationProxy(org.ServiceId);
//Disable user in AD
orgProxy.DisableUser(accountName, org.OrganizationId);
}
else
{
if (enableForceArchive)
{
var serviceId = PackageController.GetPackageServiceId(org.PackageId, ResourceGroups.HostedOrganizations);
if (serviceId != 0)
{
var settings = ServerController.GetServiceSettings(serviceId);
deletedUser.StoragePath = settings["ArchiveStoragePath"];
if (!string.IsNullOrEmpty(deletedUser.StoragePath))
{
deletedUser.FolderName = org.OrganizationId;
if (!CheckFolderExists(org.PackageId, deletedUser.StoragePath, deletedUser.FolderName))
{
CreateFolder(org.PackageId, deletedUser.StoragePath, deletedUser.FolderName);
}
QuotaValueInfo diskSpaceQuota = PackageController.GetPackageQuota(org.PackageId, Quotas.ORGANIZATION_DELETED_USERS_BACKUP_STORAGE_SPACE);
if (diskSpaceQuota.QuotaAllocatedValue != -1)
{
SetFRSMQuotaOnFolder(org.PackageId, deletedUser.StoragePath, org.OrganizationId, diskSpaceQuota, QuotaType.Hard);
}
deletedUser.FileName = string.Format("{0}.pst", account.UserPrincipalName);
ExchangeServerController.ExportMailBox(itemId, accountId,
FilesController.ConvertToUncPath(serviceId,
Path.Combine(GetDirectory(deletedUser.StoragePath), deletedUser.FolderName, deletedUser.FileName)));
}
}
}
//Set Deleted Mailbox
ExchangeServerController.SetDeletedMailbox(itemId, accountId);
}
AddDeletedUser(deletedUser);
account.AccountType = ExchangeAccountType.DeletedUser;
UpdateAccount(account);
var taskId = "SCHEDULE_TASK_DELETE_EXCHANGE_ACCOUNTS";
if (!CheckScheduleTaskRun(org.PackageId, taskId))
{
AddScheduleTask(org.PackageId, taskId, "Auto Delete Exchange Account");
}
return 0;
}
catch (Exception ex)
{
throw TaskManager.WriteError(ex);
}
finally
{
TaskManager.CompleteTask();
}
}
public static byte[] GetArchiveFileBinaryChunk(int packageId, string path, int offset, int length)
{
var os = GetOS(packageId);
if (os != null && os.CheckFileServicesInstallation())
{
return os.GetFileBinaryChunk(path, offset, length);
}
return null;
}
private static bool CheckScheduleTaskRun(int packageId, string taskId)
{
var schedules = new List<ScheduleInfo>();
ObjectUtils.FillCollectionFromDataSet(schedules, SchedulerController.GetSchedules(packageId));
foreach(var schedule in schedules)
{
if (schedule.TaskId == taskId)
{
return true;
}
}
return false;
}
private static int AddScheduleTask(int packageId, string taskId, string taskName)
{
return SchedulerController.AddSchedule(new ScheduleInfo
{
PackageId = packageId,
TaskId = taskId,
ScheduleName = taskName,
ScheduleTypeId = "Daily",
FromTime = new DateTime(2000, 1, 1, 0, 0, 0),
ToTime = new DateTime(2000, 1, 1, 23, 59, 59),
Interval = 3600,
StartTime = new DateTime(2000, 01, 01, 0, 30, 0),
MaxExecutionTime = 3600,
PriorityId = "Normal",
Enabled = true,
WeekMonthDay = 1,
HistoriesNumber = 0
});
}
private static bool CheckFolderExists(int packageId, string path, string folderName)
{
var os = GetOS(packageId);
if (os != null && os.CheckFileServicesInstallation())
{
return os.DirectoryExists(Path.Combine(path, folderName));
}
return false;
}
private static void CreateFolder(int packageId, string path, string folderName)
{
var os = GetOS(packageId);
if (os != null && os.CheckFileServicesInstallation())
{
os.CreateDirectory(Path.Combine(path, folderName));
}
}
private static void RemoveArchive(int packageId, string path, string folderName, string fileName)
{
var os = GetOS(packageId);
if (os != null && os.CheckFileServicesInstallation())
{
os.DeleteFile(Path.Combine(path, folderName, fileName));
}
}
private static string GetLocationDrive(string path)
{
var drive = System.IO.Path.GetPathRoot(path);
return drive.Split(':')[0];
}
private static string GetDirectory(string path)
{
var drive = System.IO.Path.GetPathRoot(path);
return path.Replace(drive, string.Empty);
}
private static void SetFRSMQuotaOnFolder(int packageId, string path, string folderName, QuotaValueInfo quotaInfo, QuotaType quotaType)
{
var os = GetOS(packageId);
if (os != null && os.CheckFileServicesInstallation())
{
#region figure Quota Unit
// Quota Unit
string unit = string.Empty;
if (quotaInfo.QuotaDescription.ToLower().Contains("gb"))
unit = "GB";
else if (quotaInfo.QuotaDescription.ToLower().Contains("mb"))
unit = "MB";
else
unit = "KB";
#endregion
os.SetQuotaLimitOnFolder(
Path.Combine(GetDirectory(path), folderName),
GetLocationDrive(path), quotaType,
quotaInfo.QuotaAllocatedValue.ToString() + unit,
0, String.Empty, String.Empty);
}
}
#endregion
public static int DeleteUser(int itemId, int accountId)
{
// check account
@ -1733,7 +2054,7 @@ namespace WebsitePanel.EnterpriseServer
if (accountCheck < 0) return accountCheck;
// place log record
TaskManager.StartTask("ORGANIZATION", "DELETE_USER", itemId);
TaskManager.StartTask("ORGANIZATION", "REMOVE_USER", itemId);
try
{
@ -1761,13 +2082,32 @@ namespace WebsitePanel.EnterpriseServer
return -1;
// load account
OrganizationUser user = GetAccount(itemId, accountId);
ExchangeAccount user = ExchangeServerController.GetAccount(itemId, accountId);
Organizations orgProxy = GetOrganizationProxy(org.ServiceId);
string account = GetAccountName(user.AccountName);
if (user.AccountType == ExchangeAccountType.User)
var accountType = user.AccountType;
if (accountType == ExchangeAccountType.DeletedUser)
{
var deletedUser = GetDeletedUser(user.AccountId);
if (deletedUser != null)
{
accountType = deletedUser.OriginAT;
if (!deletedUser.IsArchiveEmpty)
{
RemoveArchive(org.PackageId, deletedUser.StoragePath, deletedUser.FolderName, deletedUser.FileName);
}
RemoveDeletedUser(deletedUser.Id);
}
}
if (user.AccountType == ExchangeAccountType.User )
{
//Delete user from AD
orgProxy.DeleteUser(account, org.OrganizationId);
@ -1791,6 +2131,30 @@ namespace WebsitePanel.EnterpriseServer
}
}
public static OrganizationDeletedUser GetDeletedUser(int accountId)
{
OrganizationDeletedUser deletedUser = ObjectUtils.FillObjectFromDataReader<OrganizationDeletedUser>(
DataProvider.GetOrganizationDeletedUser(accountId));
if (deletedUser == null)
return null;
deletedUser.IsArchiveEmpty = string.IsNullOrEmpty(deletedUser.FileName);
return deletedUser;
}
private static int AddDeletedUser(OrganizationDeletedUser deletedUser)
{
return DataProvider.AddOrganizationDeletedUser(
deletedUser.AccountId, (int)deletedUser.OriginAT, deletedUser.StoragePath, deletedUser.FolderName, deletedUser.FileName, deletedUser.ExpirationDate);
}
private static void RemoveDeletedUser(int id)
{
DataProvider.DeleteOrganizationDeletedUser(id);
}
public static OrganizationUser GetAccount(int itemId, int userId)
{
OrganizationUser account = ObjectUtils.FillObjectFromDataReader<OrganizationUser>(
@ -3080,5 +3444,21 @@ namespace WebsitePanel.EnterpriseServer
}
#endregion
#region OS
private static WebsitePanel.Providers.OS.OperatingSystem GetOS(int packageId)
{
int sid = PackageController.GetPackageServiceId(packageId, ResourceGroups.Os);
if (sid <= 0)
return null;
var os = new WebsitePanel.Providers.OS.OperatingSystem();
ServiceProviderProxy.Init(os, sid);
return os;
}
#endregion
}
}

View file

@ -0,0 +1,64 @@
// Copyright (c) 2014, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text;
using WebsitePanel.Providers.Exchange;
using WebsitePanel.Providers.HostedSolution;
namespace WebsitePanel.EnterpriseServer
{
public class DeleteExchangeAccountsTask : SchedulerTask
{
public override void DoWork()
{
DeletedAccounts();
}
public void DeletedAccounts()
{
List<Organization> organizations = OrganizationController.GetOrganizations(TaskManager.TopTask.PackageId, true);
foreach (Organization organization in organizations)
{
List<OrganizationDeletedUser> deletedUsers = OrganizationController.GetOrganizationDeletedUsers(organization.Id);
foreach (OrganizationDeletedUser deletedUser in deletedUsers)
{
if (deletedUser.ExpirationDate > DateTime.UtcNow)
{
OrganizationController.DeleteUser(TaskManager.TopTask.ItemId, deletedUser.AccountId);
}
}
}
}
}
}

View file

@ -135,6 +135,7 @@
<Compile Include="SchedulerTasks\ActivatePaidInvoicesTask.cs" />
<Compile Include="SchedulerTasks\BackupDatabaseTask.cs" />
<Compile Include="SchedulerTasks\BackupTask.cs" />
<Compile Include="SchedulerTasks\DeleteExchangeAccountsTask.cs" />
<Compile Include="SchedulerTasks\CalculateExchangeDiskspaceTask.cs" />
<Compile Include="SchedulerTasks\CalculatePackagesBandwidthTask.cs" />
<Compile Include="SchedulerTasks\CalculatePackagesDiskspaceTask.cs" />