Merge
This commit is contained in:
commit
81fa984bdc
180 changed files with 13490 additions and 1913 deletions
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace WebsitePanel.EnterpriseServer.Extensions
|
||||
{
|
||||
public static class UriExtensions
|
||||
{
|
||||
public static Uri Append(this Uri uri, params string[] paths)
|
||||
{
|
||||
return new Uri(paths.Aggregate(uri.AbsoluteUri, (current, path) => string.Format("{0}/{1}", current.TrimEnd('/'), path.TrimStart('/'))));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,11 +27,13 @@
|
|||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Data;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using WebsitePanel.Providers;
|
||||
|
||||
namespace WebsitePanel.EnterpriseServer
|
||||
|
@ -704,6 +706,37 @@ namespace WebsitePanel.EnterpriseServer
|
|||
return type.FullName + ", " + type.Assembly.GetName().Name;
|
||||
}
|
||||
|
||||
public static TResult Deserialize<TResult>(string inputString)
|
||||
{
|
||||
TResult result;
|
||||
|
||||
var serializer = new XmlSerializer(typeof(TResult));
|
||||
|
||||
using (TextReader reader = new StringReader(inputString))
|
||||
{
|
||||
result = (TResult)serializer.Deserialize(reader);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string Serialize<TEntity>(TEntity entity)
|
||||
{
|
||||
string result = string.Empty;
|
||||
|
||||
var xmlSerializer = new XmlSerializer(typeof(TEntity));
|
||||
|
||||
using (var stringWriter = new StringWriter())
|
||||
{
|
||||
using (XmlWriter writer = XmlWriter.Create(stringWriter))
|
||||
{
|
||||
xmlSerializer.Serialize(writer, entity);
|
||||
result = stringWriter.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#region Helper Functions
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ using System.Configuration;
|
|||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Text.RegularExpressions;
|
||||
using WebsitePanel.EnterpriseServer.Base.HostedSolution;
|
||||
using WebsitePanel.Providers.HostedSolution;
|
||||
using Microsoft.ApplicationBlocks.Data;
|
||||
using System.Collections.Generic;
|
||||
|
@ -2409,7 +2410,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
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)
|
||||
string mailboxManagerActions, string samAccountName, int mailboxPlanId, string subscriberNumber)
|
||||
{
|
||||
SqlParameter outParam = new SqlParameter("@AccountID", SqlDbType.Int);
|
||||
outParam.Direction = ParameterDirection.Output;
|
||||
|
@ -2427,7 +2428,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
new SqlParameter("@MailEnabledPublicFolder", mailEnabledPublicFolder),
|
||||
new SqlParameter("@MailboxManagerActions", mailboxManagerActions),
|
||||
new SqlParameter("@SamAccountName", samAccountName),
|
||||
new SqlParameter("@AccountPassword", accountPassword),
|
||||
new SqlParameter("@MailboxPlanId", (mailboxPlanId == 0) ? (object)DBNull.Value : (object)mailboxPlanId),
|
||||
new SqlParameter("@SubscriberNumber", (string.IsNullOrEmpty(subscriberNumber) ? (object)DBNull.Value : (object)subscriberNumber))
|
||||
);
|
||||
|
@ -2612,7 +2612,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
public 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, int mailboxPlanId, int archivePlanId, string subscriberNumber,
|
||||
bool EnableArchiving)
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(
|
||||
|
@ -2626,7 +2626,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
new SqlParameter("@PrimaryEmailAddress", primaryEmailAddress),
|
||||
new SqlParameter("@MailEnabledPublicFolder", mailEnabledPublicFolder),
|
||||
new SqlParameter("@MailboxManagerActions", mailboxManagerActions),
|
||||
new SqlParameter("@Password", string.IsNullOrEmpty(accountPassword) ? (object)DBNull.Value : (object)accountPassword),
|
||||
new SqlParameter("@SamAccountName", samAccountName),
|
||||
new SqlParameter("@MailboxPlanId", (mailboxPlanId == 0) ? (object)DBNull.Value : (object)mailboxPlanId),
|
||||
new SqlParameter("@ArchivingMailboxPlanId", (archivePlanId < 1) ? (object)DBNull.Value : (object)archivePlanId),
|
||||
|
@ -3210,6 +3209,91 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
#region Organizations
|
||||
|
||||
public static int AddAccessToken(AccessToken token)
|
||||
{
|
||||
return AddAccessToken(token.AccessTokenGuid, token.AccountId, token.ItemId, token.ExpirationDate, token.TokenType);
|
||||
}
|
||||
|
||||
public static int AddAccessToken(Guid accessToken, int accountId, int itemId, DateTime expirationDate, AccessTokenTypes type)
|
||||
{
|
||||
SqlParameter prmId = new SqlParameter("@TokenID", SqlDbType.Int);
|
||||
prmId.Direction = ParameterDirection.Output;
|
||||
|
||||
SqlHelper.ExecuteNonQuery(
|
||||
ConnectionString,
|
||||
CommandType.StoredProcedure,
|
||||
"AddAccessToken",
|
||||
prmId,
|
||||
new SqlParameter("@AccessToken", accessToken),
|
||||
new SqlParameter("@ExpirationDate", expirationDate),
|
||||
new SqlParameter("@AccountID", accountId),
|
||||
new SqlParameter("@ItemId", itemId),
|
||||
new SqlParameter("@TokenType", (int)type)
|
||||
);
|
||||
|
||||
// read identity
|
||||
return Convert.ToInt32(prmId.Value);
|
||||
}
|
||||
|
||||
public static void SetAccessTokenResponseMessage(Guid accessToken, string response)
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(
|
||||
ConnectionString,
|
||||
CommandType.StoredProcedure,
|
||||
"SetAccessTokenSmsResponse",
|
||||
new SqlParameter("@AccessToken", accessToken),
|
||||
new SqlParameter("@SmsResponse", response)
|
||||
);
|
||||
}
|
||||
|
||||
public static void DeleteExpiredAccessTokens()
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(
|
||||
ConnectionString,
|
||||
CommandType.StoredProcedure,
|
||||
"DeleteExpiredAccessTokenTokens"
|
||||
);
|
||||
}
|
||||
|
||||
public static IDataReader GetAccessTokenByAccessToken(Guid accessToken, AccessTokenTypes type)
|
||||
{
|
||||
return SqlHelper.ExecuteReader(
|
||||
ConnectionString,
|
||||
CommandType.StoredProcedure,
|
||||
"GetAccessTokenByAccessToken",
|
||||
new SqlParameter("@AccessToken", accessToken),
|
||||
new SqlParameter("@TokenType", type)
|
||||
);
|
||||
}
|
||||
|
||||
public static void DeleteAccessToken(Guid accessToken, AccessTokenTypes type)
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(
|
||||
ConnectionString,
|
||||
CommandType.StoredProcedure,
|
||||
"DeleteAccessToken",
|
||||
new SqlParameter("@AccessToken", accessToken),
|
||||
new SqlParameter("@TokenType", type)
|
||||
);
|
||||
}
|
||||
|
||||
public static void UpdateOrganizationSettings(int itemId, string settingsName, string xml)
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
|
||||
ObjectQualifier + "UpdateExchangeOrganizationSettings",
|
||||
new SqlParameter("@ItemId", itemId),
|
||||
new SqlParameter("@SettingsName", settingsName),
|
||||
new SqlParameter("@Xml", xml));
|
||||
}
|
||||
|
||||
public static IDataReader GetOrganizationSettings(int itemId, string settingsName)
|
||||
{
|
||||
return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
|
||||
ObjectQualifier + "GetExchangeOrganizationSettings",
|
||||
new SqlParameter("@ItemId", itemId),
|
||||
new SqlParameter("@SettingsName", settingsName));
|
||||
}
|
||||
|
||||
public static int AddOrganizationDeletedUser(int accountId, int originAT, string storagePath, string folderName, string fileName, DateTime expirationDate)
|
||||
{
|
||||
SqlParameter outParam = new SqlParameter("@ID", SqlDbType.Int);
|
||||
|
|
|
@ -1650,12 +1650,12 @@ namespace WebsitePanel.EnterpriseServer
|
|||
return result;
|
||||
}
|
||||
|
||||
public static ResultObject DeleteMappedDrive(int itemId, string driveLetter)
|
||||
public static ResultObject DeleteMappedDrive(int itemId, string folderName)
|
||||
{
|
||||
return DeleteMappedDriveInternal(itemId, driveLetter);
|
||||
return DeleteMappedDriveInternal(itemId, folderName);
|
||||
}
|
||||
|
||||
protected static ResultObject DeleteMappedDriveInternal(int itemId, string driveLetter)
|
||||
protected static ResultObject DeleteMappedDriveInternal(int itemId, string folderName)
|
||||
{
|
||||
ResultObject result = TaskManager.StartResultTask<ResultObject>("ENTERPRISE_STORAGE", "DELETE_MAPPED_DRIVE", itemId);
|
||||
|
||||
|
@ -1670,9 +1670,13 @@ namespace WebsitePanel.EnterpriseServer
|
|||
return result;
|
||||
}
|
||||
|
||||
var webDavSetting = ObjectUtils.FillObjectFromDataReader<WebDavSetting>(DataProvider.GetEnterpriseFolder(itemId, folderName));
|
||||
|
||||
string path = string.Format(@"\\{0}@SSL\{1}\{2}", webDavSetting.Domain.Split('.')[0], org.OrganizationId, folderName);
|
||||
|
||||
Organizations orgProxy = OrganizationController.GetOrganizationProxy(org.ServiceId);
|
||||
|
||||
orgProxy.DeleteMappedDrive(org.OrganizationId, driveLetter);
|
||||
orgProxy.DeleteMappedDriveByPath(org.OrganizationId, path);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
@ -1211,9 +1211,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
if (account == null)
|
||||
return null;
|
||||
|
||||
// decrypt password
|
||||
account.AccountPassword = CryptoUtils.Decrypt(account.AccountPassword);
|
||||
|
||||
return account;
|
||||
}
|
||||
|
||||
|
@ -1225,9 +1222,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
if (account == null)
|
||||
return null;
|
||||
|
||||
// decrypt password
|
||||
account.AccountPassword = CryptoUtils.Decrypt(account.AccountPassword);
|
||||
|
||||
return account;
|
||||
}
|
||||
|
||||
|
@ -1268,9 +1262,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
if (account == null)
|
||||
return null;
|
||||
|
||||
// decrypt password
|
||||
account.AccountPassword = CryptoUtils.Decrypt(account.AccountPassword);
|
||||
|
||||
return account;
|
||||
}
|
||||
|
||||
|
@ -1280,14 +1271,14 @@ namespace WebsitePanel.EnterpriseServer
|
|||
{
|
||||
return DataProvider.AddExchangeAccount(itemId, (int)accountType,
|
||||
accountName, displayName, primaryEmailAddress, mailEnabledPublicFolder,
|
||||
mailboxManagerActions.ToString(), samAccountName, CryptoUtils.Encrypt(accountPassword), mailboxPlanId, (string.IsNullOrEmpty(subscriberNumber) ? null : subscriberNumber.Trim()));
|
||||
mailboxManagerActions.ToString(), samAccountName, mailboxPlanId, (string.IsNullOrEmpty(subscriberNumber) ? null : subscriberNumber.Trim()));
|
||||
}
|
||||
|
||||
private static void UpdateAccount(ExchangeAccount account)
|
||||
{
|
||||
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,
|
||||
account.MailboxManagerActions.ToString(), account.SamAccountName, account.MailboxPlanId, account.ArchivingMailboxPlanId,
|
||||
(string.IsNullOrEmpty(account.SubscriberNumber) ? null : account.SubscriberNumber.Trim()),
|
||||
account.EnableArchiving);
|
||||
}
|
||||
|
@ -1674,7 +1665,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
mailEnabledPublicFolder,
|
||||
mailboxManagerActions,
|
||||
samAccountName,
|
||||
CryptoUtils.Encrypt(accountPassword),
|
||||
mailboxPlanId, archivePlanId,
|
||||
(string.IsNullOrEmpty(subscriberNumber) ? null : subscriberNumber.Trim()), EnableArchiving);
|
||||
}
|
||||
|
@ -1952,7 +1942,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
account.AccountType = ExchangeAccountType.User;
|
||||
account.MailEnabledPublicFolder = false;
|
||||
account.AccountPassword = null;
|
||||
UpdateAccount(account);
|
||||
DataProvider.DeleteUserEmailAddresses(account.AccountId, account.PrimaryEmailAddress);
|
||||
|
||||
|
@ -2338,7 +2327,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
}
|
||||
|
||||
// save account
|
||||
account.AccountPassword = null;
|
||||
UpdateAccount(account);
|
||||
|
||||
return 0;
|
||||
|
@ -2562,7 +2550,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
else account.MailboxManagerActions &= ~action;
|
||||
|
||||
// update account
|
||||
account.AccountPassword = null;
|
||||
UpdateAccount(account);
|
||||
|
||||
return 0;
|
||||
|
@ -2629,6 +2616,13 @@ namespace WebsitePanel.EnterpriseServer
|
|||
items["AccountDomain"] = account.PrimaryEmailAddress.Substring(account.PrimaryEmailAddress.IndexOf("@") + 1);
|
||||
items["DefaultDomain"] = org.DefaultDomain;
|
||||
|
||||
var passwordResetUrl = OrganizationController.GenerateUserPasswordResetLink(account.ItemId, account.AccountId);
|
||||
if (!string.IsNullOrEmpty(passwordResetUrl))
|
||||
{
|
||||
items["PswResetUrl"] = passwordResetUrl;
|
||||
}
|
||||
|
||||
|
||||
if (!String.IsNullOrEmpty(account.SamAccountName))
|
||||
{
|
||||
int idx = account.SamAccountName.IndexOf("\\");
|
||||
|
@ -3895,7 +3889,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
// update account
|
||||
account.DisplayName = displayName;
|
||||
account.PrimaryEmailAddress = emailAddress;
|
||||
account.AccountPassword = null;
|
||||
UpdateAccount(account);
|
||||
|
||||
return 0;
|
||||
|
@ -4218,7 +4211,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
// update account
|
||||
account.DisplayName = displayName;
|
||||
account.AccountPassword = null;
|
||||
UpdateAccount(account);
|
||||
|
||||
return 0;
|
||||
|
@ -4434,7 +4426,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
addressLists.ToArray());
|
||||
|
||||
// save account
|
||||
account.AccountPassword = null;
|
||||
UpdateAccount(account);
|
||||
|
||||
return 0;
|
||||
|
@ -4997,7 +4988,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
account.AccountName = accountName;
|
||||
account.MailEnabledPublicFolder = true;
|
||||
account.PrimaryEmailAddress = email;
|
||||
account.AccountPassword = null;
|
||||
UpdateAccount(account);
|
||||
|
||||
// register e-mail
|
||||
|
@ -5049,7 +5039,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
// update and save account
|
||||
account.MailEnabledPublicFolder = false;
|
||||
account.PrimaryEmailAddress = "";
|
||||
account.AccountPassword = null;
|
||||
UpdateAccount(account);
|
||||
|
||||
|
||||
|
@ -5168,7 +5157,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
{
|
||||
// rename original folder
|
||||
account.DisplayName = newFullName;
|
||||
account.AccountPassword = null;
|
||||
UpdateAccount(account);
|
||||
|
||||
// rename nested folders
|
||||
|
@ -5383,7 +5371,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
emailAddress);
|
||||
|
||||
// save account
|
||||
account.AccountPassword = null;
|
||||
UpdateAccount(account);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -33,8 +33,10 @@ using System.Collections.Specialized;
|
|||
using System.Data;
|
||||
using System.Net.Mail;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WebsitePanel.EnterpriseServer.Code.HostedSolution;
|
||||
using WebsitePanel.EnterpriseServer.Code.SharePoint;
|
||||
using WebsitePanel.EnterpriseServer.Extensions;
|
||||
using WebsitePanel.Providers;
|
||||
using WebsitePanel.Providers.HostedSolution;
|
||||
using WebsitePanel.Providers.ResultObjects;
|
||||
|
@ -1532,7 +1534,359 @@ namespace WebsitePanel.EnterpriseServer
|
|||
return result;
|
||||
}
|
||||
|
||||
public static List<OrganizationUser> GetOrganizationUsersWithExpiredPassword(int itemId, int daysBeforeExpiration)
|
||||
{
|
||||
// load organization
|
||||
Organization org = GetOrganization(itemId);
|
||||
|
||||
if (org == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Organizations orgProxy = GetOrganizationProxy(org.ServiceId);
|
||||
|
||||
var expiredUsersAd = orgProxy.GetOrganizationUsersWithExpiredPassword(org.OrganizationId, daysBeforeExpiration);
|
||||
|
||||
var expiredUsersDb = GetOrganizationUsersPaged(itemId, null, null, null, 0, int.MaxValue).PageUsers.Where(x => expiredUsersAd.Any(z => z.SamAccountName == x.SamAccountName)).ToList();
|
||||
|
||||
foreach (var user in expiredUsersDb)
|
||||
{
|
||||
var adUser = expiredUsersAd.First(x => x.SamAccountName == user.SamAccountName);
|
||||
|
||||
user.PasswordExpirationDateTime = adUser.PasswordExpirationDateTime;
|
||||
}
|
||||
|
||||
return expiredUsersDb;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send reset user password email
|
||||
/// </summary>
|
||||
/// <param name="itemId">Organization Id</param>
|
||||
/// <param name="accountId">User Id</param>
|
||||
/// <param name="reason">Reason why reset email is sent.</param>
|
||||
/// <param name="mailTo">Optional, if null accountID user PrimaryEmailAddress will be used</param>
|
||||
public static void SendResetUserPasswordEmail(int itemId, int accountId, string reason, string mailTo = null)
|
||||
{
|
||||
// load organization
|
||||
Organization org = GetOrganization(itemId);
|
||||
|
||||
if (org == null)
|
||||
{
|
||||
throw new Exception(string.Format("Organization not found (ItemId = {0})", itemId));
|
||||
}
|
||||
|
||||
Organizations orgProxy = GetOrganizationProxy(org.ServiceId);
|
||||
|
||||
|
||||
UserInfo owner = PackageController.GetPackageOwner(org.PackageId);
|
||||
OrganizationUser user = OrganizationController.GetAccount(itemId, accountId);
|
||||
|
||||
OrganizationUser settings = orgProxy.GetUserGeneralSettings(user.AccountName, org.OrganizationId);
|
||||
|
||||
user.PasswordExpirationDateTime = settings.PasswordExpirationDateTime;
|
||||
|
||||
if (string.IsNullOrEmpty(mailTo))
|
||||
{
|
||||
mailTo = user.PrimaryEmailAddress;
|
||||
}
|
||||
|
||||
var generalSettings = OrganizationController.GetOrganizationGeneralSettings(itemId);
|
||||
|
||||
var logoUrl = generalSettings != null ? generalSettings.OrganizationLogoUrl : string.Empty;
|
||||
|
||||
SendUserPasswordEmail(owner, user, reason, mailTo, logoUrl, UserSettings.USER_PASSWORD_RESET_LETTER, "USER_PASSWORD_RESET_LETTER");
|
||||
}
|
||||
|
||||
public static void SendUserExpirationPasswordEmail(UserInfo owner, OrganizationUser user, string reason,
|
||||
string mailTo, string logoUrl)
|
||||
{
|
||||
SendUserPasswordEmail(owner, user, reason, user.PrimaryEmailAddress, logoUrl, UserSettings.USER_PASSWORD_EXPIRATION_LETTER, "USER_PASSWORD_EXPIRATION_LETTER");
|
||||
}
|
||||
|
||||
public static void SendUserPasswordEmail(UserInfo owner, OrganizationUser user, string reason, string mailTo, string logoUrl, string settingsName, string taskName)
|
||||
{
|
||||
UserSettings settings = UserController.GetUserSettings(owner.UserId,
|
||||
settingsName);
|
||||
|
||||
TaskManager.StartTask("ORGANIZATION", "SEND_" + taskName, user.ItemId);
|
||||
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(logoUrl))
|
||||
{
|
||||
logoUrl = settings["LogoUrl"];
|
||||
}
|
||||
|
||||
string from = settings["From"];
|
||||
|
||||
string subject = settings["Subject"];
|
||||
string body = owner.HtmlMail ? settings["HtmlBody"] : settings["TextBody"];
|
||||
bool isHtml = owner.HtmlMail;
|
||||
|
||||
MailPriority priority = MailPriority.Normal;
|
||||
|
||||
if (!String.IsNullOrEmpty(settings["Priority"]))
|
||||
{
|
||||
priority = (MailPriority) Enum.Parse(typeof (MailPriority), settings["Priority"], true);
|
||||
}
|
||||
|
||||
Hashtable items = new Hashtable();
|
||||
|
||||
items["user"] = user;
|
||||
items["logoUrl"] = logoUrl;
|
||||
items["passwordResetLink"] = GenerateUserPasswordResetLink(user.ItemId, user.AccountId);
|
||||
|
||||
body = PackageController.EvaluateTemplate(body, items);
|
||||
|
||||
TaskManager.Write("Organization ID : " + user.ItemId);
|
||||
TaskManager.Write("Account : " + user.DisplayName);
|
||||
TaskManager.Write("Reason : " + reason);
|
||||
TaskManager.Write("MailTo : " + mailTo);
|
||||
|
||||
// send mail message
|
||||
MailHelper.SendMessage(from, mailTo, null, subject, body, priority, isHtml);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw TaskManager.WriteError(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
TaskManager.CompleteTask();
|
||||
}
|
||||
}
|
||||
|
||||
public static AccessToken GetAccessToken(Guid accessToken, AccessTokenTypes type)
|
||||
{
|
||||
return ObjectUtils.FillObjectFromDataReader<AccessToken>(DataProvider.GetAccessTokenByAccessToken(accessToken, type));
|
||||
}
|
||||
|
||||
public static void DeleteAccessToken(Guid accessToken, AccessTokenTypes type)
|
||||
{
|
||||
DataProvider.DeleteAccessToken(accessToken, type);
|
||||
}
|
||||
|
||||
public static void DeleteAllExpiredTokens()
|
||||
{
|
||||
DataProvider.DeleteExpiredAccessTokens();
|
||||
}
|
||||
|
||||
public static SystemSettings GetWebDavSystemSettings()
|
||||
{
|
||||
return SystemController.GetSystemSettingsInternal(SystemSettings.WEBDAV_PORTAL_SETTINGS, false);
|
||||
}
|
||||
|
||||
public static string GenerateUserPasswordResetLink(int itemId, int accountId)
|
||||
{
|
||||
string passwordResetUrlFormat = "account/password-reset/step-2";
|
||||
|
||||
var settings = GetWebDavSystemSettings();
|
||||
|
||||
if (settings == null || !settings.GetValueOrDefault(SystemSettings.WEBDAV_PASSWORD_RESET_ENABLED_KEY, false) ||!settings.Contains("WebdavPortalUrl"))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var webdavPortalUrl = new Uri(settings["WebdavPortalUrl"]);
|
||||
|
||||
var token = CreateAccessToken(itemId, accountId, AccessTokenTypes.PasswrodReset);
|
||||
|
||||
return webdavPortalUrl.Append(passwordResetUrlFormat)
|
||||
.Append(token.AccessTokenGuid.ToString("n")).ToString();
|
||||
}
|
||||
|
||||
private static AccessToken CreateAccessToken(int itemId, int accountId, AccessTokenTypes type)
|
||||
{
|
||||
var token = new AccessToken
|
||||
{
|
||||
AccessTokenGuid = Guid.NewGuid(),
|
||||
ItemId = itemId,
|
||||
AccountId = accountId,
|
||||
TokenType = type,
|
||||
ExpirationDate = DateTime.Now.AddHours(12)
|
||||
};
|
||||
|
||||
token.Id = DataProvider.AddAccessToken(token);
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
public static void SetAccessTokenResponse(Guid accessToken, string response)
|
||||
{
|
||||
DataProvider.SetAccessTokenResponseMessage(accessToken, response);
|
||||
}
|
||||
|
||||
public static bool CheckPhoneNumberIsInUse(int itemId, string phoneNumber, string userSamAccountName = null)
|
||||
{
|
||||
// load organization
|
||||
Organization org = GetOrganization(itemId);
|
||||
|
||||
if (org == null)
|
||||
{
|
||||
throw new Exception(string.Format("Organization with id '{0}' not found", itemId));
|
||||
}
|
||||
|
||||
Organizations orgProxy = GetOrganizationProxy(org.ServiceId);
|
||||
|
||||
return orgProxy.CheckPhoneNumberIsInUse(phoneNumber, userSamAccountName);
|
||||
}
|
||||
|
||||
public static void UpdateOrganizationPasswordSettings(int itemId, OrganizationPasswordSettings settings)
|
||||
{
|
||||
TaskManager.StartTask("ORGANIZATION", "UPDATE_PASSWORD_SETTINGS");
|
||||
|
||||
try
|
||||
{
|
||||
// load organization
|
||||
Organization org = GetOrganization(itemId);
|
||||
|
||||
if (org == null)
|
||||
{
|
||||
TaskManager.WriteWarning("Organization with itemId '{0}' not found", itemId.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
Organizations orgProxy = GetOrganizationProxy(org.ServiceId);
|
||||
|
||||
orgProxy.ApplyPasswordSettings(org.OrganizationId, settings);
|
||||
|
||||
var xml = ObjectUtils.Serialize(settings);
|
||||
|
||||
DataProvider.UpdateOrganizationSettings(itemId, OrganizationSettings.PasswordSettings, xml);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw TaskManager.WriteError(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
TaskManager.CompleteTask();
|
||||
}
|
||||
}
|
||||
|
||||
public static OrganizationPasswordSettings GetOrganizationPasswordSettings(int itemId)
|
||||
{
|
||||
var passwordSettings = GetOrganizationSettings<OrganizationPasswordSettings>(itemId, OrganizationSettings.PasswordSettings);
|
||||
|
||||
if (passwordSettings == null)
|
||||
{
|
||||
Organization org = GetOrganization(itemId);
|
||||
|
||||
if (org == null)
|
||||
{
|
||||
throw new Exception(string.Format("Organization not found (ItemId = {0})", itemId));
|
||||
}
|
||||
|
||||
var package = PackageController.GetPackage(org.PackageId);
|
||||
|
||||
UserSettings userSettings = UserController.GetUserSettings(package.UserId, UserSettings.EXCHANGE_POLICY);
|
||||
|
||||
if (userSettings != null)
|
||||
{
|
||||
string policyValue = userSettings["MailboxPasswordPolicy"];
|
||||
|
||||
if (policyValue != null)
|
||||
{
|
||||
string[] parts = policyValue.Split(';');
|
||||
|
||||
passwordSettings = new OrganizationPasswordSettings
|
||||
{
|
||||
MinimumLength = GetValueSafe(parts, 1, 0),
|
||||
MaximumLength = GetValueSafe(parts, 2, 0),
|
||||
UppercaseLettersCount = GetValueSafe(parts, 3, 0),
|
||||
NumbersCount = GetValueSafe(parts, 4, 0),
|
||||
SymbolsCount = GetValueSafe(parts, 5, 0),
|
||||
AccountLockoutThreshold = GetValueSafe(parts, 7, 0),
|
||||
|
||||
EnforcePasswordHistory = GetValueSafe(parts, 8, 0),
|
||||
AccountLockoutDuration = GetValueSafe(parts, 9, 0),
|
||||
ResetAccountLockoutCounterAfter = GetValueSafe(parts, 10, 0),
|
||||
LockoutSettingsEnabled = GetValueSafe(parts, 11, false),
|
||||
PasswordComplexityEnabled = GetValueSafe(parts, 11, true),
|
||||
};
|
||||
|
||||
|
||||
PasswordPolicyResult passwordPolicy = GetPasswordPolicy(itemId);
|
||||
|
||||
if (passwordPolicy.IsSuccess)
|
||||
{
|
||||
passwordSettings.MinimumLength = passwordPolicy.Value.MinLength;
|
||||
if (passwordPolicy.Value.IsComplexityEnable)
|
||||
{
|
||||
passwordSettings.NumbersCount = 1;
|
||||
passwordSettings.SymbolsCount = 1;
|
||||
passwordSettings.UppercaseLettersCount = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return passwordSettings;
|
||||
}
|
||||
|
||||
public static T GetValueSafe<T>(string[] array, int index, T defaultValue)
|
||||
{
|
||||
if (array.Length > index)
|
||||
{
|
||||
if (string.IsNullOrEmpty(array[index]))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return (T)Convert.ChangeType(array[index], typeof(T));
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public static void UpdateOrganizationGeneralSettings(int itemId, OrganizationGeneralSettings settings)
|
||||
{
|
||||
TaskManager.StartTask("ORGANIZATION", "UPDATE_GENERAL_SETTINGS");
|
||||
|
||||
try
|
||||
{
|
||||
// load organization
|
||||
Organization org = GetOrganization(itemId);
|
||||
|
||||
if (org == null)
|
||||
{
|
||||
TaskManager.WriteWarning("Organization with itemId '{0}' not found", itemId.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
var xml = ObjectUtils.Serialize(settings);
|
||||
|
||||
DataProvider.UpdateOrganizationSettings(itemId, OrganizationSettings.GeneralSettings, xml);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw TaskManager.WriteError(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
TaskManager.CompleteTask();
|
||||
}
|
||||
}
|
||||
|
||||
public static OrganizationGeneralSettings GetOrganizationGeneralSettings(int itemId)
|
||||
{
|
||||
return GetOrganizationSettings<OrganizationGeneralSettings>(itemId, OrganizationSettings.GeneralSettings);
|
||||
}
|
||||
|
||||
private static T GetOrganizationSettings<T>(int itemId, string settingsName)
|
||||
{
|
||||
var entity = ObjectUtils.FillObjectFromDataReader<OrganizationSettingsEntity>(DataProvider.GetOrganizationSettings(itemId, settingsName));
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
|
||||
return ObjectUtils.Deserialize<T>(entity.Xml);
|
||||
}
|
||||
|
||||
private static bool EmailAddressExists(string emailAddress)
|
||||
{
|
||||
|
@ -1543,7 +1897,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
private static int AddOrganizationUser(int itemId, string accountName, string displayName, string email, string sAMAccountName, string accountPassword, string subscriberNumber)
|
||||
{
|
||||
return DataProvider.AddExchangeAccount(itemId, (int)ExchangeAccountType.User, accountName, displayName, email, false, string.Empty,
|
||||
sAMAccountName, CryptoUtils.Encrypt(accountPassword), 0, subscriberNumber.Trim());
|
||||
sAMAccountName, 0, subscriberNumber.Trim());
|
||||
|
||||
}
|
||||
|
||||
|
@ -2231,9 +2585,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
if (account == null)
|
||||
return null;
|
||||
|
||||
// decrypt password
|
||||
account.AccountPassword = CryptoUtils.Decrypt(account.AccountPassword);
|
||||
|
||||
return account;
|
||||
}
|
||||
|
||||
|
@ -2268,7 +2619,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
#endregion
|
||||
|
||||
// place log record
|
||||
TaskManager.StartTask("ORGANIZATION", "GET_USER_GENERAL", itemId);
|
||||
//TaskManager.StartTask("ORGANIZATION", "GET_USER_GENERAL", itemId);
|
||||
|
||||
OrganizationUser account = null;
|
||||
Organization org = null;
|
||||
|
@ -2311,7 +2662,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
catch { }
|
||||
finally
|
||||
{
|
||||
TaskManager.CompleteTask();
|
||||
//TaskManager.CompleteTask();
|
||||
}
|
||||
|
||||
return (account);
|
||||
|
@ -2395,10 +2746,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
account.IsVIP = isVIP;
|
||||
|
||||
//account.
|
||||
if (!String.IsNullOrEmpty(password))
|
||||
account.AccountPassword = CryptoUtils.Encrypt(password);
|
||||
else
|
||||
account.AccountPassword = null;
|
||||
|
||||
UpdateAccount(account);
|
||||
UpdateAccountServiceLevelSettings(account);
|
||||
|
@ -2526,6 +2873,9 @@ namespace WebsitePanel.EnterpriseServer
|
|||
// place log record
|
||||
TaskManager.StartTask("ORGANIZATION", "SET_USER_PASSWORD", itemId);
|
||||
|
||||
TaskManager.Write("ItemId: {0}", itemId.ToString());
|
||||
TaskManager.Write("AccountId: {0}", accountId.ToString());
|
||||
|
||||
try
|
||||
{
|
||||
// load organization
|
||||
|
@ -2549,10 +2899,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
password);
|
||||
|
||||
//account.
|
||||
if (!String.IsNullOrEmpty(password))
|
||||
account.AccountPassword = CryptoUtils.Encrypt(password);
|
||||
else
|
||||
account.AccountPassword = null;
|
||||
|
||||
UpdateAccount(account);
|
||||
|
||||
|
@ -2577,7 +2923,7 @@ 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,
|
||||
account.MailboxManagerActions.ToString(), account.SamAccountName, account.MailboxPlanId, account.ArchivingMailboxPlanId,
|
||||
(string.IsNullOrEmpty(account.SubscriberNumber) ? null : account.SubscriberNumber.Trim()),
|
||||
account.EnableArchiving);
|
||||
}
|
||||
|
@ -2814,7 +3160,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
{
|
||||
return DataProvider.AddExchangeAccount(itemId, (int)accountType,
|
||||
accountName, displayName, primaryEmailAddress, mailEnabledPublicFolder,
|
||||
mailboxManagerActions.ToString(), samAccountName, CryptoUtils.Encrypt(accountPassword), mailboxPlanId, (string.IsNullOrEmpty(subscriberNumber) ? null : subscriberNumber.Trim()));
|
||||
mailboxManagerActions.ToString(), samAccountName, mailboxPlanId, (string.IsNullOrEmpty(subscriberNumber) ? null : subscriberNumber.Trim()));
|
||||
}
|
||||
|
||||
#region Additional Default Groups
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Mail;
|
||||
using WebsitePanel.Providers.HostedSolution;
|
||||
|
||||
namespace WebsitePanel.EnterpriseServer
|
||||
{
|
||||
public class UserPasswordExpirationNotificationTask : SchedulerTask
|
||||
{
|
||||
// Input parameters:
|
||||
private static readonly string DaysBeforeNotify = "DAYS_BEFORE_EXPIRATION";
|
||||
|
||||
public override void DoWork()
|
||||
{
|
||||
BackgroundTask topTask = TaskManager.TopTask;
|
||||
|
||||
int daysBeforeNotify;
|
||||
|
||||
// check input parameters
|
||||
if (!int.TryParse((string)topTask.GetParamValue(DaysBeforeNotify), out daysBeforeNotify))
|
||||
{
|
||||
TaskManager.WriteWarning("Specify 'Notify before (days)' task parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
OrganizationController.DeleteAllExpiredTokens();
|
||||
|
||||
var owner = UserController.GetUser(topTask.EffectiveUserId);
|
||||
|
||||
var packages = PackageController.GetMyPackages(topTask.EffectiveUserId);
|
||||
|
||||
foreach (var package in packages)
|
||||
{
|
||||
var organizations = ExchangeServerController.GetExchangeOrganizations(package.PackageId, true);
|
||||
|
||||
foreach (var organization in organizations)
|
||||
{
|
||||
var usersWithExpiredPasswords = OrganizationController.GetOrganizationUsersWithExpiredPassword(organization.Id, daysBeforeNotify);
|
||||
|
||||
var generalSettings = OrganizationController.GetOrganizationGeneralSettings(organization.Id);
|
||||
|
||||
var logoUrl = generalSettings != null ? generalSettings.OrganizationLogoUrl : string.Empty;
|
||||
|
||||
foreach (var user in usersWithExpiredPasswords)
|
||||
{
|
||||
user.ItemId = organization.Id;
|
||||
|
||||
if (string.IsNullOrEmpty(user.PrimaryEmailAddress))
|
||||
{
|
||||
TaskManager.WriteWarning(string.Format("Unable to send email to {0} user (organization: {1}), user primary email address is not set.", user.DisplayName, organization.OrganizationId));
|
||||
continue;
|
||||
}
|
||||
|
||||
OrganizationController.SendUserExpirationPasswordEmail(owner, user, "Scheduler Password Expiration Notification", user.PrimaryEmailAddress, logoUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// send mail message
|
||||
// MailHelper.SendMessage(mailFrom, mailTo, mailSubject, mailBody, false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -3720,6 +3720,8 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
#region Replication
|
||||
|
||||
#region IsReplicaServer Part
|
||||
|
||||
public static CertificateInfo[] GetCertificates(int serviceId, string remoteServer)
|
||||
{
|
||||
VirtualizationServer2012 vs = GetVirtualizationProxy(serviceId);
|
||||
|
@ -3745,12 +3747,208 @@ namespace WebsitePanel.EnterpriseServer
|
|||
return result;
|
||||
}
|
||||
|
||||
public static bool IsReplicaServer(int serviceId, string remoteServer)
|
||||
public static ResultObject UnsetReplicaServer(int serviceId, string remoteServer)
|
||||
{
|
||||
ResultObject result = new ResultObject();
|
||||
try
|
||||
{
|
||||
VirtualizationServer2012 vs = GetVirtualizationProxy(serviceId);
|
||||
vs.UnsetReplicaServer(remoteServer);
|
||||
result.IsSuccess = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.AddError(VirtualizationErrorCodes.UNSET_REPLICA_SERVER_ERROR, ex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ReplicationServerInfo GetReplicaServer(int serviceId, string remoteServer)
|
||||
{
|
||||
VirtualizationServer2012 vs = GetVirtualizationProxy(serviceId);
|
||||
return vs.IsReplicaServer(remoteServer);
|
||||
return vs.GetReplicaServer(remoteServer);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static VmReplication GetReplication(int itemId)
|
||||
{
|
||||
VirtualMachine vm = GetVirtualMachineByItemId(itemId);
|
||||
VirtualizationServer2012 vs = GetVirtualizationProxy(vm.ServiceId);
|
||||
return vs.GetReplication(vm.VirtualMachineId);
|
||||
}
|
||||
|
||||
public static ReplicationDetailInfo GetReplicationInfo(int itemId)
|
||||
{
|
||||
VirtualMachine vm = GetVirtualMachineByItemId(itemId);
|
||||
VirtualizationServer2012 vs = GetVirtualizationProxy(vm.ServiceId);
|
||||
return vs.GetReplicationInfo(vm.VirtualMachineId);
|
||||
}
|
||||
|
||||
public static ResultObject SetVmReplication(int itemId, VmReplication replication)
|
||||
{
|
||||
TaskManager.StartTask("VPS2012", "SetVmReplication");
|
||||
|
||||
ResultObject result = new ResultObject();
|
||||
try
|
||||
{
|
||||
VirtualMachine vm = GetVirtualMachineByItemId(itemId);
|
||||
VirtualizationServer2012 vs = GetVirtualizationProxy(vm.ServiceId);
|
||||
|
||||
// Get replica server
|
||||
var replicaServerInfo = GetReplicaInfoForService(vm.ServiceId, ref result);
|
||||
if (result.ErrorCodes.Count > 0)
|
||||
return result;
|
||||
|
||||
// We should use enable replication or set replication?
|
||||
var vmReplica = vs.GetReplication(vm.VirtualMachineId);
|
||||
if (vmReplica == null) // need enable
|
||||
{
|
||||
vs.EnableVmReplication(vm.VirtualMachineId, replicaServerInfo.ComputerName, replication);
|
||||
vs.StartInitialReplication(vm.VirtualMachineId);
|
||||
}
|
||||
else // need set
|
||||
{
|
||||
vs.SetVmReplication(vm.VirtualMachineId, replicaServerInfo.ComputerName, replication);
|
||||
}
|
||||
result.IsSuccess = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw TaskManager.WriteError(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
TaskManager.CompleteTask();
|
||||
}
|
||||
TaskManager.WriteWarning("Organization with itemId '{0}' not found", itemId.ToString());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ResultObject DisableVmReplication(int itemId)
|
||||
{
|
||||
ResultObject result = new ResultObject();
|
||||
try
|
||||
{
|
||||
VirtualMachine vm = GetVirtualMachineByItemId(itemId);
|
||||
VirtualizationServer2012 vs = GetVirtualizationProxy(vm.ServiceId);
|
||||
vs.DisableVmReplication(vm.VirtualMachineId);
|
||||
|
||||
CleanUpReplicaServer(vm);
|
||||
|
||||
result.IsSuccess = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.AddError(VirtualizationErrorCodes.DISABLE_REPLICATION_ERROR, ex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ResultObject PauseReplication(int itemId)
|
||||
{
|
||||
ResultObject result = new ResultObject();
|
||||
try
|
||||
{
|
||||
VirtualMachine vm = GetVirtualMachineByItemId(itemId);
|
||||
VirtualizationServer2012 vs = GetVirtualizationProxy(vm.ServiceId);
|
||||
vs.PauseReplication(vm.VirtualMachineId);
|
||||
|
||||
result.IsSuccess = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.AddError(VirtualizationErrorCodes.PAUSE_REPLICATION_ERROR, ex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ResultObject ResumeReplication(int itemId)
|
||||
{
|
||||
ResultObject result = new ResultObject();
|
||||
try
|
||||
{
|
||||
VirtualMachine vm = GetVirtualMachineByItemId(itemId);
|
||||
VirtualizationServer2012 vs = GetVirtualizationProxy(vm.ServiceId);
|
||||
vs.ResumeReplication(vm.VirtualMachineId);
|
||||
|
||||
result.IsSuccess = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.AddError(VirtualizationErrorCodes.RESUME_REPLICATION_ERROR, ex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#region Private methods
|
||||
|
||||
private static void CleanUpReplicaServer(VirtualMachine originalVm)
|
||||
{
|
||||
try
|
||||
{
|
||||
ResultObject result = new ResultObject();
|
||||
|
||||
// Get replica server
|
||||
var replicaServer = GetReplicaForService(originalVm.ServiceId, ref result);
|
||||
|
||||
// Clean up replica server
|
||||
var replicaVm = replicaServer.GetVirtualMachines().FirstOrDefault(m => m.Name == originalVm.Name);
|
||||
if (replicaVm != null)
|
||||
{
|
||||
replicaServer.DisableVmReplication(replicaVm.VirtualMachineId);
|
||||
replicaServer.ShutDownVirtualMachine(replicaVm.VirtualMachineId, true, "ReplicaDelete");
|
||||
replicaServer.DeleteVirtualMachine(replicaVm.VirtualMachineId);
|
||||
}
|
||||
}
|
||||
catch { /* skip */ }
|
||||
}
|
||||
|
||||
private static ReplicationServerInfo GetReplicaInfoForService(int serviceId, ref ResultObject result)
|
||||
{
|
||||
// Get service id of replica server
|
||||
StringDictionary vsSesstings = ServerController.GetServiceSettings(serviceId);
|
||||
string replicaServiceId = vsSesstings["ReplicaServerId"];
|
||||
|
||||
if (string.IsNullOrEmpty(replicaServiceId))
|
||||
{
|
||||
result.ErrorCodes.Add(VirtualizationErrorCodes.NO_REPLICA_SERVER_ERROR);
|
||||
return null;
|
||||
}
|
||||
|
||||
// get replica server info for replica service id
|
||||
VirtualizationServer2012 vsReplica = GetVirtualizationProxy(Convert.ToInt32(replicaServiceId));
|
||||
StringDictionary vsReplicaSesstings = ServerController.GetServiceSettings(Convert.ToInt32(replicaServiceId));
|
||||
string computerName = vsReplicaSesstings["ServerName"];
|
||||
var replicaServerInfo = vsReplica.GetReplicaServer(computerName);
|
||||
|
||||
if (!replicaServerInfo.Enabled)
|
||||
{
|
||||
result.ErrorCodes.Add(VirtualizationErrorCodes.NO_REPLICA_SERVER_ERROR);
|
||||
return null;
|
||||
}
|
||||
|
||||
return replicaServerInfo;
|
||||
}
|
||||
|
||||
private static VirtualizationServer2012 GetReplicaForService(int serviceId, ref ResultObject result)
|
||||
{
|
||||
// Get service id of replica server
|
||||
StringDictionary vsSesstings = ServerController.GetServiceSettings(serviceId);
|
||||
string replicaServiceId = vsSesstings["ReplicaServerId"];
|
||||
|
||||
if (string.IsNullOrEmpty(replicaServiceId))
|
||||
{
|
||||
result.ErrorCodes.Add(VirtualizationErrorCodes.NO_REPLICA_SERVER_ERROR);
|
||||
return null;
|
||||
}
|
||||
|
||||
// get replica server for replica service id
|
||||
return GetVirtualizationProxy(Convert.ToInt32(replicaServiceId));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,6 +75,7 @@
|
|||
<Compile Include="Common\CryptoUtils.cs" />
|
||||
<Compile Include="Common\EnterpriseServerIdentity.cs" />
|
||||
<Compile Include="Common\EnterpriseServerPrincipal.cs" />
|
||||
<Compile Include="Common\Extensions\UriExtensions.cs" />
|
||||
<Compile Include="Common\FileUtils.cs" />
|
||||
<Compile Include="Common\Int128.cs" />
|
||||
<Compile Include="Common\IPAddress.cs" />
|
||||
|
@ -158,6 +159,7 @@
|
|||
<Compile Include="SchedulerTasks\SendMailNotificationTask.cs" />
|
||||
<Compile Include="SchedulerTasks\SuspendOverdueInvoicesTask.cs" />
|
||||
<Compile Include="SchedulerTasks\SuspendOverusedPackagesTask.cs" />
|
||||
<Compile Include="SchedulerTasks\UserPasswordExpirationNotificationTask.cs" />
|
||||
<Compile Include="SchedulerTasks\ZipFilesTask.cs" />
|
||||
<Compile Include="Scheduling\Scheduler.cs" />
|
||||
<Compile Include="Scheduling\SchedulerController.cs" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue