diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/Data/DataProvider.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/Data/DataProvider.cs
deleted file mode 100644
index b689b695..00000000
--- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/Data/DataProvider.cs
+++ /dev/null
@@ -1,3792 +0,0 @@
-// Copyright (c) 2012, 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.Configuration;
-using System.Data;
-using System.Data.SqlClient;
-using System.Text.RegularExpressions;
-using WebsitePanel.Providers.HostedSolution;
-using Microsoft.ApplicationBlocks.Data;
-using System.Collections.Generic;
-using Microsoft.Win32;
-
-namespace WebsitePanel.EnterpriseServer
-{
- ///
- /// Summary description for DataProvider.
- ///
- public static class DataProvider
- {
-
- static string EnterpriseServerRegistryPath = "SOFTWARE\\WebsitePanel\\EnterpriseServer";
-
- private static string ConnectionString
- {
- get
- {
- string ConnectionKey = ConfigurationManager.AppSettings["WebsitePanel.AltConnectionString"];
- string value = string.Empty;
-
- if (!string.IsNullOrEmpty(ConnectionKey))
- {
- RegistryKey root = Registry.LocalMachine;
- RegistryKey rk = root.OpenSubKey(EnterpriseServerRegistryPath);
- if (rk != null)
- {
- value = (string)rk.GetValue(ConnectionKey, null);
- rk.Close();
- }
- }
-
- if (!string.IsNullOrEmpty(value))
- return value;
- else
- return ConfigurationManager.ConnectionStrings["EnterpriseServer"].ConnectionString;
- }
- }
-
- private static string ObjectQualifier
- {
- get
- {
- return "";
- }
- }
-
- #region System Settings
-
- public static IDataReader GetSystemSettings(string settingsName)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetSystemSettings",
- new SqlParameter("@SettingsName", settingsName)
- );
- }
-
- public static void SetSystemSettings(string settingsName, string xml)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "SetSystemSettings",
- new SqlParameter("@SettingsName", settingsName),
- new SqlParameter("@Xml", xml)
- );
- }
-
- #endregion
-
- #region Users
- public static bool CheckUserExists(string username)
- {
- SqlParameter prmExists = new SqlParameter("@Exists", SqlDbType.Bit);
- prmExists.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "CheckUserExists",
- prmExists,
- new SqlParameter("@username", username));
-
- return Convert.ToBoolean(prmExists.Value);
- }
-
- public static DataSet GetUsersPaged(int actorId, int userId, string filterColumn, string filterValue,
- int statusId, int roleId, string sortColumn, int startRow, int maximumRows, bool recursive)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetUsersPaged",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@UserID", userId),
- new SqlParameter("@FilterColumn", VerifyColumnName(filterColumn)),
- new SqlParameter("@FilterValue", VerifyColumnValue(filterValue)),
- new SqlParameter("@statusId", statusId),
- new SqlParameter("@roleId", roleId),
- new SqlParameter("@SortColumn", VerifyColumnName(sortColumn)),
- new SqlParameter("@startRow", startRow),
- new SqlParameter("@maximumRows", maximumRows),
- new SqlParameter("@recursive", recursive));
- }
-
- public static DataSet GetUsersSummary(int actorId, int userId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetUsersSummary",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@UserID", userId));
- }
-
- public static DataSet GetUserDomainsPaged(int actorId, int userId, string filterColumn, string filterValue,
- string sortColumn, int startRow, int maximumRows)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetUserDomainsPaged",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@UserID", userId),
- new SqlParameter("@filterColumn", VerifyColumnName(filterColumn)),
- new SqlParameter("@filterValue", VerifyColumnValue(filterValue)),
- new SqlParameter("@sortColumn", VerifyColumnName(sortColumn)),
- new SqlParameter("@startRow", startRow),
- new SqlParameter("@maximumRows", maximumRows));
- }
-
- public static DataSet GetUsers(int actorId, int ownerId, bool recursive)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetUsers",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@OwnerID", ownerId),
- new SqlParameter("@Recursive", recursive));
- }
-
- public static DataSet GetUserParents(int actorId, int userId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetUserParents",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@UserID", userId));
- }
-
- public static DataSet GetUserPeers(int actorId, int userId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetUserPeers",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@userId", userId));
- }
-
- public static IDataReader GetUserByExchangeOrganizationIdInternally(int itemId)
- {
- return (IDataReader)SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetUserByExchangeOrganizationIdInternally",
- new SqlParameter("@ItemID", itemId));
- }
-
-
-
- public static IDataReader GetUserByIdInternally(int userId)
- {
- return (IDataReader)SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetUserByIdInternally",
- new SqlParameter("@UserID", userId));
- }
-
- public static IDataReader GetUserByUsernameInternally(string username)
- {
- return (IDataReader)SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetUserByUsernameInternally",
- new SqlParameter("@Username", username));
- }
-
- public static IDataReader GetUserById(int actorId, int userId)
- {
- return (IDataReader)SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetUserById",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@UserID", userId));
- }
-
- public static IDataReader GetUserByUsername(int actorId, string username)
- {
- return (IDataReader)SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetUserByUsername",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@Username", username));
- }
-
- public static int AddUser(int actorId, int ownerId, int roleId, int statusId, string subscriberNumber, int loginStatusId, bool isDemo,
- bool isPeer, string comments, string username, string password,
- string firstName, string lastName, string email, string secondaryEmail,
- string address, string city, string country, string state, string zip,
- string primaryPhone, string secondaryPhone, string fax, string instantMessenger, bool htmlMail,
- string companyName, bool ecommerceEnabled)
- {
- SqlParameter prmUserId = new SqlParameter("@UserID", SqlDbType.Int);
- prmUserId.Direction = ParameterDirection.Output;
-
- // add user to WebsitePanel Users table
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "AddUser",
- prmUserId,
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@OwnerID", ownerId),
- new SqlParameter("@RoleID", roleId),
- new SqlParameter("@StatusId", statusId),
- new SqlParameter("@SubscriberNumber", subscriberNumber),
- new SqlParameter("@LoginStatusId", loginStatusId),
- new SqlParameter("@IsDemo", isDemo),
- new SqlParameter("@IsPeer", isPeer),
- new SqlParameter("@Comments", comments),
- new SqlParameter("@username", username),
- new SqlParameter("@password", password),
- new SqlParameter("@firstName", firstName),
- new SqlParameter("@lastName", lastName),
- new SqlParameter("@email", email),
- new SqlParameter("@secondaryEmail", secondaryEmail),
- new SqlParameter("@address", address),
- new SqlParameter("@city", city),
- new SqlParameter("@country", country),
- new SqlParameter("@state", state),
- new SqlParameter("@zip", zip),
- new SqlParameter("@primaryPhone", primaryPhone),
- new SqlParameter("@secondaryPhone", secondaryPhone),
- new SqlParameter("@fax", fax),
- new SqlParameter("@instantMessenger", instantMessenger),
- new SqlParameter("@htmlMail", htmlMail),
- new SqlParameter("@CompanyName", companyName),
- new SqlParameter("@EcommerceEnabled", ecommerceEnabled));
-
- return Convert.ToInt32(prmUserId.Value);
- }
-
- public static void UpdateUser(int actorId, int userId, int roleId, int statusId, string subscriberNumber, int loginStatusId, bool isDemo,
- bool isPeer, string comments, string firstName, string lastName, string email, string secondaryEmail,
- string address, string city, string country, string state, string zip,
- string primaryPhone, string secondaryPhone, string fax, string instantMessenger, bool htmlMail,
- string companyName, bool ecommerceEnabled, string additionalParams)
- {
- // update user
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "UpdateUser",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@RoleID", roleId),
- new SqlParameter("@StatusId", statusId),
- new SqlParameter("@SubscriberNumber", subscriberNumber),
- new SqlParameter("@LoginStatusId", loginStatusId),
- new SqlParameter("@UserID", userId),
- new SqlParameter("@IsDemo", isDemo),
- new SqlParameter("@IsPeer", isPeer),
- new SqlParameter("@Comments", comments),
- new SqlParameter("@firstName", firstName),
- new SqlParameter("@lastName", lastName),
- new SqlParameter("@email", email),
- new SqlParameter("@secondaryEmail", secondaryEmail),
- new SqlParameter("@address", address),
- new SqlParameter("@city", city),
- new SqlParameter("@country", country),
- new SqlParameter("@state", state),
- new SqlParameter("@zip", zip),
- new SqlParameter("@primaryPhone", primaryPhone),
- new SqlParameter("@secondaryPhone", secondaryPhone),
- new SqlParameter("@fax", fax),
- new SqlParameter("@instantMessenger", instantMessenger),
- new SqlParameter("@htmlMail", htmlMail),
- new SqlParameter("@CompanyName", companyName),
- new SqlParameter("@EcommerceEnabled", ecommerceEnabled),
- new SqlParameter("@AdditionalParams", additionalParams));
- }
-
- public static void UpdateUserFailedLoginAttempt(int userId, int lockOut, bool reset)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "UpdateUserFailedLoginAttempt",
- new SqlParameter("@UserID", userId),
- new SqlParameter("@LockOut", lockOut),
- new SqlParameter("@Reset", reset));
- }
-
- public static void DeleteUser(int actorId, int userId)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "DeleteUser",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@UserID", userId));
- }
-
- public static void ChangeUserPassword(int actorId, int userId, string password)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "ChangeUserPassword",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@UserID", userId),
- new SqlParameter("@password", password));
- }
-
- #endregion
-
- #region User Settings
- public static IDataReader GetUserSettings(int actorId, int userId, string settingsName)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetUserSettings",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@UserID", userId),
- new SqlParameter("@SettingsName", settingsName));
- }
- public static void UpdateUserSettings(int actorId, int userId, string settingsName, string xml)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "UpdateUserSettings",
- new SqlParameter("@UserID", userId),
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@SettingsName", settingsName),
- new SqlParameter("@Xml", xml));
- }
- #endregion
-
- #region Servers
- public static DataSet GetAllServers(int actorId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetAllServers",
- new SqlParameter("@actorId", actorId));
- }
- public static DataSet GetServers(int actorId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetServers",
- new SqlParameter("@actorId", actorId));
- }
-
- public static IDataReader GetServer(int actorId, int serverId)
- {
- return (IDataReader)SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetServer",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@ServerID", serverId));
- }
-
- public static IDataReader GetServerShortDetails(int serverId)
- {
- return (IDataReader)SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetServerShortDetails",
- new SqlParameter("@ServerID", serverId));
- }
-
- public static IDataReader GetServerByName(int actorId, string serverName)
- {
- return (IDataReader)SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetServerByName",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@ServerName", serverName));
- }
-
- public static IDataReader GetServerInternal(int serverId)
- {
- return (IDataReader)SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetServerInternal",
- new SqlParameter("@ServerID", serverId));
- }
-
- public static int AddServer(string serverName, string serverUrl,
- string password, string comments, bool virtualServer, string instantDomainAlias,
- int primaryGroupId, bool adEnabled, string adRootDomain, string adUsername, string adPassword,
- string adAuthenticationType)
- {
- SqlParameter prmServerId = new SqlParameter("@ServerID", SqlDbType.Int);
- prmServerId.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "AddServer",
- prmServerId,
- new SqlParameter("@ServerName", serverName),
- new SqlParameter("@ServerUrl", serverUrl),
- new SqlParameter("@Password", password),
- new SqlParameter("@Comments", comments),
- new SqlParameter("@VirtualServer", virtualServer),
- new SqlParameter("@InstantDomainAlias", instantDomainAlias),
- new SqlParameter("@PrimaryGroupId", primaryGroupId),
- new SqlParameter("@AdEnabled", adEnabled),
- new SqlParameter("@AdRootDomain", adRootDomain),
- new SqlParameter("@AdUsername", adUsername),
- new SqlParameter("@AdPassword", adPassword),
- new SqlParameter("@AdAuthenticationType", adAuthenticationType));
-
- return Convert.ToInt32(prmServerId.Value);
- }
-
- public static void UpdateServer(int serverId, string serverName, string serverUrl,
- string password, string comments, string instantDomainAlias,
- int primaryGroupId, bool adEnabled, string adRootDomain, string adUsername, string adPassword,
- string adAuthenticationType)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "UpdateServer",
- new SqlParameter("@ServerID", serverId),
- new SqlParameter("@ServerName", serverName),
- new SqlParameter("@ServerUrl", serverUrl),
- new SqlParameter("@Password", password),
- new SqlParameter("@Comments", comments),
- new SqlParameter("@InstantDomainAlias", instantDomainAlias),
- new SqlParameter("@PrimaryGroupId", primaryGroupId),
- new SqlParameter("@AdEnabled", adEnabled),
- new SqlParameter("@AdRootDomain", adRootDomain),
- new SqlParameter("@AdUsername", adUsername),
- new SqlParameter("@AdPassword", adPassword),
- new SqlParameter("@AdAuthenticationType", adAuthenticationType));
-
- }
-
- public static int DeleteServer(int serverId)
- {
- SqlParameter prmResult = new SqlParameter("@Result", SqlDbType.Int);
- prmResult.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "DeleteServer",
- prmResult,
- new SqlParameter("@ServerID", serverId));
-
- return Convert.ToInt32(prmResult.Value);
- }
- #endregion
-
- #region Virtual Servers
- public static DataSet GetVirtualServers(int actorId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetVirtualServers",
- new SqlParameter("@actorId", actorId));
- }
-
- public static DataSet GetAvailableVirtualServices(int actorId, int serverId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetAvailableVirtualServices",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@ServerID", serverId));
- }
-
- public static DataSet GetVirtualServices(int actorId, int serverId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetVirtualServices",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@ServerID", serverId));
- }
-
- public static void AddVirtualServices(int serverId, string xml)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "AddVirtualServices",
- new SqlParameter("@ServerID", serverId),
- new SqlParameter("@xml", xml));
- }
-
- public static void DeleteVirtualServices(int serverId, string xml)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "DeleteVirtualServices",
- new SqlParameter("@ServerID", serverId),
- new SqlParameter("@xml", xml));
- }
-
- public static void UpdateVirtualGroups(int serverId, string xml)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "UpdateVirtualGroups",
- new SqlParameter("@ServerID", serverId),
- new SqlParameter("@xml", xml));
- }
- #endregion
-
- #region Providers
-
- // Providers methods
-
- public static DataSet GetProviders()
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetProviders");
- }
-
- public static DataSet GetGroupProviders(int groupId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetGroupProviders",
- new SqlParameter("@groupId", groupId));
- }
-
- public static IDataReader GetProvider(int providerId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetProvider",
- new SqlParameter("@ProviderID", providerId));
- }
-
- public static IDataReader GetProviderByServiceID(int serviceId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetProviderByServiceID",
- new SqlParameter("@ServiceID", serviceId));
- }
-
- #endregion
-
- #region IPAddresses
- public static IDataReader GetIPAddress(int ipAddressId)
- {
- return (IDataReader)SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetIPAddress",
- new SqlParameter("@AddressID", ipAddressId));
- }
-
- public static IDataReader GetIPAddresses(int actorId, int poolId, int serverId)
- {
- IDataReader reader = SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- "GetIPAddresses",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@PoolId", poolId),
- new SqlParameter("@ServerId", serverId));
- return reader;
- }
-
- public static IDataReader GetIPAddressesPaged(int actorId, int poolId, int serverId,
- string filterColumn, string filterValue,
- string sortColumn, int startRow, int maximumRows)
- {
- IDataReader reader = SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- "GetIPAddressesPaged",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@PoolId", poolId),
- new SqlParameter("@ServerId", serverId),
- new SqlParameter("@FilterColumn", VerifyColumnName(filterColumn)),
- new SqlParameter("@FilterValue", VerifyColumnValue(filterValue)),
- new SqlParameter("@SortColumn", VerifyColumnName(sortColumn)),
- new SqlParameter("@startRow", startRow),
- new SqlParameter("@maximumRows", maximumRows));
- return reader;
- }
-
- public static int AddIPAddress(int poolId, int serverId, string externalIP, string internalIP,
- string subnetMask, string defaultGateway, string comments)
- {
- SqlParameter prmAddresId = new SqlParameter("@AddressID", SqlDbType.Int);
- prmAddresId.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "AddIPAddress",
- prmAddresId,
- new SqlParameter("@ServerID", serverId),
- new SqlParameter("@externalIP", externalIP),
- new SqlParameter("@internalIP", internalIP),
- new SqlParameter("@PoolId", poolId),
- new SqlParameter("@SubnetMask", subnetMask),
- new SqlParameter("@DefaultGateway", defaultGateway),
- new SqlParameter("@Comments", comments));
-
- return Convert.ToInt32(prmAddresId.Value);
- }
-
- public static void UpdateIPAddress(int addressId, int poolId, int serverId,
- string externalIP, string internalIP, string subnetMask, string defaultGateway, string comments)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "UpdateIPAddress",
- new SqlParameter("@AddressID", addressId),
- new SqlParameter("@externalIP", externalIP),
- new SqlParameter("@internalIP", internalIP),
- new SqlParameter("@ServerID", serverId),
- new SqlParameter("@PoolId", poolId),
- new SqlParameter("@SubnetMask", subnetMask),
- new SqlParameter("@DefaultGateway", defaultGateway),
- new SqlParameter("@Comments", comments));
- }
-
- public static void UpdateIPAddresses(string xmlIds, int poolId, int serverId,
- string subnetMask, string defaultGateway, string comments)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "UpdateIPAddresses",
- new SqlParameter("@Xml", xmlIds),
- new SqlParameter("@ServerID", serverId),
- new SqlParameter("@PoolId", poolId),
- new SqlParameter("@SubnetMask", subnetMask),
- new SqlParameter("@DefaultGateway", defaultGateway),
- new SqlParameter("@Comments", comments));
- }
-
- public static int DeleteIPAddress(int ipAddressId)
- {
- SqlParameter prmResult = new SqlParameter("@Result", SqlDbType.Int);
- prmResult.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "DeleteIPAddress",
- prmResult,
- new SqlParameter("@AddressID", ipAddressId));
-
- return Convert.ToInt32(prmResult.Value);
- }
-
-
-
- #endregion
-
- #region Clusters
- public static IDataReader GetClusters(int actorId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetClusters",
- new SqlParameter("@actorId", actorId));
- }
-
- public static int AddCluster(string clusterName)
- {
- SqlParameter prmId = new SqlParameter("@ClusterID", SqlDbType.Int);
- prmId.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "AddCluster",
- prmId,
- new SqlParameter("@ClusterName", clusterName));
-
- return Convert.ToInt32(prmId.Value);
- }
-
- public static void DeleteCluster(int clusterId)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "DeleteCluster",
- new SqlParameter("@ClusterId", clusterId));
- }
-
- #endregion
-
- #region Global DNS records
- public static DataSet GetDnsRecordsByService(int actorId, int serviceId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetDnsRecordsByService",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@ServiceId", serviceId));
- }
-
- public static DataSet GetDnsRecordsByServer(int actorId, int serverId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetDnsRecordsByServer",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@ServerId", serverId));
- }
-
- public static DataSet GetDnsRecordsByPackage(int actorId, int packageId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetDnsRecordsByPackage",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@PackageId", packageId));
- }
-
- public static DataSet GetDnsRecordsByGroup(int groupId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetDnsRecordsByGroup",
- new SqlParameter("@GroupId", groupId));
- }
-
- public static DataSet GetDnsRecordsTotal(int actorId, int packageId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetDnsRecordsTotal",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@packageId", packageId));
- }
-
- public static IDataReader GetDnsRecord(int actorId, int recordId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetDnsRecord",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@RecordId", recordId));
- }
-
- public static void AddDnsRecord(int actorId, int serviceId, int serverId, int packageId, string recordType,
- string recordName, string recordData, int mxPriority, int SrvPriority, int SrvWeight, int SrvPort, int ipAddressId)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "AddDnsRecord",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@ServiceId", serviceId),
- new SqlParameter("@ServerId", serverId),
- new SqlParameter("@PackageId", packageId),
- new SqlParameter("@RecordType", recordType),
- new SqlParameter("@RecordName", recordName),
- new SqlParameter("@RecordData", recordData),
- new SqlParameter("@MXPriority", mxPriority),
- new SqlParameter("@SrvPriority", SrvPriority),
- new SqlParameter("@SrvWeight", SrvWeight),
- new SqlParameter("@SrvPort", SrvPort),
- new SqlParameter("@IpAddressId", ipAddressId));
- }
-
- public static void UpdateDnsRecord(int actorId, int recordId, string recordType,
- string recordName, string recordData, int mxPriority, int SrvPriority, int SrvWeight, int SrvPort, int ipAddressId)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "UpdateDnsRecord",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@RecordId", recordId),
- new SqlParameter("@RecordType", recordType),
- new SqlParameter("@RecordName", recordName),
- new SqlParameter("@RecordData", recordData),
- new SqlParameter("@MXPriority", mxPriority),
- new SqlParameter("@SrvPriority", SrvPriority),
- new SqlParameter("@SrvWeight", SrvWeight),
- new SqlParameter("@SrvPort", SrvPort),
- new SqlParameter("@IpAddressId", ipAddressId));
- }
-
-
- public static void DeleteDnsRecord(int actorId, int recordId)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "DeleteDnsRecord",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@RecordId", recordId));
- }
- #endregion
-
- #region Domains
- public static DataSet GetDomains(int actorId, int packageId, bool recursive)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetDomains",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@PackageId", packageId),
- new SqlParameter("@Recursive", recursive));
- }
-
- public static DataSet GetResellerDomains(int actorId, int packageId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetResellerDomains",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@PackageId", packageId));
- }
-
- public static DataSet GetDomainsPaged(int actorId, int packageId, int serverId, bool recursive, string filterColumn, string filterValue,
- string sortColumn, int startRow, int maximumRows)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetDomainsPaged",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@PackageId", packageId),
- new SqlParameter("@serverId", serverId),
- new SqlParameter("@recursive", recursive),
- new SqlParameter("@FilterColumn", VerifyColumnName(filterColumn)),
- new SqlParameter("@FilterValue", VerifyColumnValue(filterValue)),
- new SqlParameter("@SortColumn", VerifyColumnName(sortColumn)),
- new SqlParameter("@StartRow", startRow),
- new SqlParameter("@MaximumRows", maximumRows));
- }
-
- public static IDataReader GetDomain(int actorId, int domainId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetDomain",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@domainId", domainId));
- }
-
- public static IDataReader GetDomainByName(int actorId, string domainName, bool searchOnDomainPointer, bool isDomainPointer)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetDomainByName",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@domainName", domainName),
- new SqlParameter("@SearchOnDomainPointer", searchOnDomainPointer),
- new SqlParameter("@IsDomainPointer", isDomainPointer));
- }
-
-
- public static DataSet GetDomainsByZoneId(int actorId, int zoneId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetDomainsByZoneID",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@ZoneID", zoneId));
- }
-
- public static DataSet GetDomainsByDomainItemId(int actorId, int domainId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetDomainsByDomainItemId",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@DomainID", domainId));
- }
-
-
-
- public static int CheckDomain(int packageId, string domainName, bool isDomainPointer)
- {
- SqlParameter prmId = new SqlParameter("@Result", SqlDbType.Int);
- prmId.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "CheckDomain",
- prmId,
- new SqlParameter("@packageId", packageId),
- new SqlParameter("@domainName", domainName),
- new SqlParameter("@isDomainPointer", isDomainPointer));
-
- return Convert.ToInt32(prmId.Value);
- }
-
-
-
- public static int CheckDomainUsedByHostedOrganization(string domainName)
- {
- SqlParameter prmId = new SqlParameter("@Result", SqlDbType.Int);
- prmId.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "CheckDomainUsedByHostedOrganization",
- prmId,
- new SqlParameter("@domainName", domainName));
-
- return Convert.ToInt32(prmId.Value);
- }
-
-
- public static int AddDomain(int actorId, int packageId, int zoneItemId, string domainName,
- bool hostingAllowed, int webSiteId, int mailDomainId, bool isSubDomain, bool isInstantAlias, bool isDomainPointer)
- {
- SqlParameter prmId = new SqlParameter("@DomainID", SqlDbType.Int);
- prmId.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "AddDomain",
- prmId,
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@PackageId", packageId),
- new SqlParameter("@ZoneItemId", zoneItemId),
- new SqlParameter("@DomainName", domainName),
- new SqlParameter("@HostingAllowed", hostingAllowed),
- new SqlParameter("@WebSiteId", webSiteId),
- new SqlParameter("@MailDomainId", mailDomainId),
- new SqlParameter("@IsSubDomain", isSubDomain),
- new SqlParameter("@IsInstantAlias", isInstantAlias),
- new SqlParameter("@IsDomainPointer", isDomainPointer));
-
- return Convert.ToInt32(prmId.Value);
- }
-
- public static void UpdateDomain(int actorId, int domainId, int zoneItemId,
- bool hostingAllowed, int webSiteId, int mailDomainId, int domainItemId)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "UpdateDomain",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@DomainId", domainId),
- new SqlParameter("@ZoneItemId", zoneItemId),
- new SqlParameter("@HostingAllowed", hostingAllowed),
- new SqlParameter("@WebSiteId", webSiteId),
- new SqlParameter("@MailDomainId", mailDomainId),
- new SqlParameter("@DomainItemId", domainItemId));
- }
-
- public static void DeleteDomain(int actorId, int domainId)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "DeleteDomain",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@DomainId", domainId));
- }
- #endregion
-
- #region Services
- public static IDataReader GetServicesByServerId(int actorId, int serverId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetServicesByServerID",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@ServerID", serverId));
- }
-
- public static IDataReader GetServicesByServerIdGroupName(int actorId, int serverId, string groupName)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetServicesByServerIdGroupName",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@ServerID", serverId),
- new SqlParameter("@GroupName", groupName));
- }
-
- public static DataSet GetRawServicesByServerId(int actorId, int serverId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetRawServicesByServerID",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@ServerID", serverId));
- }
-
- public static DataSet GetServicesByGroupId(int actorId, int groupId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetServicesByGroupID",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@groupId", groupId));
- }
-
- public static DataSet GetServicesByGroupName(int actorId, string groupName)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetServicesByGroupName",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@GroupName", groupName));
- }
-
- public static IDataReader GetService(int actorId, int serviceId)
- {
- return (IDataReader)SqlHelper.ExecuteReader(ConnectionString,
- CommandType.StoredProcedure,
- ObjectQualifier + "GetService",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@ServiceID", serviceId));
- }
-
- public static int AddService(int serverId, int providerId, string serviceName, int serviceQuotaValue,
- int clusterId, string comments)
- {
- SqlParameter prmServiceId = new SqlParameter("@ServiceID", SqlDbType.Int);
- prmServiceId.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "AddService",
- prmServiceId,
- new SqlParameter("@ServerID", serverId),
- new SqlParameter("@ProviderID", providerId),
- new SqlParameter("@ServiceName", serviceName),
- new SqlParameter("@ServiceQuotaValue", serviceQuotaValue),
- new SqlParameter("@ClusterId", clusterId),
- new SqlParameter("@comments", comments));
-
- return Convert.ToInt32(prmServiceId.Value);
- }
-
- public static void UpdateService(int serviceId, string serviceName, int serviceQuotaValue,
- int clusterId, string comments)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "UpdateService",
- new SqlParameter("@ServiceName", serviceName),
- new SqlParameter("@ServiceID", serviceId),
- new SqlParameter("@ServiceQuotaValue", serviceQuotaValue),
- new SqlParameter("@ClusterId", clusterId),
- new SqlParameter("@Comments", comments));
- }
-
- public static int DeleteService(int serviceId)
- {
- SqlParameter prmResult = new SqlParameter("@Result", SqlDbType.Int);
- prmResult.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "DeleteService",
- prmResult,
- new SqlParameter("@ServiceID", serviceId));
-
- return Convert.ToInt32(prmResult.Value);
- }
-
- public static IDataReader GetServiceProperties(int actorId, int serviceId)
- {
- return (IDataReader)SqlHelper.ExecuteReader(ConnectionString,
- CommandType.StoredProcedure,
- ObjectQualifier + "GetServiceProperties",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@ServiceID", serviceId));
- }
-
- public static void UpdateServiceProperties(int serviceId, string xml)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "UpdateServiceProperties",
- new SqlParameter("@ServiceId", serviceId),
- new SqlParameter("@Xml", xml));
- }
-
- public static IDataReader GetResourceGroup(int groupId)
- {
- return SqlHelper.ExecuteReader(ConnectionString,
- CommandType.StoredProcedure,
- ObjectQualifier + "GetResourceGroup",
- new SqlParameter("@groupId", groupId));
- }
-
- public static DataSet GetResourceGroups()
- {
- return SqlHelper.ExecuteDataset(ConnectionString,
- CommandType.StoredProcedure,
- ObjectQualifier + "GetResourceGroups");
- }
- #endregion
-
- #region Service Items
- public static DataSet GetServiceItems(int actorId, int packageId, string groupName, string itemTypeName, bool recursive)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetServiceItems",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@PackageID", packageId),
- new SqlParameter("@GroupName", groupName),
- new SqlParameter("@ItemTypeName", itemTypeName),
- new SqlParameter("@Recursive", recursive));
-
- }
-
- public static DataSet GetServiceItemsPaged(int actorId, int packageId, string groupName, string itemTypeName,
- int serverId, bool recursive, string filterColumn, string filterValue,
- string sortColumn, int startRow, int maximumRows)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetServiceItemsPaged",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@packageId", packageId),
- new SqlParameter("@groupName", groupName),
- new SqlParameter("@serverId", serverId),
- new SqlParameter("@itemTypeName", itemTypeName),
- new SqlParameter("@recursive", recursive),
- new SqlParameter("@FilterColumn", VerifyColumnName(filterColumn)),
- new SqlParameter("@FilterValue", VerifyColumnValue(filterValue)),
- new SqlParameter("@SortColumn", VerifyColumnName(sortColumn)),
- new SqlParameter("@startRow", startRow),
- new SqlParameter("@maximumRows", maximumRows));
- }
-
- public static DataSet GetSearchableServiceItemTypes()
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetSearchableServiceItemTypes");
- }
-
- public static DataSet GetServiceItemsByService(int actorId, int serviceId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetServiceItemsByService",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@ServiceID", serviceId));
- }
-
- public static int GetServiceItemsCount(string typeName, string groupName, int serviceId)
- {
- SqlParameter prmTotalNumber = new SqlParameter("@TotalNumber", SqlDbType.Int);
- prmTotalNumber.Direction = ParameterDirection.Output;
-
- DataSet ds = SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetServiceItemsCount",
- prmTotalNumber,
- new SqlParameter("@itemTypeName", typeName),
- new SqlParameter("@groupName", groupName),
- new SqlParameter("@serviceId", serviceId));
-
- // read identity
- return Convert.ToInt32(prmTotalNumber.Value);
- }
-
- public static DataSet GetServiceItemsForStatistics(int actorId, int serviceId, int packageId,
- bool calculateDiskspace, bool calculateBandwidth, bool suspendable, bool disposable)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetServiceItemsForStatistics",
- new SqlParameter("@ActorID", actorId),
- new SqlParameter("@ServiceID", serviceId),
- new SqlParameter("@packageId", packageId),
- new SqlParameter("@calculateDiskspace", calculateDiskspace),
- new SqlParameter("@calculateBandwidth", calculateBandwidth),
- new SqlParameter("@suspendable", suspendable),
- new SqlParameter("@disposable", disposable));
- }
-
- public static DataSet GetServiceItemsByPackage(int actorId, int packageId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetServiceItemsByPackage",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@PackageID", packageId));
- }
-
- public static DataSet GetServiceItem(int actorId, int itemId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetServiceItem",
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@actorId", actorId));
- }
-
- public static bool CheckServiceItemExists(int serviceId, string itemName, string itemTypeName)
- {
- SqlParameter prmExists = new SqlParameter("@Exists", SqlDbType.Bit);
- prmExists.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "CheckServiceItemExistsInService",
- prmExists,
- new SqlParameter("@serviceId", serviceId),
- new SqlParameter("@itemName", itemName),
- new SqlParameter("@itemTypeName", itemTypeName));
-
- return Convert.ToBoolean(prmExists.Value);
- }
-
- public static bool CheckServiceItemExists(string itemName, string groupName, string itemTypeName)
- {
- SqlParameter prmExists = new SqlParameter("@Exists", SqlDbType.Bit);
- prmExists.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "CheckServiceItemExists",
- prmExists,
- new SqlParameter("@itemName", itemName),
- new SqlParameter("@groupName", groupName),
- new SqlParameter("@itemTypeName", itemTypeName));
-
- return Convert.ToBoolean(prmExists.Value);
- }
-
- public static DataSet GetServiceItemByName(int actorId, int packageId, string groupName,
- string itemName, string itemTypeName)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetServiceItemByName",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@packageId", packageId),
- new SqlParameter("@itemName", itemName),
- new SqlParameter("@itemTypeName", itemTypeName),
- new SqlParameter("@groupName", groupName));
- }
-
- public static DataSet GetServiceItemsByName(int actorId, int packageId, string itemName)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetServiceItemsByName",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@packageId", packageId),
- new SqlParameter("@itemName", itemName));
- }
-
- public static int AddServiceItem(int actorId, int serviceId, int packageId, string itemName,
- string itemTypeName, string xmlProperties)
- {
- // add item
- SqlParameter prmItemId = new SqlParameter("@ItemID", SqlDbType.Int);
- prmItemId.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "AddServiceItem",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@PackageID", packageId),
- new SqlParameter("@ServiceID", serviceId),
- new SqlParameter("@ItemName", itemName),
- new SqlParameter("@ItemTypeName", itemTypeName),
- new SqlParameter("@xmlProperties", xmlProperties),
- new SqlParameter("@CreatedDate", DateTime.Now),
- prmItemId);
-
- return Convert.ToInt32(prmItemId.Value);
- }
-
- public static void UpdateServiceItem(int actorId, int itemId, string itemName, string xmlProperties)
- {
- // update item
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "UpdateServiceItem",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@ItemName", itemName),
- new SqlParameter("@ItemId", itemId),
- new SqlParameter("@XmlProperties", xmlProperties));
- }
-
- public static void DeleteServiceItem(int actorId, int itemId)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "DeleteServiceItem",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@ItemID", itemId));
- }
-
- public static void MoveServiceItem(int actorId, int itemId, int destinationServiceId)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "MoveServiceItem",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@DestinationServiceID", destinationServiceId));
- }
-
- public static int GetPackageServiceId(int actorId, int packageId, string groupName)
- {
- SqlParameter prmServiceId = new SqlParameter("@ServiceID", SqlDbType.Int);
- prmServiceId.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetPackageServiceID",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@PackageID", packageId),
- new SqlParameter("@groupName", groupName),
- prmServiceId);
-
- return Convert.ToInt32(prmServiceId.Value);
- }
-
- public static void UpdatePackageDiskSpace(int packageId, string xml)
- {
- ExecuteLongNonQuery(
- ObjectQualifier + "UpdatePackageDiskSpace",
- new SqlParameter("@packageId", packageId),
- new SqlParameter("@xml", xml));
- }
-
- public static void UpdatePackageBandwidth(int packageId, string xml)
- {
- ExecuteLongNonQuery(
- ObjectQualifier + "UpdatePackageBandwidth",
- new SqlParameter("@packageId", packageId),
- new SqlParameter("@xml", xml));
- }
-
- public static DateTime GetPackageBandwidthUpdate(int packageId)
- {
- SqlParameter prmUpdateDate = new SqlParameter("@UpdateDate", SqlDbType.DateTime);
- prmUpdateDate.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetPackageBandwidthUpdate",
- prmUpdateDate,
- new SqlParameter("@packageId", packageId));
-
- return (prmUpdateDate.Value != DBNull.Value) ? Convert.ToDateTime(prmUpdateDate.Value) : DateTime.MinValue;
- }
-
- public static void UpdatePackageBandwidthUpdate(int packageId, DateTime updateDate)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "UpdatePackageBandwidthUpdate",
- new SqlParameter("@packageId", packageId),
- new SqlParameter("@updateDate", updateDate));
- }
-
- public static IDataReader GetServiceItemType(int itemTypeId)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetServiceItemType",
- new SqlParameter("@ItemTypeID", itemTypeId)
- );
- }
-
- public static IDataReader GetServiceItemTypes()
- {
- return SqlHelper.ExecuteReader (
- ConnectionString,
- CommandType.StoredProcedure,
- "GetServiceItemTypes"
- );
- }
- #endregion
-
- #region Plans
- // Plans methods
- public static DataSet GetHostingPlans(int actorId, int userId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetHostingPlans",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@userId", userId));
- }
-
- public static DataSet GetHostingAddons(int actorId, int userId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetHostingAddons",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@userId", userId));
- }
-
- public static DataSet GetUserAvailableHostingPlans(int actorId, int userId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetUserAvailableHostingPlans",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@userId", userId));
- }
-
- public static DataSet GetUserAvailableHostingAddons(int actorId, int userId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetUserAvailableHostingAddons",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@userId", userId));
- }
-
- public static IDataReader GetHostingPlan(int actorId, int planId)
- {
- return (IDataReader)SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetHostingPlan",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@PlanId", planId));
- }
-
- public static DataSet GetHostingPlanQuotas(int actorId, int packageId, int planId, int serverId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetHostingPlanQuotas",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@packageId", packageId),
- new SqlParameter("@planId", planId),
- new SqlParameter("@serverId", serverId));
- }
-
- public static int AddHostingPlan(int actorId, int userId, int packageId, string planName,
- string planDescription, bool available, int serverId, decimal setupPrice, decimal recurringPrice,
- int recurrenceUnit, int recurrenceLength, bool isAddon, string quotasXml)
- {
- SqlParameter prmPlanId = new SqlParameter("@PlanID", SqlDbType.Int);
- prmPlanId.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "AddHostingPlan",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@userId", userId),
- new SqlParameter("@packageId", packageId),
- new SqlParameter("@planName", planName),
- new SqlParameter("@planDescription", planDescription),
- new SqlParameter("@available", available),
- new SqlParameter("@serverId", serverId),
- new SqlParameter("@setupPrice", setupPrice),
- new SqlParameter("@recurringPrice", recurringPrice),
- new SqlParameter("@recurrenceUnit", recurrenceUnit),
- new SqlParameter("@recurrenceLength", recurrenceLength),
- new SqlParameter("@isAddon", isAddon),
- new SqlParameter("@quotasXml", quotasXml),
- prmPlanId);
-
- // read identity
- return Convert.ToInt32(prmPlanId.Value);
- }
-
- public static DataSet UpdateHostingPlan(int actorId, int planId, int packageId, int serverId, string planName,
- string planDescription, bool available, decimal setupPrice, decimal recurringPrice,
- int recurrenceUnit, int recurrenceLength, string quotasXml)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "UpdateHostingPlan",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@planId", planId),
- new SqlParameter("@packageId", packageId),
- new SqlParameter("@serverId", serverId),
- new SqlParameter("@planName", planName),
- new SqlParameter("@planDescription", planDescription),
- new SqlParameter("@available", available),
- new SqlParameter("@setupPrice", setupPrice),
- new SqlParameter("@recurringPrice", recurringPrice),
- new SqlParameter("@recurrenceUnit", recurrenceUnit),
- new SqlParameter("@recurrenceLength", recurrenceLength),
- new SqlParameter("@quotasXml", quotasXml));
- }
-
- public static int CopyHostingPlan(int planId, int userId, int packageId)
- {
- SqlParameter prmPlanId = new SqlParameter("@DestinationPlanID", SqlDbType.Int);
- prmPlanId.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "CopyHostingPlan",
- new SqlParameter("@SourcePlanID", planId),
- new SqlParameter("@UserID", userId),
- new SqlParameter("@PackageID", packageId),
- prmPlanId);
-
- return Convert.ToInt32(prmPlanId.Value);
- }
-
- public static int DeleteHostingPlan(int actorId, int planId)
- {
- SqlParameter prmResult = new SqlParameter("@Result", SqlDbType.Int);
- prmResult.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "DeleteHostingPlan",
- prmResult,
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@PlanId", planId));
-
- return Convert.ToInt32(prmResult.Value);
- }
- #endregion
-
- #region Packages
-
- // Packages
- public static DataSet GetMyPackages(int actorId, int userId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetMyPackages",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@UserID", userId));
- }
-
- public static DataSet GetPackages(int actorId, int userId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetPackages",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@UserID", userId));
- }
-
- public static DataSet GetNestedPackagesSummary(int actorId, int packageId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetNestedPackagesSummary",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@PackageID", packageId));
- }
-
- public static DataSet SearchServiceItemsPaged(int actorId, int userId, int itemTypeId, string filterValue,
- string sortColumn, int startRow, int maximumRows)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "SearchServiceItemsPaged",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@UserID", userId),
- new SqlParameter("@itemTypeId", itemTypeId),
- new SqlParameter("@FilterValue", VerifyColumnValue(filterValue)),
- new SqlParameter("@SortColumn", VerifyColumnName(sortColumn)),
- new SqlParameter("@startRow", startRow),
- new SqlParameter("@maximumRows", maximumRows));
- }
-
- public static DataSet GetPackagesPaged(int actorId, int userId, string filterColumn, string filterValue,
- string sortColumn, int startRow, int maximumRows)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetPackagesPaged",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@UserID", userId),
- new SqlParameter("@FilterColumn", VerifyColumnName(filterColumn)),
- new SqlParameter("@FilterValue", VerifyColumnValue(filterValue)),
- new SqlParameter("@SortColumn", VerifyColumnName(sortColumn)),
- new SqlParameter("@startRow", startRow),
- new SqlParameter("@maximumRows", maximumRows));
- }
-
- public static DataSet GetNestedPackagesPaged(int actorId, int packageId, string filterColumn, string filterValue,
- int statusId, int planId, int serverId, string sortColumn, int startRow, int maximumRows)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetNestedPackagesPaged",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@packageId", packageId),
- new SqlParameter("@FilterColumn", VerifyColumnName(filterColumn)),
- new SqlParameter("@FilterValue", VerifyColumnValue(filterValue)),
- new SqlParameter("@statusId", statusId),
- new SqlParameter("@planId", planId),
- new SqlParameter("@serverId", serverId),
- new SqlParameter("@SortColumn", VerifyColumnName(sortColumn)),
- new SqlParameter("@startRow", startRow),
- new SqlParameter("@maximumRows", maximumRows));
- }
-
- public static DataSet GetPackagePackages(int actorId, int packageId, bool recursive)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetPackagePackages",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@packageId", packageId),
- new SqlParameter("@recursive", recursive));
- }
-
- public static IDataReader GetPackage(int actorId, int packageId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetPackage",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@PackageID", packageId));
- }
-
- public static DataSet GetPackageQuotas(int actorId, int packageId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetPackageQuotas",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@PackageID", packageId));
- }
-
- public static DataSet GetPackageQuotasForEdit(int actorId, int packageId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetPackageQuotasForEdit",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@PackageID", packageId));
- }
-
- public static DataSet AddPackage(int actorId, out int packageId, int userId, int planId, string packageName,
- string packageComments, int statusId, DateTime purchaseDate)
- {
- SqlParameter prmPackageId = new SqlParameter("@PackageID", SqlDbType.Int);
- prmPackageId.Direction = ParameterDirection.Output;
-
- DataSet ds = SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "AddPackage",
- prmPackageId,
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@userId", userId),
- new SqlParameter("@packageName", packageName),
- new SqlParameter("@packageComments", packageComments),
- new SqlParameter("@statusId", statusId),
- new SqlParameter("@planId", planId),
- new SqlParameter("@purchaseDate", purchaseDate));
-
- // read identity
- packageId = Convert.ToInt32(prmPackageId.Value);
-
- return ds;
- }
-
- public static DataSet UpdatePackage(int actorId, int packageId, int planId, string packageName,
- string packageComments, int statusId, DateTime purchaseDate,
- bool overrideQuotas, string quotasXml)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "UpdatePackage",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@packageId", packageId),
- new SqlParameter("@packageName", packageName),
- new SqlParameter("@packageComments", packageComments),
- new SqlParameter("@statusId", statusId),
- new SqlParameter("@planId", planId),
- new SqlParameter("@purchaseDate", purchaseDate),
- new SqlParameter("@overrideQuotas", overrideQuotas),
- new SqlParameter("@quotasXml", quotasXml));
- }
-
- public static void UpdatePackageName(int actorId, int packageId, string packageName,
- string packageComments)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "UpdatePackageName",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@packageId", packageId),
- new SqlParameter("@packageName", packageName),
- new SqlParameter("@packageComments", packageComments));
- }
-
- public static void DeletePackage(int actorId, int packageId)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "DeletePackage",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@PackageID", packageId));
- }
-
- // Package Add-ons
- public static DataSet GetPackageAddons(int actorId, int packageId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetPackageAddons",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@PackageID", packageId));
- }
-
- public static IDataReader GetPackageAddon(int actorId, int packageAddonId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetPackageAddon",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@PackageAddonID", packageAddonId));
- }
-
- public static DataSet AddPackageAddon(int actorId, out int addonId, int packageId, int planId, int quantity,
- int statusId, DateTime purchaseDate, string comments)
- {
- SqlParameter prmPackageAddonId = new SqlParameter("@PackageAddonID", SqlDbType.Int);
- prmPackageAddonId.Direction = ParameterDirection.Output;
-
- DataSet ds = SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "AddPackageAddon",
- prmPackageAddonId,
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@PackageID", packageId),
- new SqlParameter("@planId", planId),
- new SqlParameter("@Quantity", quantity),
- new SqlParameter("@statusId", statusId),
- new SqlParameter("@PurchaseDate", purchaseDate),
- new SqlParameter("@Comments", comments));
-
- // read identity
- addonId = Convert.ToInt32(prmPackageAddonId.Value);
-
- return ds;
- }
-
- public static DataSet UpdatePackageAddon(int actorId, int packageAddonId, int planId, int quantity,
- int statusId, DateTime purchaseDate, string comments)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "UpdatePackageAddon",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@PackageAddonID", packageAddonId),
- new SqlParameter("@planId", planId),
- new SqlParameter("@Quantity", quantity),
- new SqlParameter("@statusId", statusId),
- new SqlParameter("@PurchaseDate", purchaseDate),
- new SqlParameter("@Comments", comments));
- }
-
- public static void DeletePackageAddon(int actorId, int packageAddonId)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "DeletePackageAddon",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@PackageAddonID", packageAddonId));
- }
-
- #endregion
-
- #region Packages Settings
- public static IDataReader GetPackageSettings(int actorId, int packageId, string settingsName)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetPackageSettings",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@PackageId", packageId),
- new SqlParameter("@SettingsName", settingsName));
- }
- public static void UpdatePackageSettings(int actorId, int packageId, string settingsName, string xml)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "UpdatePackageSettings",
- new SqlParameter("@PackageId", packageId),
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@SettingsName", settingsName),
- new SqlParameter("@Xml", xml));
- }
- #endregion
-
- #region Quotas
- public static IDataReader GetProviderServiceQuota(int providerId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetProviderServiceQuota",
- new SqlParameter("@providerId", providerId));
- }
-
- public static IDataReader GetPackageQuota(int actorId, int packageId, string quotaName)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetPackageQuota",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@PackageID", packageId),
- new SqlParameter("@QuotaName", quotaName));
- }
- #endregion
-
- #region Log
- public static void AddAuditLogRecord(string recordId, int severityId,
- int userId, string username, int packageId, int itemId, string itemName, DateTime startDate, DateTime finishDate, string sourceName,
- string taskName, string executionLog)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "AddAuditLogRecord",
- new SqlParameter("@recordId", recordId),
- new SqlParameter("@severityId", severityId),
- new SqlParameter("@UserID", userId),
- new SqlParameter("@username", username),
- new SqlParameter("@PackageID", packageId),
- new SqlParameter("@ItemId", itemId),
- new SqlParameter("@itemName", itemName),
- new SqlParameter("@startDate", startDate),
- new SqlParameter("@finishDate", finishDate),
- new SqlParameter("@sourceName", sourceName),
- new SqlParameter("@taskName", taskName),
- new SqlParameter("@executionLog", executionLog));
- }
-
- public static DataSet GetAuditLogRecordsPaged(int actorId, int userId, int packageId, int itemId, string itemName, DateTime startDate, DateTime endDate,
- int severityId, string sourceName, string taskName, string sortColumn, int startRow, int maximumRows)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetAuditLogRecordsPaged",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@UserID", userId),
- new SqlParameter("@PackageID", packageId),
- new SqlParameter("@itemId", itemId),
- new SqlParameter("@itemName", itemName),
- new SqlParameter("@StartDate", startDate),
- new SqlParameter("@EndDate", endDate),
- new SqlParameter("@severityId", severityId),
- new SqlParameter("@sourceName", sourceName),
- new SqlParameter("@taskName", taskName),
- new SqlParameter("@sortColumn", VerifyColumnName(sortColumn)),
- new SqlParameter("@startRow", startRow),
- new SqlParameter("@maximumRows", maximumRows));
- }
-
- public static DataSet GetAuditLogSources()
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetAuditLogSources");
- }
-
- public static DataSet GetAuditLogTasks(string sourceName)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetAuditLogTasks",
- new SqlParameter("@sourceName", sourceName));
- }
-
- public static IDataReader GetAuditLogRecord(string recordId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetAuditLogRecord",
- new SqlParameter("@recordId", recordId));
- }
-
- public static void DeleteAuditLogRecords(int actorId, int userId, int itemId, string itemName, DateTime startDate, DateTime endDate,
- int severityId, string sourceName, string taskName)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "DeleteAuditLogRecords",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@userId", userId),
- new SqlParameter("@itemId", itemId),
- new SqlParameter("@itemName", itemName),
- new SqlParameter("@startDate", startDate),
- new SqlParameter("@endDate", endDate),
- new SqlParameter("@severityId", severityId),
- new SqlParameter("@sourceName", sourceName),
- new SqlParameter("@taskName", taskName));
- }
-
- public static void DeleteAuditLogRecordsComplete()
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "DeleteAuditLogRecordsComplete");
- }
-
- #endregion
-
- #region Reports
- public static DataSet GetPackagesBandwidthPaged(int actorId, int userId, int packageId,
- DateTime startDate, DateTime endDate, string sortColumn,
- int startRow, int maximumRows)
- {
- return ExecuteLongDataSet(
- ObjectQualifier + "GetPackagesBandwidthPaged",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@userId", userId),
- new SqlParameter("@packageId", packageId),
- new SqlParameter("@StartDate", startDate),
- new SqlParameter("@EndDate", endDate),
- new SqlParameter("@sortColumn", VerifyColumnName(sortColumn)),
- new SqlParameter("@startRow", startRow),
- new SqlParameter("@maximumRows", maximumRows));
- }
-
- public static DataSet GetPackagesDiskspacePaged(int actorId, int userId, int packageId, string sortColumn,
- int startRow, int maximumRows)
- {
- return ExecuteLongDataSet(
- ObjectQualifier + "GetPackagesDiskspacePaged",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@userId", userId),
- new SqlParameter("@packageId", packageId),
- new SqlParameter("@sortColumn", VerifyColumnName(sortColumn)),
- new SqlParameter("@startRow", startRow),
- new SqlParameter("@maximumRows", maximumRows));
- }
-
- public static DataSet GetPackageBandwidth(int actorId, int packageId, DateTime startDate, DateTime endDate)
- {
- return ExecuteLongDataSet(
- ObjectQualifier + "GetPackageBandwidth",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@PackageId", packageId),
- new SqlParameter("@StartDate", startDate),
- new SqlParameter("@EndDate", endDate));
- }
-
- public static DataSet GetPackageDiskspace(int actorId, int packageId)
- {
- return ExecuteLongDataSet(
- ObjectQualifier + "GetPackageDiskspace",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@PackageId", packageId));
- }
-
- #endregion
-
- #region Scheduler
- public static IDataReader GetScheduleTasks(int actorId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetScheduleTasks",
- new SqlParameter("@actorId", actorId));
- }
-
- public static IDataReader GetScheduleTask(int actorId, string taskId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetScheduleTask",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@taskId", taskId));
- }
-
- public static DataSet GetSchedules(int actorId, int packageId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetSchedules",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@packageId", packageId));
- }
-
- public static DataSet GetSchedulesPaged(int actorId, int packageId, bool recursive,
- string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetSchedulesPaged",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@packageId", packageId),
- new SqlParameter("@recursive", recursive),
- new SqlParameter("@FilterColumn", VerifyColumnName(filterColumn)),
- new SqlParameter("@FilterValue", VerifyColumnValue(filterValue)),
- new SqlParameter("@SortColumn", VerifyColumnName(sortColumn)),
- new SqlParameter("@startRow", startRow),
- new SqlParameter("@maximumRows", maximumRows));
- }
-
- public static DataSet GetSchedule(int actorId, int scheduleId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetSchedule",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@scheduleId", scheduleId));
- }
- public static IDataReader GetScheduleInternal(int scheduleId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetScheduleInternal",
- new SqlParameter("@scheduleId", scheduleId));
- }
- public static DataSet GetNextSchedule()
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetNextSchedule");
- }
- public static IDataReader GetScheduleParameters(int actorId, string taskId, int scheduleId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetScheduleParameters",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@taskId", taskId),
- new SqlParameter("@scheduleId", scheduleId));
- }
-
- ///
- /// Loads view configuration for the task with specified id.
- ///
- /// Task id which points to task for which view configuration will be loaded.
- /// View configuration for the task with supplied id.
- public static IDataReader GetScheduleTaskViewConfigurations(string taskId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetScheduleTaskViewConfigurations",
- new SqlParameter("@taskId", taskId));
- }
-
- public static int AddSchedule(int actorId, string taskId, int packageId,
- string scheduleName, string scheduleTypeId, int interval,
- DateTime fromTime, DateTime toTime, DateTime startTime,
- DateTime nextRun, bool enabled, string priorityId, int historiesNumber,
- int maxExecutionTime, int weekMonthDay, string xmlParameters)
- {
- SqlParameter prmId = new SqlParameter("@ScheduleID", SqlDbType.Int);
- prmId.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "AddSchedule",
- prmId,
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@taskId", taskId),
- new SqlParameter("@packageId", packageId),
- new SqlParameter("@scheduleName", scheduleName),
- new SqlParameter("@scheduleTypeId", scheduleTypeId),
- new SqlParameter("@interval", interval),
- new SqlParameter("@fromTime", fromTime),
- new SqlParameter("@toTime", toTime),
- new SqlParameter("@startTime", startTime),
- new SqlParameter("@nextRun", nextRun),
- new SqlParameter("@enabled", enabled),
- new SqlParameter("@priorityId", priorityId),
- new SqlParameter("@historiesNumber", historiesNumber),
- new SqlParameter("@maxExecutionTime", maxExecutionTime),
- new SqlParameter("@weekMonthDay", weekMonthDay),
- new SqlParameter("@xmlParameters", xmlParameters));
-
- // read identity
- return Convert.ToInt32(prmId.Value);
- }
- public static void UpdateSchedule(int actorId, int scheduleId, string taskId,
- string scheduleName, string scheduleTypeId, int interval,
- DateTime fromTime, DateTime toTime, DateTime startTime,
- DateTime lastRun, DateTime nextRun, bool enabled, string priorityId, int historiesNumber,
- int maxExecutionTime, int weekMonthDay, string xmlParameters)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "UpdateSchedule",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@scheduleId", scheduleId),
- new SqlParameter("@taskId", taskId),
- new SqlParameter("@scheduleName", scheduleName),
- new SqlParameter("@scheduleTypeId", scheduleTypeId),
- new SqlParameter("@interval", interval),
- new SqlParameter("@fromTime", fromTime),
- new SqlParameter("@toTime", toTime),
- new SqlParameter("@startTime", startTime),
- new SqlParameter("@lastRun", (lastRun == DateTime.MinValue) ? DBNull.Value : (object)lastRun),
- new SqlParameter("@nextRun", nextRun),
- new SqlParameter("@enabled", enabled),
- new SqlParameter("@priorityId", priorityId),
- new SqlParameter("@historiesNumber", historiesNumber),
- new SqlParameter("@maxExecutionTime", maxExecutionTime),
- new SqlParameter("@weekMonthDay", weekMonthDay),
- new SqlParameter("@xmlParameters", xmlParameters));
- }
- public static void DeleteSchedule(int actorId, int scheduleId)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "DeleteSchedule",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@scheduleId", scheduleId));
- }
-
- public static DataSet GetScheduleHistories(int actorId, int scheduleId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetScheduleHistories",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@scheduleId", scheduleId));
- }
- public static IDataReader GetScheduleHistory(int actorId, int scheduleHistoryId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetScheduleHistory",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@scheduleHistoryId", scheduleHistoryId));
- }
- public static int AddScheduleHistory(int actorId, int scheduleId,
- DateTime startTime, DateTime finishTime, string statusId, string executionLog)
- {
- SqlParameter prmId = new SqlParameter("@ScheduleHistoryID", SqlDbType.Int);
- prmId.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "AddScheduleHistory",
- prmId,
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@scheduleId", scheduleId),
- new SqlParameter("@startTime", (startTime == DateTime.MinValue) ? DBNull.Value : (object)startTime),
- new SqlParameter("@finishTime", (finishTime == DateTime.MinValue) ? DBNull.Value : (object)finishTime),
- new SqlParameter("@statusId", statusId),
- new SqlParameter("@executionLog", executionLog));
-
- // read identity
- return Convert.ToInt32(prmId.Value);
- }
- public static void UpdateScheduleHistory(int actorId, int scheduleHistoryId,
- DateTime startTime, DateTime finishTime, string statusId, string executionLog)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "UpdateScheduleHistory",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@scheduleHistoryId", scheduleHistoryId),
- new SqlParameter("@startTime", (startTime == DateTime.MinValue) ? DBNull.Value : (object)startTime),
- new SqlParameter("@finishTime", (finishTime == DateTime.MinValue) ? DBNull.Value : (object)finishTime),
- new SqlParameter("@statusId", statusId),
- new SqlParameter("@executionLog", executionLog));
- }
- public static void DeleteScheduleHistories(int actorId, int scheduleId)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "DeleteScheduleHistories",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@scheduleId", scheduleId));
- }
- #endregion
-
- #region Comments
- public static DataSet GetComments(int actorId, int userId, string itemTypeId, int itemId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetComments",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@userId", userId),
- new SqlParameter("@itemTypeId", itemTypeId),
- new SqlParameter("@itemId", itemId));
- }
-
- public static void AddComment(int actorId, string itemTypeId, int itemId,
- string commentText, int severityId)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "AddComment",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@itemTypeId", itemTypeId),
- new SqlParameter("@itemId", itemId),
- new SqlParameter("@commentText", commentText),
- new SqlParameter("@severityId", severityId));
- }
-
- public static void DeleteComment(int actorId, int commentId)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "DeleteComment",
- new SqlParameter("@actorId", actorId),
- new SqlParameter("@commentId", commentId));
- }
- #endregion
-
- #region Helper Methods
- private static string VerifyColumnName(string str)
- {
- if (str == null)
- str = "";
- return Regex.Replace(str, @"[^\w\. ]", "");
- }
-
- private static string VerifyColumnValue(string str)
- {
- return String.IsNullOrEmpty(str) ? str : str.Replace("'", "''");
- }
-
- private static DataSet ExecuteLongDataSet(string spName, params SqlParameter[] parameters)
- {
- return ExecuteLongDataSet(spName, CommandType.StoredProcedure, parameters);
- }
-
- private static DataSet ExecuteLongQueryDataSet(string spName, params SqlParameter[] parameters)
- {
- return ExecuteLongDataSet(spName, CommandType.Text, parameters);
- }
-
- private static DataSet ExecuteLongDataSet(string commandText, CommandType commandType, params SqlParameter[] parameters)
- {
- SqlConnection conn = new SqlConnection(ConnectionString);
- SqlCommand cmd = new SqlCommand(commandText, conn);
- cmd.CommandType = commandType;
- cmd.CommandTimeout = 300;
-
- if (parameters != null)
- {
- foreach (SqlParameter prm in parameters)
- {
- cmd.Parameters.Add(prm);
- }
- }
-
- DataSet ds = new DataSet();
- try
- {
- SqlDataAdapter da = new SqlDataAdapter(cmd);
- da.Fill(ds);
- }
- finally
- {
- if (conn.State == ConnectionState.Open)
- conn.Close();
- }
-
- return ds;
- }
-
- private static void ExecuteLongNonQuery(string spName, params SqlParameter[] parameters)
- {
- SqlConnection conn = new SqlConnection(ConnectionString);
- SqlCommand cmd = new SqlCommand(spName, conn);
- cmd.CommandType = CommandType.StoredProcedure;
- cmd.CommandTimeout = 300;
-
- if (parameters != null)
- {
- foreach (SqlParameter prm in parameters)
- {
- cmd.Parameters.Add(prm);
- }
- }
-
- try
- {
- conn.Open();
- cmd.ExecuteNonQuery();
- }
- finally
- {
- if (conn.State == ConnectionState.Open)
- conn.Close();
- }
- }
- #endregion
-
- #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)
- {
- SqlParameter outParam = new SqlParameter("@AccountID", SqlDbType.Int);
- outParam.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "AddExchangeAccount",
- outParam,
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@AccountType", accountType),
- new SqlParameter("@AccountName", accountName),
- new SqlParameter("@DisplayName", displayName),
- new SqlParameter("@PrimaryEmailAddress", primaryEmailAddress),
- 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))
- );
-
- return Convert.ToInt32(outParam.Value);
- }
-
-
- public static void AddExchangeAccountEmailAddress(int accountId, string emailAddress)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "AddExchangeAccountEmailAddress",
- new SqlParameter("@AccountID", accountId),
- new SqlParameter("@EmailAddress", emailAddress)
- );
- }
-
- public static void AddExchangeOrganization(int itemId, string organizationId)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "AddExchangeOrganization",
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@OrganizationID", organizationId)
- );
- }
-
- public static void AddExchangeOrganizationDomain(int itemId, int domainId, bool isHost)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "AddExchangeOrganizationDomain",
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@DomainID", domainId),
- new SqlParameter("@IsHost", isHost)
- );
- }
-
- public static void ChangeExchangeAcceptedDomainType(int itemId, int domainId, int domainTypeId)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "ChangeExchangeAcceptedDomainType",
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@DomainID", domainId),
- new SqlParameter("@DomainTypeID", domainTypeId)
- );
- }
-
- public static IDataReader GetExchangeOrganizationStatistics(int itemId)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetExchangeOrganizationStatistics",
- new SqlParameter("@ItemID", itemId)
- );
- }
-
- public static void DeleteUserEmailAddresses(int accountId, string primaryAddress)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "DeleteUserEmailAddresses",
- new SqlParameter("@AccountID", accountId),
- new SqlParameter("@PrimaryEmailAddress", primaryAddress)
- );
- }
-
- public static void DeleteExchangeAccount(int itemId, int accountId)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "DeleteExchangeAccount",
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@AccountID", accountId)
- );
- }
-
-
- public static void DeleteExchangeAccountEmailAddress(int accountId, string emailAddress)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "DeleteExchangeAccountEmailAddress",
- new SqlParameter("@AccountID", accountId),
- new SqlParameter("@EmailAddress", emailAddress)
- );
- }
-
- public static void DeleteExchangeOrganization(int itemId)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "DeleteExchangeOrganization",
- new SqlParameter("@ItemID", itemId)
- );
- }
-
- public static void DeleteExchangeOrganizationDomain(int itemId, int domainId)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "DeleteExchangeOrganizationDomain",
- new SqlParameter("@ItemId", itemId),
- new SqlParameter("@DomainID", domainId)
- );
- }
-
- public static bool ExchangeAccountEmailAddressExists(string emailAddress)
- {
- SqlParameter outParam = new SqlParameter("@Exists", SqlDbType.Bit);
- outParam.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "ExchangeAccountEmailAddressExists",
- new SqlParameter("@EmailAddress", emailAddress),
- outParam
- );
-
- return Convert.ToBoolean(outParam.Value);
- }
-
- public static bool ExchangeOrganizationDomainExists(int domainId)
- {
- SqlParameter outParam = new SqlParameter("@Exists", SqlDbType.Bit);
- outParam.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "ExchangeOrganizationDomainExists",
- new SqlParameter("@DomainID", domainId),
- outParam
- );
-
- return Convert.ToBoolean(outParam.Value);
- }
-
- public static bool ExchangeOrganizationExists(string organizationId)
- {
- SqlParameter outParam = new SqlParameter("@Exists", SqlDbType.Bit);
- outParam.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "ExchangeOrganizationExists",
- new SqlParameter("@OrganizationID", organizationId),
- outParam
- );
-
- return Convert.ToBoolean(outParam.Value);
- }
-
- public static bool ExchangeAccountExists(string accountName)
- {
- SqlParameter outParam = new SqlParameter("@Exists", SqlDbType.Bit);
- outParam.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "ExchangeAccountExists",
- new SqlParameter("@AccountName", accountName),
- outParam
- );
-
- return Convert.ToBoolean(outParam.Value);
- }
-
- public static void UpdateExchangeAccount(int accountId, string accountName, ExchangeAccountType accountType,
- string displayName, string primaryEmailAddress, bool mailEnabledPublicFolder,
- string mailboxManagerActions, string samAccountName, string accountPassword, int mailboxPlanId, string subscriberNumber)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "UpdateExchangeAccount",
- new SqlParameter("@AccountID", accountId),
- new SqlParameter("@AccountName", accountName),
- new SqlParameter("@DisplayName", displayName),
- new SqlParameter("@AccountType", (int)accountType),
- 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("@SubscriberNumber", (string.IsNullOrEmpty(subscriberNumber) ? (object)DBNull.Value : (object)subscriberNumber))
- );
- }
-
- public static void UpdateExchangeAccountUserPrincipalName(int accountId, string userPrincipalName)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "UpdateExchangeAccountUserPrincipalName",
- new SqlParameter("@AccountID", accountId),
- new SqlParameter("@UserPrincipalName", userPrincipalName));
- }
-
- public static IDataReader GetExchangeAccount(int itemId, int accountId)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetExchangeAccount",
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@AccountID", accountId)
- );
- }
-
- public static IDataReader GetExchangeAccountByAccountName(int itemId, string accountName)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetExchangeAccountByAccountName",
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@AccountName", accountName)
- );
- }
-
- public static IDataReader GetExchangeAccountByMailboxPlanId(int itemId, int MailboxPlanId)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetExchangeAccountByMailboxPlanId",
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@MailboxPlanId", MailboxPlanId)
- );
- }
-
-
- public static IDataReader GetExchangeAccountEmailAddresses(int accountId)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetExchangeAccountEmailAddresses",
- new SqlParameter("@AccountID", accountId)
- );
- }
-
- public static IDataReader GetExchangeOrganizationDomains(int itemId)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetExchangeOrganizationDomains",
- new SqlParameter("@ItemID", itemId)
- );
- }
-
-
- public static IDataReader GetExchangeAccounts(int itemId, int accountType)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetExchangeAccounts",
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@AccountType", accountType)
- );
- }
-
- public static IDataReader GetExchangeMailboxes(int itemId)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetExchangeMailboxes",
- new SqlParameter("@ItemID", itemId)
- );
- }
-
- public static DataSet GetExchangeAccountsPaged(int actorId, int itemId, string accountTypes,
- string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows)
- {
- // check input parameters
- string[] types = accountTypes.Split(',');
- for (int i = 0; i < types.Length; i++)
- {
- try
- {
- int type = Int32.Parse(types[i]);
- }
- catch
- {
- throw new ArgumentException("Wrong patameter", "accountTypes");
- }
- }
-
- string searchTypes = String.Join(",", types);
-
- return SqlHelper.ExecuteDataset(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetExchangeAccountsPaged",
- new SqlParameter("@ActorID", actorId),
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@AccountTypes", searchTypes),
- new SqlParameter("@FilterColumn", VerifyColumnName(filterColumn)),
- new SqlParameter("@FilterValue", VerifyColumnValue(filterValue)),
- new SqlParameter("@SortColumn", VerifyColumnName(sortColumn)),
- new SqlParameter("@StartRow", startRow),
- new SqlParameter("@MaximumRows", maximumRows)
- );
- }
-
- public static IDataReader SearchExchangeAccounts(int actorId, int itemId, bool includeMailboxes,
- bool includeContacts, bool includeDistributionLists, bool includeRooms, bool includeEquipment,
- string filterColumn, string filterValue, string sortColumn)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "SearchExchangeAccounts",
- new SqlParameter("@ActorID", actorId),
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@IncludeMailboxes", includeMailboxes),
- new SqlParameter("@IncludeContacts", includeContacts),
- new SqlParameter("@IncludeDistributionLists", includeDistributionLists),
- new SqlParameter("@IncludeRooms", includeRooms),
- new SqlParameter("@IncludeEquipment", includeEquipment),
- new SqlParameter("@FilterColumn", VerifyColumnName(filterColumn)),
- new SqlParameter("@FilterValue", VerifyColumnValue(filterValue)),
- new SqlParameter("@SortColumn", VerifyColumnName(sortColumn))
- );
- }
-
- public static IDataReader SearchExchangeAccount(int actorId, int accountType, string primaryEmailAddress)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "SearchExchangeAccount",
- new SqlParameter("@ActorID", actorId),
- new SqlParameter("@AccountType", accountType),
- new SqlParameter("@PrimaryEmailAddress", primaryEmailAddress)
- );
- }
-
- #endregion
-
- #region Exchange Mailbox Plans
- public static int AddExchangeMailboxPlan(int itemID, 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)
- {
- SqlParameter outParam = new SqlParameter("@MailboxPlanId", SqlDbType.Int);
- outParam.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "AddExchangeMailboxPlan",
- outParam,
- new SqlParameter("@ItemID", itemID),
- new SqlParameter("@MailboxPlan", mailboxPlan),
- new SqlParameter("@EnableActiveSync", enableActiveSync),
- new SqlParameter("@EnableIMAP", enableIMAP),
- new SqlParameter("@EnableMAPI", enableMAPI),
- new SqlParameter("@EnableOWA", enableOWA),
- new SqlParameter("@EnablePOP", enablePOP),
- new SqlParameter("@IsDefault", isDefault),
- new SqlParameter("@IssueWarningPct", issueWarningPct),
- new SqlParameter("@KeepDeletedItemsDays", keepDeletedItemsDays),
- new SqlParameter("@MailboxSizeMB", mailboxSizeMB),
- new SqlParameter("@MaxReceiveMessageSizeKB", maxReceiveMessageSizeKB),
- new SqlParameter("@MaxRecipients", maxRecipients),
- new SqlParameter("@MaxSendMessageSizeKB", maxSendMessageSizeKB),
- new SqlParameter("@ProhibitSendPct", prohibitSendPct),
- new SqlParameter("@ProhibitSendReceivePct", prohibitSendReceivePct),
- new SqlParameter("@HideFromAddressBook", hideFromAddressBook),
- new SqlParameter("@MailboxPlanType", mailboxPlanType),
- new SqlParameter("@AllowLitigationHold",enabledLitigationHold),
- new SqlParameter("@RecoverableItemsWarningPct", recoverabelItemsWarning),
- new SqlParameter("@RecoverableItemsSpace",recoverabelItemsSpace),
- new SqlParameter("@LitigationHoldUrl",litigationHoldUrl),
- new SqlParameter("@LitigationHoldMsg",litigationHoldMsg)
- );
-
- return Convert.ToInt32(outParam.Value);
- }
-
-
-
- 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)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "UpdateExchangeMailboxPlan",
- new SqlParameter("@MailboxPlanID", mailboxPlanID),
- new SqlParameter("@MailboxPlan", mailboxPlan),
- new SqlParameter("@EnableActiveSync", enableActiveSync),
- new SqlParameter("@EnableIMAP", enableIMAP),
- new SqlParameter("@EnableMAPI", enableMAPI),
- new SqlParameter("@EnableOWA", enableOWA),
- new SqlParameter("@EnablePOP", enablePOP),
- new SqlParameter("@IsDefault", isDefault),
- new SqlParameter("@IssueWarningPct", issueWarningPct),
- new SqlParameter("@KeepDeletedItemsDays", keepDeletedItemsDays),
- new SqlParameter("@MailboxSizeMB", mailboxSizeMB),
- new SqlParameter("@MaxReceiveMessageSizeKB", maxReceiveMessageSizeKB),
- new SqlParameter("@MaxRecipients", maxRecipients),
- new SqlParameter("@MaxSendMessageSizeKB", maxSendMessageSizeKB),
- new SqlParameter("@ProhibitSendPct", prohibitSendPct),
- new SqlParameter("@ProhibitSendReceivePct", prohibitSendReceivePct),
- new SqlParameter("@HideFromAddressBook", hideFromAddressBook),
- new SqlParameter("@MailboxPlanType", mailboxPlanType),
- new SqlParameter("@AllowLitigationHold", enabledLitigationHold),
- new SqlParameter("@RecoverableItemsWarningPct", recoverabelItemsWarning),
- new SqlParameter("@RecoverableItemsSpace", recoverabelItemsSpace),
- new SqlParameter("@LitigationHoldUrl",litigationHoldUrl),
- new SqlParameter("@LitigationHoldMsg",litigationHoldMsg)
-
- );
- }
-
-
-
- public static void DeleteExchangeMailboxPlan(int mailboxPlanId)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "DeleteExchangeMailboxPlan",
- new SqlParameter("@MailboxPlanId", mailboxPlanId)
- );
- }
-
-
- public static IDataReader GetExchangeMailboxPlan(int mailboxPlanId)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetExchangeMailboxPlan",
- new SqlParameter("@MailboxPlanId", mailboxPlanId)
- );
- }
-
- public static IDataReader GetExchangeMailboxPlans(int itemId)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetExchangeMailboxPlans",
- new SqlParameter("@ItemID", itemId)
- );
- }
-
-
- public static IDataReader GetExchangeOrganization(int itemId)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetExchangeOrganization",
- new SqlParameter("@ItemID", itemId)
- );
- }
-
-
- public static void SetOrganizationDefaultExchangeMailboxPlan(int itemId, int mailboxPlanId)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "SetOrganizationDefaultExchangeMailboxPlan",
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@MailboxPlanId", mailboxPlanId)
- );
- }
-
- public static void SetExchangeAccountMailboxPlan(int accountId, int mailboxPlanId)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "SetExchangeAccountMailboxplan",
- new SqlParameter("@AccountID", accountId),
- new SqlParameter("@MailboxPlanId", (mailboxPlanId == 0) ? (object)DBNull.Value : (object)mailboxPlanId)
- );
- }
-
- #endregion
-
- #region Exchange Disclaimer
- public static int AddExchangeDisclaimer(int itemID, ExchangeDisclaimer disclaimer)
- {
- SqlParameter outParam = new SqlParameter("@ExchangeDisclaimerId", SqlDbType.Int);
- outParam.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "AddExchangeDisclaimer",
- outParam,
-
- new SqlParameter("@ItemID", itemID),
- new SqlParameter("@DisclaimerName", disclaimer.DisclaimerName),
- new SqlParameter("@DisclaimerText", disclaimer.DisclaimerText)
- );
-
- return Convert.ToInt32(outParam.Value);
- }
-
- public static void UpdateExchangeDisclaimer(int itemID, ExchangeDisclaimer disclaimer)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "UpdateExchangeDisclaimer",
- new SqlParameter("@ExchangeDisclaimerId", disclaimer.ExchangeDisclaimerId),
- new SqlParameter("@DisclaimerName", disclaimer.DisclaimerName),
- new SqlParameter("@DisclaimerText", disclaimer.DisclaimerText)
- );
- }
-
- public static void DeleteExchangeDisclaimer(int exchangeDisclaimerId)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "DeleteExchangeDisclaimer",
- new SqlParameter("@ExchangeDisclaimerId", exchangeDisclaimerId)
- );
- }
-
- public static IDataReader GetExchangeDisclaimer(int exchangeDisclaimerId)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetExchangeDisclaimer",
- new SqlParameter("@ExchangeDisclaimerId", exchangeDisclaimerId)
- );
- }
-
- public static IDataReader GetExchangeDisclaimers(int itemId)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetExchangeDisclaimers",
- new SqlParameter("@ItemID", itemId)
- );
- }
-
- public static void SetExchangeAccountDisclaimerId(int AccountID, int ExchangeDisclaimerId)
- {
- object id = null;
- if (ExchangeDisclaimerId != -1) id = ExchangeDisclaimerId;
-
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "SetExchangeAccountDisclaimerId",
- new SqlParameter("@AccountID", AccountID),
- new SqlParameter("@ExchangeDisclaimerId", id)
- );
- }
-
- public static int GetExchangeAccountDisclaimerId(int AccountID)
- {
- object objReturn = SqlHelper.ExecuteScalar(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetExchangeAccountDisclaimerId",
- new SqlParameter("@AccountID", AccountID)
- );
-
- int ret;
- if (!int.TryParse(objReturn.ToString(), out ret)) return -1;
- return ret;
- }
-
- #endregion
-
- #region Organizations
-
- public static void DeleteOrganizationUser(int itemId)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure, "DeleteOrganizationUsers", new SqlParameter("@ItemID", itemId));
- }
-
- public static int GetItemIdByOrganizationId(string id)
- {
- object obj =SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "GetItemIdByOrganizationId",
- new SqlParameter("@OrganizationId", id));
-
- return (obj == null || DBNull.Value == obj) ? 0 : (int)obj;
-
- }
-
- public static IDataReader GetOrganizationStatistics(int itemId)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetOrganizationStatistics",
- new SqlParameter("@ItemID", itemId)
- );
- }
-
- public static IDataReader SearchOrganizationAccounts(int actorId, int itemId,
- string filterColumn, string filterValue, string sortColumn, bool includeMailboxes)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "SearchOrganizationAccounts",
- new SqlParameter("@ActorID", actorId),
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@FilterColumn", VerifyColumnName(filterColumn)),
- new SqlParameter("@FilterValue", VerifyColumnValue(filterValue)),
- new SqlParameter("@SortColumn", VerifyColumnName(sortColumn)),
- new SqlParameter("@IncludeMailboxes", includeMailboxes)
- );
- }
-
- #endregion
-
- #region CRM
-
- public static int GetCRMUsersCount(int itemId, string name, string email)
- {
- SqlParameter[] sqlParams = new SqlParameter[]
- {
- new SqlParameter("@ItemID", itemId),
- GetFilterSqlParam("@Name", name),
- GetFilterSqlParam("@Email", email),
- };
-
- return (int) SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "GetCRMUsersCount", sqlParams);
-
- }
-
- private static SqlParameter GetFilterSqlParam(string paramName, string value)
- {
- if (string.IsNullOrEmpty(value))
- return new SqlParameter(paramName, DBNull.Value);
-
- return new SqlParameter(paramName, value);
- }
-
- public static IDataReader GetCrmUsers(int itemId, string sortColumn, string sortDirection, string name, string email, int startRow, int count )
- {
- SqlParameter[] sqlParams = new SqlParameter[]
- {
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@SortColumn", sortColumn),
- new SqlParameter("@SortDirection", sortDirection),
- GetFilterSqlParam("@Name", name),
- GetFilterSqlParam("@Email", email),
- new SqlParameter("@StartRow", startRow),
- new SqlParameter("Count", count)
- };
-
-
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetCRMUsers", sqlParams);
- }
-
- public static IDataReader GetCRMOrganizationUsers(int itemId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure, "GetCRMOrganizationUsers",
- new SqlParameter[] {new SqlParameter("@ItemID", itemId)});
- }
-
- public static void CreateCRMUser(int itemId, Guid crmId, Guid businessUnitId)
- {
- SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure, "InsertCRMUser",
- new SqlParameter[]
- {
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@CrmUserID", crmId),
- new SqlParameter("@BusinessUnitId", businessUnitId)
- });
-
- }
-
-
- public static IDataReader GetCrmUser(int itemId)
- {
- IDataReader reader = SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure, "GetCRMUser",
- new SqlParameter[]
- {
- new SqlParameter("@AccountID", itemId)
- });
- return reader;
-
- }
-
- public static int GetCrmUserCount(int itemId)
- {
- return (int)SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "GetOrganizationCRMUserCount",
- new SqlParameter[]
- { new SqlParameter("@ItemID",itemId)});
- }
-
- public static void DeleteCrmOrganization(int organizationId)
- {
- SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "DeleteCRMOrganization",
- new SqlParameter[] { new SqlParameter("@ItemID", organizationId) });
- }
-
- #endregion
-
- #region VPS - Virtual Private Servers
-
- public static IDataReader GetVirtualMachinesPaged(int actorId, int packageId, string filterColumn, string filterValue,
- string sortColumn, int startRow, int maximumRows, bool recursive)
- {
- IDataReader reader = SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- "GetVirtualMachinesPaged",
- new SqlParameter("@ActorID", actorId),
- new SqlParameter("@PackageID", packageId),
- new SqlParameter("@FilterColumn", VerifyColumnName(filterColumn)),
- new SqlParameter("@FilterValue", VerifyColumnValue(filterValue)),
- new SqlParameter("@SortColumn", VerifyColumnName(sortColumn)),
- new SqlParameter("@StartRow", startRow),
- new SqlParameter("@MaximumRows", maximumRows),
- new SqlParameter("@Recursive", recursive));
- return reader;
- }
- #endregion
-
- public static IDataReader GetVirtualMachinesForPCPaged(int actorId, int packageId, string filterColumn, string filterValue,
- string sortColumn, int startRow, int maximumRows, bool recursive)
- {
- IDataReader reader = SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- "GetVirtualMachinesPagedForPC",
- new SqlParameter("@ActorID", actorId),
- new SqlParameter("@PackageID", packageId),
- new SqlParameter("@FilterColumn", VerifyColumnName(filterColumn)),
- new SqlParameter("@FilterValue", VerifyColumnValue(filterValue)),
- new SqlParameter("@SortColumn", VerifyColumnName(sortColumn)),
- new SqlParameter("@StartRow", startRow),
- new SqlParameter("@MaximumRows", maximumRows),
- new SqlParameter("@Recursive", recursive));
- return reader;
- }
-
-
- #region VPS - External Network
-
- public static IDataReader GetUnallottedIPAddresses(int packageId, int serviceId, int poolId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- "GetUnallottedIPAddresses",
- new SqlParameter("@PackageId", packageId),
- new SqlParameter("@ServiceId", serviceId),
- new SqlParameter("@PoolId", poolId));
- }
-
-
- public static void AllocatePackageIPAddresses(int packageId, string xml)
- {
- SqlParameter[] param = new[]
- {
- new SqlParameter("@PackageID", packageId),
- new SqlParameter("@xml", xml)
- };
-
- ExecuteLongNonQuery("AllocatePackageIPAddresses", param);
- }
-
- public static IDataReader GetPackageIPAddresses(int packageId, int poolId, string filterColumn, string filterValue,
- string sortColumn, int startRow, int maximumRows, bool recursive)
- {
- IDataReader reader = SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- "GetPackageIPAddresses",
- new SqlParameter("@PackageID", packageId),
- new SqlParameter("@PoolId", poolId),
- new SqlParameter("@FilterColumn", VerifyColumnName(filterColumn)),
- new SqlParameter("@FilterValue", VerifyColumnValue(filterValue)),
- new SqlParameter("@SortColumn", VerifyColumnName(sortColumn)),
- new SqlParameter("@startRow", startRow),
- new SqlParameter("@maximumRows", maximumRows),
- new SqlParameter("@Recursive", recursive));
- return reader;
- }
-
-
- public static void DeallocatePackageIPAddress(int id)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure, "DeallocatePackageIPAddress",
- new SqlParameter("@PackageAddressID", id));
- }
- #endregion
-
- #region VPS - Private Network
-
- public static IDataReader GetPackagePrivateIPAddressesPaged(int packageId, string filterColumn, string filterValue,
- string sortColumn, int startRow, int maximumRows)
- {
- IDataReader reader = SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- "GetPackagePrivateIPAddressesPaged",
- new SqlParameter("@PackageID", packageId),
- new SqlParameter("@FilterColumn", VerifyColumnName(filterColumn)),
- new SqlParameter("@FilterValue", VerifyColumnValue(filterValue)),
- new SqlParameter("@SortColumn", VerifyColumnName(sortColumn)),
- new SqlParameter("@startRow", startRow),
- new SqlParameter("@maximumRows", maximumRows));
- return reader;
- }
-
- public static IDataReader GetPackagePrivateIPAddresses(int packageId)
- {
- IDataReader reader = SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- "GetPackagePrivateIPAddresses",
- new SqlParameter("@PackageID", packageId));
- return reader;
- }
- #endregion
-
- #region VPS - External Network Adapter
- public static IDataReader GetPackageUnassignedIPAddresses(int actorId, int packageId, int poolId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- "GetPackageUnassignedIPAddresses",
- new SqlParameter("@ActorID", actorId),
- new SqlParameter("@PackageID", packageId),
- new SqlParameter("@PoolId", poolId));
- }
-
- public static IDataReader GetPackageIPAddress(int packageAddressId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- "GetPackageIPAddress",
- new SqlParameter("@PackageAddressId", packageAddressId));
- }
-
- public static IDataReader GetItemIPAddresses(int actorId, int itemId, int poolId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- "GetItemIPAddresses",
- new SqlParameter("@ActorID", actorId),
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@PoolID", poolId));
- }
-
- public static int AddItemIPAddress(int actorId, int itemId, int packageAddressId)
- {
- return SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- "AddItemIPAddress",
- new SqlParameter("@ActorID", actorId),
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@PackageAddressID", packageAddressId));
- }
-
- public static int SetItemPrimaryIPAddress(int actorId, int itemId, int packageAddressId)
- {
- return SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- "SetItemPrimaryIPAddress",
- new SqlParameter("@ActorID", actorId),
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@PackageAddressID", packageAddressId));
- }
-
- public static int DeleteItemIPAddress(int actorId, int itemId, int packageAddressId)
- {
- return SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- "DeleteItemIPAddress",
- new SqlParameter("@ActorID", actorId),
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@PackageAddressID", packageAddressId));
- }
-
- public static int DeleteItemIPAddresses(int actorId, int itemId)
- {
- return SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- "DeleteItemIPAddresses",
- new SqlParameter("@ActorID", actorId),
- new SqlParameter("@ItemID", itemId));
- }
- #endregion
-
- #region VPS - Private Network Adapter
- public static IDataReader GetItemPrivateIPAddresses(int actorId, int itemId)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- "GetItemPrivateIPAddresses",
- new SqlParameter("@ActorID", actorId),
- new SqlParameter("@ItemID", itemId));
- }
-
- public static int AddItemPrivateIPAddress(int actorId, int itemId, string ipAddress)
- {
- return SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- "AddItemPrivateIPAddress",
- new SqlParameter("@ActorID", actorId),
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@IPAddress", ipAddress));
- }
-
- public static int SetItemPrivatePrimaryIPAddress(int actorId, int itemId, int privateAddressId)
- {
- return SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- "SetItemPrivatePrimaryIPAddress",
- new SqlParameter("@ActorID", actorId),
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@PrivateAddressID", privateAddressId));
- }
-
- public static int DeleteItemPrivateIPAddress(int actorId, int itemId, int privateAddressId)
- {
- return SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- "DeleteItemPrivateIPAddress",
- new SqlParameter("@ActorID", actorId),
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@PrivateAddressID", privateAddressId));
- }
-
- public static int DeleteItemPrivateIPAddresses(int actorId, int itemId)
- {
- return SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- "DeleteItemPrivateIPAddresses",
- new SqlParameter("@ActorID", actorId),
- new SqlParameter("@ItemID", itemId));
- }
- #endregion
-
- #region BlackBerry
-
- public static void AddBlackBerryUser(int accountId)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString,
- CommandType.StoredProcedure,
- "AddBlackBerryUser",
- new[]
- {
- new SqlParameter("@AccountID", accountId)
- });
- }
-
-
- public static bool CheckBlackBerryUserExists(int accountId)
- {
- int res = (int)SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "CheckBlackBerryUserExists",
- new SqlParameter("@AccountID", accountId));
- return res > 0;
- }
-
-
- public static IDataReader GetBlackBerryUsers(int itemId, string sortColumn, string sortDirection, string name, string email, int startRow, int count)
- {
- SqlParameter[] sqlParams = new SqlParameter[]
- {
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@SortColumn", sortColumn),
- new SqlParameter("@SortDirection", sortDirection),
- GetFilterSqlParam("@Name", name),
- GetFilterSqlParam("@Email", email),
- new SqlParameter("@StartRow", startRow),
- new SqlParameter("Count", count)
- };
-
-
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetBlackBerryUsers", sqlParams);
- }
-
- public static int GetBlackBerryUsersCount(int itemId, string name, string email)
- {
- SqlParameter[] sqlParams = new SqlParameter[]
- {
- new SqlParameter("@ItemID", itemId),
- GetFilterSqlParam("@Name", name),
- GetFilterSqlParam("@Email", email),
- };
-
- return
- (int)
- SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "GetBlackBerryUsersCount", sqlParams);
- }
-
- public static void DeleteBlackBerryUser(int accountId)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString,
- CommandType.StoredProcedure,
- "DeleteBlackBerryUser",
- new[]
- {
- new SqlParameter("@AccountID", accountId)
- });
-
- }
-
- #endregion
-
- #region OCS
-
- public static void AddOCSUser(int accountId, string instanceId)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString,
- CommandType.StoredProcedure,
- "AddOCSUser",
- new[]
- {
- new SqlParameter("@AccountID", accountId),
- new SqlParameter("@InstanceID", instanceId)
- });
- }
-
-
- public static bool CheckOCSUserExists(int accountId)
- {
- int res = (int)SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "CheckOCSUserExists",
- new SqlParameter("@AccountID", accountId));
- return res > 0;
- }
-
-
- public static IDataReader GetOCSUsers(int itemId, string sortColumn, string sortDirection, string name, string email, int startRow, int count)
- {
- SqlParameter[] sqlParams = new SqlParameter[]
- {
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@SortColumn", sortColumn),
- new SqlParameter("@SortDirection", sortDirection),
- GetFilterSqlParam("@Name", name),
- GetFilterSqlParam("@Email", email),
- new SqlParameter("@StartRow", startRow),
- new SqlParameter("Count", count)
- };
-
-
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetOCSUsers", sqlParams);
- }
-
- public static int GetOCSUsersCount(int itemId, string name, string email)
- {
- SqlParameter[] sqlParams = new SqlParameter[]
- {
- new SqlParameter("@ItemID", itemId),
- GetFilterSqlParam("@Name", name),
- GetFilterSqlParam("@Email", email),
- };
-
- return
- (int)
- SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "GetOCSUsersCount", sqlParams);
- }
-
- public static void DeleteOCSUser(string instanceId)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString,
- CommandType.StoredProcedure,
- "DeleteOCSUser",
- new[]
- {
- new SqlParameter("@InstanceId", instanceId)
- });
-
- }
-
- public static string GetOCSUserInstanceID(int accountId)
- {
- return (string)SqlHelper.ExecuteScalar(ConnectionString,
- CommandType.StoredProcedure,
- "GetInstanceID",
- new[]
- {
- new SqlParameter("@AccountID", accountId)
- });
- }
-
- #endregion
-
- #region SSL
- public static int AddSSLRequest(int actorId, int packageId, int siteID, int userID, string friendlyname, string hostname, string csr, int csrLength, string distinguishedName, bool isRenewal, int previousID)
- {
- SqlParameter prmId = new SqlParameter("@SSLID", SqlDbType.Int);
- prmId.Direction = ParameterDirection.Output;
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "AddSSLRequest", prmId,
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@PackageId", packageId),
- new SqlParameter("@UserID", userID),
- new SqlParameter("@WebSiteID", siteID),
- new SqlParameter("@FriendlyName", friendlyname),
- new SqlParameter("@HostName", hostname),
- new SqlParameter("@CSR", csr),
- new SqlParameter("@CSRLength", csrLength),
- new SqlParameter("@DistinguishedName", distinguishedName),
- new SqlParameter("@IsRenewal", isRenewal),
- new SqlParameter("@PreviousId", previousID)
- );
- return Convert.ToInt32(prmId.Value);
-
- }
-
- public static void CompleteSSLRequest(int actorId, int packageId, int id, string certificate, string distinguishedName, string serialNumber, byte[] hash, DateTime validFrom, DateTime expiryDate)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "CompleteSSLRequest",
- new SqlParameter("@ActorID", actorId),
- new SqlParameter("@PackageID", packageId),
- new SqlParameter("@ID", id),
- new SqlParameter("@DistinguishedName", distinguishedName),
- new SqlParameter("@Certificate", certificate),
- new SqlParameter("@SerialNumber", serialNumber),
- new SqlParameter("@Hash", Convert.ToBase64String(hash)),
- new SqlParameter("@ValidFrom", validFrom),
- new SqlParameter("@ExpiryDate", expiryDate));
-
- }
-
- public static void AddPFX(int actorId, int packageId, int siteID, int userID, string hostname, string friendlyName, string distinguishedName, int csrLength, string serialNumber, DateTime validFrom, DateTime expiryDate)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "AddPFX",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@PackageId", packageId),
- new SqlParameter("@UserID", userID),
- new SqlParameter("@WebSiteID", siteID),
- new SqlParameter("@FriendlyName", friendlyName),
- new SqlParameter("@HostName", hostname),
- new SqlParameter("@CSRLength", csrLength),
- new SqlParameter("@DistinguishedName", distinguishedName),
- new SqlParameter("@SerialNumber", serialNumber),
- new SqlParameter("@ValidFrom", validFrom),
- new SqlParameter("@ExpiryDate", expiryDate));
-
- }
-
- public static DataSet GetSSL(int actorId, int packageId, int id)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetSSL",
- new SqlParameter("@SSLID", id));
-
- }
-
- public static DataSet GetCertificatesForSite(int actorId, int packageId, int siteId)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetCertificatesForSite",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@PackageId", packageId),
- new SqlParameter("@websiteid", siteId));
-
- }
-
- public static DataSet GetPendingCertificates(int actorId, int packageId, int id, bool recursive)
- {
- return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetPendingSSLForWebsite",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@PackageId", packageId),
- new SqlParameter("@websiteid", id),
- new SqlParameter("@Recursive", recursive));
-
- }
-
- public static IDataReader GetSSLCertificateByID(int actorId, int id)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetSSLCertificateByID",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@ID", id));
- }
-
- public static int CheckSSL(int siteID, bool renewal)
- {
- SqlParameter prmId = new SqlParameter("@Result", SqlDbType.Int);
- prmId.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "CheckSSL",
- prmId,
- new SqlParameter("@siteID", siteID),
- new SqlParameter("@Renewal", renewal));
-
- return Convert.ToInt32(prmId.Value);
- }
-
- public static IDataReader GetSiteCert(int actorId, int siteID)
- {
- return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "GetSSLCertificateByID",
- new SqlParameter("@ActorId", actorId),
- new SqlParameter("@ID", siteID));
- }
-
- public static void DeleteCertificate(int actorId, int packageId, int id)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "DeleteCertificate",
- new SqlParameter("@ActorID", actorId),
- new SqlParameter("@PackageID", packageId),
- new SqlParameter("@id", id));
- }
-
- public static bool CheckSSLExistsForWebsite(int siteId)
- {
- SqlParameter prmId = new SqlParameter("@Result", SqlDbType.Bit);
- prmId.Direction = ParameterDirection.Output;
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
- ObjectQualifier + "CheckSSLExistsForWebsite", prmId,
- new SqlParameter("@siteID", siteId),
- new SqlParameter("@SerialNumber", ""));
- return Convert.ToBoolean(prmId.Value);
- }
- #endregion
-
- #region Lync
-
- public static void AddLyncUser(int accountId, int lyncUserPlanId, string sipAddress)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString,
- CommandType.StoredProcedure,
- "AddLyncUser",
- new[]
- {
- new SqlParameter("@AccountID", accountId),
- new SqlParameter("@LyncUserPlanID", lyncUserPlanId),
- new SqlParameter("@SipAddress", sipAddress)
- });
- }
-
- public static void UpdateLyncUser(int accountId, string sipAddress)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString,
- CommandType.StoredProcedure,
- "UpdateLyncUser",
- new[]
- {
- new SqlParameter("@AccountID", accountId),
- new SqlParameter("@SipAddress", sipAddress)
- });
- }
-
-
- public static bool CheckLyncUserExists(int accountId)
- {
- int res = (int)SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "CheckLyncUserExists",
- new SqlParameter("@AccountID", accountId));
- return res > 0;
- }
-
- public static bool LyncUserExists(int accountId, string sipAddress)
- {
- SqlParameter outParam = new SqlParameter("@Exists", SqlDbType.Bit);
- outParam.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "LyncUserExists",
- new SqlParameter("@AccountID", accountId),
- new SqlParameter("@SipAddress", sipAddress),
- outParam
- );
-
- return Convert.ToBoolean(outParam.Value);
- }
-
-
-
- public static IDataReader GetLyncUsers(int itemId, string sortColumn, string sortDirection, int startRow, int count)
- {
- SqlParameter[] sqlParams = new SqlParameter[]
- {
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@SortColumn", sortColumn),
- new SqlParameter("@SortDirection", sortDirection),
- new SqlParameter("@StartRow", startRow),
- new SqlParameter("Count", count)
- };
-
-
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetLyncUsers", sqlParams);
- }
-
-
- public static IDataReader GetLyncUsersByPlanId(int itemId, int planId)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetLyncUsersByPlanId",
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@PlanId", planId)
- );
- }
-
- public static int GetLyncUsersCount(int itemId)
- {
- SqlParameter[] sqlParams = new SqlParameter[]
- {
- new SqlParameter("@ItemID", itemId)
- };
-
- return
- (int)
- SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "GetLyncUsersCount", sqlParams);
- }
-
- public static void DeleteLyncUser(int accountId)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString,
- CommandType.StoredProcedure,
- "DeleteLyncUser",
- new[]
- {
- new SqlParameter("@AccountId", accountId)
- });
-
- }
-
- public static int AddLyncUserPlan(int itemID, LyncUserPlan lyncUserPlan)
- {
- SqlParameter outParam = new SqlParameter("@LyncUserPlanId", SqlDbType.Int);
- outParam.Direction = ParameterDirection.Output;
-
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "AddLyncUserPlan",
- outParam,
-
- new SqlParameter("@ItemID", itemID),
- new SqlParameter("@LyncUserPlanName", lyncUserPlan.LyncUserPlanName),
- new SqlParameter("@LyncUserPlanType", lyncUserPlan.LyncUserPlanType),
- new SqlParameter("@IM", lyncUserPlan.IM),
- new SqlParameter("@Mobility", lyncUserPlan.Mobility),
- new SqlParameter("@MobilityEnableOutsideVoice", lyncUserPlan.MobilityEnableOutsideVoice),
- new SqlParameter("@Federation", lyncUserPlan.Federation),
- new SqlParameter("@Conferencing", lyncUserPlan.Conferencing),
- new SqlParameter("@EnterpriseVoice", lyncUserPlan.EnterpriseVoice),
- new SqlParameter("@VoicePolicy", lyncUserPlan.VoicePolicy),
- new SqlParameter("@IsDefault", lyncUserPlan.IsDefault)
- );
-
- return Convert.ToInt32(outParam.Value);
- }
-
-
- public static void UpdateLyncUserPlan(int itemID, LyncUserPlan lyncUserPlan)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "UpdateLyncUserPlan",
- new SqlParameter("@LyncUserPlanId", lyncUserPlan.LyncUserPlanId),
- new SqlParameter("@LyncUserPlanName", lyncUserPlan.LyncUserPlanName),
- new SqlParameter("@LyncUserPlanType", lyncUserPlan.LyncUserPlanType),
- new SqlParameter("@IM", lyncUserPlan.IM),
- new SqlParameter("@Mobility", lyncUserPlan.Mobility),
- new SqlParameter("@MobilityEnableOutsideVoice", lyncUserPlan.MobilityEnableOutsideVoice),
- new SqlParameter("@Federation", lyncUserPlan.Federation),
- new SqlParameter("@Conferencing", lyncUserPlan.Conferencing),
- new SqlParameter("@EnterpriseVoice", lyncUserPlan.EnterpriseVoice),
- new SqlParameter("@VoicePolicy", lyncUserPlan.VoicePolicy),
- new SqlParameter("@IsDefault", lyncUserPlan.IsDefault)
- );
- }
-
- public static void DeleteLyncUserPlan(int lyncUserPlanId)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "DeleteLyncUserPlan",
- new SqlParameter("@LyncUserPlanId", lyncUserPlanId)
- );
- }
-
- public static IDataReader GetLyncUserPlan(int lyncUserPlanId)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetLyncUserPlan",
- new SqlParameter("@LyncUserPlanId", lyncUserPlanId)
- );
- }
-
-
- public static IDataReader GetLyncUserPlans(int itemId)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetLyncUserPlans",
- new SqlParameter("@ItemID", itemId)
- );
- }
-
-
- public static void SetOrganizationDefaultLyncUserPlan(int itemId, int lyncUserPlanId)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "SetOrganizationDefaultLyncUserPlan",
- new SqlParameter("@ItemID", itemId),
- new SqlParameter("@LyncUserPlanId", lyncUserPlanId)
- );
- }
-
- public static IDataReader GetLyncUserPlanByAccountId(int AccountId)
- {
- return SqlHelper.ExecuteReader(
- ConnectionString,
- CommandType.StoredProcedure,
- "GetLyncUserPlanByAccountId",
- new SqlParameter("@AccountID", AccountId)
- );
- }
-
-
- public static void SetLyncUserLyncUserplan(int accountId, int lyncUserPlanId)
- {
- SqlHelper.ExecuteNonQuery(
- ConnectionString,
- CommandType.StoredProcedure,
- "SetLyncUserLyncUserplan",
- new SqlParameter("@AccountID", accountId),
- new SqlParameter("@LyncUserPlanId", (lyncUserPlanId == 0) ? (object)DBNull.Value : (object)lyncUserPlanId)
- );
- }
-
-
- #endregion
-
- public static int GetPackageIdByName(string Name)
- {
- int packageId = -1;
- List providers = ServerController.GetProviders();
- foreach (ProviderInfo providerInfo in providers)
- {
- if (string.Equals(Name, providerInfo.ProviderName, StringComparison.OrdinalIgnoreCase))
- {
- packageId = providerInfo.ProviderId;
- break;
- }
- }
-
- //if (-1 == packageId)
- //{
- // throw new Exception("Provider not found");
- //}
-
- return packageId;
- }
-
- public static int GetServiceIdByProviderForServer(int providerId, int serverId)
- {
- IDataReader reader = SqlHelper.ExecuteReader(ConnectionString, CommandType.Text,
- @"SELECT TOP 1
- ServiceID
- FROM Services
- WHERE ProviderID = @ProviderID AND ServerID = @ServerID",
- new SqlParameter("@ProviderID", providerId),
- new SqlParameter("@ServerID", serverId));
-
- if (reader.Read())
- {
- return (int)reader["ServiceID"];
- }
-
- return -1;
- }
-
- #region Helicon Zoo
-
- public static void GetHeliconZooProviderAndGroup(string providerName, out int providerId, out int groupId)
- {
- IDataReader reader = SqlHelper.ExecuteReader(ConnectionString, CommandType.Text,
- @"SELECT TOP 1
- ProviderID, GroupID
- FROM Providers
- WHERE ProviderName = @ProviderName",
- new SqlParameter("@ProviderName", providerName));
-
- reader.Read();
-
- providerId = (int) reader["ProviderID"];
- groupId = (int) reader["GroupID"];
-
- }
-
- public static IDataReader GetHeliconZooQuotas(int providerId)
- {
- IDataReader reader = SqlHelper.ExecuteReader(ConnectionString, CommandType.Text,
- @"SELECT
- Q.QuotaID,
- Q.GroupID,
- Q.QuotaName,
- Q.QuotaDescription,
- Q.QuotaTypeID,
- Q.ServiceQuota
- FROM Providers AS P
- INNER JOIN Quotas AS Q ON P.GroupID = Q.GroupID
- WHERE P.ProviderID = @ProviderID",
- new SqlParameter("@ProviderID", providerId));
-
- return reader;
- }
-
- public static void RemoveHeliconZooQuota(int groupId, string engineName)
- {
- int quotaId;
-
- // find quota id
- IDataReader reader = SqlHelper.ExecuteReader(ConnectionString, CommandType.Text,
- @"SELECT TOP 1
- QuotaID
- FROM Quotas
- WHERE QuotaName = @QuotaName AND GroupID = @GroupID",
- new SqlParameter("@QuotaName", engineName),
- new SqlParameter("@GroupID", groupId));
-
- reader.Read();
- quotaId = (int)reader["QuotaID"];
-
- // delete references from HostingPlanQuotas
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.Text,
- "DELETE FROM HostingPlanQuotas WHERE QuotaID = @QuotaID",
- new SqlParameter("@QuotaID", quotaId)
- );
-
- // delete from Quotas
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.Text,
- "DELETE FROM Quotas WHERE QuotaID = @QuotaID",
- new SqlParameter("@QuotaID", quotaId)
- );
-
- }
-
- public static void AddHeliconZooQuota(int groupId, int quotaId, string engineName, string engineDescription, int quotaOrder)
- {
- SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.Text,
- @"INSERT INTO Quotas (QuotaID, GroupID, QuotaOrder, QuotaName, QuotaDescription, QuotaTypeID, ServiceQuota)
- VALUES (@QuotaID, @GroupID, @QuotaOrder, @QuotaName, @QuotaDescription, 1, 0)",
- new SqlParameter("@QuotaID", quotaId),
- new SqlParameter("@GroupID", groupId),
- new SqlParameter("@QuotaOrder", quotaOrder),
- new SqlParameter("@QuotaName", engineName),
- new SqlParameter("@QuotaDescription", engineDescription)
- );
- }
-
- public static IDataReader GetEnabledHeliconZooQuotasForPackage(int packageId)
- {
- int providerId, groupId;
-
- GetHeliconZooProviderAndGroup("HeliconZoo", out providerId, out groupId);
-
- IDataReader reader = SqlHelper.ExecuteReader(ConnectionString, CommandType.Text,
- @"SELECT HostingPlanQuotas.QuotaID, Quotas.QuotaName, Quotas.QuotaDescription
- FROM HostingPlanQuotas
- INNER JOIN Packages ON HostingPlanQuotas.PlanID = Packages.PlanID
- INNER JOIN Quotas ON HostingPlanQuotas.QuotaID = Quotas.QuotaID
- WHERE
- (Packages.PackageID = @PackageID) AND (Quotas.GroupID = @GroupID) AND (HostingPlanQuotas.QuotaValue = 1)",
- new SqlParameter("@PackageID", packageId),
- new SqlParameter("@GroupID", groupId)
- );
-
- return reader;
- }
-
- public static int GetServerIdForPackage(int packageId)
- {
- IDataReader reader = SqlHelper.ExecuteReader(ConnectionString, CommandType.Text,
- @"SELECT TOP 1
- ServerID
- FROM Packages
- WHERE PackageID = @PackageID",
- new SqlParameter("@PackageID", packageId)
- );
-
- if (reader.Read())
- {
- return (int)reader["ServerID"];
- }
-
- return -1;
- }
-
- #endregion
- }
-}
diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/ExchangeServer/ExchangeServerController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/ExchangeServer/ExchangeServerController.cs
deleted file mode 100644
index 1d6f2906..00000000
--- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/ExchangeServer/ExchangeServerController.cs
+++ /dev/null
@@ -1,5149 +0,0 @@
-// Copyright (c) 2012, 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.Collections;
-using System.Collections.Generic;
-using System.Collections.Specialized;
-using System.Data;
-using System.Net.Mail;
-using System.Threading;
-using WebsitePanel.EnterpriseServer.Code.HostedSolution;
-using WebsitePanel.Providers;
-using WebsitePanel.Providers.Common;
-using WebsitePanel.Providers.Exchange;
-using WebsitePanel.Providers.HostedSolution;
-using WebsitePanel.Providers.OCS;
-using WebsitePanel.Providers.ResultObjects;
-
-
-namespace WebsitePanel.EnterpriseServer
-{
- public class ExchangeServerController
- {
- #region Organizations
- public static DataSet GetRawExchangeOrganizationsPaged(int packageId, bool recursive,
- string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- DataSet ds = new DataSet();
-
- // total records
- DataTable dtTotal = ds.Tables.Add();
- dtTotal.Columns.Add("Records", typeof(int));
- dtTotal.Rows.Add(3);
-
- // organizations
- DataTable dtItems = ds.Tables.Add();
- dtItems.Columns.Add("ItemID", typeof(int));
- dtItems.Columns.Add("OrganizationID", typeof(string));
- dtItems.Columns.Add("ItemName", typeof(string));
- dtItems.Columns.Add("PackageName", typeof(string));
- dtItems.Columns.Add("PackageID", typeof(int));
- dtItems.Columns.Add("Username", typeof(string));
- dtItems.Columns.Add("UserID", typeof(int));
- dtItems.Rows.Add(1, "fabrikam", "Fabrikam Inc", "Hosted Exchange", 1, "Customer", 1);
- dtItems.Rows.Add(1, "contoso", "Contoso", "Hosted Exchange", 1, "Customer", 1);
- dtItems.Rows.Add(1, "gencons", "General Consultants", "Hosted Exchange", 1, "Customer", 1);
-
- return ds;
- }
- #endregion
-
- return PackageController.GetRawPackageItemsPaged(
- packageId, ResourceGroups.Exchange, typeof(Organization),
- recursive, filterColumn, filterValue, sortColumn, startRow, maximumRows);
- }
-
- public static OrganizationsPaged GetExchangeOrganizationsPaged(int packageId, bool recursive,
- string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows)
- {
- ServiceItemsPaged items = PackageController.GetPackageItemsPaged(
- packageId, ResourceGroups.Exchange, typeof(Organization),
- recursive, filterColumn, filterValue, sortColumn, startRow, maximumRows);
-
- OrganizationsPaged orgs = new OrganizationsPaged();
- orgs.RecordsCount = items.RecordsCount;
- orgs.PageItems = new Organization[items.PageItems.Length];
-
- for (int i = 0; i < orgs.PageItems.Length; i++)
- orgs.PageItems[i] = (Organization)items.PageItems[i];
-
- return orgs;
- }
-
- public static List GetExchangeOrganizations(int packageId, bool recursive)
- {
- List items = PackageController.GetPackageItemsByType(
- packageId, typeof(Organization), recursive);
-
- return items.ConvertAll(
- new Converter(
- delegate(ServiceProviderItem item) { return (Organization)item; }));
- }
-
- public static List GetExchangeOrganizationsInternal(int packageId, bool recursive)
- {
- List items = PackageController.GetPackageItemsByTypeInternal(packageId, null, typeof(Organization), recursive);
-
- return items.ConvertAll(
- new Converter(
- delegate(ServiceProviderItem item) { return (Organization)item; }));
- }
-
- public static Organization GetOrganization(int itemId)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- // load package by user
- Organization org = new Organization();
- org.PackageId = 0;
- org.Id = 1;
- org.OrganizationId = "fabrikam";
- org.Name = "Fabrikam Inc";
- org.KeepDeletedItemsDays = 14;
- return org;
- }
- #endregion
-
- return (Organization)PackageController.GetPackageItem(itemId);
- }
-
- public static OrganizationStatistics GetOrganizationStatistics(int itemId)
- {
- return GetOrganizationStatisticsInternal(itemId, false);
- }
-
- public static OrganizationStatistics GetOrganizationStatisticsByOrganization(int itemId)
- {
- return GetOrganizationStatisticsInternal(itemId, true);
- }
-
-
- private static OrganizationStatistics GetOrganizationStatisticsInternal(int itemId, bool byOrganization)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- OrganizationStatistics stats = new OrganizationStatistics();
- stats.AllocatedMailboxes = 10;
- stats.CreatedMailboxes = 4;
- stats.AllocatedContacts = 4;
- stats.CreatedContacts = 2;
- stats.AllocatedDistributionLists = 5;
- stats.CreatedDistributionLists = 1;
- stats.AllocatedPublicFolders = 40;
- stats.CreatedPublicFolders = 4;
- stats.AllocatedDomains = 5;
- stats.CreatedDomains = 2;
- stats.AllocatedDiskSpace = 200;
- stats.UsedDiskSpace = 70;
- return stats;
- }
- #endregion
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_ORG_STATS");
- TaskManager.ItemId = itemId;
-
- try
- {
- Organization org = (Organization)PackageController.GetPackageItem(itemId);
- if (org == null)
- return null;
-
- OrganizationStatistics stats = new OrganizationStatistics();
-
- if (byOrganization)
- {
- OrganizationStatistics tempStats = ObjectUtils.FillObjectFromDataReader(DataProvider.GetExchangeOrganizationStatistics(org.Id));
-
- stats.CreatedMailboxes = tempStats.CreatedMailboxes;
- stats.CreatedContacts = tempStats.CreatedContacts;
- stats.CreatedDistributionLists = tempStats.CreatedDistributionLists;
- stats.CreatedDomains = tempStats.CreatedDomains;
- stats.CreatedPublicFolders = tempStats.CreatedPublicFolders;
- stats.UsedDiskSpace = tempStats.UsedDiskSpace;
- stats.UsedLitigationHoldSpace = tempStats.UsedLitigationHoldSpace;
- }
- else
- {
- UserInfo user = ObjectUtils.FillObjectFromDataReader(DataProvider.GetUserByExchangeOrganizationIdInternally(org.Id));
- List Packages = PackageController.GetPackages(user.UserId);
-
- if ((Packages != null) & (Packages.Count > 0))
- {
- foreach (PackageInfo Package in Packages)
- {
- List orgs = null;
-
- orgs = GetExchangeOrganizations(Package.PackageId, false);
-
- if ((orgs != null) & (orgs.Count > 0))
- {
- foreach (Organization o in orgs)
- {
- OrganizationStatistics tempStats = ObjectUtils.FillObjectFromDataReader(DataProvider.GetExchangeOrganizationStatistics(o.Id));
-
- stats.CreatedMailboxes += tempStats.CreatedMailboxes;
- stats.CreatedContacts += tempStats.CreatedContacts;
- stats.CreatedDistributionLists += tempStats.CreatedDistributionLists;
- stats.CreatedDomains += tempStats.CreatedDomains;
- stats.CreatedPublicFolders += tempStats.CreatedPublicFolders;
- stats.UsedDiskSpace += tempStats.UsedDiskSpace;
- stats.UsedLitigationHoldSpace += tempStats.UsedLitigationHoldSpace;
- }
- }
- }
- }
- }
-
- // disk space
- //stats.UsedDiskSpace = org.DiskSpace;
-
-
- // allocated quotas
- PackageContext cntx = PackageController.GetPackageContext(org.PackageId);
- stats.AllocatedMailboxes = cntx.Quotas[Quotas.EXCHANGE2007_MAILBOXES].QuotaAllocatedValue;
- stats.AllocatedContacts = cntx.Quotas[Quotas.EXCHANGE2007_CONTACTS].QuotaAllocatedValue;
- stats.AllocatedDistributionLists = cntx.Quotas[Quotas.EXCHANGE2007_DISTRIBUTIONLISTS].QuotaAllocatedValue;
- stats.AllocatedPublicFolders = cntx.Quotas[Quotas.EXCHANGE2007_PUBLICFOLDERS].QuotaAllocatedValue;
- stats.AllocatedDiskSpace = cntx.Quotas[Quotas.EXCHANGE2007_DISKSPACE].QuotaAllocatedValue;
- stats.AllocatedLitigationHoldSpace = cntx.Quotas[Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE].QuotaAllocatedValue;
-
- return stats;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
-
-
- public static int CalculateOrganizationDiskspace(int itemId)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "CALCULATE_DISKSPACE");
- TaskManager.ItemId = itemId;
-
- try
- {
- // create thread parameters
- ThreadStartParameters prms = new ThreadStartParameters();
- prms.UserId = SecurityContext.User.UserId;
- prms.Parameters = new object[] { itemId };
-
- Thread t = new Thread(CalculateOrganizationDiskspaceAsync);
- t.Start(prms);
- return 0;
-
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- private static void CalculateOrganizationDiskspaceAsync(object objPrms)
- {
- ThreadStartParameters prms = (ThreadStartParameters)objPrms;
-
- // impersonate thread
- SecurityContext.SetThreadPrincipal(prms.UserId);
-
- int itemId = (int)prms.Parameters[0];
-
- // calculate disk space
- CalculateOrganizationDiskspaceInternal(itemId);
- }
-
- internal static void CalculateOrganizationDiskspaceInternal(int itemId)
- {
- try
- {
- // calculate disk space
- Organization org = (Organization)PackageController.GetPackageItem(itemId);
- if (org == null)
- return;
-
- SoapServiceProviderItem soapOrg = SoapServiceProviderItem.Wrap(org);
-
-
- int exchangeServiceId = PackageController.GetPackageServiceId(org.PackageId, ResourceGroups.Exchange);
-
- if (exchangeServiceId != 0)
- {
- ServiceProvider exchange = GetServiceProvider(exchangeServiceId, org.ServiceId);
-
- ServiceProviderItemDiskSpace[] itemsDiskspace = exchange.GetServiceItemsDiskSpace(new SoapServiceProviderItem[] { soapOrg });
-
-
- if (itemsDiskspace != null && itemsDiskspace.Length > 0)
- {
- // set disk space
- org.DiskSpace = (int)Math.Round(((float)itemsDiskspace[0].DiskSpace / 1024 / 1024));
-
- // save organization
- UpdateOrganization(org);
- }
- }
- }
- catch (Exception ex)
- {
- // write to audit log
- TaskManager.WriteError(ex);
- }
- }
-
- private static bool OrganizationIdentifierExists(string organizationId)
- {
- return DataProvider.ExchangeOrganizationExists(organizationId);
- }
-
-
-
-
-
- private static int ExtendToExchangeOrganization(ref Organization org)
- {
- // place log record
- TaskManager.StartTask("EXCHANGE", "CREATE_ORG", org.Name);
- TaskManager.TaskParameters["Organization ID"] = org.OrganizationId;
-
- try
- {
- // provision organization in Exchange
- int serviceId = GetExchangeServiceID(org.PackageId);
- int[] hubTransportServiceIds;
- int[] clientAccessServiceIds;
-
- GetExchangeServices(serviceId, out hubTransportServiceIds, out clientAccessServiceIds);
-
-
- ExchangeServer mailboxRole = GetExchangeServer(serviceId, org.ServiceId);
-
-
- bool authDomainCreated = false;
- int itemId = 0;
- bool organizationExtended = false;
-
- List domains = null;
- try
- {
- PackageContext cntx = PackageController.GetPackageContext(org.PackageId);
-
- // 1) Create Organization (Mailbox)
- // ================================
- Organization exchangeOrganization = mailboxRole.ExtendToExchangeOrganization(org.OrganizationId,
- org.SecurityGroup,
- Convert.ToBoolean(cntx.Quotas[Quotas.EXCHANGE2007_ISCONSUMER].QuotaAllocatedValue));
-
- organizationExtended = true;
-
- exchangeOrganization.OrganizationId = org.OrganizationId;
- exchangeOrganization.PackageId = org.PackageId;
- exchangeOrganization.ServiceId = org.ServiceId;
-
- exchangeOrganization.DefaultDomain = org.DefaultDomain;
- exchangeOrganization.Name = org.Name;
- exchangeOrganization.Id = org.Id;
- exchangeOrganization.SecurityGroup = org.SecurityGroup;
- exchangeOrganization.DistinguishedName = org.DistinguishedName;
- exchangeOrganization.CrmAdministratorId = org.CrmAdministratorId;
- exchangeOrganization.CrmCollation = org.CrmCollation;
- exchangeOrganization.CrmCurrency = org.CrmCurrency;
- exchangeOrganization.CrmLanguadgeCode = org.CrmLanguadgeCode;
- exchangeOrganization.CrmOrganizationId = org.CrmOrganizationId;
- exchangeOrganization.CrmOrgState = org.CrmOrgState;
- exchangeOrganization.CrmUrl = org.CrmUrl;
-
- org = exchangeOrganization;
-
- // 2) Get OAB virtual directories from Client Access servers and
- // create Create Organization OAB (Mailbox)
- // ==========================================
- List oabVirtualDirs = new List();
- foreach (int id in clientAccessServiceIds)
- {
- ExchangeServer clientAccessRole = null;
- try
- {
- clientAccessRole = GetExchangeServer(id, org.ServiceId);
- }
- catch(Exception ex)
- {
- TaskManager.WriteError(ex);
- continue;
- }
- oabVirtualDirs.Add(clientAccessRole.GetOABVirtualDirectory());
- }
-
- Organization orgOAB = mailboxRole.CreateOrganizationOfflineAddressBook(org.OrganizationId, org.SecurityGroup, string.Join(",", oabVirtualDirs.ToArray()));
- org.OfflineAddressBook = orgOAB.OfflineAddressBook;
-
-
- // 3) Add organization domains (Hub Transport)
- domains = OrganizationController.GetOrganizationDomains(org.Id);
-
- foreach (int id in hubTransportServiceIds)
- {
- ExchangeServer hubTransportRole = null;
- try
- {
- hubTransportRole = GetExchangeServer(id, org.ServiceId);
- }
- catch(Exception ex)
- {
- TaskManager.WriteError(ex);
- continue;
- }
-
- string[] existingDomains = hubTransportRole.GetAuthoritativeDomains();
- if (existingDomains != null)
- Array.Sort(existingDomains);
-
- foreach (OrganizationDomainName domain in domains)
- {
- if (existingDomains == null || Array.BinarySearch(existingDomains, domain.DomainName) < 0)
- {
- hubTransportRole.AddAuthoritativeDomain(domain.DomainName);
- }
- if (domain.DomainType != ExchangeAcceptedDomainType.Authoritative)
- {
- hubTransportRole.ChangeAcceptedDomainType(domain.DomainName, domain.DomainType);
- }
- }
- authDomainCreated = true;
- break;
- }
-
- foreach (OrganizationDomainName d in domains)
- {
- DomainInfo domain = ServerController.GetDomain(d.DomainId);
-
- //Add the service records
- if (domain != null)
- {
- if (domain.ZoneItemId != 0)
- {
- ServerController.AddServiceDNSRecords(org.PackageId, ResourceGroups.Exchange, domain, "");
- ServerController.AddServiceDNSRecords(org.PackageId, ResourceGroups.BlackBerry, domain, "");
- ServerController.AddServiceDNSRecords(org.PackageId, ResourceGroups.OCS, domain, "");
- }
- }
- }
-
-
- // 4) Add the address book policy (Exchange 2010 SP2
- //
- // ==========================================
- Organization OrgTmp = mailboxRole.CreateOrganizationAddressBookPolicy(org.OrganizationId,
- org.GlobalAddressList,
- org.AddressList,
- org.RoomsAddressList,
- org.OfflineAddressBook);
-
- org.AddressBookPolicy = OrgTmp.AddressBookPolicy;
-
- StringDictionary settings = ServerController.GetServiceSettings(serviceId);
- org.KeepDeletedItemsDays = Utils.ParseInt(settings["KeepDeletedItemsDays"], 14);
-
- }
- catch (Exception ex)
- {
-
- // rollback organization creation
- if (organizationExtended)
- mailboxRole.DeleteOrganization(org.OrganizationId, org.DistinguishedName,
- org.GlobalAddressList, org.AddressList, org.RoomsAddressList, org.OfflineAddressBook, org.SecurityGroup, org.AddressBookPolicy);
-
- // rollback domain
- if (authDomainCreated)
- foreach (int id in hubTransportServiceIds)
- {
- ExchangeServer hubTransportRole = null;
- try
- {
- hubTransportRole = GetExchangeServer(id, org.ServiceId);
- }
- catch (Exception exe)
- {
- TaskManager.WriteError(exe);
- continue;
- }
-
- foreach (OrganizationDomainName domain in domains)
- {
- hubTransportRole.DeleteAuthoritativeDomain(domain.DomainName);
-
- }
-
- break;
- }
-
- throw TaskManager.WriteError(ex);
- }
-
- return itemId;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- private static int[] ParseMultiSetting(int mailboxServiceId, string settingName)
- {
- List retIds = new List();
- StringDictionary settings = ServerController.GetServiceSettings(mailboxServiceId);
- if (!String.IsNullOrEmpty(settings[settingName]))
- {
- string[] ids = settings[settingName].Split(',');
-
- int res;
- foreach (string id in ids)
- {
- if (int.TryParse(id, out res))
- retIds.Add(res);
- }
- }
-
- if (retIds.Count == 0)
- retIds.Add(mailboxServiceId);
-
- return retIds.ToArray();
-
- }
-
- private static void GetExchangeServices(int mailboxServiceId,
- out int[] hubTransportServiceIds, out int[] clientAccessServiceIds)
- {
- hubTransportServiceIds = ParseMultiSetting(mailboxServiceId, "HubTransportServiceID");
-
- clientAccessServiceIds = ParseMultiSetting(mailboxServiceId, "ClientAccessServiceID");
- }
-
- public static int DeleteOrganization(int itemId)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "DELETE_ORG");
- TaskManager.ItemId = itemId;
-
- try
- {
- // delete organization in Exchange
- //System.Threading.Thread.Sleep(5000);
- Organization org = (Organization)PackageController.GetPackageItem(itemId);
-
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- bool successful = exchange.DeleteOrganization(
- org.OrganizationId,
- org.DistinguishedName,
- org.GlobalAddressList,
- org.AddressList,
- org.RoomsAddressList,
- org.OfflineAddressBook,
- org.SecurityGroup,
- org.AddressBookPolicy);
-
-
- return successful ? 0 : BusinessErrorCodes.ERROR_EXCHANGE_DELETE_SOME_PROBLEMS;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static Organization GetOrganizationStorageLimits(int itemId)
- {
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_ORG_LIMITS");
- TaskManager.ItemId = itemId;
-
- try
- {
- return GetOrganization(itemId);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int SetOrganizationStorageLimits(int itemId, int issueWarningKB, int prohibitSendKB,
- int prohibitSendReceiveKB, int keepDeletedItemsDays, bool applyToMailboxes)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "SET_ORG_LIMITS");
- TaskManager.ItemId = itemId;
-
- try
- {
- Organization org = (Organization)PackageController.GetPackageItem(itemId);
- if (org == null)
- return 0;
-
- // load package context
- PackageContext cntx = PackageController.GetPackageContext(org.PackageId);
-
- int maxDiskSpace = 0;
- if (cntx.Quotas.ContainsKey(Quotas.EXCHANGE2007_DISKSPACE)
- && cntx.Quotas[Quotas.EXCHANGE2007_DISKSPACE].QuotaAllocatedValue > 0)
- maxDiskSpace = cntx.Quotas[Quotas.EXCHANGE2007_DISKSPACE].QuotaAllocatedValue * 1024;
-
- if (maxDiskSpace > 0 && (issueWarningKB > maxDiskSpace || prohibitSendKB > maxDiskSpace || prohibitSendReceiveKB > maxDiskSpace || issueWarningKB == -1 || prohibitSendKB == -1 || prohibitSendReceiveKB == -1))
- return BusinessErrorCodes.ERROR_EXCHANGE_STORAGE_QUOTAS_EXCEED_HOST_VALUES;
-
- // set limits
- org.KeepDeletedItemsDays = keepDeletedItemsDays;
-
- // save organization
- UpdateOrganization(org);
-
- if (applyToMailboxes)
- {
-
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.SetOrganizationStorageLimits(org.DistinguishedName,
- issueWarningKB,
- prohibitSendKB,
- prohibitSendReceiveKB,
- keepDeletedItemsDays);
- }
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static ExchangeItemStatistics[] GetMailboxesStatistics(int itemId)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- List items = new List();
- ExchangeItemStatistics item1 = new ExchangeItemStatistics();
- item1.ItemName = "John Smith";
- item1.TotalItems = 105;
- item1.TotalSizeMB = 14;
- item1.LastLogon = DateTime.Now;
- item1.LastLogoff = DateTime.Now;
- items.Add(item1);
-
- ExchangeItemStatistics item2 = new ExchangeItemStatistics();
- item2.ItemName = "Jack Brown";
- item2.TotalItems = 5;
- item2.TotalSizeMB = 2;
- item2.LastLogon = DateTime.Now;
- item2.LastLogoff = DateTime.Now;
- items.Add(item2);
-
- ExchangeItemStatistics item3 = new ExchangeItemStatistics();
- item3.ItemName = "Marry Smith";
- item3.TotalItems = 1302;
- item3.TotalSizeMB = 45;
- item3.LastLogon = DateTime.Now;
- item3.LastLogoff = DateTime.Now;
- items.Add(item3);
-
- return items.ToArray();
- }
- #endregion
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_MAILBOXES_STATS");
- TaskManager.ItemId = itemId;
-
- try
- {
- Organization org = (Organization)PackageController.GetPackageItem(itemId);
- if (org == null)
- return null;
-
-
- // get stats
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- return exchange.GetMailboxesStatistics(org.DistinguishedName);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static ExchangeMailboxStatistics GetMailboxStatistics(int itemId, int accountId)
- {
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_MAILBOX_STATS");
- TaskManager.ItemId = itemId;
-
- try
- {
- Organization org = (Organization)PackageController.GetPackageItem(itemId);
- if (org == null)
- return null;
-
-
- // get stats
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- return exchange.GetMailboxStatistics(account.UserPrincipalName);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
-
- public static ExchangeItemStatistics[] GetPublicFoldersStatistics(int itemId)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- List items = new List();
- ExchangeItemStatistics item1 = new ExchangeItemStatistics();
- item1.ItemName = "\\fabrikam\\Documents";
- item1.TotalItems = 6;
- item1.TotalSizeMB = 56;
- item1.LastModificationTime = DateTime.Now;
- item1.LastAccessTime = DateTime.Now;
- items.Add(item1);
-
- ExchangeItemStatistics item2 = new ExchangeItemStatistics();
- item2.ItemName = "\\fabrikam\\Documents\\Legal";
- item2.TotalItems = 5;
- item2.TotalSizeMB = 4;
- item2.LastModificationTime = DateTime.Now;
- item2.LastAccessTime = DateTime.Now;
- items.Add(item2);
-
- ExchangeItemStatistics item3 = new ExchangeItemStatistics();
- item3.ItemName = "\\fabrikam\\Documents\\Contracts";
- item3.TotalItems = 8;
- item3.TotalSizeMB = 2;
- item3.LastModificationTime = DateTime.Now;
- item3.LastAccessTime = DateTime.Now;
- items.Add(item3);
-
- return items.ToArray();
- }
- #endregion
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_FOLDERS_STATS");
- TaskManager.ItemId = itemId;
-
- try
- {
- Organization org = (Organization)PackageController.GetPackageItem(itemId);
- if (org == null)
- return null;
-
- // get the list of all public folders
- List folderNames = new List();
- List folders = GetAccounts(itemId, ExchangeAccountType.PublicFolder);
- foreach (ExchangeAccount folder in folders)
- folderNames.Add(folder.DisplayName);
-
- // get stats
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
- return exchange.GetPublicFoldersStatistics(org.OrganizationId, folderNames.ToArray());
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static ExchangeActiveSyncPolicy GetActiveSyncPolicy(int itemId)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- ExchangeActiveSyncPolicy p = new ExchangeActiveSyncPolicy();
- p.MaxAttachmentSizeKB = -1;
- p.MaxPasswordFailedAttempts = -1;
- p.MinPasswordLength = 0;
- p.InactivityLockMin = -1;
- p.PasswordExpirationDays = -1;
- p.PasswordHistory = 0;
- return p;
- }
- #endregion
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_ACTIVESYNC_POLICY");
- TaskManager.ItemId = itemId;
-
- try
- {
- Organization org = (Organization)PackageController.GetPackageItem(itemId);
- if (org == null)
- return null;
-
- // get policy
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- //Create Exchange Organization
- if (string.IsNullOrEmpty(org.GlobalAddressList))
- {
- ExtendToExchangeOrganization(ref org);
-
- PackageController.UpdatePackageItem(org);
- }
- ExchangeActiveSyncPolicy policy = exchange.GetActiveSyncPolicy(org.OrganizationId);
-
- // create policy if required
- if (policy == null)
- {
- exchange.CreateOrganizationActiveSyncPolicy(org.OrganizationId);
- return exchange.GetActiveSyncPolicy(org.OrganizationId);
- }
-
- return policy;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int SetActiveSyncPolicy(int itemId, bool allowNonProvisionableDevices,
- bool attachmentsEnabled, int maxAttachmentSizeKB, bool uncAccessEnabled, bool wssAccessEnabled,
- bool devicePasswordEnabled, bool alphanumericPasswordRequired, bool passwordRecoveryEnabled,
- bool deviceEncryptionEnabled, bool allowSimplePassword, int maxPasswordFailedAttempts, int minPasswordLength,
- int inactivityLockMin, int passwordExpirationDays, int passwordHistory, int refreshInterval)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "SET_ACTIVESYNC_POLICY");
- TaskManager.ItemId = itemId;
-
- try
- {
- Organization org = (Organization)PackageController.GetPackageItem(itemId);
- if (org == null)
- return 0;
-
- // get policy
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
- exchange.SetActiveSyncPolicy(org.OrganizationId, allowNonProvisionableDevices, attachmentsEnabled,
- maxAttachmentSizeKB, uncAccessEnabled, wssAccessEnabled, devicePasswordEnabled, alphanumericPasswordRequired,
- passwordRecoveryEnabled, deviceEncryptionEnabled, allowSimplePassword, maxPasswordFailedAttempts,
- minPasswordLength, inactivityLockMin, passwordExpirationDays, passwordHistory, refreshInterval);
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- private static void UpdateOrganization(Organization organization)
- {
- PackageController.UpdatePackageItem(organization);
- }
- #endregion
-
- #region Accounts
-
- private static bool AccountExists(string accountName)
- {
- return DataProvider.ExchangeAccountExists(accountName);
- }
-
- public static ExchangeAccountsPaged GetAccountsPaged(int itemId, string accountTypes,
- string filterColumn, string filterValue, string sortColumn,
- int startRow, int maximumRows)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- string []parseedAccountTypes = Utils.ParseDelimitedString(accountTypes, ',');
-
- ExchangeAccountsPaged res = new ExchangeAccountsPaged();
- res.PageItems = GetAccounts(itemId, (ExchangeAccountType)Utils.ParseInt(parseedAccountTypes[0], 1)).ToArray();
- res.RecordsCount = res.PageItems.Length;
- return res;
- }
- #endregion
-
- DataSet ds = DataProvider.GetExchangeAccountsPaged(SecurityContext.User.UserId, itemId,
- accountTypes, filterColumn, filterValue, sortColumn, startRow, maximumRows);
-
- ExchangeAccountsPaged result = new ExchangeAccountsPaged();
- result.RecordsCount = (int)ds.Tables[0].Rows[0][0];
-
- List accounts = new List();
- ObjectUtils.FillCollectionFromDataView(accounts, ds.Tables[1].DefaultView);
- result.PageItems = accounts.ToArray();
- return result;
- }
-
- public static List GetAccounts(int itemId, ExchangeAccountType accountType)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- if (accountType == ExchangeAccountType.Mailbox)
- return SearchAccounts(0, true, false, false, true, true, "", "", "");
- else if (accountType == ExchangeAccountType.Contact)
- return SearchAccounts(0, false, true, false, false, false, "", "", "");
- else if (accountType == ExchangeAccountType.DistributionList)
- return SearchAccounts(0, false, false, true, false, false, "", "", "");
- else
- {
- List demoAccounts = new List();
- ExchangeAccount f1 = new ExchangeAccount();
- f1.AccountId = 7;
- f1.AccountName = "documents_fabrikam";
- f1.AccountType = ExchangeAccountType.PublicFolder;
- f1.DisplayName = "\\fabrikam\\Documents";
- f1.PrimaryEmailAddress = "documents@fabrikam.net";
- f1.MailEnabledPublicFolder = true;
- demoAccounts.Add(f1);
-
- ExchangeAccount f2 = new ExchangeAccount();
- f2.AccountId = 8;
- f2.AccountName = "documents_fabrikam";
- f2.AccountType = ExchangeAccountType.PublicFolder;
- f2.DisplayName = "\\fabrikam\\Documents\\Legal";
- f2.PrimaryEmailAddress = "";
- demoAccounts.Add(f2);
-
- ExchangeAccount f3 = new ExchangeAccount();
- f3.AccountId = 9;
- f3.AccountName = "documents_fabrikam";
- f3.AccountType = ExchangeAccountType.PublicFolder;
- f3.DisplayName = "\\fabrikam\\Documents\\Contracts";
- f3.PrimaryEmailAddress = "";
- demoAccounts.Add(f3);
- return demoAccounts;
- }
- }
- #endregion
-
- return ObjectUtils.CreateListFromDataReader(
- DataProvider.GetExchangeAccounts(itemId, (int)accountType));
- }
-
-
- public static List GetExchangeAccountByMailboxPlanId(int itemId, int mailboxPlanId)
- {
- return ObjectUtils.CreateListFromDataReader(DataProvider.GetExchangeAccountByMailboxPlanId(itemId, mailboxPlanId));
- }
-
-
- public static List GetExchangeMailboxes(int itemId)
- {
- return ObjectUtils.CreateListFromDataReader(DataProvider.GetExchangeMailboxes(itemId));
- }
-
- public static List SearchAccounts(int itemId,
- bool includeMailboxes, bool includeContacts, bool includeDistributionLists,
- bool includeRooms, bool includeEquipment,
- string filterColumn, string filterValue, string sortColumn)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- List demoAccounts = new List();
-
- if (includeMailboxes)
- {
- ExchangeAccount m1 = new ExchangeAccount();
- m1.AccountId = 1;
- m1.AccountName = "john_fabrikam";
- m1.AccountType = ExchangeAccountType.Mailbox;
- m1.DisplayName = "John Smith";
- m1.PrimaryEmailAddress = "john@fabrikam.net";
- demoAccounts.Add(m1);
-
-
-
- ExchangeAccount m3 = new ExchangeAccount();
- m3.AccountId = 3;
- m3.AccountName = "marry_fabrikam";
- m3.AccountType = ExchangeAccountType.Mailbox;
- m3.DisplayName = "Marry Smith";
- m3.PrimaryEmailAddress = "marry@fabrikam.net";
- demoAccounts.Add(m3);
- }
-
- if (includeRooms)
- {
- ExchangeAccount r1 = new ExchangeAccount();
- r1.AccountId = 20;
- r1.AccountName = "room1_fabrikam";
- r1.AccountType = ExchangeAccountType.Room;
- r1.DisplayName = "Meeting Room 1";
- r1.PrimaryEmailAddress = "room1@fabrikam.net";
- demoAccounts.Add(r1);
- }
-
- if (includeEquipment)
- {
- ExchangeAccount e1 = new ExchangeAccount();
- e1.AccountId = 21;
- e1.AccountName = "projector_fabrikam";
- e1.AccountType = ExchangeAccountType.Equipment;
- e1.DisplayName = "Projector 1";
- e1.PrimaryEmailAddress = "projector@fabrikam.net";
- demoAccounts.Add(e1);
- }
-
- if (includeContacts)
- {
- ExchangeAccount c1 = new ExchangeAccount();
- c1.AccountId = 4;
- c1.AccountName = "pntr1_fabrikam";
- c1.AccountType = ExchangeAccountType.Contact;
- c1.DisplayName = "WebsitePanel Support";
- c1.PrimaryEmailAddress = "support@websitepanel.net";
- demoAccounts.Add(c1);
-
- ExchangeAccount c2 = new ExchangeAccount();
- c2.AccountId = 5;
- c2.AccountName = "acc1_fabrikam";
- c2.AccountType = ExchangeAccountType.Contact;
- c2.DisplayName = "John Home Account";
- c2.PrimaryEmailAddress = "john@yahoo.com";
- demoAccounts.Add(c2);
- }
-
- if (includeDistributionLists)
- {
- ExchangeAccount d1 = new ExchangeAccount();
- d1.AccountId = 6;
- d1.AccountName = "sales_fabrikam";
- d1.AccountType = ExchangeAccountType.DistributionList;
- d1.DisplayName = "Fabrikam Sales Dept";
- d1.PrimaryEmailAddress = "sales@fabrikam.net";
- demoAccounts.Add(d1);
- }
-
- return demoAccounts;
- }
- #endregion
-
- return ObjectUtils.CreateListFromDataReader(
- DataProvider.SearchExchangeAccounts(SecurityContext.User.UserId, itemId, includeMailboxes, includeContacts,
- includeDistributionLists, includeRooms, includeEquipment,
- filterColumn, filterValue, sortColumn));
- }
-
-
-
- public static ExchangeAccount GetAccount(int itemId, int accountId)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- ExchangeAccount m1 = new ExchangeAccount();
- m1.AccountId = 1;
- m1.AccountName = "john_fabrikam";
- m1.AccountType = ExchangeAccountType.Mailbox;
- m1.DisplayName = "John Smith";
- m1.PrimaryEmailAddress = "john@fabrikam.net";
- return m1;
- }
- #endregion
-
- ExchangeAccount account = ObjectUtils.FillObjectFromDataReader(
- DataProvider.GetExchangeAccount(itemId, accountId));
-
- if (account == null)
- return null;
-
- // decrypt password
- account.AccountPassword = CryptoUtils.Decrypt(account.AccountPassword);
-
- return account;
- }
-
- public static bool CheckAccountCredentials(int itemId, string email, string password)
- {
- // place log record
- TaskManager.StartTask("EXCHANGE", "AUTHENTICATE", email);
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return false;
-
- // check credentials
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
- return exchange.CheckAccountCredentials(email, password);
- }
- catch (Exception ex)
- {
- TaskManager.WriteError(ex);
- return false;
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static ExchangeAccount SearchAccount(ExchangeAccountType accountType, string primaryEmailAddress)
- {
- ExchangeAccount account = ObjectUtils.FillObjectFromDataReader(
- DataProvider.SearchExchangeAccount(SecurityContext.User.UserId,
- (int)accountType, primaryEmailAddress));
-
- if (account == null)
- return null;
-
- // decrypt password
- account.AccountPassword = CryptoUtils.Decrypt(account.AccountPassword);
-
- return account;
- }
-
- private static int AddAccount(int itemId, ExchangeAccountType accountType,
- string accountName, string displayName, string primaryEmailAddress, bool mailEnabledPublicFolder,
- MailboxManagerActions mailboxManagerActions, string samAccountName, string accountPassword, int mailboxPlanId, string subscriberNumber)
- {
- return DataProvider.AddExchangeAccount(itemId, (int)accountType,
- accountName, displayName, primaryEmailAddress, mailEnabledPublicFolder,
- mailboxManagerActions.ToString(), samAccountName, CryptoUtils.Encrypt(accountPassword), 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,
- (string.IsNullOrEmpty(account.SubscriberNumber) ? null : account.SubscriberNumber.Trim()));
- }
-
- private static void DeleteAccount(int itemId, int accountId)
- {
- // try to get organization
- if (GetOrganization(itemId) == null)
- return;
-
- DataProvider.DeleteExchangeAccount(itemId, accountId);
- }
-
- private static string BuildAccountName(string orgId, string name)
- {
- string accountName = name = name.Replace(" ", "");
- int counter = 0;
- bool bFound = false;
-
- if (!AccountExists(accountName)) return accountName;
-
- do
- {
- accountName = genSamLogin(name, counter.ToString("d5"));
-
- if (!AccountExists(accountName)) bFound = true;
-
- counter++;
- }
- while (!bFound);
-
- return accountName;
- }
-
- private static string genSamLogin(string login, string strCounter)
- {
- int maxLogin = 20;
- int fullLen = login.Length + strCounter.Length;
- if (fullLen <= maxLogin)
- return login + strCounter;
- else
- {
- if (login.Length - (fullLen - maxLogin) > 0)
- return login.Substring(0, login.Length - (fullLen - maxLogin)) + strCounter;
- else return strCounter; // ????
- }
-
- }
-
-
- #endregion
-
- #region Account Email Addresses
- private static bool EmailAddressExists(string emailAddress)
- {
- return DataProvider.ExchangeAccountEmailAddressExists(emailAddress);
- }
-
-
- private static ExchangeEmailAddress[] GetAccountEmailAddresses(int itemId, int accountId)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- List demoEmails = new List();
- ExchangeEmailAddress e1 = new ExchangeEmailAddress();
- e1.EmailAddress = "john@fabrikam.net";
- e1.IsPrimary = true;
- demoEmails.Add(e1);
-
- ExchangeEmailAddress e2 = new ExchangeEmailAddress();
- e2.EmailAddress = "john.smith@fabrikam.net";
- demoEmails.Add(e2);
-
- ExchangeEmailAddress e3 = new ExchangeEmailAddress();
- e3.EmailAddress = "john@fabrikam.hosted-exchange.com";
- demoEmails.Add(e3);
- return demoEmails.ToArray();
- }
- #endregion
-
- List emails = ObjectUtils.CreateListFromDataReader(
- DataProvider.GetExchangeAccountEmailAddresses(accountId));
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- foreach (ExchangeEmailAddress email in emails)
- {
- if (String.Compare(account.PrimaryEmailAddress, email.EmailAddress, true) == 0)
- {
- email.IsPrimary = true;
- }
-
- if (String.Compare(account.UserPrincipalName, email.EmailAddress, true) == 0)
- {
- email.IsUserPrincipalName = true;
- }
-
- }
-
- return emails.ToArray();
- }
-
- private static void AddAccountEmailAddress(int accountId, string emailAddress)
- {
- DataProvider.AddExchangeAccountEmailAddress(accountId, emailAddress);
- }
-
- private static void DeleteAccountEmailAddresses(int accountId, string[] emailAddresses)
- {
- foreach (string emailAddress in emailAddresses)
- DataProvider.DeleteExchangeAccountEmailAddress(accountId, emailAddress);
- }
-
- #endregion
-
- #region Domains
- public static List GetOrganizationDomains(int itemId)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- List demoDomains = new List();
- ExchangeDomainName d1 = new ExchangeDomainName();
- d1.DomainId = 1;
- d1.DomainName = "fabrikam.hosted-exchange.com";
- d1.IsDefault = false;
- d1.IsHost = true;
- demoDomains.Add(d1);
-
- ExchangeDomainName d2 = new ExchangeDomainName();
- d2.DomainId = 2;
- d2.DomainName = "fabrikam.net";
- d2.IsDefault = true;
- d2.IsHost = false;
- demoDomains.Add(d2);
-
- return demoDomains;
- }
- #endregion
-
- // load organization
- Organization org = (Organization)PackageController.GetPackageItem(itemId);
- if (org == null)
- return null;
-
- // load all domains
- List domains = ObjectUtils.CreateListFromDataReader(
- DataProvider.GetExchangeOrganizationDomains(itemId));
-
- // set default domain
- foreach (ExchangeDomainName domain in domains)
- {
- if (String.Compare(domain.DomainName, org.DefaultDomain, true) == 0)
- {
- domain.IsDefault = true;
- break;
- }
- }
-
- return domains;
- }
-
- public static int AddAuthoritativeDomain(int itemId, int domainId)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "ADD_DOMAIN");
- TaskManager.TaskParameters["Domain ID"] = domainId;
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = (Organization)PackageController.GetPackageItem(itemId);
- if (org == null)
- return -1;
-
- // load domain
- DomainInfo domain = ServerController.GetDomain(domainId);
- if (domain == null)
- return -1;
-
-
- // delete domain on Exchange
- int[] hubTransportServiceIds;
- int[] clientAccessServiceIds;
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- GetExchangeServices(exchangeServiceId, out hubTransportServiceIds, out clientAccessServiceIds);
-
- foreach (int id in hubTransportServiceIds)
- {
- ExchangeServer hubTransportRole = null;
- try
- {
- hubTransportRole = GetExchangeServer(id, org.ServiceId);
- }
- catch (Exception ex)
- {
- TaskManager.WriteError(ex);
- continue;
- }
-
- string[] domains = hubTransportRole.GetAuthoritativeDomains();
- if (domains != null)
- Array.Sort(domains);
-
- if (domains == null || Array.BinarySearch(domains, domain.DomainName) < 0)
- hubTransportRole.AddAuthoritativeDomain(domain.DomainName);
- break;
- }
-
- //Add the service records
- if (domain != null)
- {
- if (domain.ZoneItemId != 0)
- {
- ServerController.AddServiceDNSRecords(org.PackageId, ResourceGroups.Exchange, domain, "");
- }
- }
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int ChangeAcceptedDomainType(int itemId, int domainId, ExchangeAcceptedDomainType domainType)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "CHANGE_DOMAIN_TYPE");
- TaskManager.TaskParameters["Domain ID"] = domainId;
- TaskManager.TaskParameters["Domain Type"] = domainType.ToString();
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = (Organization)PackageController.GetPackageItem(itemId);
- if (org == null)
- return -1;
-
- // load domain
- DomainInfo domain = ServerController.GetDomain(domainId);
- if (domain == null)
- return -1;
-
- int[] hubTransportServiceIds;
- int[] clientAccessServiceIds;
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- GetExchangeServices(exchangeServiceId, out hubTransportServiceIds, out clientAccessServiceIds);
-
- foreach (int id in hubTransportServiceIds)
- {
- ExchangeServer hubTransportRole = null;
- try
- {
- hubTransportRole = GetExchangeServer(id, org.ServiceId);
- }
- catch (Exception ex)
- {
- TaskManager.WriteError(ex);
- continue;
- }
-
- hubTransportRole.ChangeAcceptedDomainType(domain.DomainName, domainType);
- break;
-
- }
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int DeleteAuthoritativeDomain(int itemId, int domainId)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "DELETE_DOMAIN");
- TaskManager.TaskParameters["Domain ID"] = domainId;
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = (Organization)PackageController.GetPackageItem(itemId);
- if (org == null)
- return -1;
-
- // load domain
- DomainInfo domain = ServerController.GetDomain(domainId);
- if(domain == null)
- return -1;
-
- if (DataProvider.CheckDomainUsedByHostedOrganization(domain.DomainName) == 1)
- {
- return -1;
- }
-
- // delete domain on Exchange
- int[] hubTransportServiceIds;
- int[] clientAccessServiceIds;
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- GetExchangeServices(exchangeServiceId, out hubTransportServiceIds, out clientAccessServiceIds);
-
- foreach (int id in hubTransportServiceIds)
- {
- ExchangeServer hubTransportRole = null;
- try
- {
- hubTransportRole = GetExchangeServer(id, org.ServiceId);
- }
- catch (Exception ex)
- {
- TaskManager.WriteError(ex);
- continue;
- }
-
- hubTransportRole.DeleteAuthoritativeDomain(domain.DomainName);
- break;
-
- }
-
- //Add the service records
- if (domain != null)
- {
- if (domain.ZoneItemId != 0)
- {
- ServerController.RemoveServiceDNSRecords(org.PackageId, ResourceGroups.Exchange, domain, "", false);
- }
- }
-
-
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
-
- #endregion
-
- #region Mailboxes
-
- private static void UpdateExchangeAccount(int accountId, string accountName, ExchangeAccountType accountType,
- string displayName, string primaryEmailAddress, bool mailEnabledPublicFolder,
- string mailboxManagerActions, string samAccountName, string accountPassword, int mailboxPlanId, string subscriberNumber)
- {
- DataProvider.UpdateExchangeAccount(accountId,
- accountName,
- accountType,
- displayName,
- primaryEmailAddress,
- mailEnabledPublicFolder,
- mailboxManagerActions,
- samAccountName,
- CryptoUtils.Encrypt(accountPassword),
- mailboxPlanId,
- (string.IsNullOrEmpty(subscriberNumber) ? null : subscriberNumber.Trim()));
- }
-
-
- 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, string subscriberNumber)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // check mailbox quota
- OrganizationStatistics orgStats = GetOrganizationStatistics(itemId);
- if ((orgStats.AllocatedMailboxes > -1) && (orgStats.CreatedMailboxes >= orgStats.AllocatedMailboxes))
- return BusinessErrorCodes.ERROR_EXCHANGE_MAILBOXES_QUOTA_LIMIT;
-
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "CREATE_MAILBOX");
- TaskManager.ItemId = itemId;
- bool userCreated = false;
- Organization org = null;
- try
- {
- accountName = accountName.Trim();
- displayName = displayName.Trim();
- name = name.Trim();
- domain = domain.Trim();
-
-
- // load organization
- org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // e-mail
- string email = name + "@" + domain;
- bool enabled = (accountType == ExchangeAccountType.Mailbox);
-
-
- // string accountName = string.Empty;
- //Create AD user if needed
- if (accountId == 0)
- {
- accountId = OrganizationController.CreateUser(org.Id, displayName, name, domain, password, subscriberNumber, enabled, false, string.Empty, out accountName);
- if (accountId > 0)
- userCreated = true;
- }
- if (accountId < 0)
- return accountId;
-
- // get mailbox settings
- Organizations orgProxy = OrganizationController.GetOrganizationProxy(org.ServiceId);
- OrganizationUser retUser = orgProxy.GetUserGeneralSettings(accountName, org.OrganizationId);
-
-
- int exchangeServiceId = PackageController.GetPackageServiceId(org.PackageId, ResourceGroups.Exchange);
-
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
-
- //Create Exchange Organization
- if (string.IsNullOrEmpty(org.GlobalAddressList))
- {
- ExtendToExchangeOrganization(ref org);
-
- PackageController.UpdatePackageItem(org);
- }
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- //verify if the mailbox fits in the storage quota
- // load package context
- PackageContext cntx = PackageController.GetPackageContext(org.PackageId);
-
- int maxDiskSpace = -1;
- int quotaUsed = 0;
- if (cntx.Quotas.ContainsKey(Quotas.EXCHANGE2007_DISKSPACE)
- && cntx.Quotas[Quotas.EXCHANGE2007_DISKSPACE].QuotaAllocatedValue > 0)
- {
- maxDiskSpace = cntx.Quotas[Quotas.EXCHANGE2007_DISKSPACE].QuotaAllocatedValue;
- quotaUsed = cntx.Quotas[Quotas.EXCHANGE2007_DISKSPACE].QuotaUsedValue;
- }
-
- ExchangeMailboxPlan plan = GetExchangeMailboxPlan(itemId, mailboxPlanId);
- if (maxDiskSpace != -1)
- {
- if (plan.MailboxSizeMB == -1)
- return BusinessErrorCodes.ERROR_EXCHANGE_STORAGE_QUOTAS_EXCEED_HOST_VALUES;
-
- if ((quotaUsed + plan.MailboxSizeMB) > (maxDiskSpace))
- return BusinessErrorCodes.ERROR_EXCHANGE_STORAGE_QUOTAS_EXCEED_HOST_VALUES;
- }
-
- int maxRecoverableItemsSpace = -1;
- int quotaRecoverableItemsUsed = 0;
- if (cntx.Quotas.ContainsKey(Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE)
- && cntx.Quotas[Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE].QuotaAllocatedValue > 0)
- {
- maxRecoverableItemsSpace = cntx.Quotas[Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE].QuotaAllocatedValue;
- quotaRecoverableItemsUsed = cntx.Quotas[Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE].QuotaUsedValue;
- }
-
- if (maxRecoverableItemsSpace != -1)
- {
- if (plan.RecoverableItemsSpace == -1)
- return BusinessErrorCodes.ERROR_EXCHANGE_STORAGE_QUOTAS_EXCEED_HOST_VALUES;
-
- if ((quotaRecoverableItemsUsed + plan.RecoverableItemsSpace) > (maxRecoverableItemsSpace))
- return BusinessErrorCodes.ERROR_EXCHANGE_STORAGE_QUOTAS_EXCEED_HOST_VALUES;
- }
-
-
- //GetServiceSettings
- StringDictionary primSettings = ServerController.GetServiceSettings(exchangeServiceId);
-
- string samAccount = exchange.CreateMailEnableUser(email, org.OrganizationId, org.DistinguishedName, accountType, primSettings["mailboxdatabase"],
- org.OfflineAddressBook,
- org.AddressBookPolicy,
- retUser.SamAccountName,
- plan.EnablePOP,
- plan.EnableIMAP,
- plan.EnableOWA,
- plan.EnableMAPI,
- plan.EnableActiveSync,
- plan.MailboxSizeMB != -1 ? (((long)plan.IssueWarningPct * (long)plan.MailboxSizeMB * 1024) / 100) : -1,
- plan.MailboxSizeMB != -1 ? (((long)plan.ProhibitSendPct * (long)plan.MailboxSizeMB * 1024) / 100) : -1,
- plan.MailboxSizeMB != -1 ? (((long)plan.ProhibitSendReceivePct * (long)plan.MailboxSizeMB * 1024) / 100) : -1,
- plan.KeepDeletedItemsDays,
- plan.MaxRecipients,
- plan.MaxSendMessageSizeKB,
- plan.MaxReceiveMessageSizeKB,
- plan.HideFromAddressBook,
- Convert.ToBoolean(cntx.Quotas[Quotas.EXCHANGE2007_ISCONSUMER].QuotaAllocatedValue),
- plan.AllowLitigationHold,
- plan.RecoverableItemsSpace != -1 ? (plan.RecoverableItemsSpace * 1024) : -1,
- plan.RecoverableItemsSpace != -1 ? (((long)plan.RecoverableItemsWarningPct * (long)plan.RecoverableItemsSpace * 1024) / 100) : -1);
-
- MailboxManagerActions pmmActions = MailboxManagerActions.GeneralSettings
- | MailboxManagerActions.MailFlowSettings
- | MailboxManagerActions.AdvancedSettings
- | MailboxManagerActions.EmailAddresses;
-
-
- UpdateExchangeAccount(accountId, accountName, accountType, displayName, email, false, pmmActions.ToString(), samAccount, password, mailboxPlanId, subscriberNumber);
-
-
-
- // send setup instructions
- if (sendSetupInstructions)
- {
- try
- {
- // send setup instructions
- int sendResult = SendMailboxSetupInstructions(itemId, accountId, true, setupInstructionMailAddress, null);
- if (sendResult < 0)
- TaskManager.WriteWarning("Setup instructions were not sent. Error code: " + sendResult);
- }
- catch (Exception ex)
- {
- TaskManager.WriteError(ex);
- }
- }
-
- try
- {
- // update OAB
- // check if this is the first mailbox within the organization
- if (GetAccounts(itemId, ExchangeAccountType.Mailbox).Count == 1)
- exchange.UpdateOrganizationOfflineAddressBook(org.OfflineAddressBook);
- }
- catch (Exception ex)
- {
- TaskManager.WriteError(ex);
- }
-
- return accountId;
- }
- catch (Exception ex)
- {
- //rollback AD user
- if (userCreated)
- {
- try
- {
- OrganizationController.DeleteUser(org.Id, accountId);
- }
- catch (Exception rollbackException)
- {
- TaskManager.WriteError(rollbackException);
- }
- }
- throw TaskManager.WriteError(ex);
-
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int DisableMailbox(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", "DISABLE_MAILBOX");
- TaskManager.ItemId = 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);
-
- account.AccountType = ExchangeAccountType.User;
- account.MailEnabledPublicFolder = false;
- account.AccountPassword = null;
- UpdateAccount(account);
- DataProvider.DeleteUserEmailAddresses(account.AccountId, account.PrimaryEmailAddress);
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
-
- public static int DeleteMailbox(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", "DELETE_MAILBOX");
- TaskManager.ItemId = 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.DeleteMailbox(account.UserPrincipalName);
-
-
-
- // unregister account
- DeleteAccount(itemId, accountId);
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- private static ExchangeMailbox GetDemoMailboxSettings()
- {
- ExchangeMailbox mb = new ExchangeMailbox();
- mb.DisplayName = "John Smith";
- mb.Domain = "HSTDEXCH1";
- mb.AccountName = "john_fabrikam";
- mb.EnableForwarding = true;
- mb.EnableIMAP = true;
- mb.EnableMAPI = true;
- mb.EnablePOP = true;
- mb.FirstName = "John";
- mb.LastName = "Smith";
- mb.ForwardingAccount = GetAccounts(0, ExchangeAccountType.Mailbox)[1];
- mb.EnableForwarding = true;
- mb.IssueWarningKB = 150000;
- mb.KeepDeletedItemsDays = 14;
- mb.LastLogoff = DateTime.Now;
- mb.LastLogon = DateTime.Now;
- mb.ManagerAccount = GetAccounts(0, ExchangeAccountType.Mailbox)[1];
- mb.MaxReceiveMessageSizeKB = 20000;
- mb.MaxRecipients = 30;
- mb.MaxSendMessageSizeKB = 10000;
- mb.ProhibitSendKB = 160000;
- mb.ProhibitSendReceiveKB = 170000;
- mb.TotalItems = 5;
- mb.TotalSizeMB = 4;
- return mb;
- }
-
- public static ExchangeMailbox GetMailboxGeneralSettings(int itemId, int accountId)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- return GetDemoMailboxSettings();
- }
- #endregion
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_MAILBOX_GENERAL");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return null;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // get mailbox settings
-
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
- return exchange.GetMailboxGeneralSettings(account.UserPrincipalName);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int SetMailboxGeneralSettings(int itemId, int accountId, bool hideAddressBook, bool disabled)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "UPDATE_MAILBOX_GENERAL");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // get mailbox settings
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
-
- PackageContext cntx = PackageController.GetPackageContext(org.PackageId);
-
- if (Convert.ToBoolean(cntx.Quotas[Quotas.EXCHANGE2007_ISCONSUMER].QuotaAllocatedValue))
- hideAddressBook = true;
-
- exchange.SetMailboxGeneralSettings(
- account.UserPrincipalName,
- hideAddressBook,
- disabled);
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static ExchangeEmailAddress[] GetMailboxEmailAddresses(int itemId, int accountId)
- {
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_MAILBOX_ADDRESSES");
- TaskManager.ItemId = itemId;
-
- try
- {
- return GetAccountEmailAddresses(itemId, accountId);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int AddMailboxEmailAddress(int itemId, int accountId, string emailAddress)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "ADD_MAILBOX_ADDRESS");
- TaskManager.ItemId = itemId;
-
- try
- {
- // check
- if (EmailAddressExists(emailAddress))
- return BusinessErrorCodes.ERROR_EXCHANGE_EMAIL_EXISTS;
-
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // add e-mail
- AddAccountEmailAddress(accountId, emailAddress);
-
- // update e-mail addresses
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.SetMailboxEmailAddresses(
- account.UserPrincipalName,
- GetAccountSimpleEmailAddresses(itemId, accountId));
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- private static OCSServer GetOCSProxy(int itemId)
- {
- Organization org = OrganizationController.GetOrganization(itemId);
- int serviceId = PackageController.GetPackageServiceId(org.PackageId, ResourceGroups.OCS);
-
- OCSServer ocs = new OCSServer();
- ServiceProviderProxy.Init(ocs, serviceId);
-
-
- return ocs;
- }
-
- public static int SetMailboxPrimaryEmailAddress(int itemId, int accountId, string emailAddress)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "SET_PRIMARY_MAILBOX_ADDRESS");
- TaskManager.ItemId = itemId;
-
- try
- {
- // get account
- ExchangeAccount account = GetAccount(itemId, accountId);
- account.PrimaryEmailAddress = emailAddress;
-
- // update exchange
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.SetMailboxPrimaryEmailAddress(
- account.UserPrincipalName,
- emailAddress);
-
- if (DataProvider.CheckOCSUserExists(account.AccountId))
- {
- OCSServer ocs = GetOCSProxy(itemId);
- string instanceId = DataProvider.GetOCSUserInstanceID(account.AccountId);
- ocs.SetUserPrimaryUri(instanceId, emailAddress);
- }
-
- if (DataProvider.CheckLyncUserExists(account.AccountId))
- {
- LyncController.SetLyncUserGeneralSettings(itemId, accountId, emailAddress, null);
- }
-
- // save account
- account.AccountPassword = null;
- UpdateAccount(account);
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int DeleteMailboxEmailAddresses(int itemId, int accountId, string[] emailAddresses)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "DELETE_MAILBOX_ADDRESSES");
- TaskManager.ItemId = itemId;
-
- try
- {
- // get account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // delete e-mail addresses
- List toDelete = new List();
- foreach (string emailAddress in emailAddresses)
- {
- if ((String.Compare(account.PrimaryEmailAddress, emailAddress, true) != 0) &
- (String.Compare(account.UserPrincipalName, emailAddress, true) != 0))
- toDelete.Add(emailAddress);
- }
-
- // delete from meta-base
- DeleteAccountEmailAddresses(accountId, toDelete.ToArray());
-
- // delete from Exchange
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // update e-mail addresses
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.SetMailboxEmailAddresses(
- account.UserPrincipalName,
- GetAccountSimpleEmailAddresses(itemId, accountId));
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static ExchangeMailbox GetMailboxMailFlowSettings(int itemId, int accountId)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- return GetDemoMailboxSettings();
- }
- #endregion
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_MAILBOX_MAILFLOW");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return null;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // get mailbox settings
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
- ExchangeMailbox mailbox = exchange.GetMailboxMailFlowSettings(account.UserPrincipalName);
- mailbox.DisplayName = account.DisplayName;
- return mailbox;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int SetMailboxMailFlowSettings(int itemId, int accountId,
- bool enableForwarding, string forwardingAccountName, bool forwardToBoth,
- string[] sendOnBehalfAccounts, string[] acceptAccounts, string[] rejectAccounts,
- bool requireSenderAuthentication)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "UPDATE_MAILBOX_MAILFLOW");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // get mailbox settings
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.SetMailboxMailFlowSettings(account.UserPrincipalName,
- enableForwarding,
- forwardingAccountName,
- forwardToBoth,
- sendOnBehalfAccounts,
- acceptAccounts,
- rejectAccounts,
- requireSenderAuthentication);
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
-
- public static ExchangeMailbox GetMailboxAdvancedSettings(int itemId, int accountId)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- return GetDemoMailboxSettings();
- }
- #endregion
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_MAILBOX_ADVANCED");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return null;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // get mailbox settings
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
- ExchangeMailbox mailbox = exchange.GetMailboxAdvancedSettings(account.UserPrincipalName);
- mailbox.DisplayName = account.DisplayName;
- return mailbox;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int SetMailboxManagerSettings(int itemId, int accountId, bool pmmAllowed, MailboxManagerActions action)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "UPDATE_MAILBOX_GENERAL");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // PMM settings
- if (pmmAllowed) account.MailboxManagerActions |= action;
- else account.MailboxManagerActions &= ~action;
-
- // update account
- account.AccountPassword = null;
- UpdateAccount(account);
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static string GetMailboxSetupInstructions(int itemId, int accountId, bool pmm, bool emailMode, bool signup)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- return string.Empty;
- }
- #endregion
-
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return null;
-
- // load user info
- UserInfo user = PackageController.GetPackageOwner(org.PackageId);
-
- // get letter settings
- UserSettings settings = UserController.GetUserSettings(user.UserId, UserSettings.EXCHANGE_MAILBOX_SETUP_LETTER);
-
- string settingName = user.HtmlMail ? "HtmlBody" : "TextBody";
- string body = settings[settingName];
- if (String.IsNullOrEmpty(body))
- return null;
-
- string result = EvaluateMailboxTemplate(itemId, accountId, pmm, false, false, body);
- return user.HtmlMail ? result : result.Replace("\n", "
");
- }
-
- private static string EvaluateMailboxTemplate(int itemId, int accountId,
- bool pmm, bool emailMode, bool signup, string template)
- {
- Hashtable items = new Hashtable();
-
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return null;
-
- // add organization
- items["Organization"] = org;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
- if (account == null)
- return null;
-
- // add account
- items["Account"] = account;
- items["AccountDomain"] = account.PrimaryEmailAddress.Substring(account.PrimaryEmailAddress.IndexOf("@") + 1);
- items["DefaultDomain"] = org.DefaultDomain;
-
- if (!String.IsNullOrEmpty(account.SamAccountName))
- {
- int idx = account.SamAccountName.IndexOf("\\");
- items["SamDomain"] = account.SamAccountName.Substring(0, idx);
- items["SamUsername"] = account.SamAccountName.Substring(idx + 1);
- }
-
- // name servers
- PackageSettings packageSettings = PackageController.GetPackageSettings(org.PackageId, PackageSettings.NAME_SERVERS);
- string[] nameServers = new string[] { };
- if (!String.IsNullOrEmpty(packageSettings["NameServers"]))
- nameServers = packageSettings["NameServers"].Split(';');
-
- items["NameServers"] = nameServers;
-
- // service settings
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- StringDictionary exchangeSettings = ServerController.GetServiceSettings(exchangeServiceId);
- if (exchangeSettings != null)
- {
- items["TempDomain"] = exchangeSettings["TempDomain"];
- items["AutodiscoverIP"] = exchangeSettings["AutodiscoverIP"];
- items["AutodiscoverDomain"] = exchangeSettings["AutodiscoverDomain"];
- items["OwaUrl"] = exchangeSettings["OwaUrl"];
- items["ActiveSyncServer"] = exchangeSettings["ActiveSyncServer"];
- items["SmtpServers"] = Utils.ParseDelimitedString(exchangeSettings["SmtpServers"], '\n');
- }
-
- items["Email"] = emailMode;
- items["Signup"] = signup;
- items["PMM"] = pmm;
-
- // evaluate template
- return PackageController.EvaluateTemplate(template, items);
- }
-
- public static int SendMailboxSetupInstructions(int itemId, int accountId, bool signup, string to, string cc)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);
- if (accountCheck < 0) return accountCheck;
-
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // load user info
- UserInfo user = PackageController.GetPackageOwner(org.PackageId);
-
- // get letter settings
- UserSettings settings = UserController.GetUserSettings(user.UserId, UserSettings.EXCHANGE_MAILBOX_SETUP_LETTER);
-
- string from = settings["From"];
- if (cc == null)
- cc = settings["CC"];
- string subject = settings["Subject"];
- string body = user.HtmlMail ? settings["HtmlBody"] : settings["TextBody"];
- bool isHtml = user.HtmlMail;
-
- MailPriority priority = MailPriority.Normal;
- if (!String.IsNullOrEmpty(settings["Priority"]))
- priority = (MailPriority)Enum.Parse(typeof(MailPriority), settings["Priority"], true);
-
- if (String.IsNullOrEmpty(body))
- return 0;// BusinessErrorCodes.ERROR_SETTINGS_ACCOUNT_LETTER_EMPTY_BODY;
-
- // load user info
- if (to == null)
- to = user.Email;
-
- subject = EvaluateMailboxTemplate(itemId, accountId, false, true, signup, subject);
- body = EvaluateMailboxTemplate(itemId, accountId, false, true, signup, body);
-
- // send message
- return MailHelper.SendMessage(from, to, cc, subject, body, priority, isHtml);
- }
-
-
- public static ExchangeMailbox GetMailboxPermissions(int itemId, int accountId)
- {
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_MAILBOX_PERMISSIONS");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return null;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // get mailbox settings
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
- ExchangeMailbox mailbox = exchange.GetMailboxPermissions(org.OrganizationId, account.UserPrincipalName);
- mailbox.DisplayName = account.DisplayName;
- return mailbox;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int SetMailboxPermissions(int itemId, int accountId, string[] sendAsaccounts, string[] fullAccessAcounts)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "SET_MAILBOX_PERMISSIONS");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // get mailbox settings
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.SetMailboxPermissions(org.OrganizationId, account.UserPrincipalName, sendAsaccounts, fullAccessAcounts);
-
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
-
- }
-
-
- #endregion
-
-
- #region Mailbox plan
- public static int SetExchangeMailboxPlan(int itemId, int accountId, int mailboxPlanId)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "SET_MAILBOXPLAN");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // load package context
- PackageContext cntx = PackageController.GetPackageContext(org.PackageId);
-
- int maxDiskSpace = -1;
- int quotaUsed = 0;
- if (cntx.Quotas.ContainsKey(Quotas.EXCHANGE2007_DISKSPACE)
- && cntx.Quotas[Quotas.EXCHANGE2007_DISKSPACE].QuotaAllocatedValue > 0)
- {
- maxDiskSpace = cntx.Quotas[Quotas.EXCHANGE2007_DISKSPACE].QuotaAllocatedValue;
- quotaUsed = cntx.Quotas[Quotas.EXCHANGE2007_DISKSPACE].QuotaUsedValue;
- }
-
- ExchangeMailboxPlan plan = GetExchangeMailboxPlan(itemId, mailboxPlanId);
-
- if (maxDiskSpace != -1)
- {
- if (plan.MailboxSizeMB == -1)
- return BusinessErrorCodes.ERROR_EXCHANGE_STORAGE_QUOTAS_EXCEED_HOST_VALUES;
-
- ExchangeAccount exchangeAccount = GetAccount(itemId, accountId);
- if (exchangeAccount.MailboxPlanId > 0)
- {
- ExchangeMailboxPlan oldPlan = GetExchangeMailboxPlan(itemId, exchangeAccount.MailboxPlanId);
-
- if (((quotaUsed - oldPlan.MailboxSizeMB) + plan.MailboxSizeMB) > (maxDiskSpace))
- return BusinessErrorCodes.ERROR_EXCHANGE_STORAGE_QUOTAS_EXCEED_HOST_VALUES;
- }
- else
- {
- if ((quotaUsed + plan.MailboxSizeMB) > (maxDiskSpace))
- return BusinessErrorCodes.ERROR_EXCHANGE_STORAGE_QUOTAS_EXCEED_HOST_VALUES;
- }
- }
-
- int maxRecoverableItemsSpace = -1;
- int quotaRecoverableItemsUsed = 0;
- if (cntx.Quotas.ContainsKey(Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE)
- && cntx.Quotas[Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE].QuotaAllocatedValue > 0)
- {
- maxRecoverableItemsSpace = cntx.Quotas[Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE].QuotaAllocatedValue;
- quotaRecoverableItemsUsed = cntx.Quotas[Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE].QuotaUsedValue;
- }
-
- if (maxRecoverableItemsSpace != -1)
- {
- if (plan.RecoverableItemsSpace == -1)
- return BusinessErrorCodes.ERROR_EXCHANGE_STORAGE_QUOTAS_EXCEED_HOST_VALUES;
-
- if ((quotaRecoverableItemsUsed + plan.RecoverableItemsSpace) > (maxRecoverableItemsSpace))
- return BusinessErrorCodes.ERROR_EXCHANGE_STORAGE_QUOTAS_EXCEED_HOST_VALUES;
- }
-
- // get mailbox settings
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.SetMailboxAdvancedSettings(
- org.OrganizationId,
- account.UserPrincipalName,
- plan.EnablePOP,
- plan.EnableIMAP,
- plan.EnableOWA,
- plan.EnableMAPI,
- plan.EnableActiveSync,
- plan.MailboxSizeMB != -1 ? (((long)plan.IssueWarningPct * (long)plan.MailboxSizeMB * 1024) / 100) : -1,
- plan.MailboxSizeMB != -1 ? (((long)plan.ProhibitSendPct * (long)plan.MailboxSizeMB * 1024) / 100) : -1,
- plan.MailboxSizeMB != -1 ? (((long)plan.ProhibitSendReceivePct * (long)plan.MailboxSizeMB * 1024) / 100) : -1,
- plan.KeepDeletedItemsDays,
- plan.MaxRecipients,
- plan.MaxSendMessageSizeKB,
- plan.MaxReceiveMessageSizeKB,
- plan.AllowLitigationHold,
- plan.RecoverableItemsSpace != -1 ? (plan.RecoverableItemsSpace * 1024) : -1,
- plan.RecoverableItemsSpace != -1 ? (((long)plan.RecoverableItemsWarningPct * (long)plan.RecoverableItemsSpace * 1024) / 100) : -1,
- plan.LitigationHoldUrl,
- plan.LitigationHoldMsg);
-
- DataProvider.SetExchangeAccountMailboxPlan(accountId, mailboxPlanId);
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static List GetExchangeMailboxPlans(int itemId)
- {
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_EXCHANGE_MAILBOXPLANS");
- TaskManager.ItemId = itemId;
-
- try
- {
- List mailboxPlans = new List();
-
- UserInfo user = ObjectUtils.FillObjectFromDataReader(DataProvider.GetUserByExchangeOrganizationIdInternally(itemId));
-
- if (user.Role == UserRole.User)
- ExchangeServerController.GetExchangeMailboxPlansByUser(itemId, user, ref mailboxPlans);
- else
- ExchangeServerController.GetExchangeMailboxPlansByUser(0, user, ref mailboxPlans);
-
-
- ExchangeOrganization ExchangeOrg = ObjectUtils.FillObjectFromDataReader(DataProvider.GetExchangeOrganization(itemId));
-
- if (ExchangeOrg != null)
- {
- foreach (ExchangeMailboxPlan p in mailboxPlans)
- {
- p.IsDefault = (p.MailboxPlanId == ExchangeOrg.ExchangeMailboxPlanID);
- }
- }
-
- return mailboxPlans;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- private static void GetExchangeMailboxPlansByUser(int itemId, UserInfo user, ref ListmailboxPlans)
- {
- if ((user != null))
- {
- List orgs = null;
-
- if (user.UserId != 1)
- {
- List Packages = PackageController.GetPackages(user.UserId);
-
- if ((Packages != null) & (Packages.Count > 0))
- {
- orgs = GetExchangeOrganizationsInternal(Packages[0].PackageId, false);
- }
- }
- else
- {
- orgs = GetExchangeOrganizationsInternal(1, false);
- }
-
- int OrgId = -1;
- if (itemId > 0) OrgId = itemId;
- else if ((orgs != null) & (orgs.Count > 0)) OrgId = orgs[0].Id;
-
-
- if (OrgId != -1)
- {
- List Plans = ObjectUtils.CreateListFromDataReader(DataProvider.GetExchangeMailboxPlans(OrgId));
-
- foreach (ExchangeMailboxPlan p in Plans)
- {
- mailboxPlans.Add(p);
- }
- }
-
- UserInfo owner = UserController.GetUserInternally(user.OwnerId);
-
- GetExchangeMailboxPlansByUser(0, owner, ref mailboxPlans);
- }
- }
-
-
- public static ExchangeMailboxPlan GetExchangeMailboxPlan(int itemID, int mailboxPlanId)
- {
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_EXCHANGE_MAILBOXPLAN");
- TaskManager.ItemId = mailboxPlanId;
-
- try
- {
- return ObjectUtils.FillObjectFromDataReader(
- DataProvider.GetExchangeMailboxPlan(mailboxPlanId));
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int AddExchangeMailboxPlan(int itemID, ExchangeMailboxPlan mailboxPlan)
- {
- // place log record
- TaskManager.StartTask("EXCHANGE", "ADD_EXCHANGE_MAILBOXPLAN");
- TaskManager.ItemId = itemID;
-
- try
- {
- Organization org = GetOrganization(itemID);
- if (org == null)
- return -1;
-
- // load package context
- PackageContext cntx = PackageController.GetPackageContext(org.PackageId);
-
- if (org.PackageId > 1)
- {
- mailboxPlan.EnableActiveSync = mailboxPlan.EnableActiveSync & Convert.ToBoolean(cntx.Quotas[Quotas.EXCHANGE2007_ACTIVESYNCALLOWED].QuotaAllocatedValue);
- mailboxPlan.EnableIMAP = mailboxPlan.EnableIMAP & Convert.ToBoolean(cntx.Quotas[Quotas.EXCHANGE2007_IMAPALLOWED].QuotaAllocatedValue);
- mailboxPlan.EnableMAPI = mailboxPlan.EnableMAPI & Convert.ToBoolean(cntx.Quotas[Quotas.EXCHANGE2007_MAPIALLOWED].QuotaAllocatedValue);
- mailboxPlan.EnableOWA = mailboxPlan.EnableOWA & Convert.ToBoolean(cntx.Quotas[Quotas.EXCHANGE2007_OWAALLOWED].QuotaAllocatedValue);
- mailboxPlan.EnablePOP = mailboxPlan.EnablePOP & Convert.ToBoolean(cntx.Quotas[Quotas.EXCHANGE2007_POP3ALLOWED].QuotaAllocatedValue);
-
- if (cntx.Quotas[Quotas.EXCHANGE2007_KEEPDELETEDITEMSDAYS].QuotaAllocatedValue != -1)
- if (mailboxPlan.KeepDeletedItemsDays > cntx.Quotas[Quotas.EXCHANGE2007_KEEPDELETEDITEMSDAYS].QuotaAllocatedValue)
- mailboxPlan.KeepDeletedItemsDays = cntx.Quotas[Quotas.EXCHANGE2007_KEEPDELETEDITEMSDAYS].QuotaAllocatedValue;
-
- if (cntx.Quotas[Quotas.EXCHANGE2007_DISKSPACE].QuotaAllocatedValue != -1)
- if (mailboxPlan.MailboxSizeMB > cntx.Quotas[Quotas.EXCHANGE2007_DISKSPACE].QuotaAllocatedValue)
- mailboxPlan.MailboxSizeMB = cntx.Quotas[Quotas.EXCHANGE2007_DISKSPACE].QuotaAllocatedValue;
-
- if (cntx.Quotas[Quotas.EXCHANGE2007_MAXRECEIVEMESSAGESIZEKB].QuotaAllocatedValue != -1)
- if (mailboxPlan.MaxReceiveMessageSizeKB > cntx.Quotas[Quotas.EXCHANGE2007_MAXRECEIVEMESSAGESIZEKB].QuotaAllocatedValue)
- mailboxPlan.MaxReceiveMessageSizeKB = cntx.Quotas[Quotas.EXCHANGE2007_MAXRECEIVEMESSAGESIZEKB].QuotaAllocatedValue;
-
- if (cntx.Quotas[Quotas.EXCHANGE2007_MAXSENDMESSAGESIZEKB].QuotaAllocatedValue != -1)
- if (mailboxPlan.MaxSendMessageSizeKB > cntx.Quotas[Quotas.EXCHANGE2007_MAXSENDMESSAGESIZEKB].QuotaAllocatedValue)
- mailboxPlan.MaxSendMessageSizeKB = cntx.Quotas[Quotas.EXCHANGE2007_MAXSENDMESSAGESIZEKB].QuotaAllocatedValue;
-
- if (cntx.Quotas[Quotas.EXCHANGE2007_MAXRECIPIENTS].QuotaAllocatedValue != -1)
- if (mailboxPlan.MaxRecipients > cntx.Quotas[Quotas.EXCHANGE2007_MAXRECIPIENTS].QuotaAllocatedValue)
- mailboxPlan.MaxRecipients = cntx.Quotas[Quotas.EXCHANGE2007_MAXRECIPIENTS].QuotaAllocatedValue;
-
- if (Convert.ToBoolean(cntx.Quotas[Quotas.EXCHANGE2007_ISCONSUMER].QuotaAllocatedValue)) mailboxPlan.HideFromAddressBook = true;
-
- mailboxPlan.AllowLitigationHold = mailboxPlan.AllowLitigationHold & Convert.ToBoolean(cntx.Quotas[Quotas.EXCHANGE2007_ALLOWLITIGATIONHOLD].QuotaAllocatedValue);
-
- if (cntx.Quotas[Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE].QuotaAllocatedValue != -1)
- if (mailboxPlan.RecoverableItemsSpace > cntx.Quotas[Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE].QuotaAllocatedValue)
- mailboxPlan.RecoverableItemsSpace = cntx.Quotas[Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE].QuotaAllocatedValue;
- }
-
- return DataProvider.AddExchangeMailboxPlan(itemID, mailboxPlan.MailboxPlan, mailboxPlan.EnableActiveSync, mailboxPlan.EnableIMAP, mailboxPlan.EnableMAPI, mailboxPlan.EnableOWA, mailboxPlan.EnablePOP,
- 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);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
-
- }
-
-
- public static int UpdateExchangeMailboxPlan(int itemID, ExchangeMailboxPlan mailboxPlan)
- {
- // place log record
- TaskManager.StartTask("EXCHANGE", "UPDATE_EXCHANGE_MAILBOXPLAN");
- TaskManager.ItemId = itemID;
-
- try
- {
- Organization org = GetOrganization(itemID);
- if (org == null)
- return -1;
-
- // load package context
- PackageContext cntx = PackageController.GetPackageContext(org.PackageId);
-
- if (org.PackageId > 1)
- {
- mailboxPlan.EnableActiveSync = mailboxPlan.EnableActiveSync & Convert.ToBoolean(cntx.Quotas[Quotas.EXCHANGE2007_ACTIVESYNCALLOWED].QuotaAllocatedValue);
- mailboxPlan.EnableIMAP = mailboxPlan.EnableIMAP & Convert.ToBoolean(cntx.Quotas[Quotas.EXCHANGE2007_IMAPALLOWED].QuotaAllocatedValue);
- mailboxPlan.EnableMAPI = mailboxPlan.EnableMAPI & Convert.ToBoolean(cntx.Quotas[Quotas.EXCHANGE2007_MAPIALLOWED].QuotaAllocatedValue);
- mailboxPlan.EnableOWA = mailboxPlan.EnableOWA & Convert.ToBoolean(cntx.Quotas[Quotas.EXCHANGE2007_OWAALLOWED].QuotaAllocatedValue);
- mailboxPlan.EnablePOP = mailboxPlan.EnablePOP & Convert.ToBoolean(cntx.Quotas[Quotas.EXCHANGE2007_POP3ALLOWED].QuotaAllocatedValue);
-
- if (cntx.Quotas[Quotas.EXCHANGE2007_KEEPDELETEDITEMSDAYS].QuotaAllocatedValue != -1)
- if (mailboxPlan.KeepDeletedItemsDays > cntx.Quotas[Quotas.EXCHANGE2007_KEEPDELETEDITEMSDAYS].QuotaAllocatedValue)
- mailboxPlan.KeepDeletedItemsDays = cntx.Quotas[Quotas.EXCHANGE2007_KEEPDELETEDITEMSDAYS].QuotaAllocatedValue;
-
- if (cntx.Quotas[Quotas.EXCHANGE2007_DISKSPACE].QuotaAllocatedValue != -1)
- if (mailboxPlan.MailboxSizeMB > cntx.Quotas[Quotas.EXCHANGE2007_DISKSPACE].QuotaAllocatedValue)
- mailboxPlan.MailboxSizeMB = cntx.Quotas[Quotas.EXCHANGE2007_DISKSPACE].QuotaAllocatedValue;
-
- if (cntx.Quotas[Quotas.EXCHANGE2007_MAXRECEIVEMESSAGESIZEKB].QuotaAllocatedValue != -1)
- if (mailboxPlan.MaxReceiveMessageSizeKB > cntx.Quotas[Quotas.EXCHANGE2007_MAXRECEIVEMESSAGESIZEKB].QuotaAllocatedValue)
- mailboxPlan.MaxReceiveMessageSizeKB = cntx.Quotas[Quotas.EXCHANGE2007_MAXRECEIVEMESSAGESIZEKB].QuotaAllocatedValue;
-
- if (cntx.Quotas[Quotas.EXCHANGE2007_MAXSENDMESSAGESIZEKB].QuotaAllocatedValue != -1)
- if (mailboxPlan.MaxSendMessageSizeKB > cntx.Quotas[Quotas.EXCHANGE2007_MAXSENDMESSAGESIZEKB].QuotaAllocatedValue)
- mailboxPlan.MaxSendMessageSizeKB = cntx.Quotas[Quotas.EXCHANGE2007_MAXSENDMESSAGESIZEKB].QuotaAllocatedValue;
-
- if (cntx.Quotas[Quotas.EXCHANGE2007_MAXRECIPIENTS].QuotaAllocatedValue != -1)
- if (mailboxPlan.MaxRecipients > cntx.Quotas[Quotas.EXCHANGE2007_MAXRECIPIENTS].QuotaAllocatedValue)
- mailboxPlan.MaxRecipients = cntx.Quotas[Quotas.EXCHANGE2007_MAXRECIPIENTS].QuotaAllocatedValue;
-
- if (Convert.ToBoolean(cntx.Quotas[Quotas.EXCHANGE2007_ISCONSUMER].QuotaAllocatedValue)) mailboxPlan.HideFromAddressBook = true;
-
- mailboxPlan.AllowLitigationHold = mailboxPlan.AllowLitigationHold & Convert.ToBoolean(cntx.Quotas[Quotas.EXCHANGE2007_ALLOWLITIGATIONHOLD].QuotaAllocatedValue);
-
- if (cntx.Quotas[Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE].QuotaAllocatedValue != -1)
- if (mailboxPlan.RecoverableItemsSpace > cntx.Quotas[Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE].QuotaAllocatedValue)
- mailboxPlan.RecoverableItemsSpace = cntx.Quotas[Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE].QuotaAllocatedValue;
-
- }
-
- DataProvider.UpdateExchangeMailboxPlan(mailboxPlan.MailboxPlanId, mailboxPlan.MailboxPlan, mailboxPlan.EnableActiveSync, mailboxPlan.EnableIMAP, mailboxPlan.EnableMAPI, mailboxPlan.EnableOWA, mailboxPlan.EnablePOP,
- 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);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
-
-
- return 0;
- }
-
-
-
- public static int DeleteExchangeMailboxPlan(int itemID, int mailboxPlanId)
- {
- TaskManager.StartTask("EXCHANGE", "DELETE_EXCHANGE_MAILBOXPLAN");
- TaskManager.ItemId = itemID;
-
- try
- {
- DataProvider.DeleteExchangeMailboxPlan(mailboxPlanId);
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
-
- }
-
- public static void SetOrganizationDefaultExchangeMailboxPlan(int itemId, int mailboxPlanId)
- {
- TaskManager.StartTask("EXCHANGE", "SET_EXCHANGE_MAILBOXPLAN");
- TaskManager.ItemId = itemId;
-
- try
- {
- DataProvider.SetOrganizationDefaultExchangeMailboxPlan(itemId, mailboxPlanId);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
-
- }
-
-
-
- #endregion
-
-
- #region Contacts
- public static int CreateContact(int itemId, string displayName, string email)
- {
- //if (EmailAddressExists(email))
- // return BusinessErrorCodes.ERROR_EXCHANGE_EMAIL_EXISTS;
-
-
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // check mailbox quota
- OrganizationStatistics orgStats = GetOrganizationStatistics(itemId);
- if (orgStats.AllocatedContacts > -1
- && orgStats.CreatedContacts >= orgStats.AllocatedContacts)
- return BusinessErrorCodes.ERROR_EXCHANGE_CONTACTS_QUOTA_LIMIT;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "CREATE_CONTACT");
- TaskManager.ItemId = itemId;
-
- try
- {
-
- displayName = displayName.Trim();
- email = email.Trim();
-
- // load organization
- Organization org = GetOrganization(itemId);
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- string name = email;
- int idx = email.IndexOf("@");
- if (idx > -1)
- name = email.Substring(0, idx);
-
- string accountName = BuildAccountName(org.OrganizationId, name);
-
- // add contact
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- //Create Exchange Organization
- if (string.IsNullOrEmpty(org.GlobalAddressList))
- {
- ExtendToExchangeOrganization(ref org);
-
- PackageController.UpdatePackageItem(org);
- }
-
- exchange.CreateContact(
- org.OrganizationId,
- org.DistinguishedName,
- displayName,
- accountName,
- email, org.DefaultDomain);
-
- ExchangeContact contact = exchange.GetContactGeneralSettings(accountName);
-
- // add meta-item
- int accountId = AddAccount(itemId, ExchangeAccountType.Contact, accountName,
- displayName, email, false,
- 0, contact.SAMAccountName, null, 0, null);
-
- return accountId;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int DeleteContact(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", "DELETE_CONTACT");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // delete contact
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.DeleteContact(account.AccountName);
-
- // remove meta-item
- DeleteAccount(itemId, accountId);
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- private static ExchangeContact GetDemoContactSettings()
- {
- ExchangeContact c = new ExchangeContact();
- c.DisplayName = "WebsitePanel Support";
- c.AccountName = "wsp_fabrikam";
- c.FirstName = "WebsitePanel";
- c.LastName = "Support";
- c.EmailAddress = "support@websitepanel.net";
- c.AcceptAccounts = GetAccounts(0, ExchangeAccountType.Mailbox).ToArray();
- return c;
- }
-
- public static ExchangeContact GetContactGeneralSettings(int itemId, int accountId)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- return GetDemoContactSettings();
- }
- #endregion
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_CONTACT_GENERAL");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return null;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // get mailbox settings
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- return exchange.GetContactGeneralSettings(account.AccountName);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int SetContactGeneralSettings(int itemId, int accountId, string displayName, string emailAddress,
- bool hideAddressBook, string firstName, string initials,
- string lastName, string address, string city, string state, string zip, string country,
- string jobTitle, string company, string department, string office, string managerAccountName,
- string businessPhone, string fax, string homePhone, string mobilePhone, string pager,
- string webPage, string notes, int useMapiRichTextFormat)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "UPDATE_CONTACT_GENERAL");
- TaskManager.ItemId = itemId;
-
- try
- {
- displayName = displayName.Trim();
- emailAddress = emailAddress.Trim();
- firstName = firstName.Trim();
- lastName = lastName.Trim();
-
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // get mailbox settings
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.SetContactGeneralSettings(
- account.AccountName,
- displayName,
- emailAddress,
- hideAddressBook,
- firstName,
- initials,
- lastName,
- address,
- city,
- state,
- zip,
- country,
- jobTitle,
- company,
- department,
- office,
- managerAccountName,
- businessPhone,
- fax,
- homePhone,
- mobilePhone,
- pager,
- webPage,
- notes,
- useMapiRichTextFormat, org.DefaultDomain);
-
- // update account
- account.DisplayName = displayName;
- account.PrimaryEmailAddress = emailAddress;
- account.AccountPassword = null;
- UpdateAccount(account);
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static ExchangeContact GetContactMailFlowSettings(int itemId, int accountId)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- return GetDemoContactSettings();
- }
- #endregion
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_CONTACT_MAILFLOW");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return null;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // get mailbox settings
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- ExchangeContact contact = exchange.GetContactMailFlowSettings(account.AccountName);
- contact.DisplayName = account.DisplayName;
- return contact;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int SetContactMailFlowSettings(int itemId, int accountId,
- string[] acceptAccounts, string[] rejectAccounts, bool requireSenderAuthentication)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "UPDATE_CONTACT_MAILFLOW");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // get mailbox settings
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.SetContactMailFlowSettings(account.AccountName,
- acceptAccounts,
- rejectAccounts,
- requireSenderAuthentication);
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
- #endregion
-
- #region Distribution Lists
- public static int CreateDistributionList(int itemId, string displayName, string name, string domain, int managerId)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // check mailbox quota
- OrganizationStatistics orgStats = GetOrganizationStatistics(itemId);
- if (orgStats.AllocatedDistributionLists > -1
- && orgStats.CreatedDistributionLists >= orgStats.AllocatedDistributionLists)
- return BusinessErrorCodes.ERROR_EXCHANGE_DLISTS_QUOTA_LIMIT;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "CREATE_DISTR_LIST");
- TaskManager.ItemId = itemId;
-
- try
- {
- displayName = displayName.Trim();
- name = name.Trim();
- domain = domain.Trim();
-
- // e-mail
- string email = name + "@" + domain;
-
- // check e-mail
- if (EmailAddressExists(email))
- return BusinessErrorCodes.ERROR_EXCHANGE_EMAIL_EXISTS;
-
- // load organization
- Organization org = GetOrganization(itemId);
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- string accountName = BuildAccountName(org.OrganizationId, name);
-
- // add account
- // add contact
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- //Create Exchange Organization
- if (string.IsNullOrEmpty(org.GlobalAddressList))
- {
- ExtendToExchangeOrganization(ref org);
-
- PackageController.UpdatePackageItem(org);
- }
-
- OrganizationUser manager = OrganizationController.GetAccount(itemId, managerId);
-
- List addressLists = new List();
- addressLists.Add(org.GlobalAddressList);
- addressLists.Add(org.AddressList);
-
- exchange.CreateDistributionList(
- org.OrganizationId,
- org.DistinguishedName,
- displayName,
- accountName,
- name,
- domain, manager.SamAccountName, addressLists.ToArray());
-
- ExchangeDistributionList dl = exchange.GetDistributionListGeneralSettings(accountName);
-
- // add meta-item
- int accountId = AddAccount(itemId, ExchangeAccountType.DistributionList, email,
- displayName, email, false,
- 0, dl.SAMAccountName, null, 0, null);
-
- // register email address
- AddAccountEmailAddress(accountId, email);
-
- return accountId;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int DeleteDistributionList(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", "DELETE_DISTR_LIST");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // delete mailbox
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.DeleteDistributionList(account.AccountName);
-
- // unregister account
- DeleteAccount(itemId, accountId);
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- private static ExchangeDistributionList GetDemoDistributionListSettings()
- {
- ExchangeDistributionList c = new ExchangeDistributionList();
- c.DisplayName = "Fabrikam Sales";
- c.AccountName = "sales_fabrikam";
- c.ManagerAccount = GetAccounts(0, ExchangeAccountType.Mailbox)[0];
- c.MembersAccounts = GetAccounts(0, ExchangeAccountType.Mailbox).ToArray();
- c.AcceptAccounts = GetAccounts(0, ExchangeAccountType.Mailbox).ToArray();
- return c;
- }
-
- public static ExchangeDistributionList GetDistributionListGeneralSettings(int itemId, int accountId)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- return GetDemoDistributionListSettings();
- }
- #endregion
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_DISTR_LIST_GENERAL");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return null;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // get mailbox settings
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- return exchange.GetDistributionListGeneralSettings(account.AccountName);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int SetDistributionListGeneralSettings(int itemId, int accountId, string displayName,
- bool hideAddressBook, string managerAccount, string[] memberAccounts,
- string notes)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "UPDATE_DISTR_LIST_GENERAL");
- TaskManager.ItemId = itemId;
-
- try
- {
- displayName = displayName.Trim();
-
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // get mailbox settings
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- List addressLists = new List();
- addressLists.Add(org.GlobalAddressList);
- addressLists.Add(org.AddressList);
-
- exchange.SetDistributionListGeneralSettings(
- account.AccountName,
- displayName,
- hideAddressBook,
- managerAccount,
- memberAccounts,
- notes,
- addressLists.ToArray());
-
- // update account
- account.DisplayName = displayName;
- account.AccountPassword = null;
- UpdateAccount(account);
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static ExchangeDistributionList GetDistributionListMailFlowSettings(int itemId, int accountId)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- return GetDemoDistributionListSettings();
- }
- #endregion
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_DISTR_LIST_MAILFLOW");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return null;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // get mailbox settings
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- ExchangeDistributionList list = exchange.GetDistributionListMailFlowSettings(account.AccountName);
- list.DisplayName = account.DisplayName;
- return list;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int SetDistributionListMailFlowSettings(int itemId, int accountId,
- string[] acceptAccounts, string[] rejectAccounts, bool requireSenderAuthentication)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "UPDATE_DISTR_LIST_MAILFLOW");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // get mailbox settings
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- List addressLists = new List();
- addressLists.Add(org.GlobalAddressList);
- addressLists.Add(org.AddressList);
-
-
- exchange.SetDistributionListMailFlowSettings(account.AccountName,
- acceptAccounts,
- rejectAccounts,
- requireSenderAuthentication,
- addressLists.ToArray());
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static ExchangeEmailAddress[] GetDistributionListEmailAddresses(int itemId, int accountId)
- {
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_DISTR_LIST_ADDRESSES");
- TaskManager.ItemId = itemId;
-
- try
- {
- return GetAccountEmailAddresses(itemId, accountId);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int AddDistributionListEmailAddress(int itemId, int accountId, string emailAddress)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "ADD_DISTR_LIST_ADDRESS");
- TaskManager.ItemId = itemId;
-
- try
- {
- // check
- if (EmailAddressExists(emailAddress))
- return BusinessErrorCodes.ERROR_EXCHANGE_EMAIL_EXISTS;
-
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // add e-mail
- AddAccountEmailAddress(accountId, emailAddress);
-
- // update e-mail addresses
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- List addressLists = new List();
- addressLists.Add(org.GlobalAddressList);
- addressLists.Add(org.AddressList);
-
- exchange.SetDistributionListEmailAddresses(
- account.AccountName,
- GetAccountSimpleEmailAddresses(itemId, accountId), addressLists.ToArray());
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int SetDistributionListPrimaryEmailAddress(int itemId, int accountId, string emailAddress)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "SET_PRIMARY_DISTR_LIST_ADDRESS");
- TaskManager.ItemId = itemId;
-
- try
- {
- // get account
- ExchangeAccount account = GetAccount(itemId, accountId);
- account.PrimaryEmailAddress = emailAddress;
-
- // update exchange
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- List addressLists = new List();
- addressLists.Add(org.GlobalAddressList);
- addressLists.Add(org.AddressList);
-
- exchange.SetDistributionListPrimaryEmailAddress(
- account.AccountName,
- emailAddress,
- addressLists.ToArray());
-
- // save account
- account.AccountPassword = null;
- UpdateAccount(account);
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int DeleteDistributionListEmailAddresses(int itemId, int accountId, string[] emailAddresses)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "DELETE_DISTR_LIST_ADDRESSES");
- TaskManager.ItemId = itemId;
-
- try
- {
- // get account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // delete e-mail addresses
- List toDelete = new List();
- foreach (string emailAddress in emailAddresses)
- {
- if (String.Compare(account.PrimaryEmailAddress, emailAddress, true) != 0)
- toDelete.Add(emailAddress);
- }
-
- // delete from meta-base
- DeleteAccountEmailAddresses(accountId, toDelete.ToArray());
-
- // delete from Exchange
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // update e-mail addresses
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- List addressLists = new List();
- addressLists.Add(org.GlobalAddressList);
- addressLists.Add(org.AddressList);
-
- exchange.SetDistributionListEmailAddresses(
- account.AccountName,
- GetAccountSimpleEmailAddresses(itemId, accountId), addressLists.ToArray());
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
-
- public static ResultObject SetDistributionListPermissions(int itemId, int accountId, string[] sendAsAccounts, string[] sendOnBehalfAccounts)
- {
- ResultObject res = TaskManager.StartResultTask("EXCHANGE", "SET_DISTRIBUTION_LIST_PERMISSINS");
- Organization org;
- try
- {
- org = GetOrganization(itemId);
- if (org == null)
- throw new ApplicationException("Organization is null");
- }
- catch(Exception ex)
- {
- TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ORGANIZATION_BY_ITEM_ID, ex);
- return res;
- }
-
- ExchangeServer exchange;
- try
- {
-
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
- }
- catch(Exception ex)
- {
- TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ORGANIZATION_PROXY, ex);
- return res;
- }
-
- ExchangeAccount account;
-
- try
- {
- account = GetAccount(itemId, accountId);
- }
- catch(Exception ex)
- {
- TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ACCOUNT, ex);
- return res;
- }
-
- try
- {
- List addressLists = new List();
- addressLists.Add(org.GlobalAddressList);
- addressLists.Add(org.AddressList);
-
- exchange.SetDistributionListPermissions(org.OrganizationId, account.AccountName, sendAsAccounts,
- sendOnBehalfAccounts, addressLists.ToArray());
- }
- catch(Exception ex)
- {
- TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_SET_DISTRIBUTION_LIST_PERMISSIONS, ex);
- return res;
- }
-
- TaskManager.CompleteTask();
- return res;
- }
-
- public static ExchangeDistributionListResult GetDistributionListPermissions(int itemId, int accountId)
- {
- Organization org;
- ExchangeDistributionListResult res = TaskManager.StartResultTask("EXCHANGE", "GET_DISTRIBUTION_LIST_RESULT");
-
- try
- {
- org = GetOrganization(itemId);
- if (org == null)
- throw new ApplicationException("Organization is null");
- }
- catch(Exception ex)
- {
- TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ORGANIZATION_BY_ITEM_ID, ex);
- return res;
- }
-
- ExchangeServer exchange;
- try
- {
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
- }
- catch(Exception ex)
- {
- TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ORGANIZATION_PROXY, ex);
- return res;
- }
-
- ExchangeAccount account;
- try
- {
- account = GetAccount(itemId, accountId);
- }
- catch(Exception ex)
- {
- TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ACCOUNT, ex);
- return res;
- }
-
- try
- {
- res.Value = exchange.GetDistributionListPermissions(org.OrganizationId, account.AccountName);
- res.Value.DisplayName = account.DisplayName;
- }
- catch(Exception ex)
- {
- TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_DISTRIBUTION_LIST_PERMISSIONS, ex);
- return res;
- }
-
- TaskManager.CompleteTask();
- return res;
- }
-
- #endregion
-
- #region Public Folders
- public static int CreatePublicFolder(int itemId, string parentFolder, string folderName,
- bool mailEnabled, string name, string domain)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // check mailbox quota
- OrganizationStatistics orgStats = GetOrganizationStatistics(itemId);
- if (orgStats.AllocatedPublicFolders > -1
- && orgStats.CreatedPublicFolders >= orgStats.AllocatedPublicFolders)
- return BusinessErrorCodes.ERROR_EXCHANGE_PFOLDERS_QUOTA_LIMIT;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "CREATE_PUBLIC_FOLDER");
- TaskManager.ItemId = itemId;
-
- try
- {
- // e-mail
- string email = "";
- if (mailEnabled && !String.IsNullOrEmpty(name))
- {
- email = name + "@" + domain;
-
- // check e-mail
- if (EmailAddressExists(email))
- return BusinessErrorCodes.ERROR_EXCHANGE_EMAIL_EXISTS;
- }
-
- // full folder name
- string normParent = parentFolder;
- if (!normParent.StartsWith("\\"))
- normParent = "\\" + normParent;
- if (!normParent.EndsWith("\\"))
- normParent = normParent + "\\";
-
- string folderPath = normParent + folderName;
-
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- if (String.IsNullOrEmpty(name))
- name = Utils.CleanIdentifier(folderName);
-
- string accountName = BuildAccountName(org.OrganizationId, name);
-
- // add mailbox
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- //Create Exchange Organization
- if (string.IsNullOrEmpty(org.GlobalAddressList))
- {
- ExtendToExchangeOrganization(ref org);
-
- PackageController.UpdatePackageItem(org);
- }
-
- exchange.CreatePublicFolder(org.DistinguishedName,
- org.OrganizationId,
- org.SecurityGroup,
- parentFolder,
- folderName,
- mailEnabled,
- accountName,
- name,
- domain);
-
-
- ExchangePublicFolder folder = exchange.GetPublicFolderGeneralSettings(org.OrganizationId, parentFolder + "\\" + folderName);
-
- // add meta-item
- int accountId = AddAccount(itemId, ExchangeAccountType.PublicFolder, accountName,
- folderPath, email, mailEnabled,
- 0, folder.NETBIOS+"\\"+accountName, null, 0, null);
-
- // register email address
- if(mailEnabled)
- AddAccountEmailAddress(accountId, email);
-
- return accountId;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int DeletePublicFolders(int itemId, int[] accountIds)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- if (accountIds != null)
- foreach (int accountId in accountIds)
- {
- int result = DeletePublicFolder(itemId, accountId);
- if (result < 0)
- return result;
- }
- return 0;
- }
-
- public static int DeletePublicFolder(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", "DELETE_PUBLIC_FOLDER");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // delete folder
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.DeletePublicFolder(org.OrganizationId, account.DisplayName);
-
- // unregister account
- DeleteAccount(itemId, accountId);
-
- // delete all nested folder meta-items
- List folders = GetAccounts(itemId, ExchangeAccountType.PublicFolder);
- foreach (ExchangeAccount folder in folders)
- {
- if (folder.DisplayName.ToLower().StartsWith(account.DisplayName.ToLower() + "\\"))
- DeleteAccount(itemId, folder.AccountId);
- }
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int EnableMailPublicFolder(int itemId, int accountId,
- string name, string domain)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "ENABLE_MAIL_PUBLIC_FOLDER");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
- if (account.MailEnabledPublicFolder)
- return 0;
-
- // check email
- string email = name + "@" + domain;
-
- // check e-mail
- if (EmailAddressExists(email))
- return BusinessErrorCodes.ERROR_EXCHANGE_EMAIL_EXISTS;
-
- string accountName = BuildAccountName(org.OrganizationId, name);
-
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.EnableMailPublicFolder(
- org.OrganizationId,
- account.DisplayName,
- account.AccountName,
- name,
- domain);
-
- // update and save account
- account.AccountName = accountName;
- account.MailEnabledPublicFolder = true;
- account.PrimaryEmailAddress = email;
- account.AccountPassword = null;
- UpdateAccount(account);
-
- // register e-mail
- AddAccountEmailAddress(accountId, email);
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int DisableMailPublicFolder(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", "DISABLE_MAIL_PUBLIC_FOLDER");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
- if (!account.MailEnabledPublicFolder)
- return 0;
-
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.DisableMailPublicFolder(org.OrganizationId, account.DisplayName);
-
-
- // update and save account
- account.MailEnabledPublicFolder = false;
- account.PrimaryEmailAddress = "";
- account.AccountPassword = null;
- UpdateAccount(account);
-
-
- // delete all mail accounts
- List addrs = new List();
- ExchangeEmailAddress[] emails = GetAccountEmailAddresses(itemId, accountId);
- foreach (ExchangeEmailAddress email in emails)
- addrs.Add(email.EmailAddress);
-
- DeleteAccountEmailAddresses(accountId, addrs.ToArray());
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- private static ExchangePublicFolder GetDemoPublicFolderSettings()
- {
- ExchangePublicFolder c = new ExchangePublicFolder();
- c.DisplayName = "\\fabrikam\\Documents";
- c.MailEnabled = true;
- c.Name = "Documents";
- c.Accounts = GetAccounts(0, ExchangeAccountType.Mailbox).ToArray();
- c.AcceptAccounts = GetAccounts(0, ExchangeAccountType.Mailbox).ToArray();
- return c;
- }
-
- public static ExchangePublicFolder GetPublicFolderGeneralSettings(int itemId, int accountId)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- return GetDemoPublicFolderSettings();
- }
- #endregion
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_PUBLIC_FOLDER_GENERAL");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return null;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- ExchangePublicFolder folder = exchange.GetPublicFolderGeneralSettings(org.OrganizationId, account.DisplayName);
- folder.MailEnabled = account.MailEnabledPublicFolder;
- folder.DisplayName = account.DisplayName;
- return folder;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int SetPublicFolderGeneralSettings(int itemId, int accountId, string newName,
- bool hideAddressBook, ExchangeAccount[] accounts)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "UPDATE_PUBLIC_FOLDER_GENERAL");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // get mailbox settings
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.SetPublicFolderGeneralSettings(
- org.OrganizationId,
- account.DisplayName,
- newName,
- hideAddressBook,
- accounts
- );
-
- // update folder name
- string origName = account.DisplayName;
- string newFullName = origName.Substring(0, origName.LastIndexOf("\\") + 1) + newName;
-
- if (String.Compare(origName, newFullName, true) != 0)
- {
- // rename original folder
- account.DisplayName = newFullName;
- account.AccountPassword = null;
- UpdateAccount(account);
-
- // rename nested folders
- List folders = GetAccounts(itemId, ExchangeAccountType.PublicFolder);
- foreach (ExchangeAccount folder in folders)
- {
- if (folder.DisplayName.ToLower().StartsWith(origName.ToLower() + "\\"))
- {
- folder.DisplayName = newFullName + folder.DisplayName.Substring(origName.Length);
- UpdateAccount(folder);
- }
- }
- }
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static ExchangePublicFolder GetPublicFolderMailFlowSettings(int itemId, int accountId)
- {
- #region Demo Mode
- if (IsDemoMode)
- {
- return GetDemoPublicFolderSettings();
- }
- #endregion
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_PUBLIC_FOLDER_MAILFLOW");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return null;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // get mailbox settings
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- ExchangePublicFolder folder = exchange.GetPublicFolderMailFlowSettings(org.OrganizationId, account.DisplayName);
- folder.DisplayName = account.DisplayName;
- return folder;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int SetPublicFolderMailFlowSettings(int itemId, int accountId,
- string[] acceptAccounts, string[] rejectAccounts, bool requireSenderAuthentication)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "UPDATE_PUBLIC_FOLDER_MAILFLOW");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // get mailbox settings
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.SetPublicFolderMailFlowSettings(org.OrganizationId, account.DisplayName,
- acceptAccounts,
- rejectAccounts,
- requireSenderAuthentication);
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static ExchangeEmailAddress[] GetPublicFolderEmailAddresses(int itemId, int accountId)
- {
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_PUBLIC_FOLDER_ADDRESSES");
- TaskManager.ItemId = itemId;
-
- try
- {
- return GetAccountEmailAddresses(itemId, accountId);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int AddPublicFolderEmailAddress(int itemId, int accountId, string emailAddress)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "ADD_PUBLIC_FOLDER_ADDRESS");
- TaskManager.ItemId = itemId;
-
- try
- {
- // check
- if (EmailAddressExists(emailAddress))
- return BusinessErrorCodes.ERROR_EXCHANGE_EMAIL_EXISTS;
-
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // add e-mail
- AddAccountEmailAddress(accountId, emailAddress);
-
- // update e-mail addresses
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.SetPublicFolderEmailAddresses(
- org.OrganizationId,
- account.DisplayName,
- GetAccountSimpleEmailAddresses(itemId, accountId));
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int SetPublicFolderPrimaryEmailAddress(int itemId, int accountId, string emailAddress)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "SET_PRIMARY_PUBLIC_FOLDER_ADDRESS");
- TaskManager.ItemId = itemId;
-
- try
- {
- // get account
- ExchangeAccount account = GetAccount(itemId, accountId);
- account.PrimaryEmailAddress = emailAddress;
-
- // update exchange
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // check package
- int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0) return packageCheck;
-
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.SetPublicFolderPrimaryEmailAddress(
- org.OrganizationId,
- account.DisplayName,
- emailAddress);
-
- // save account
- account.AccountPassword = null;
- UpdateAccount(account);
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int DeletePublicFolderEmailAddresses(int itemId, int accountId, string[] emailAddresses)
- {
- // check account
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "DELETE_PUBLIC_FOLDER_ADDRESSES");
- TaskManager.ItemId = itemId;
-
- try
- {
- // get account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- // delete e-mail addresses
- List toDelete = new List();
- foreach (string emailAddress in emailAddresses)
- {
- if (String.Compare(account.PrimaryEmailAddress, emailAddress, true) != 0)
- toDelete.Add(emailAddress);
- }
-
- // delete from meta-base
- DeleteAccountEmailAddresses(accountId, toDelete.ToArray());
-
- // delete from Exchange
- Organization org = GetOrganization(itemId);
- if (org == null)
- return -1;
-
- // update e-mail addresses
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.SetPublicFolderEmailAddresses(
- org.OrganizationId,
- account.DisplayName,
- GetAccountSimpleEmailAddresses(itemId, accountId));
-
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
- #endregion
-
- #region Private Helpers
-
-
- private static string GetPrimaryDomainController(int organizationServiceId)
- {
-
- Organizations orgProxy = new Organizations();
-
- ServiceProviderProxy.Init(orgProxy, organizationServiceId);
-
- string[] organizationSettings = orgProxy.ServiceProviderSettingsSoapHeaderValue.Settings;
-
-
-
- string orgPrimaryDomainController = string.Empty;
- foreach (string str in organizationSettings)
- {
- string[] props = str.Split('=');
- if (props[0].ToLower() == "primarydomaincontroller")
- {
- orgPrimaryDomainController = str;
- break;
- }
- }
-
- return orgPrimaryDomainController;
- }
-
- private static void ExtendExchangeSettings(List exchangeSettings, string primaryDomainController)
- {
- bool isAdded = false;
- for (int i = 0; i < exchangeSettings.Count; i++)
- {
- string[] props = exchangeSettings[i].Split('=');
- if (props[0].ToLower() == "primarydomaincontroller")
- {
- exchangeSettings[i] = primaryDomainController;
- isAdded = true;
- break;
- }
- }
-
- if (!isAdded)
- {
- exchangeSettings.Add(primaryDomainController);
- }
- }
-
- internal static ServiceProvider GetServiceProvider(int exchangeServiceId, int organizationServiceId)
- {
- ServiceProvider ws = new ServiceProvider();
-
- ServiceProviderProxy.Init(ws, exchangeServiceId);
-
- string[] exchangeSettings = ws.ServiceProviderSettingsSoapHeaderValue.Settings;
-
- List resSettings = new List(exchangeSettings);
-
- string orgPrimaryDomainController = GetPrimaryDomainController(organizationServiceId);
-
- ExtendExchangeSettings(resSettings, orgPrimaryDomainController);
- ws.ServiceProviderSettingsSoapHeaderValue.Settings = resSettings.ToArray();
- return ws;
- }
-
- internal static ExchangeServer GetExchangeServer(int exchangeServiceId, int organizationServiceId)
- {
- ExchangeServer ws = new ExchangeServer();
-
- ServiceProviderProxy.Init(ws, exchangeServiceId);
-
- string []exchangeSettings = ws.ServiceProviderSettingsSoapHeaderValue.Settings;
-
- List resSettings = new List(exchangeSettings);
-
- string orgPrimaryDomainController = GetPrimaryDomainController(organizationServiceId);
-
- ExtendExchangeSettings(resSettings, orgPrimaryDomainController);
- ws.ServiceProviderSettingsSoapHeaderValue.Settings = resSettings.ToArray();
- return ws;
- }
-
- internal static ServiceProvider GetExchangeServiceProvider(int exchangeServiceId, int organizationServiceId)
- {
- ServiceProvider ws = new ServiceProvider();
-
- ServiceProviderProxy.Init(ws, exchangeServiceId);
-
- string[] exchangeSettings = ws.ServiceProviderSettingsSoapHeaderValue.Settings;
-
- List resSettings = new List(exchangeSettings);
-
- string orgPrimaryDomainController = GetPrimaryDomainController(organizationServiceId);
-
- ExtendExchangeSettings(resSettings, orgPrimaryDomainController);
- ws.ServiceProviderSettingsSoapHeaderValue.Settings = resSettings.ToArray();
- return ws;
- }
-
-
- private static int GetExchangeServiceID(int packageId)
- {
- return PackageController.GetPackageServiceId(packageId, ResourceGroups.Exchange);
- }
-
- private static string[] GetAccountSimpleEmailAddresses(int itemId, int accountId)
- {
- ExchangeEmailAddress[] emails = GetAccountEmailAddresses(itemId, accountId);
- List result = new List();
- foreach (ExchangeEmailAddress email in emails)
- {
- string prefix = email.IsPrimary ? "SMTP:" : "smtp:";
- result.Add(prefix + email.EmailAddress);
- }
-
- return result.ToArray();
- }
-
- private static bool QuotaEnabled(PackageContext cntx, string quotaName)
- {
- return cntx.Quotas.ContainsKey(quotaName) && !cntx.Quotas[quotaName].QuotaExhausted;
- }
-
- private static bool IsDemoMode
- {
- get
- {
- return (SecurityContext.CheckAccount(DemandAccount.NotDemo) < 0);
- }
- }
- #endregion
-
- public static ExchangeMobileDevice[] GetMobileDevices(int itemId, int accountId)
- {
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_MOBILE_DEVICES");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return null;
-
- // load account
- ExchangeAccount account = GetAccount(itemId, accountId);
-
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- return exchange.GetMobileDevices(account.UserPrincipalName);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static ExchangeMobileDevice GetMobileDevice(int itemId, string deviceId)
- {
- // place log record
- TaskManager.StartTask("EXCHANGE", "GET_MOBILE_DEVICE");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return null;
-
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- return exchange.GetMobileDevice(deviceId);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static void WipeDataFromDevice(int itemId, string deviceId)
- {
- // place log record
- TaskManager.StartTask("EXCHANGE", "WIPE_DATA_FROM_DEVICE");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return;
-
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.WipeDataFromDevice(deviceId);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static void CancelRemoteWipeRequest(int itemId, string deviceId)
- {
- // place log record
- TaskManager.StartTask("EXCHANGE", "CANCEL_REMOTE_WIPE_REQUEST");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return;
-
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.CancelRemoteWipeRequest(deviceId);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static void RemoveDevice(int itemId, string deviceId)
- {
- // place log record
- TaskManager.StartTask("EXCHANGE", "REMOVE_DEVICE");
- TaskManager.ItemId = itemId;
-
- try
- {
- // load organization
- Organization org = GetOrganization(itemId);
- if (org == null)
- return;
-
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- exchange.RemoveDevice(deviceId);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- public static int AddExchangeDisclaimer(int itemID, ExchangeDisclaimer disclaimer)
- {
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "ADD_EXCHANGE_EXCHANGEDISCLAIMER");
- TaskManager.ItemId = itemID;
-
- try
- {
- return DataProvider.AddExchangeDisclaimer(itemID, disclaimer);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
-
-
- }
-
- public static int UpdateExchangeDisclaimer(int itemID, ExchangeDisclaimer disclaimer)
- {
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "UPDATE_EXCHANGE_EXCHANGEDISCLAIMER");
- TaskManager.ItemId = itemID;
-
- try
- {
- DataProvider.UpdateExchangeDisclaimer(itemID, disclaimer);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
-
- return 0;
- }
-
- public static int DeleteExchangeDisclaimer(int itemId, int exchangeDisclaimerId)
- {
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- TaskManager.StartTask("EXCHANGE", "DELETE_EXCHANGE_EXCHANGEDISCLAIMER");
- TaskManager.ItemId = itemId;
-
- try
- {
- DataProvider.DeleteExchangeDisclaimer(exchangeDisclaimerId);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
-
- return 0;
- }
-
- public static ExchangeDisclaimer GetExchangeDisclaimer(int itemId, int exchangeDisclaimerId)
- {
-
- TaskManager.StartTask("EXCHANGE", "GET_EXCHANGE_EXCHANGEDISCLAIMER");
- TaskManager.ItemId = itemId;
-
- try
- {
- return ObjectUtils.FillObjectFromDataReader(
- DataProvider.GetExchangeDisclaimer(exchangeDisclaimerId));
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
-
- }
-
- public static List GetExchangeDisclaimers(int itemId)
- {
- TaskManager.StartTask("EXCHANGE", "GET_EXCHANGE_EXCHANGEDISCLAIMER");
- TaskManager.ItemId = itemId;
-
- try
- {
- List disclaimers = ObjectUtils.CreateListFromDataReader(DataProvider.GetExchangeDisclaimers(itemId));
- return disclaimers;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
-
- }
-
- public static int SetExchangeAccountDisclaimerId(int itemId, int AccountID, int ExchangeDisclaimerId)
- {
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0) return accountCheck;
-
- // place log record
- TaskManager.StartTask("EXCHANGE", "SET_EXCHANGE_ACCOUNTDISCLAIMERID");
- TaskManager.ItemId = AccountID;
-
- try
- {
- ExchangeDisclaimer disclaimer = null;
-
- if (ExchangeDisclaimerId != -1)
- disclaimer = GetExchangeDisclaimer(itemId, ExchangeDisclaimerId);
-
- // load account
- ExchangeAccount account = GetAccount(itemId, AccountID);
-
- Organization org = (Organization)PackageController.GetPackageItem(itemId);
- if (org == null)
- return -1;
-
- int exchangeServiceId = GetExchangeServiceID(org.PackageId);
- ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);
-
- string transportRuleName = org.Name + "_" + account.PrimaryEmailAddress;
-
- exchange.RemoveTransportRule(transportRuleName);
-
- if (disclaimer != null)
- {
- if (!string.IsNullOrEmpty(disclaimer.DisclaimerText))
- exchange.NewDisclaimerTransportRule(transportRuleName, account.PrimaryEmailAddress, disclaimer.DisclaimerText);
- }
-
- DataProvider.SetExchangeAccountDisclaimerId(AccountID, ExchangeDisclaimerId);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
-
- return 0;
-
- }
-
- public static int GetExchangeAccountDisclaimerId(int itemId, int AccountID)
- {
- TaskManager.StartTask("EXCHANGE", "GET_EXCHANGE_ACCOUNTDISCLAIMERID");
- TaskManager.ItemId = AccountID;
-
- try
- {
- return DataProvider.GetExchangeAccountDisclaimerId(AccountID);
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
-
- }
-
- }
-}