From 80d4843693edeb0b5c1ef859f5202adfa33972e7 Mon Sep 17 00:00:00 2001 From: vfedosevich Date: Wed, 28 Aug 2013 20:18:56 +0300 Subject: [PATCH] fixed bugs --- WebsitePanel/Database/update_db.sql | 70 +- .../ExchangeServerProxy.cs | 13 +- .../OrganizationProxy.cs | 49 +- .../Data/DataProvider.cs | 39 +- .../ExchangeServerController.cs | 3580 +++++++++-------- .../HostedSolution/OrganizationController.cs | 637 +-- .../esExchangeServer.asmx.cs | 4 +- .../esOrganizations.asmx.cs | 12 +- .../HostedSolution/ADAttributes.cs | 2 +- .../HostedSolution/ActiveDirectoryUtils.cs | 22 +- .../HostedSolution/IOrganization.cs | 2 +- .../OrganizationSecurityGroup.cs | 2 +- .../OrganizationProvider.cs | 76 +- .../OrganizationProxy.cs | 2 +- .../ExchangeDistributionListMemberOf.ascx | 3 +- .../ExchangeMailboxMemberOf.ascx | 3 +- .../UserControls/AccountsList.ascx | 2 + .../UserControls/AccountsList.ascx.cs | 21 +- .../AccountsList.ascx.designer.cs | 18 +- .../AccountsListWithPermissions.ascx.cs | 2 +- .../App_LocalResources/AccountsList.ascx.resx | 7 +- .../UserControls/GroupsList.ascx.cs | 39 +- .../UserControls/MailboxSelector.ascx.cs | 2 +- .../UserControls/UsersList.ascx.cs | 141 +- 24 files changed, 2453 insertions(+), 2295 deletions(-) diff --git a/WebsitePanel/Database/update_db.sql b/WebsitePanel/Database/update_db.sql index 24dbdd04..2826a68f 100644 --- a/WebsitePanel/Database/update_db.sql +++ b/WebsitePanel/Database/update_db.sql @@ -1977,6 +1977,7 @@ ALTER PROCEDURE [dbo].[SearchExchangeAccounts] @IncludeDistributionLists bit, @IncludeRooms bit, @IncludeEquipment bit, + @IncludeSecurityGroups bit, @FilterColumn nvarchar(50) = '', @FilterValue nvarchar(50) = '', @SortColumn nvarchar(50) @@ -1998,7 +1999,7 @@ OR (@IncludeContacts = 1 AND EA.AccountType = 2) OR (@IncludeDistributionLists = 1 AND EA.AccountType = 3) OR (@IncludeRooms = 1 AND EA.AccountType = 5) OR (@IncludeEquipment = 1 AND EA.AccountType = 6) -OR (@IncludeEquipment = 0 AND @IncludeContacts = 0 AND @IncludeDistributionLists = 0 AND @IncludeRooms = 0 AND @IncludeEquipment = 0 AND EA.AccountType = 8)) +OR (@IncludeSecurityGroups = 1 AND EA.AccountType = 8)) AND EA.ItemID = @ItemID ' @@ -2028,8 +2029,71 @@ WHERE ' + @condition print @sql exec sp_executesql @sql, N'@ItemID int, @IncludeMailboxes int, @IncludeContacts int, - @IncludeDistributionLists int, @IncludeRooms bit, @IncludeEquipment bit', -@ItemID, @IncludeMailboxes, @IncludeContacts, @IncludeDistributionLists, @IncludeRooms, @IncludeEquipment + @IncludeDistributionLists int, @IncludeRooms bit, @IncludeEquipment bit, @IncludeSecurityGroups bit', +@ItemID, @IncludeMailboxes, @IncludeContacts, @IncludeDistributionLists, @IncludeRooms, @IncludeEquipment, @IncludeSecurityGroups + +RETURN +GO + +CREATE PROCEDURE [dbo].[SearchExchangeAccountsByTypes] +( + @ActorID int, + @ItemID int, + @AccountTypes nvarchar(30), + @FilterColumn nvarchar(50) = '', + @FilterValue nvarchar(50) = '', + @SortColumn nvarchar(50) +) +AS + +DECLARE @PackageID int +SELECT @PackageID = PackageID FROM ServiceItems +WHERE ItemID = @ItemID + +-- check rights +IF dbo.CheckActorPackageRights(@ActorID, @PackageID) = 0 +RAISERROR('You are not allowed to access this package', 16, 1) + +DECLARE @condition nvarchar(700) +SET @condition = 'EA.ItemID = @ItemID AND EA.AccountType IN (' + @AccountTypes + ')' + +IF @FilterColumn <> '' AND @FilterColumn IS NOT NULL +AND @FilterValue <> '' AND @FilterValue IS NOT NULL +BEGIN + IF @FilterColumn = 'PrimaryEmailAddress' AND @AccountTypes <> '2' + BEGIN + SET @condition = @condition + ' AND EA.AccountID IN (SELECT EAEA.AccountID FROM ExchangeAccountEmailAddresses EAEA WHERE EAEA.EmailAddress LIKE ''' + @FilterValue + ''')' + END + ELSE + BEGIN + SET @condition = @condition + ' AND ' + @FilterColumn + ' LIKE ''' + @FilterValue + '''' + END +END + +IF @SortColumn IS NULL OR @SortColumn = '' +SET @SortColumn = 'EA.DisplayName ASC' + +DECLARE @sql nvarchar(3500) +SET @sql = ' +SELECT + EA.AccountID, + EA.ItemID, + EA.AccountType, + EA.AccountName, + EA.DisplayName, + EA.PrimaryEmailAddress, + EA.MailEnabledPublicFolder, + EA.MailboxPlanId, + P.MailboxPlan, + EA.SubscriberNumber, + EA.UserPrincipalName +FROM + ExchangeAccounts AS EA +LEFT OUTER JOIN ExchangeMailboxPlans AS P ON EA.MailboxPlanId = P.MailboxPlanId + WHERE ' + @condition + + ' ORDER BY ' + @SortColumn + +EXEC sp_executesql @sql, N'@ItemID int', @ItemID RETURN GO \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/ExchangeServerProxy.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/ExchangeServerProxy.cs index c2434558..8fda3459 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/ExchangeServerProxy.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/ExchangeServerProxy.cs @@ -3053,7 +3053,7 @@ namespace WebsitePanel.EnterpriseServer /// [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/SearchAccounts", RequestNamespace = "http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace = "http://smbsaas/websitepanel/enterpriseserver", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] - public ExchangeAccount[] SearchAccounts(int itemId, bool includeMailboxes, bool includeContacts, bool includeDistributionLists, bool includeRooms, bool includeEquipment, string filterColumn, string filterValue, string sortColumn) + public ExchangeAccount[] SearchAccounts(int itemId, bool includeMailboxes, bool includeContacts, bool includeDistributionLists, bool includeRooms, bool includeEquipment, bool includeSecurityGroups, string filterColumn, string filterValue, string sortColumn) { object[] results = this.Invoke("SearchAccounts", new object[] { itemId, @@ -3062,6 +3062,7 @@ namespace WebsitePanel.EnterpriseServer includeDistributionLists, includeRooms, includeEquipment, + includeSecurityGroups, filterColumn, filterValue, sortColumn}); @@ -3069,7 +3070,7 @@ namespace WebsitePanel.EnterpriseServer } /// - public System.IAsyncResult BeginSearchAccounts(int itemId, bool includeMailboxes, bool includeContacts, bool includeDistributionLists, bool includeRooms, bool includeEquipment, string filterColumn, string filterValue, string sortColumn, System.AsyncCallback callback, object asyncState) + public System.IAsyncResult BeginSearchAccounts(int itemId, bool includeMailboxes, bool includeContacts, bool includeDistributionLists, bool includeRooms, bool includeEquipment, bool includeSecurityGroups, string filterColumn, string filterValue, string sortColumn, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("SearchAccounts", new object[] { itemId, @@ -3078,6 +3079,7 @@ namespace WebsitePanel.EnterpriseServer includeDistributionLists, includeRooms, includeEquipment, + includeSecurityGroups, filterColumn, filterValue, sortColumn}, callback, asyncState); @@ -3091,13 +3093,13 @@ namespace WebsitePanel.EnterpriseServer } /// - public void SearchAccountsAsync(int itemId, bool includeMailboxes, bool includeContacts, bool includeDistributionLists, bool includeRooms, bool includeEquipment, string filterColumn, string filterValue, string sortColumn) + public void SearchAccountsAsync(int itemId, bool includeMailboxes, bool includeContacts, bool includeDistributionLists, bool includeRooms, bool includeEquipment, bool includeSecurityGroups, string filterColumn, string filterValue, string sortColumn) { - this.SearchAccountsAsync(itemId, includeMailboxes, includeContacts, includeDistributionLists, includeRooms, includeEquipment, filterColumn, filterValue, sortColumn, null); + this.SearchAccountsAsync(itemId, includeMailboxes, includeContacts, includeDistributionLists, includeRooms, includeEquipment, includeSecurityGroups, filterColumn, filterValue, sortColumn, null); } /// - public void SearchAccountsAsync(int itemId, bool includeMailboxes, bool includeContacts, bool includeDistributionLists, bool includeRooms, bool includeEquipment, string filterColumn, string filterValue, string sortColumn, object userState) + public void SearchAccountsAsync(int itemId, bool includeMailboxes, bool includeContacts, bool includeDistributionLists, bool includeRooms, bool includeEquipment, bool includeSecurityGroups, string filterColumn, string filterValue, string sortColumn, object userState) { if ((this.SearchAccountsOperationCompleted == null)) { @@ -3110,6 +3112,7 @@ namespace WebsitePanel.EnterpriseServer includeDistributionLists, includeRooms, includeEquipment, + includeSecurityGroups, filterColumn, filterValue, sortColumn}, this.SearchAccountsOperationCompleted, userState); diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/OrganizationProxy.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/OrganizationProxy.cs index 14c795fd..fe3e9e11 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/OrganizationProxy.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/OrganizationProxy.cs @@ -133,7 +133,7 @@ namespace WebsitePanel.EnterpriseServer.HostedSolution private System.Threading.SendOrPostCallback GetSecurityGroupsByMemberOperationCompleted; - private System.Threading.SendOrPostCallback SearchSecurityGroupsOperationCompleted; + private System.Threading.SendOrPostCallback SearchOrganizationAccountsOperationCompleted; /// public esOrganizations() @@ -244,7 +244,7 @@ namespace WebsitePanel.EnterpriseServer.HostedSolution public event GetSecurityGroupsByMemberCompletedEventHandler GetSecurityGroupsByMemberCompleted; /// - public event SearchSecurityGroupsCompletedEventHandler SearchSecurityGroupsCompleted; + public event SearchOrganizationAccountsCompletedEventHandler SearchOrganizationAccountsCompleted; /// [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/CheckOrgIdExists", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] @@ -2328,60 +2328,63 @@ namespace WebsitePanel.EnterpriseServer.HostedSolution } /// - [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/SearchSecurityGroups", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] - public ExchangeAccount[] SearchSecurityGroups(int itemId, string filterColumn, string filterValue, string sortColumn) + [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/SearchOrganizationAccounts", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] + public ExchangeAccount[] SearchOrganizationAccounts(int itemId, string filterColumn, string filterValue, string sortColumn, bool includeOnlySecurityGroups) { - object[] results = this.Invoke("SearchSecurityGroups", new object[] { + object[] results = this.Invoke("SearchOrganizationAccounts", new object[] { itemId, filterColumn, filterValue, - sortColumn}); + sortColumn, + includeOnlySecurityGroups}); return ((ExchangeAccount[])(results[0])); } /// - public System.IAsyncResult BeginSearchSecurityGroups(int itemId, string filterColumn, string filterValue, string sortColumn, System.AsyncCallback callback, object asyncState) + public System.IAsyncResult BeginSearchOrganizationAccounts(int itemId, string filterColumn, string filterValue, string sortColumn, bool includeOnlySecurityGroups, System.AsyncCallback callback, object asyncState) { - return this.BeginInvoke("SearchSecurityGroups", new object[] { + return this.BeginInvoke("SearchOrganizationAccounts", new object[] { itemId, filterColumn, filterValue, - sortColumn}, callback, asyncState); + sortColumn, + includeOnlySecurityGroups}, callback, asyncState); } /// - public ExchangeAccount[] EndSearchSecurityGroups(System.IAsyncResult asyncResult) + public ExchangeAccount[] EndSearchOrganizationAccounts(System.IAsyncResult asyncResult) { object[] results = this.EndInvoke(asyncResult); return ((ExchangeAccount[])(results[0])); } /// - public void SearchSecurityGroupsAsync(int itemId, string filterColumn, string filterValue, string sortColumn) + public void SearchOrganizationAccountsAsync(int itemId, string filterColumn, string filterValue, string sortColumn, bool includeOnlySecurityGroups) { - this.SearchSecurityGroupsAsync(itemId, filterColumn, filterValue, sortColumn, null); + this.SearchOrganizationAccountsAsync(itemId, filterColumn, filterValue, sortColumn, includeOnlySecurityGroups, null); } /// - public void SearchSecurityGroupsAsync(int itemId, string filterColumn, string filterValue, string sortColumn, object userState) + public void SearchOrganizationAccountsAsync(int itemId, string filterColumn, string filterValue, string sortColumn, bool includeOnlySecurityGroups, object userState) { - if ((this.SearchSecurityGroupsOperationCompleted == null)) + if ((this.SearchOrganizationAccountsOperationCompleted == null)) { - this.SearchSecurityGroupsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSearchSecurityGroupsOperationCompleted); + this.SearchOrganizationAccountsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSearchOrganizationAccountsOperationCompleted); } - this.InvokeAsync("SearchSecurityGroups", new object[] { + this.InvokeAsync("SearchOrganizationAccounts", new object[] { itemId, filterColumn, filterValue, - sortColumn}, this.SearchSecurityGroupsOperationCompleted, userState); + sortColumn, + includeOnlySecurityGroups}, this.SearchOrganizationAccountsOperationCompleted, userState); } - private void OnSearchSecurityGroupsOperationCompleted(object arg) + private void OnSearchOrganizationAccountsOperationCompleted(object arg) { - if ((this.SearchSecurityGroupsCompleted != null)) + if ((this.SearchOrganizationAccountsCompleted != null)) { System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg)); - this.SearchSecurityGroupsCompleted(this, new SearchSecurityGroupsCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState)); + this.SearchOrganizationAccountsCompleted(this, new SearchOrganizationAccountsCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState)); } } @@ -3414,18 +3417,18 @@ namespace WebsitePanel.EnterpriseServer.HostedSolution /// [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")] - public delegate void SearchSecurityGroupsCompletedEventHandler(object sender, SearchSecurityGroupsCompletedEventArgs e); + public delegate void SearchOrganizationAccountsCompletedEventHandler(object sender, SearchOrganizationAccountsCompletedEventArgs e); /// [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] - public partial class SearchSecurityGroupsCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs + public partial class SearchOrganizationAccountsCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs { private object[] results; - internal SearchSecurityGroupsCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : + internal SearchOrganizationAccountsCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : base(exception, cancelled, userState) { this.results = results; diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs index 1db00f99..5aab5932 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs @@ -1868,7 +1868,7 @@ namespace WebsitePanel.EnterpriseServer public static IDataReader GetProcessBackgroundTasks(BackgroundTaskStatus status) { return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure, - ObjectQualifier + "GetProcessBackgroundTasks", + ObjectQualifier + "GetProcessBackgroundTasks", new SqlParameter("@status", (int)status)); } @@ -1952,7 +1952,7 @@ namespace WebsitePanel.EnterpriseServer new SqlParameter("@finishDate", finishDate == DateTime.MinValue ? DBNull.Value - : (object) finishDate), + : (object)finishDate), new SqlParameter("@indicatorCurrent", indicatorCurrent), new SqlParameter("@indicatorMaximum", indicatorMaximum), new SqlParameter("@maximumExecutionTime", maximumExecutionTime), @@ -2636,6 +2636,38 @@ namespace WebsitePanel.EnterpriseServer ); } + public static IDataReader SearchExchangeAccountsByTypes(int actorId, int itemId, string accountTypes, + string filterColumn, string filterValue, string sortColumn) + { + // 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.ExecuteReader( + ConnectionString, + CommandType.StoredProcedure, + "SearchExchangeAccountsByTypes", + 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)) + ); + } + public static DataSet GetExchangeAccountsPaged(int actorId, int itemId, string accountTypes, string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows) { @@ -2672,7 +2704,7 @@ namespace WebsitePanel.EnterpriseServer public static IDataReader SearchExchangeAccounts(int actorId, int itemId, bool includeMailboxes, bool includeContacts, bool includeDistributionLists, bool includeRooms, bool includeEquipment, - string filterColumn, string filterValue, string sortColumn) + bool includeSecurityGroups, string filterColumn, string filterValue, string sortColumn) { return SqlHelper.ExecuteReader( ConnectionString, @@ -2685,6 +2717,7 @@ namespace WebsitePanel.EnterpriseServer new SqlParameter("@IncludeDistributionLists", includeDistributionLists), new SqlParameter("@IncludeRooms", includeRooms), new SqlParameter("@IncludeEquipment", includeEquipment), + new SqlParameter("@IncludeSecurityGroups", includeSecurityGroups), new SqlParameter("@FilterColumn", VerifyColumnName(filterColumn)), new SqlParameter("@FilterValue", VerifyColumnValue(filterValue)), new SqlParameter("@SortColumn", VerifyColumnName(sortColumn)) diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/ExchangeServer/ExchangeServerController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/ExchangeServer/ExchangeServerController.cs index c15f832c..47d067fb 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/ExchangeServer/ExchangeServerController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/ExchangeServer/ExchangeServerController.cs @@ -44,70 +44,70 @@ 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(); + 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); + // 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); + // 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 ds; + } + #endregion - return PackageController.GetRawPackageItemsPaged( - packageId, ResourceGroups.Exchange, typeof(Organization), - recursive, filterColumn, filterValue, sortColumn, startRow, maximumRows); - } + 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); + 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]; + 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]; + for (int i = 0; i < orgs.PageItems.Length; i++) + orgs.PageItems[i] = (Organization)items.PageItems[i]; - return orgs; - } + return orgs; + } - public static List GetExchangeOrganizations(int packageId, bool recursive) - { - List items = PackageController.GetPackageItemsByType( - packageId, typeof(Organization), recursive); + 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; })); - } + return items.ConvertAll( + new Converter( + delegate(ServiceProviderItem item) { return (Organization)item; })); + } public static List GetExchangeOrganizationsInternal(int packageId, bool recursive) { @@ -118,29 +118,29 @@ namespace WebsitePanel.EnterpriseServer 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 + 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); - } + return (Organization)PackageController.GetPackageItem(itemId); + } - public static OrganizationStatistics GetOrganizationStatistics(int itemId) - { + public static OrganizationStatistics GetOrganizationStatistics(int itemId) + { return GetOrganizationStatisticsInternal(itemId, false); - } + } public static OrganizationStatistics GetOrganizationStatisticsByOrganization(int itemId) { @@ -252,58 +252,58 @@ namespace WebsitePanel.EnterpriseServer - public static int CalculateOrganizationDiskspace(int itemId) - { - // check account - int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo); - if (accountCheck < 0) return accountCheck; + 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", itemId); + // place log record + TaskManager.StartTask("EXCHANGE", "CALCULATE_DISKSPACE", itemId); - try - { - // create thread parameters - ThreadStartParameters prms = new ThreadStartParameters(); - prms.UserId = SecurityContext.User.UserId; - prms.Parameters = new object[] { 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; + Thread t = new Thread(CalculateOrganizationDiskspaceAsync); + t.Start(prms); + return 0; - } - catch (Exception ex) - { - throw TaskManager.WriteError(ex); - } - finally - { - TaskManager.CompleteTask(); - } - } + } + catch (Exception ex) + { + throw TaskManager.WriteError(ex); + } + finally + { + TaskManager.CompleteTask(); + } + } - private static void CalculateOrganizationDiskspaceAsync(object objPrms) - { - ThreadStartParameters prms = (ThreadStartParameters)objPrms; + private static void CalculateOrganizationDiskspaceAsync(object objPrms) + { + ThreadStartParameters prms = (ThreadStartParameters)objPrms; - // impersonate thread - SecurityContext.SetThreadPrincipal(prms.UserId); + // impersonate thread + SecurityContext.SetThreadPrincipal(prms.UserId); - int itemId = (int)prms.Parameters[0]; - - // calculate disk space - CalculateOrganizationDiskspaceInternal(itemId); - } + int itemId = (int)prms.Parameters[0]; - internal static void CalculateOrganizationDiskspaceInternal(int itemId) - { - try - { - // calculate disk space - Organization org = (Organization)PackageController.GetPackageItem(itemId); - if (org == null) - return; + // 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); @@ -326,50 +326,50 @@ namespace WebsitePanel.EnterpriseServer UpdateOrganization(org); } } - } - catch (Exception ex) - { - // write to audit log - TaskManager.WriteError(ex); - } - } + } + catch (Exception ex) + { + // write to audit log + TaskManager.WriteError(ex); + } + } + + private static bool OrganizationIdentifierExists(string organizationId) + { + return DataProvider.ExchangeOrganizationExists(organizationId); + } + + - 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, new BackgroundTaskParameter("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; + + 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, @@ -408,17 +408,17 @@ namespace WebsitePanel.EnterpriseServer { clientAccessRole = GetExchangeServer(id, org.ServiceId); } - catch(Exception ex) + 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); @@ -430,12 +430,12 @@ namespace WebsitePanel.EnterpriseServer { hubTransportRole = GetExchangeServer(id, org.ServiceId); } - catch(Exception ex) + catch (Exception ex) { TaskManager.WriteError(ex); - continue; + continue; } - + string[] existingDomains = hubTransportRole.GetAuthoritativeDomains(); if (existingDomains != null) Array.Sort(existingDomains); @@ -483,41 +483,41 @@ namespace WebsitePanel.EnterpriseServer org.AddressBookPolicy = OrgTmp.AddressBookPolicy; - StringDictionary settings = ServerController.GetServiceSettings(serviceId); - org.KeepDeletedItemsDays = Utils.ParseInt(settings["KeepDeletedItemsDays"], 14); - + 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) + // rollback domain + if (authDomainCreated) + foreach (int id in hubTransportServiceIds) + { + ExchangeServer hubTransportRole = null; + try { - 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; + 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); } @@ -534,53 +534,53 @@ namespace WebsitePanel.EnterpriseServer } } - private static int[] ParseMultiSetting(int mailboxServiceId, string settingName) - { + 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) - { + out int[] hubTransportServiceIds, out int[] clientAccessServiceIds) + { hubTransportServiceIds = ParseMultiSetting(mailboxServiceId, "HubTransportServiceID"); - clientAccessServiceIds = ParseMultiSetting(mailboxServiceId, "ClientAccessServiceID"); - } + 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; + 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", itemId); + // place log record + TaskManager.StartTask("EXCHANGE", "DELETE_ORG", itemId); - try - { - // delete organization in Exchange - //System.Threading.Thread.Sleep(5000); - Organization org = (Organization)PackageController.GetPackageItem(itemId); + try + { + // delete organization in Exchange + //System.Threading.Thread.Sleep(5000); + Organization org = (Organization)PackageController.GetPackageItem(itemId); - int exchangeServiceId = GetExchangeServiceID(org.PackageId); + int exchangeServiceId = GetExchangeServiceID(org.PackageId); ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId); bool successful = exchange.DeleteOrganization( @@ -592,156 +592,156 @@ namespace WebsitePanel.EnterpriseServer 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", itemId); - try - { - return GetOrganization(itemId); - } - catch (Exception ex) - { - throw TaskManager.WriteError(ex); - } - finally - { - TaskManager.CompleteTask(); - } - } + return successful ? 0 : BusinessErrorCodes.ERROR_EXCHANGE_DELETE_SOME_PROBLEMS; + } + 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; + public static Organization GetOrganizationStorageLimits(int itemId) + { + // place log record + TaskManager.StartTask("EXCHANGE", "GET_ORG_LIMITS", itemId); - // place log record + 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", itemId); - try - { - Organization org = (Organization)PackageController.GetPackageItem(itemId); - if (org == null) - return 0; + try + { + Organization org = (Organization)PackageController.GetPackageItem(itemId); + if (org == null) + return 0; - // load package context - PackageContext cntx = PackageController.GetPackageContext(org.PackageId); + // 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; + 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; + // set limits + org.KeepDeletedItemsDays = keepDeletedItemsDays; - // save organization - UpdateOrganization(org); + // save organization + UpdateOrganization(org); - if (applyToMailboxes) - { + if (applyToMailboxes) + { int exchangeServiceId = GetExchangeServiceID(org.PackageId); ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId); - exchange.SetOrganizationStorageLimits(org.DistinguishedName, - issueWarningKB, - prohibitSendKB, - prohibitSendReceiveKB, - keepDeletedItemsDays); - } + exchange.SetOrganizationStorageLimits(org.DistinguishedName, + issueWarningKB, + prohibitSendKB, + prohibitSendReceiveKB, + keepDeletedItemsDays); + } - return 0; - } - catch (Exception ex) - { - throw TaskManager.WriteError(ex); - } - finally - { - TaskManager.CompleteTask(); - } - } + 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); + 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 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); + 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 + return items.ToArray(); + } + #endregion - // place log record + // place log record TaskManager.StartTask("EXCHANGE", "GET_MAILBOXES_STATS", itemId); - try - { - Organization org = (Organization)PackageController.GetPackageItem(itemId); - if (org == null) - return null; + 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(); - } - } + return exchange.GetMailboxesStatistics(org.DistinguishedName); + } + catch (Exception ex) + { + throw TaskManager.WriteError(ex); + } + finally + { + TaskManager.CompleteTask(); + } + } public static ExchangeMailboxStatistics GetMailboxStatistics(int itemId, int accountId) { @@ -775,69 +775,69 @@ namespace WebsitePanel.EnterpriseServer } - 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); + 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 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); + 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 + return items.ToArray(); + } + #endregion - // place log record + // place log record TaskManager.StartTask("EXCHANGE", "GET_FOLDERS_STATS", itemId); - try - { - Organization org = (Organization)PackageController.GetPackageItem(itemId); - if (org == null) - return null; + 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 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 + // 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(); - } - } + } + catch (Exception ex) + { + throw TaskManager.WriteError(ex); + } + finally + { + TaskManager.CompleteTask(); + } + } public static ExchangeActiveSyncPolicy GetActiveSyncPolicy(int itemId) { @@ -920,7 +920,7 @@ namespace WebsitePanel.EnterpriseServer ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId); exchange.SetActiveSyncPolicy(org.OrganizationId, allowNonProvisionableDevices, attachmentsEnabled, maxAttachmentSizeKB, uncAccessEnabled, wssAccessEnabled, devicePasswordEnabled, alphanumericPasswordRequired, - passwordRecoveryEnabled, deviceEncryptionEnabled, allowSimplePassword, maxPasswordFailedAttempts, + passwordRecoveryEnabled, deviceEncryptionEnabled, allowSimplePassword, maxPasswordFailedAttempts, minPasswordLength, inactivityLockMin, passwordExpirationDays, passwordHistory, refreshInterval); return 0; @@ -935,93 +935,93 @@ namespace WebsitePanel.EnterpriseServer } } - private static void UpdateOrganization(Organization organization) - { - PackageController.UpdatePackageItem(organization); - } - #endregion + private static void UpdateOrganization(Organization organization) + { + PackageController.UpdatePackageItem(organization); + } + #endregion - #region Accounts + #region Accounts - private static bool AccountExists(string accountName) - { - return DataProvider.ExchangeAccountExists(accountName); - } + 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(); + 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 + res.RecordsCount = res.PageItems.Length; + return res; + } + #endregion - DataSet ds = DataProvider.GetExchangeAccountsPaged(SecurityContext.User.UserId, itemId, + 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; - } + ExchangeAccountsPaged result = new ExchangeAccountsPaged(); + result.RecordsCount = (int)ds.Tables[0].Rows[0][0]; - 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); + List accounts = new List(); + ObjectUtils.FillCollectionFromDataView(accounts, ds.Tables[1].DefaultView); + result.PageItems = accounts.ToArray(); + return result; + } - 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); + 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, false, "", "", ""); + else if (accountType == ExchangeAccountType.Contact) + return SearchAccounts(0, false, true, false, false, false, false, "", "", ""); + else if (accountType == ExchangeAccountType.DistributionList) + return SearchAccounts(0, false, false, true, false, 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 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 + 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); - return ObjectUtils.CreateListFromDataReader( - DataProvider.GetExchangeAccounts(itemId, (int)accountType)); - } + 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) @@ -1035,36 +1035,36 @@ namespace WebsitePanel.EnterpriseServer 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(); + public static List SearchAccounts(int itemId, + bool includeMailboxes, bool includeContacts, bool includeDistributionLists, + bool includeRooms, bool includeEquipment, bool includeSecurityGroups, + 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); + 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); - } + + 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) { @@ -1088,65 +1088,75 @@ namespace WebsitePanel.EnterpriseServer 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); + 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); - } + 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); - } + 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 + if (includeSecurityGroups) + { + ExchangeAccount g1 = new ExchangeAccount(); + g1.AccountId = 7; + g1.AccountName = "group_fabrikam"; + g1.AccountType = ExchangeAccountType.SecurityGroup; + g1.DisplayName = "Fabrikam Sales Dept"; + demoAccounts.Add(g1); + } - return ObjectUtils.CreateListFromDataReader( - DataProvider.SearchExchangeAccounts(SecurityContext.User.UserId, itemId, includeMailboxes, includeContacts, - includeDistributionLists, includeRooms, includeEquipment, + return demoAccounts; + } + #endregion + + return ObjectUtils.CreateListFromDataReader( + DataProvider.SearchExchangeAccounts(SecurityContext.User.UserId, itemId, includeMailboxes, includeContacts, + includeDistributionLists, includeRooms, includeEquipment, includeSecurityGroups, 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 + 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)); + ExchangeAccount account = ObjectUtils.FillObjectFromDataReader( + DataProvider.GetExchangeAccount(itemId, accountId)); if (account == null) return null; @@ -1155,7 +1165,7 @@ namespace WebsitePanel.EnterpriseServer account.AccountPassword = CryptoUtils.Decrypt(account.AccountPassword); return account; - } + } public static bool CheckAccountCredentials(int itemId, string email, string password) { @@ -1217,14 +1227,14 @@ namespace WebsitePanel.EnterpriseServer (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; + private static void DeleteAccount(int itemId, int accountId) + { + // try to get organization + if (GetOrganization(itemId) == null) + return; - DataProvider.DeleteExchangeAccount(itemId, accountId); - } + DataProvider.DeleteExchangeAccount(itemId, accountId); + } private static string BuildAccountName(string orgId, string name) { @@ -1263,119 +1273,119 @@ namespace WebsitePanel.EnterpriseServer } - #endregion + #endregion - #region Account Email Addresses - private static bool EmailAddressExists(string emailAddress) - { - return DataProvider.ExchangeAccountEmailAddressExists(emailAddress); - } + #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); + 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 e3 = new ExchangeEmailAddress(); - e3.EmailAddress = "john@fabrikam.hosted-exchange.com"; - demoEmails.Add(e3); - return demoEmails.ToArray(); - } - #endregion + ExchangeEmailAddress e2 = new ExchangeEmailAddress(); + e2.EmailAddress = "john.smith@fabrikam.net"; + demoEmails.Add(e2); - List emails = ObjectUtils.CreateListFromDataReader( - DataProvider.GetExchangeAccountEmailAddresses(accountId)); + ExchangeEmailAddress e3 = new ExchangeEmailAddress(); + e3.EmailAddress = "john@fabrikam.hosted-exchange.com"; + demoEmails.Add(e3); + return demoEmails.ToArray(); + } + #endregion - // load account - ExchangeAccount account = GetAccount(itemId, accountId); + List emails = ObjectUtils.CreateListFromDataReader( + DataProvider.GetExchangeAccountEmailAddresses(accountId)); - foreach (ExchangeEmailAddress email in emails) - { - if (String.Compare(account.PrimaryEmailAddress, email.EmailAddress, true) == 0) - { - email.IsPrimary = true; - } + // 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(); - } + return emails.ToArray(); + } - private static void AddAccountEmailAddress(int accountId, string emailAddress) - { - DataProvider.AddExchangeAccountEmailAddress(accountId, emailAddress); - } + 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); - } + private static void DeleteAccountEmailAddresses(int accountId, string[] emailAddresses) + { + foreach (string emailAddress in emailAddresses) + DataProvider.DeleteExchangeAccountEmailAddress(accountId, emailAddress); + } - #endregion + #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); + #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); + ExchangeDomainName d2 = new ExchangeDomainName(); + d2.DomainId = 2; + d2.DomainName = "fabrikam.net"; + d2.IsDefault = true; + d2.IsHost = false; + demoDomains.Add(d2); - return demoDomains; - } - #endregion + return demoDomains; + } + #endregion - // load organization - Organization org = (Organization)PackageController.GetPackageItem(itemId); - if (org == null) - return null; + // load organization + Organization org = (Organization)PackageController.GetPackageItem(itemId); + if (org == null) + return null; - // load all domains - List domains = ObjectUtils.CreateListFromDataReader( - DataProvider.GetExchangeOrganizationDomains(itemId)); + // 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; - } - } + // set default domain + foreach (ExchangeDomainName domain in domains) + { + if (String.Compare(domain.DomainName, org.DefaultDomain, true) == 0) + { + domain.IsDefault = true; + break; + } + } - return domains; - } + return domains; + } public static int AddAuthoritativeDomain(int itemId, int domainId) { @@ -1435,7 +1445,7 @@ namespace WebsitePanel.EnterpriseServer ServerController.AddServiceDNSRecords(org.PackageId, ResourceGroups.Exchange, domain, ""); } } - + return 0; } catch (Exception ex) @@ -1463,7 +1473,7 @@ namespace WebsitePanel.EnterpriseServer TaskManager.StartTask("EXCHANGE", "CHANGE_DOMAIN_TYPE", itemId, parameters); try - { + { // load organization Organization org = (Organization)PackageController.GetPackageItem(itemId); if (org == null) @@ -1507,38 +1517,38 @@ namespace WebsitePanel.EnterpriseServer 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", itemId, new BackgroundTaskParameter("Domain ID", domainId)); + public static int DeleteAuthoritativeDomain(int itemId, int domainId) + { + // check account + int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); + if (accountCheck < 0) return accountCheck; - try - { - // load organization - Organization org = (Organization)PackageController.GetPackageItem(itemId); - if (org == null) - return -1; + // place log record + TaskManager.StartTask("EXCHANGE", "DELETE_DOMAIN", itemId, new BackgroundTaskParameter("Domain ID", domainId)); - // load domain - DomainInfo domain = ServerController.GetDomain(domainId); - if(domain == null) - return -1; + 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; + + // delete domain on Exchange + int[] hubTransportServiceIds; + int[] clientAccessServiceIds; int exchangeServiceId = GetExchangeServiceID(org.PackageId); - GetExchangeServices(exchangeServiceId, out hubTransportServiceIds, out clientAccessServiceIds); + GetExchangeServices(exchangeServiceId, out hubTransportServiceIds, out clientAccessServiceIds); foreach (int id in hubTransportServiceIds) { @@ -1569,22 +1579,22 @@ namespace WebsitePanel.EnterpriseServer - return 0; - } - catch (Exception ex) - { - throw TaskManager.WriteError(ex); - } - finally - { - TaskManager.CompleteTask(); - } - } + return 0; + } + catch (Exception ex) + { + throw TaskManager.WriteError(ex); + } + finally + { + TaskManager.CompleteTask(); + } + } - #endregion + #endregion - #region Mailboxes + #region Mailboxes private static void UpdateExchangeAccount(int accountId, string accountName, ExchangeAccountType accountType, string displayName, string primaryEmailAddress, bool mailEnabledPublicFolder, @@ -1701,7 +1711,7 @@ namespace WebsitePanel.EnterpriseServer if (cntx.Quotas.ContainsKey(Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE) && cntx.Quotas[Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE].QuotaAllocatedValue > 0) { - maxRecoverableItemsSpace = cntx.Quotas[Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE].QuotaAllocatedValue; + maxRecoverableItemsSpace = cntx.Quotas[Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE].QuotaAllocatedValue; quotaRecoverableItemsUsed = cntx.Quotas[Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE].QuotaUsedValue; } @@ -1826,18 +1836,18 @@ namespace WebsitePanel.EnterpriseServer { 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.AccountType = ExchangeAccountType.User; account.MailEnabledPublicFolder = false; account.AccountPassword = null; UpdateAccount(account); DataProvider.DeleteUserEmailAddresses(account.AccountId, account.PrimaryEmailAddress); - + return 0; } catch (Exception ex) @@ -1850,120 +1860,120 @@ namespace WebsitePanel.EnterpriseServer } } - - 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 + 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", itemId); - try - { - // load organization - Organization org = GetOrganization(itemId); - if (org == null) - return -1; + try + { + // load organization + Organization org = GetOrganization(itemId); + if (org == null) + return -1; - // load account - ExchangeAccount account = GetAccount(itemId, accountId); + // load account + ExchangeAccount account = GetAccount(itemId, accountId); if (BlackBerryController.CheckBlackBerryUserExists(accountId)) { BlackBerryController.DeleteBlackBerryUser(itemId, accountId); } - - // delete mailbox - int serviceExchangeId = GetExchangeServiceID(org.PackageId); + + // delete mailbox + int serviceExchangeId = GetExchangeServiceID(org.PackageId); ExchangeServer exchange = GetExchangeServer(serviceExchangeId, org.ServiceId); - exchange.DeleteMailbox(account.UserPrincipalName); + exchange.DeleteMailbox(account.UserPrincipalName); + + - - // unregister account - DeleteAccount(itemId, accountId); + DeleteAccount(itemId, accountId); - return 0; - } - catch (Exception ex) - { - throw TaskManager.WriteError(ex); - } - finally - { - TaskManager.CompleteTask(); - } - } + 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; - } + 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 + public static ExchangeMailbox GetMailboxGeneralSettings(int itemId, int accountId) + { + #region Demo Mode + if (IsDemoMode) + { + return GetDemoMailboxSettings(); + } + #endregion - // place log record + // place log record TaskManager.StartTask("EXCHANGE", "GET_MAILBOX_GENERAL", itemId); - try - { - // load organization - Organization org = GetOrganization(itemId); - if (org == null) - return null; + try + { + // load organization + Organization org = GetOrganization(itemId); + if (org == null) + return null; - // load account - ExchangeAccount account = GetAccount(itemId, accountId); + // load account + ExchangeAccount account = GetAccount(itemId, accountId); - // get mailbox settings + // get mailbox settings - int exchangeServiceId = GetExchangeServiceID(org.PackageId); + 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(); - } - } + 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) { @@ -2015,74 +2025,74 @@ namespace WebsitePanel.EnterpriseServer } } - public static ExchangeEmailAddress[] GetMailboxEmailAddresses(int itemId, int accountId) - { - // place log record + public static ExchangeEmailAddress[] GetMailboxEmailAddresses(int itemId, int accountId) + { + // place log record TaskManager.StartTask("EXCHANGE", "GET_MAILBOX_ADDRESSES", itemId); - try - { - return GetAccountEmailAddresses(itemId, accountId); - } - catch (Exception ex) - { - throw TaskManager.WriteError(ex); - } - finally - { - TaskManager.CompleteTask(); - } - } + 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; + 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 + // place log record TaskManager.StartTask("EXCHANGE", "ADD_MAILBOX_ADDRESS", itemId); - try - { - // check - if (EmailAddressExists(emailAddress)) - return BusinessErrorCodes.ERROR_EXCHANGE_EMAIL_EXISTS; + try + { + // check + if (EmailAddressExists(emailAddress)) + return BusinessErrorCodes.ERROR_EXCHANGE_EMAIL_EXISTS; - // load organization - Organization org = GetOrganization(itemId); - if (org == null) - return -1; + // 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; + // check package + int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive); + if (packageCheck < 0) return packageCheck; - // load account - ExchangeAccount account = GetAccount(itemId, accountId); + // load account + ExchangeAccount account = GetAccount(itemId, accountId); - // add e-mail - AddAccountEmailAddress(accountId, emailAddress); + // add e-mail + AddAccountEmailAddress(accountId, emailAddress); - // update e-mail addresses - int exchangeServiceId = GetExchangeServiceID(org.PackageId); + // update e-mail addresses + int exchangeServiceId = GetExchangeServiceID(org.PackageId); ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId); exchange.SetMailboxEmailAddresses( - account.UserPrincipalName, - GetAccountSimpleEmailAddresses(itemId, accountId)); + account.UserPrincipalName, + GetAccountSimpleEmailAddresses(itemId, accountId)); - return 0; - } - catch (Exception ex) - { - throw TaskManager.WriteError(ex); - } - finally - { - TaskManager.CompleteTask(); - } - } + return 0; + } + catch (Exception ex) + { + throw TaskManager.WriteError(ex); + } + finally + { + TaskManager.CompleteTask(); + } + } private static OCSServer GetOCSProxy(int itemId) { @@ -2095,37 +2105,37 @@ namespace WebsitePanel.EnterpriseServer 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 + 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", itemId); - try - { - // get account - ExchangeAccount account = GetAccount(itemId, accountId); - account.PrimaryEmailAddress = emailAddress; + try + { + // get account + ExchangeAccount account = GetAccount(itemId, accountId); + account.PrimaryEmailAddress = emailAddress; - // update exchange - Organization org = GetOrganization(itemId); - if (org == null) - return -1; + // 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; + // 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); + + exchange.SetMailboxPrimaryEmailAddress( + account.UserPrincipalName, + emailAddress); if (DataProvider.CheckOCSUserExists(account.AccountId)) { @@ -2139,111 +2149,111 @@ namespace WebsitePanel.EnterpriseServer LyncController.SetLyncUserGeneralSettings(itemId, accountId, emailAddress, null); } - // save account + // save account account.AccountPassword = null; - UpdateAccount(account); + UpdateAccount(account); - return 0; - } - catch (Exception ex) - { - throw TaskManager.WriteError(ex); - } - finally - { - TaskManager.CompleteTask(); - } - } + 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; + 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 + // place log record TaskManager.StartTask("EXCHANGE", "DELETE_MAILBOX_ADDRESSES", itemId); - try - { - // get account - ExchangeAccount account = GetAccount(itemId, accountId); + 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) & + // 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); - } + toDelete.Add(emailAddress); + } - // delete from meta-base - DeleteAccountEmailAddresses(accountId, toDelete.ToArray()); + // delete from meta-base + DeleteAccountEmailAddresses(accountId, toDelete.ToArray()); - // delete from Exchange - Organization org = GetOrganization(itemId); - if (org == null) - return -1; + // delete from Exchange + Organization org = GetOrganization(itemId); + if (org == null) + return -1; - // update e-mail addresses + // 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(); - } - } + exchange.SetMailboxEmailAddresses( + account.UserPrincipalName, + GetAccountSimpleEmailAddresses(itemId, accountId)); - public static ExchangeMailbox GetMailboxMailFlowSettings(int itemId, int accountId) - { - #region Demo Mode - if (IsDemoMode) - { - return GetDemoMailboxSettings(); - } - #endregion + return 0; + } + catch (Exception ex) + { + throw TaskManager.WriteError(ex); + } + finally + { + TaskManager.CompleteTask(); + } + } - // place log record + 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", itemId); - try - { - // load organization - Organization org = GetOrganization(itemId); - if (org == null) - return null; + try + { + // load organization + Organization org = GetOrganization(itemId); + if (org == null) + return null; - // load account - ExchangeAccount account = GetAccount(itemId, accountId); + // load account + ExchangeAccount account = GetAccount(itemId, accountId); - // get mailbox settings + // 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(); - } - } + 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, @@ -2297,44 +2307,44 @@ namespace WebsitePanel.EnterpriseServer } - public static ExchangeMailbox GetMailboxAdvancedSettings(int itemId, int accountId) - { - #region Demo Mode - if (IsDemoMode) - { - return GetDemoMailboxSettings(); - } - #endregion + public static ExchangeMailbox GetMailboxAdvancedSettings(int itemId, int accountId) + { + #region Demo Mode + if (IsDemoMode) + { + return GetDemoMailboxSettings(); + } + #endregion - // place log record + // place log record TaskManager.StartTask("EXCHANGE", "GET_MAILBOX_ADVANCED", itemId); - try - { - // load organization - Organization org = GetOrganization(itemId); - if (org == null) - return null; + try + { + // load organization + Organization org = GetOrganization(itemId); + if (org == null) + return null; - // load account - ExchangeAccount account = GetAccount(itemId, accountId); + // load account + ExchangeAccount account = GetAccount(itemId, accountId); - // get mailbox settings + // 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(); - } - } + 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) { @@ -2387,7 +2397,7 @@ namespace WebsitePanel.EnterpriseServer return string.Empty; } #endregion - + // load organization Organization org = GetOrganization(itemId); if (org == null) @@ -2528,7 +2538,7 @@ namespace WebsitePanel.EnterpriseServer // get mailbox settings int exchangeServiceId = GetExchangeServiceID(org.PackageId); ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId); - ExchangeMailbox mailbox = exchange.GetMailboxPermissions(org.OrganizationId, account.UserPrincipalName); + ExchangeMailbox mailbox = exchange.GetMailboxPermissions(org.OrganizationId, account.UserPrincipalName); mailbox.DisplayName = account.DisplayName; return mailbox; } @@ -2539,7 +2549,7 @@ namespace WebsitePanel.EnterpriseServer finally { TaskManager.CompleteTask(); - } + } } public static int SetMailboxPermissions(int itemId, int accountId, string[] sendAsaccounts, string[] fullAccessAcounts) @@ -2568,9 +2578,9 @@ namespace WebsitePanel.EnterpriseServer // get mailbox settings int exchangeServiceId = GetExchangeServiceID(org.PackageId); ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId); - + exchange.SetMailboxPermissions(org.OrganizationId, account.UserPrincipalName, sendAsaccounts, fullAccessAcounts); - + return 0; } @@ -2581,12 +2591,12 @@ namespace WebsitePanel.EnterpriseServer finally { TaskManager.CompleteTask(); - } - + } + } - #endregion + #endregion #region Mailbox plan @@ -2743,7 +2753,7 @@ namespace WebsitePanel.EnterpriseServer } } - private static void GetExchangeMailboxPlansByUser(int itemId, UserInfo user, ref ListmailboxPlans) + private static void GetExchangeMailboxPlansByUser(int itemId, UserInfo user, ref List mailboxPlans) { if ((user != null)) { @@ -2752,7 +2762,7 @@ namespace WebsitePanel.EnterpriseServer if (user.UserId != 1) { List Packages = PackageController.GetPackages(user.UserId); - + if ((Packages != null) & (Packages.Count > 0)) { orgs = GetExchangeOrganizationsInternal(Packages[0].PackageId, false); @@ -2995,7 +3005,7 @@ namespace WebsitePanel.EnterpriseServer #region Contacts public static int CreateContact(int itemId, string displayName, string email) - { + { //if (EmailAddressExists(email)) // return BusinessErrorCodes.ERROR_EXCHANGE_EMAIL_EXISTS; @@ -3071,103 +3081,103 @@ namespace WebsitePanel.EnterpriseServer } } - public static int DeleteContact(int itemId, int accountId) - { - // check account - int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); - if (accountCheck < 0) return accountCheck; + 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 + // place log record TaskManager.StartTask("EXCHANGE", "DELETE_CONTACT", itemId); try - { - // load organization - Organization org = GetOrganization(itemId); - if (org == null) - return -1; + { + // load organization + Organization org = GetOrganization(itemId); + if (org == null) + return -1; - // load account - ExchangeAccount account = GetAccount(itemId, accountId); + // load account + ExchangeAccount account = GetAccount(itemId, accountId); - // delete contact + // delete contact int exchangeServiceId = GetExchangeServiceID(org.PackageId); ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId); - - exchange.DeleteContact(account.AccountName); - // remove meta-item - DeleteAccount(itemId, accountId); + exchange.DeleteContact(account.AccountName); - return 0; - } - catch (Exception ex) - { - throw TaskManager.WriteError(ex); - } - finally - { - TaskManager.CompleteTask(); - } - } + // remove meta-item + DeleteAccount(itemId, accountId); - 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; - } + return 0; + } + catch (Exception ex) + { + throw TaskManager.WriteError(ex); + } + finally + { + TaskManager.CompleteTask(); + } + } - public static ExchangeContact GetContactGeneralSettings(int itemId, int accountId) - { - #region Demo Mode - if (IsDemoMode) - { - return GetDemoContactSettings(); - } - #endregion + 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; + } - // place log record + 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", itemId); - try - { - // load organization - Organization org = GetOrganization(itemId); - if (org == null) - return null; + try + { + // load organization + Organization org = GetOrganization(itemId); + if (org == null) + return null; - // load account - ExchangeAccount account = GetAccount(itemId, accountId); + // load account + ExchangeAccount account = GetAccount(itemId, accountId); - // get mailbox settings + // 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, + 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; @@ -3243,95 +3253,95 @@ namespace WebsitePanel.EnterpriseServer } } - public static ExchangeContact GetContactMailFlowSettings(int itemId, int accountId) - { - #region Demo Mode - if (IsDemoMode) - { - return GetDemoContactSettings(); - } - #endregion + public static ExchangeContact GetContactMailFlowSettings(int itemId, int accountId) + { + #region Demo Mode + if (IsDemoMode) + { + return GetDemoContactSettings(); + } + #endregion - // place log record + // place log record TaskManager.StartTask("EXCHANGE", "GET_CONTACT_MAILFLOW", itemId); - try - { - // load organization - Organization org = GetOrganization(itemId); - if (org == null) - return null; + try + { + // load organization + Organization org = GetOrganization(itemId); + if (org == null) + return null; - // load account - ExchangeAccount account = GetAccount(itemId, accountId); + // load account + ExchangeAccount account = GetAccount(itemId, accountId); - // get mailbox settings + // 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; + ExchangeContact contact = exchange.GetContactMailFlowSettings(account.AccountName); + contact.DisplayName = account.DisplayName; + return contact; + } + catch (Exception ex) + { + throw TaskManager.WriteError(ex); + } + finally + { + TaskManager.CompleteTask(); + } + } - // place log record + 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", itemId); - try - { - // load organization - Organization org = GetOrganization(itemId); - if (org == null) - return -1; + 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; + // check package + int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive); + if (packageCheck < 0) return packageCheck; - // load account - ExchangeAccount account = GetAccount(itemId, accountId); + // load account + ExchangeAccount account = GetAccount(itemId, accountId); - // get mailbox settings + // 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 + exchange.SetContactMailFlowSettings(account.AccountName, + acceptAccounts, + rejectAccounts, + requireSenderAuthentication); - #region Distribution Lists - public static int CreateDistributionList(int itemId, string displayName, string name, string domain, int managerId) - { + 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; @@ -3416,99 +3426,99 @@ namespace WebsitePanel.EnterpriseServer } } - public static int DeleteDistributionList(int itemId, int accountId) - { - // check account - int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); - if (accountCheck < 0) return accountCheck; + 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 + // place log record TaskManager.StartTask("EXCHANGE", "DELETE_DISTR_LIST", itemId); - try - { - // load organization - Organization org = GetOrganization(itemId); - if (org == null) - return -1; + try + { + // load organization + Organization org = GetOrganization(itemId); + if (org == null) + return -1; - // load account - ExchangeAccount account = GetAccount(itemId, accountId); + // load account + ExchangeAccount account = GetAccount(itemId, accountId); - // delete mailbox + // delete mailbox int exchangeServiceId = GetExchangeServiceID(org.PackageId); ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId); - - exchange.DeleteDistributionList(account.AccountName); - // unregister account - DeleteAccount(itemId, accountId); + exchange.DeleteDistributionList(account.AccountName); - return 0; - } - catch (Exception ex) - { - throw TaskManager.WriteError(ex); - } - finally - { - TaskManager.CompleteTask(); - } - } + // unregister account + DeleteAccount(itemId, accountId); - 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; - } + return 0; + } + catch (Exception ex) + { + throw TaskManager.WriteError(ex); + } + finally + { + TaskManager.CompleteTask(); + } + } - public static ExchangeDistributionList GetDistributionListGeneralSettings(int itemId, int accountId) - { - #region Demo Mode - if (IsDemoMode) - { - return GetDemoDistributionListSettings(); - } - #endregion + 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; + } - // place log record + 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", itemId); - try - { - // load organization - Organization org = GetOrganization(itemId); - if (org == null) - return null; + try + { + // load organization + Organization org = GetOrganization(itemId); + if (org == null) + return null; - // load account - ExchangeAccount account = GetAccount(itemId, accountId); + // load account + ExchangeAccount account = GetAccount(itemId, accountId); - // get mailbox settings + // 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) - { + 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; @@ -3566,49 +3576,49 @@ namespace WebsitePanel.EnterpriseServer } } - public static ExchangeDistributionList GetDistributionListMailFlowSettings(int itemId, int accountId) - { - #region Demo Mode - if (IsDemoMode) - { - return GetDemoDistributionListSettings(); - } - #endregion + public static ExchangeDistributionList GetDistributionListMailFlowSettings(int itemId, int accountId) + { + #region Demo Mode + if (IsDemoMode) + { + return GetDemoDistributionListSettings(); + } + #endregion - // place log record + // place log record TaskManager.StartTask("EXCHANGE", "GET_DISTR_LIST_MAILFLOW", itemId); - try - { - // load organization - Organization org = GetOrganization(itemId); - if (org == null) - return null; + try + { + // load organization + Organization org = GetOrganization(itemId); + if (org == null) + return null; - // load account - ExchangeAccount account = GetAccount(itemId, accountId); + // load account + ExchangeAccount account = GetAccount(itemId, accountId); - // get mailbox settings + // 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) - { + 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; @@ -3657,27 +3667,27 @@ namespace WebsitePanel.EnterpriseServer } } - public static ExchangeEmailAddress[] GetDistributionListEmailAddresses(int itemId, int accountId) - { - // place log record + public static ExchangeEmailAddress[] GetDistributionListEmailAddresses(int itemId, int accountId) + { + // place log record TaskManager.StartTask("EXCHANGE", "GET_DISTR_LIST_ADDRESSES", itemId); - try - { - return GetAccountEmailAddresses(itemId, accountId); - } - catch (Exception ex) - { - throw TaskManager.WriteError(ex); - } - finally - { - TaskManager.CompleteTask(); - } - } + 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) - { + 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; @@ -3730,8 +3740,8 @@ namespace WebsitePanel.EnterpriseServer } } - public static int SetDistributionListPrimaryEmailAddress(int itemId, int accountId, string emailAddress) - { + 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; @@ -3782,8 +3792,8 @@ namespace WebsitePanel.EnterpriseServer } } - public static int DeleteDistributionListEmailAddresses(int itemId, int accountId, string[] emailAddresses) - { + 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; @@ -3847,7 +3857,7 @@ namespace WebsitePanel.EnterpriseServer if (org == null) throw new ApplicationException("Organization is null"); } - catch(Exception ex) + catch (Exception ex) { TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ORGANIZATION_BY_ITEM_ID, ex); return res; @@ -3860,7 +3870,7 @@ namespace WebsitePanel.EnterpriseServer int exchangeServiceId = GetExchangeServiceID(org.PackageId); exchange = GetExchangeServer(exchangeServiceId, org.ServiceId); } - catch(Exception ex) + catch (Exception ex) { TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ORGANIZATION_PROXY, ex); return res; @@ -3872,7 +3882,7 @@ namespace WebsitePanel.EnterpriseServer { account = GetAccount(itemId, accountId); } - catch(Exception ex) + catch (Exception ex) { TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ACCOUNT, ex); return res; @@ -3887,7 +3897,7 @@ namespace WebsitePanel.EnterpriseServer exchange.SetDistributionListPermissions(org.OrganizationId, account.AccountName, sendAsAccounts, sendOnBehalfAccounts, addressLists.ToArray()); } - catch(Exception ex) + catch (Exception ex) { TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_SET_DISTRIBUTION_LIST_PERMISSIONS, ex); return res; @@ -3897,20 +3907,20 @@ namespace WebsitePanel.EnterpriseServer return res; } - public static ExchangeDistributionListResult GetDistributionListPermissions(int itemId, int accountId) + 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) + catch (Exception ex) { - TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ORGANIZATION_BY_ITEM_ID, ex); + TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ORGANIZATION_BY_ITEM_ID, ex); return res; } @@ -3920,18 +3930,18 @@ namespace WebsitePanel.EnterpriseServer int exchangeServiceId = GetExchangeServiceID(org.PackageId); exchange = GetExchangeServer(exchangeServiceId, org.ServiceId); } - catch(Exception ex) + catch (Exception ex) { TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ORGANIZATION_PROXY, ex); return res; } - + ExchangeAccount account; try { account = GetAccount(itemId, accountId); } - catch(Exception ex) + catch (Exception ex) { TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ACCOUNT, ex); return res; @@ -3942,12 +3952,12 @@ namespace WebsitePanel.EnterpriseServer res.Value = exchange.GetDistributionListPermissions(org.OrganizationId, account.AccountName); res.Value.DisplayName = account.DisplayName; } - catch(Exception ex) + catch (Exception ex) { TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_DISTRIBUTION_LIST_PERMISSIONS, ex); return res; } - + TaskManager.CompleteTask(); return res; } @@ -4113,65 +4123,65 @@ namespace WebsitePanel.EnterpriseServer } return 0; - } + } - #endregion + #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; + #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; + // 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 + // place log record TaskManager.StartTask("EXCHANGE", "CREATE_PUBLIC_FOLDER", itemId); - try - { - // e-mail - string email = ""; - if (mailEnabled && !String.IsNullOrEmpty(name)) - { - email = name + "@" + domain; + 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; - } + // 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 + "\\"; + // full folder name + string normParent = parentFolder; + if (!normParent.StartsWith("\\")) + normParent = "\\" + normParent; + if (!normParent.EndsWith("\\")) + normParent = normParent + "\\"; - string folderPath = normParent + folderName; + string folderPath = normParent + folderName; - // load organization - Organization org = GetOrganization(itemId); - if (org == null) - return -1; + // 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; + // check package + int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive); + if (packageCheck < 0) return packageCheck; - if (String.IsNullOrEmpty(name)) - name = Utils.CleanIdentifier(folderName); + if (String.IsNullOrEmpty(name)) + name = Utils.CleanIdentifier(folderName); - string accountName = BuildAccountName(org.OrganizationId, name); + string accountName = BuildAccountName(org.OrganizationId, name); - // add mailbox + // add mailbox int exchangeServiceId = GetExchangeServiceID(org.PackageId); ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId); @@ -4183,195 +4193,195 @@ namespace WebsitePanel.EnterpriseServer PackageController.UpdatePackageItem(org); } - exchange.CreatePublicFolder(org.DistinguishedName, - org.OrganizationId, - org.SecurityGroup, - parentFolder, - folderName, - mailEnabled, - accountName, - name, - domain); + 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); + // 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); + // register email address + if (mailEnabled) + AddAccountEmailAddress(accountId, email); - return accountId; - } - catch (Exception ex) - { - throw TaskManager.WriteError(ex); - } - finally - { - TaskManager.CompleteTask(); - } - } + 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; + 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; - } + 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; + 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 + // place log record TaskManager.StartTask("EXCHANGE", "DELETE_PUBLIC_FOLDER", itemId); - try - { - // load organization - Organization org = GetOrganization(itemId); - if (org == null) - return -1; + try + { + // load organization + Organization org = GetOrganization(itemId); + if (org == null) + return -1; - // load account - ExchangeAccount account = GetAccount(itemId, accountId); + // load account + ExchangeAccount account = GetAccount(itemId, accountId); - // delete folder + // delete folder int exchangeServiceId = GetExchangeServiceID(org.PackageId); ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId); exchange.DeletePublicFolder(org.OrganizationId, account.DisplayName); - // unregister account - DeleteAccount(itemId, accountId); + // 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); - } + // 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(); - } - } + 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; + 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 + // place log record TaskManager.StartTask("EXCHANGE", "ENABLE_MAIL_PUBLIC_FOLDER", itemId); - try - { - // load organization - Organization org = GetOrganization(itemId); - if (org == null) - return -1; + 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; + // 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; + // load account + ExchangeAccount account = GetAccount(itemId, accountId); + if (account.MailEnabledPublicFolder) + return 0; - // check email - string email = name + "@" + domain; + // check email + string email = name + "@" + domain; - // check e-mail - if (EmailAddressExists(email)) - return BusinessErrorCodes.ERROR_EXCHANGE_EMAIL_EXISTS; + // check e-mail + if (EmailAddressExists(email)) + return BusinessErrorCodes.ERROR_EXCHANGE_EMAIL_EXISTS; - string accountName = BuildAccountName(org.OrganizationId, name); + 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; + 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); + UpdateAccount(account); - // register e-mail - AddAccountEmailAddress(accountId, email); + // register e-mail + AddAccountEmailAddress(accountId, email); - return 0; - } - catch (Exception ex) - { - throw TaskManager.WriteError(ex); - } - finally - { - TaskManager.CompleteTask(); - } - } + 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; + 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 + // place log record TaskManager.StartTask("EXCHANGE", "DISABLE_MAIL_PUBLIC_FOLDER", itemId); - try - { - // load organization - Organization org = GetOrganization(itemId); - if (org == null) - return -1; + 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; + // 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; + // load account + ExchangeAccount account = GetAccount(itemId, accountId); + if (!account.MailEnabledPublicFolder) + return 0; int exchangeServiceId = GetExchangeServiceID(org.PackageId); ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId); @@ -4379,416 +4389,416 @@ namespace WebsitePanel.EnterpriseServer exchange.DisableMailPublicFolder(org.OrganizationId, account.DisplayName); - // update and save account - account.MailEnabledPublicFolder = false; - account.PrimaryEmailAddress = ""; + // update and save account + account.MailEnabledPublicFolder = false; + account.PrimaryEmailAddress = ""; account.AccountPassword = null; - UpdateAccount(account); + UpdateAccount(account); - // delete all mail accounts - List addrs = new List(); - ExchangeEmailAddress[] emails = GetAccountEmailAddresses(itemId, accountId); - foreach (ExchangeEmailAddress email in emails) - addrs.Add(email.EmailAddress); + // 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()); + DeleteAccountEmailAddresses(accountId, addrs.ToArray()); - return 0; - } - catch (Exception ex) - { - throw TaskManager.WriteError(ex); - } - finally - { - TaskManager.CompleteTask(); - } - } + 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; - } + 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 + public static ExchangePublicFolder GetPublicFolderGeneralSettings(int itemId, int accountId) + { + #region Demo Mode + if (IsDemoMode) + { + return GetDemoPublicFolderSettings(); + } + #endregion - // place log record + // place log record TaskManager.StartTask("EXCHANGE", "GET_PUBLIC_FOLDER_GENERAL", itemId); - try - { - // load organization - Organization org = GetOrganization(itemId); - if (org == null) - return null; + try + { + // load organization + Organization org = GetOrganization(itemId); + if (org == null) + return null; - // load account - ExchangeAccount account = GetAccount(itemId, accountId); + // 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(); - } - } + 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; + 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 + // place log record TaskManager.StartTask("EXCHANGE", "UPDATE_PUBLIC_FOLDER_GENERAL", itemId); - try - { - // load organization - Organization org = GetOrganization(itemId); - if (org == null) - return -1; + 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; + // check package + int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive); + if (packageCheck < 0) return packageCheck; - // load account - ExchangeAccount account = GetAccount(itemId, accountId); + // load account + ExchangeAccount account = GetAccount(itemId, accountId); - // get mailbox settings + // get mailbox settings int exchangeServiceId = GetExchangeServiceID(org.PackageId); ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId); - - exchange.SetPublicFolderGeneralSettings( + + exchange.SetPublicFolderGeneralSettings( org.OrganizationId, - account.DisplayName, - newName, - hideAddressBook, + account.DisplayName, + newName, + hideAddressBook, accounts ); - // update folder name - string origName = account.DisplayName; - string newFullName = origName.Substring(0, origName.LastIndexOf("\\") + 1) + newName; + // 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; + if (String.Compare(origName, newFullName, true) != 0) + { + // rename original folder + account.DisplayName = newFullName; account.AccountPassword = null; - UpdateAccount(account); + 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); - } - } - } + // 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(); - } - } + 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 + public static ExchangePublicFolder GetPublicFolderMailFlowSettings(int itemId, int accountId) + { + #region Demo Mode + if (IsDemoMode) + { + return GetDemoPublicFolderSettings(); + } + #endregion - // place log record + // place log record TaskManager.StartTask("EXCHANGE", "GET_PUBLIC_FOLDER_MAILFLOW", itemId); - try - { - // load organization - Organization org = GetOrganization(itemId); - if (org == null) - return null; + try + { + // load organization + Organization org = GetOrganization(itemId); + if (org == null) + return null; - // load account - ExchangeAccount account = GetAccount(itemId, accountId); + // load account + ExchangeAccount account = GetAccount(itemId, accountId); - // get mailbox settings + // 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(); - } - } + 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; + 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 + // place log record TaskManager.StartTask("EXCHANGE", "UPDATE_PUBLIC_FOLDER_MAILFLOW", itemId); - try - { - // load organization - Organization org = GetOrganization(itemId); - if (org == null) - return -1; + 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; + // check package + int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive); + if (packageCheck < 0) return packageCheck; - // load account - ExchangeAccount account = GetAccount(itemId, accountId); + // load account + ExchangeAccount account = GetAccount(itemId, accountId); - // get mailbox settings + // get mailbox settings int exchangeServiceId = GetExchangeServiceID(org.PackageId); ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId); exchange.SetPublicFolderMailFlowSettings(org.OrganizationId, account.DisplayName, - acceptAccounts, - rejectAccounts, - requireSenderAuthentication); + acceptAccounts, + rejectAccounts, + requireSenderAuthentication); - return 0; - } - catch (Exception ex) - { - throw TaskManager.WriteError(ex); - } - finally - { - TaskManager.CompleteTask(); - } - } + return 0; + } + catch (Exception ex) + { + throw TaskManager.WriteError(ex); + } + finally + { + TaskManager.CompleteTask(); + } + } - public static ExchangeEmailAddress[] GetPublicFolderEmailAddresses(int itemId, int accountId) - { - // place log record + public static ExchangeEmailAddress[] GetPublicFolderEmailAddresses(int itemId, int accountId) + { + // place log record TaskManager.StartTask("EXCHANGE", "GET_PUBLIC_FOLDER_ADDRESSES", itemId); - try - { - return GetAccountEmailAddresses(itemId, accountId); - } - catch (Exception ex) - { - throw TaskManager.WriteError(ex); - } - finally - { - TaskManager.CompleteTask(); - } - } + 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; + 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 + // place log record TaskManager.StartTask("EXCHANGE", "ADD_PUBLIC_FOLDER_ADDRESS", itemId); - try - { - // check - if (EmailAddressExists(emailAddress)) - return BusinessErrorCodes.ERROR_EXCHANGE_EMAIL_EXISTS; + try + { + // check + if (EmailAddressExists(emailAddress)) + return BusinessErrorCodes.ERROR_EXCHANGE_EMAIL_EXISTS; - // load organization - Organization org = GetOrganization(itemId); - if (org == null) - return -1; + // 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; + // check package + int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive); + if (packageCheck < 0) return packageCheck; - // load account - ExchangeAccount account = GetAccount(itemId, accountId); + // load account + ExchangeAccount account = GetAccount(itemId, accountId); - // add e-mail - AddAccountEmailAddress(accountId, emailAddress); + // add e-mail + AddAccountEmailAddress(accountId, emailAddress); - // update e-mail addresses + // update e-mail addresses int exchangeServiceId = GetExchangeServiceID(org.PackageId); ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId); - - exchange.SetPublicFolderEmailAddresses( + + exchange.SetPublicFolderEmailAddresses( org.OrganizationId, - account.DisplayName, - GetAccountSimpleEmailAddresses(itemId, accountId)); + account.DisplayName, + GetAccountSimpleEmailAddresses(itemId, accountId)); - return 0; - } - catch (Exception ex) - { - throw TaskManager.WriteError(ex); - } - finally - { - TaskManager.CompleteTask(); - } - } + 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; + 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 + // place log record TaskManager.StartTask("EXCHANGE", "SET_PRIMARY_PUBLIC_FOLDER_ADDRESS", itemId); - try - { - // get account - ExchangeAccount account = GetAccount(itemId, accountId); - account.PrimaryEmailAddress = emailAddress; + try + { + // get account + ExchangeAccount account = GetAccount(itemId, accountId); + account.PrimaryEmailAddress = emailAddress; - // update exchange - Organization org = GetOrganization(itemId); - if (org == null) - return -1; + // 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; + // 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( + + exchange.SetPublicFolderPrimaryEmailAddress( org.OrganizationId, - account.DisplayName, - emailAddress); + account.DisplayName, + emailAddress); - // save account + // save account account.AccountPassword = null; - UpdateAccount(account); + UpdateAccount(account); - return 0; - } - catch (Exception ex) - { - throw TaskManager.WriteError(ex); - } - finally - { - TaskManager.CompleteTask(); - } - } + 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; + 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 + // place log record TaskManager.StartTask("EXCHANGE", "DELETE_PUBLIC_FOLDER_ADDRESSES", itemId); - try - { - // get account - ExchangeAccount account = GetAccount(itemId, accountId); + 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 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 meta-base + DeleteAccountEmailAddresses(accountId, toDelete.ToArray()); - // delete from Exchange - Organization org = GetOrganization(itemId); - if (org == null) - return -1; + // delete from Exchange + Organization org = GetOrganization(itemId); + if (org == null) + return -1; - // update e-mail addresses + // update e-mail addresses int exchangeServiceId = GetExchangeServiceID(org.PackageId); ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId); - - exchange.SetPublicFolderEmailAddresses( + + exchange.SetPublicFolderEmailAddresses( org.OrganizationId, - account.DisplayName, - GetAccountSimpleEmailAddresses(itemId, accountId)); + account.DisplayName, + GetAccountSimpleEmailAddresses(itemId, accountId)); - return 0; - } - catch (Exception ex) - { - throw TaskManager.WriteError(ex); - } - finally - { - TaskManager.CompleteTask(); - } - } - #endregion + return 0; + } + catch (Exception ex) + { + throw TaskManager.WriteError(ex); + } + finally + { + TaskManager.CompleteTask(); + } + } + #endregion - #region Private Helpers + #region Private Helpers private static string GetPrimaryDomainController(int organizationServiceId) { - + Organizations orgProxy = new Organizations(); ServiceProviderProxy.Init(orgProxy, organizationServiceId); @@ -4835,35 +4845,35 @@ namespace WebsitePanel.EnterpriseServer { ServiceProvider ws = new ServiceProvider(); - ServiceProviderProxy.Init(ws, exchangeServiceId); + 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; + 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) { @@ -4880,40 +4890,40 @@ namespace WebsitePanel.EnterpriseServer ExtendExchangeSettings(resSettings, orgPrimaryDomainController); ws.ServiceProviderSettingsSoapHeaderValue.Settings = resSettings.ToArray(); return ws; - } + } - private static int GetExchangeServiceID(int packageId) - { - return PackageController.GetPackageServiceId(packageId, ResourceGroups.Exchange); - } + 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); - } + 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(); - } + return result.ToArray(); + } - private static bool QuotaEnabled(PackageContext cntx, string quotaName) - { - return cntx.Quotas.ContainsKey(quotaName) && !cntx.Quotas[quotaName].QuotaExhausted; - } + 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 + private static bool IsDemoMode + { + get + { + return (SecurityContext.CheckAccount(DemandAccount.NotDemo) < 0); + } + } + #endregion public static ExchangeMobileDevice[] GetMobileDevices(int itemId, int accountId) { diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/HostedSolution/OrganizationController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/HostedSolution/OrganizationController.cs index 556ca2db..d2fb54ce 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/HostedSolution/OrganizationController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/HostedSolution/OrganizationController.cs @@ -58,14 +58,14 @@ namespace WebsitePanel.EnterpriseServer { errorCode = 0; OrganizationStatistics stats = GetOrganizationStatistics(orgId); - - - if (stats.AllocatedUsers != -1 && (stats.CreatedUsers >= stats.AllocatedUsers) ) + + + if (stats.AllocatedUsers != -1 && (stats.CreatedUsers >= stats.AllocatedUsers)) { errorCode = BusinessErrorCodes.ERROR_USERS_RESOURCE_QUOTA_LIMIT; return false; } - + return true; } @@ -81,14 +81,14 @@ namespace WebsitePanel.EnterpriseServer // add organization items["Organization"] = org; OrganizationUser user = GetAccount(itemId, accountId); - + items["account"] = user; - + // evaluate template return PackageController.EvaluateTemplate(template, items); } - + public static string GetOrganizationUserSummuryLetter(int itemId, int accountId, bool pmm, bool emailMode, bool signup) { // load organization @@ -110,7 +110,7 @@ namespace WebsitePanel.EnterpriseServer string result = EvaluateMailboxTemplate(itemId, accountId, pmm, false, false, body); return user.HtmlMail ? result : result.Replace("\n", "
"); } - + public static int SendSummaryLetter(int itemId, int accountId, bool signup, string to, string cc) { // check account @@ -152,10 +152,10 @@ namespace WebsitePanel.EnterpriseServer // send message return MailHelper.SendMessage(from, to, cc, subject, body, priority, isHtml); } - + private static bool CheckQuotas(int packageId, out int errorCode) { - + // check account errorCode = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (errorCode < 0) return false; @@ -165,7 +165,7 @@ namespace WebsitePanel.EnterpriseServer if (errorCode < 0) return false; // check organizations quota - QuotaValueInfo quota = PackageController.GetPackageQuota(packageId, Quotas.ORGANIZATIONS ); + QuotaValueInfo quota = PackageController.GetPackageQuota(packageId, Quotas.ORGANIZATIONS); if (quota.QuotaExhausted) { errorCode = BusinessErrorCodes.ERROR_ORGS_RESOURCE_QUOTA_LIMIT; @@ -180,32 +180,32 @@ namespace WebsitePanel.EnterpriseServer errorCode = BusinessErrorCodes.ERROR_SUBDOMAIN_QUOTA_LIMIT; return false; } - - - return true; + + + return true; } private static string CreateTemporyDomainName(int serviceId, string organizationId) { // load service settings StringDictionary serviceSettings = ServerController.GetServiceSettings(serviceId); - + string tempDomain = serviceSettings[TemporyDomainName]; - return String.IsNullOrEmpty(tempDomain) ? null : organizationId + "."+ tempDomain; + return String.IsNullOrEmpty(tempDomain) ? null : organizationId + "." + tempDomain; } - + private static DomainInfo CreateNewDomain(int packageId, string domainName) - { + { // new domain DomainInfo domain = new DomainInfo(); domain.PackageId = packageId; domain.DomainName = domainName; domain.IsInstantAlias = true; domain.IsSubDomain = true; - + return domain; } - + private static int CreateDomain(string domainName, int packageId, out bool domainCreated) { // trying to locate (register) temp domain @@ -251,18 +251,18 @@ namespace WebsitePanel.EnterpriseServer return domainId; } - + private static int AddOrganizationToPackageItems(Organization org, int serviceId, int packageId, string organizationName, string organizationId, string domainName) - { + { org.ServiceId = serviceId; org.PackageId = packageId; org.Name = organizationName; org.OrganizationId = organizationId; org.DefaultDomain = domainName; - + int itemId = PackageController.AddPackageItem(org); - - + + return itemId; } @@ -271,26 +271,26 @@ namespace WebsitePanel.EnterpriseServer return DataProvider.ExchangeOrganizationExists(organizationId); } - private static void RollbackOrganization(int packageId, string organizationId) - { - try - { - int serviceId = PackageController.GetPackageServiceId(packageId, ResourceGroups.HostedOrganizations); - Organizations orgProxy = GetOrganizationProxy(serviceId); - orgProxy.DeleteOrganization(organizationId); - } - catch (Exception ex) - { - TaskManager.WriteError(ex); - } - } - public static int CreateOrganization(int packageId, string organizationId, string organizationName, string domainName) + private static void RollbackOrganization(int packageId, string organizationId) + { + try + { + int serviceId = PackageController.GetPackageServiceId(packageId, ResourceGroups.HostedOrganizations); + Organizations orgProxy = GetOrganizationProxy(serviceId); + orgProxy.DeleteOrganization(organizationId); + } + catch (Exception ex) + { + TaskManager.WriteError(ex); + } + } + public static int CreateOrganization(int packageId, string organizationId, string organizationName, string domainName) { int itemId; int errorCode; if (!CheckQuotas(packageId, out errorCode)) return errorCode; - + // place log record List parameters = new List(); parameters.Add(new BackgroundTaskParameter("Organization ID", organizationId)); @@ -298,49 +298,49 @@ namespace WebsitePanel.EnterpriseServer TaskManager.StartTask("ORGANIZATION", "CREATE_ORG", organizationName, parameters); - try - { - // Check if organization exitsts. - if (OrganizationIdentifierExists(organizationId)) - return BusinessErrorCodes.ERROR_ORG_ID_EXISTS; + try + { + // Check if organization exitsts. + if (OrganizationIdentifierExists(organizationId)) + return BusinessErrorCodes.ERROR_ORG_ID_EXISTS; - // Create Organization Unit - int serviceId = PackageController.GetPackageServiceId(packageId, ResourceGroups.HostedOrganizations); + // Create Organization Unit + int serviceId = PackageController.GetPackageServiceId(packageId, ResourceGroups.HostedOrganizations); - Organizations orgProxy = GetOrganizationProxy(serviceId); - Organization org = null; - if (!orgProxy.OrganizationExists(organizationId)) - { - org = orgProxy.CreateOrganization(organizationId); - } - else - return BusinessErrorCodes.ERROR_ORG_ID_EXISTS; + Organizations orgProxy = GetOrganizationProxy(serviceId); + Organization org = null; + if (!orgProxy.OrganizationExists(organizationId)) + { + org = orgProxy.CreateOrganization(organizationId); + } + else + return BusinessErrorCodes.ERROR_ORG_ID_EXISTS; - //create temporary domain name; + //create temporary domain name; if (string.IsNullOrEmpty(domainName)) { string tmpDomainName = CreateTemporyDomainName(serviceId, organizationId); if (!string.IsNullOrEmpty(tmpDomainName)) domainName = tmpDomainName; } - - if (string.IsNullOrEmpty(domainName)) - { - domainName = organizationName; - //RollbackOrganization(packageId, organizationId); - //return BusinessErrorCodes.ERROR_ORGANIZATION_TEMP_DOMAIN_IS_NOT_SPECIFIED; - } - - bool domainCreated; - int domainId = CreateDomain(domainName, packageId, out domainCreated); - //create domain - if (domainId < 0) - { - RollbackOrganization(packageId, organizationId); - return domainId; - } - + if (string.IsNullOrEmpty(domainName)) + { + domainName = organizationName; + //RollbackOrganization(packageId, organizationId); + //return BusinessErrorCodes.ERROR_ORGANIZATION_TEMP_DOMAIN_IS_NOT_SPECIFIED; + } + + + bool domainCreated; + int domainId = CreateDomain(domainName, packageId, out domainCreated); + //create domain + if (domainId < 0) + { + RollbackOrganization(packageId, organizationId); + return domainId; + } + DomainInfo domain = ServerController.GetDomain(domainId); if (domain != null) { @@ -352,63 +352,63 @@ namespace WebsitePanel.EnterpriseServer } - PackageContext cntx = PackageController.GetPackageContext(packageId); + PackageContext cntx = PackageController.GetPackageContext(packageId); - if (cntx.Quotas[Quotas.HOSTED_SHAREPOINT_STORAGE_SIZE] != null) - org.MaxSharePointStorage = cntx.Quotas[Quotas.HOSTED_SHAREPOINT_STORAGE_SIZE].QuotaAllocatedValue; - + if (cntx.Quotas[Quotas.HOSTED_SHAREPOINT_STORAGE_SIZE] != null) + org.MaxSharePointStorage = cntx.Quotas[Quotas.HOSTED_SHAREPOINT_STORAGE_SIZE].QuotaAllocatedValue; - if (cntx.Quotas[Quotas.HOSTED_SHAREPOINT_STORAGE_SIZE] != null) - org.WarningSharePointStorage = cntx.Quotas[Quotas.HOSTED_SHAREPOINT_STORAGE_SIZE].QuotaAllocatedValue; - - //add organization to package items - itemId = AddOrganizationToPackageItems(org, serviceId, packageId, organizationName, organizationId, domainName); + if (cntx.Quotas[Quotas.HOSTED_SHAREPOINT_STORAGE_SIZE] != null) + org.WarningSharePointStorage = cntx.Quotas[Quotas.HOSTED_SHAREPOINT_STORAGE_SIZE].QuotaAllocatedValue; - // register org ID - DataProvider.AddExchangeOrganization(itemId, organizationId); + //add organization to package items + itemId = AddOrganizationToPackageItems(org, serviceId, packageId, organizationName, organizationId, domainName); - // register domain - DataProvider.AddExchangeOrganizationDomain(itemId, domainId, true); + // register org ID + + DataProvider.AddExchangeOrganization(itemId, organizationId); + + // register domain + DataProvider.AddExchangeOrganizationDomain(itemId, domainId, true); //add to exchangeAcounts AddAccount(itemId, ExchangeAccountType.DefaultSecurityGroup, org.GroupName, org.GroupName, null, false, 0, org.GroupName, null, 0, null); - // register organization domain service item - OrganizationDomain orgDomain = new OrganizationDomain - { - Name = domainName, - PackageId = packageId, - ServiceId = serviceId - }; + // register organization domain service item + OrganizationDomain orgDomain = new OrganizationDomain + { + Name = domainName, + PackageId = packageId, + ServiceId = serviceId + }; - PackageController.AddPackageItem(orgDomain); + PackageController.AddPackageItem(orgDomain); - } - catch (Exception ex) - { - //rollback organization - try - { - RollbackOrganization(packageId, organizationId); - } - catch (Exception rollbackException) - { - TaskManager.WriteError(rollbackException); - } + } + catch (Exception ex) + { + //rollback organization + try + { + RollbackOrganization(packageId, organizationId); + } + catch (Exception rollbackException) + { + TaskManager.WriteError(rollbackException); + } - throw TaskManager.WriteError(ex); - } + throw TaskManager.WriteError(ex); + } finally { TaskManager.CompleteTask(); } - + return itemId; } @@ -440,7 +440,7 @@ namespace WebsitePanel.EnterpriseServer return -1; } } - + // unregister domain DataProvider.DeleteExchangeOrganizationDomain(itemId, domainId); @@ -477,52 +477,52 @@ namespace WebsitePanel.EnterpriseServer private static void DeleteOCSUsers(int itemId, ref bool successful) { try - { - OCSUsersPagedResult res = OCSController.GetOCSUsers(itemId, string.Empty, string.Empty, string.Empty, - string.Empty, 0, int.MaxValue); - if (res.IsSuccess) - { - foreach (OCSUser user in res.Value.PageUsers) - { - try - { - ResultObject delUserResult = OCSController.DeleteOCSUser(itemId, user.InstanceId); - if (!delUserResult.IsSuccess) - { - StringBuilder sb = new StringBuilder(); - foreach(string str in delUserResult.ErrorCodes) - { - sb.Append(str); - sb.Append('\n'); - } - - throw new ApplicationException(sb.ToString()); - } - } - catch(Exception ex) - { - successful = false; - TaskManager.WriteError(ex); - } - } - } - else - { - StringBuilder sb = new StringBuilder(); - foreach(string str in res.ErrorCodes) - { - sb.Append(str); - sb.Append('\n'); - } - - throw new ApplicationException(sb.ToString()); - } - } - catch(Exception ex) + { + OCSUsersPagedResult res = OCSController.GetOCSUsers(itemId, string.Empty, string.Empty, string.Empty, + string.Empty, 0, int.MaxValue); + if (res.IsSuccess) { - successful = false; - TaskManager.WriteError(ex); + foreach (OCSUser user in res.Value.PageUsers) + { + try + { + ResultObject delUserResult = OCSController.DeleteOCSUser(itemId, user.InstanceId); + if (!delUserResult.IsSuccess) + { + StringBuilder sb = new StringBuilder(); + foreach (string str in delUserResult.ErrorCodes) + { + sb.Append(str); + sb.Append('\n'); + } + + throw new ApplicationException(sb.ToString()); + } + } + catch (Exception ex) + { + successful = false; + TaskManager.WriteError(ex); + } + } } + else + { + StringBuilder sb = new StringBuilder(); + foreach (string str in res.ErrorCodes) + { + sb.Append(str); + sb.Append('\n'); + } + + throw new ApplicationException(sb.ToString()); + } + } + catch (Exception ex) + { + successful = false; + TaskManager.WriteError(ex); + } } @@ -611,7 +611,7 @@ namespace WebsitePanel.EnterpriseServer if (org.IsOCSOrganization) { - DeleteOCSUsers(itemId, ref successful); + DeleteOCSUsers(itemId, ref successful); } try @@ -623,10 +623,10 @@ namespace WebsitePanel.EnterpriseServer { successful = false; TaskManager.WriteError(ex); - } + } try - { + { OrganizationUsersPagedResult res = BlackBerryController.GetBlackBerryUsers(itemId, string.Empty, string.Empty, string.Empty, string.Empty, 0, int.MaxValue); if (res.IsSuccess) @@ -635,11 +635,11 @@ namespace WebsitePanel.EnterpriseServer { try { - ResultObject delUserResult = BlackBerryController.DeleteBlackBerryUser(itemId, user.AccountId); + ResultObject delUserResult = BlackBerryController.DeleteBlackBerryUser(itemId, user.AccountId); if (!delUserResult.IsSuccess) { - StringBuilder sb = new StringBuilder(); - foreach(string str in delUserResult.ErrorCodes) + StringBuilder sb = new StringBuilder(); + foreach (string str in delUserResult.ErrorCodes) { sb.Append(str); sb.Append('\n'); @@ -648,7 +648,7 @@ namespace WebsitePanel.EnterpriseServer throw new ApplicationException(sb.ToString()); } } - catch(Exception ex) + catch (Exception ex) { successful = false; TaskManager.WriteError(ex); @@ -657,8 +657,8 @@ namespace WebsitePanel.EnterpriseServer } else { - StringBuilder sb = new StringBuilder(); - foreach(string str in res.ErrorCodes) + StringBuilder sb = new StringBuilder(); + foreach (string str in res.ErrorCodes) { sb.Append(str); sb.Append('\n'); @@ -667,7 +667,7 @@ namespace WebsitePanel.EnterpriseServer throw new ApplicationException(sb.ToString()); } } - catch(Exception ex) + catch (Exception ex) { successful = false; TaskManager.WriteError(ex); @@ -699,10 +699,10 @@ namespace WebsitePanel.EnterpriseServer TaskManager.WriteError(ex); } - - - Organizations orgProxy = GetOrganizationProxy(org.ServiceId); - + + + Organizations orgProxy = GetOrganizationProxy(org.ServiceId); + try { orgProxy.DeleteOrganization(org.OrganizationId); @@ -712,8 +712,8 @@ namespace WebsitePanel.EnterpriseServer successful = false; TaskManager.WriteError(ex); } - - + + // delete organization domains List domains = GetOrganizationDomains(itemId); @@ -728,15 +728,15 @@ namespace WebsitePanel.EnterpriseServer successful = false; TaskManager.WriteError(ex); } - + } DataProvider.DeleteOrganizationUser(itemId); - + // delete meta-item PackageController.DeletePackageItem(itemId); - - + + return successful ? 0 : BusinessErrorCodes.ERROR_ORGANIZATION_DELETE_SOME_PROBLEMS; } catch (Exception ex) @@ -749,11 +749,11 @@ namespace WebsitePanel.EnterpriseServer } } - + public static Organizations GetOrganizationProxy(int serviceId) - { + { Organizations ws = new Organizations(); - ServiceProviderProxy.Init(ws, serviceId); + ServiceProviderProxy.Init(ws, serviceId); return ws; } @@ -768,7 +768,7 @@ namespace WebsitePanel.EnterpriseServer public static DataSet GetRawOrganizationsPaged(int packageId, bool recursive, string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows) - { + { #region Demo Mode if (IsDemoMode) { @@ -790,15 +790,15 @@ namespace WebsitePanel.EnterpriseServer dtItems.Columns.Add("UserID", typeof(int)); dtItems.Rows.Add(1, "fabrikam", "Fabrikam Inc", "Hosted Exchange", 1, "Customer", 1); - + dtItems.Rows.Add(2, "Contoso", "Contoso Ltd", "Hosted Exchange", 2, "Customer", 2); - + return ds; } #endregion - - + + return PackageController.GetRawPackageItemsPaged( packageId, ResourceGroups.HostedOrganizations, typeof(Organization), recursive, filterColumn, filterValue, sortColumn, startRow, maximumRows); @@ -813,9 +813,9 @@ namespace WebsitePanel.EnterpriseServer Organization org = GetOrganization(itemId); - return org; + return org; } - + public static Organization GetOrganization(int itemId) { #region Demo Mode @@ -1029,13 +1029,13 @@ namespace WebsitePanel.EnterpriseServer TaskManager.StartTask("ORGANIZATION", "CHANGE_DOMAIN_TYPE", domainId, itemId); try - { + { // change accepted domain type on Exchange int checkResult = ExchangeServerController.ChangeAcceptedDomainType(itemId, domainId, newDomainType); // change accepted domain type in DB - int domainTypeId= (int) newDomainType; + int domainTypeId = (int)newDomainType; DataProvider.ChangeExchangeAcceptedDomainType(itemId, domainId, domainTypeId); return checkResult; @@ -1061,7 +1061,7 @@ namespace WebsitePanel.EnterpriseServer if (orgStats.AllocatedDomains > -1 && orgStats.CreatedDomains >= orgStats.AllocatedDomains) return BusinessErrorCodes.ERROR_EXCHANGE_DOMAINS_QUOTA_LIMIT; - + // place log record TaskManager.StartTask("ORGANIZATION", "ADD_DOMAIN", domainName, itemId); @@ -1111,13 +1111,13 @@ namespace WebsitePanel.EnterpriseServer int domainId = ServerController.AddDomain(domain); if (domainId < 0) return domainId; - + // add domain domain.DomainId = domainId; } - - + + // register domain DataProvider.AddExchangeOrganizationDomain(itemId, domain.DomainId, false); @@ -1128,7 +1128,7 @@ namespace WebsitePanel.EnterpriseServer exchDomain.ServiceId = org.ServiceId; PackageController.AddPackageItem(exchDomain); - + Organizations orgProxy = GetOrganizationProxy(org.ServiceId); orgProxy.CreateOrganizationDomain(org.DistinguishedName, domainName); if (!string.IsNullOrEmpty(org.GlobalAddressList)) @@ -1187,18 +1187,18 @@ namespace WebsitePanel.EnterpriseServer #region Users - - + + public static OrganizationUsersPaged GetOrganizationUsersPaged(int itemId, string filterColumn, string filterValue, string sortColumn, - int startRow, int maximumRows) + int startRow, int maximumRows) { #region Demo Mode if (IsDemoMode) - { + { OrganizationUsersPaged res = new OrganizationUsersPaged(); List demoAccounts = SearchAccounts(1, "", "", "", true); - + OrganizationUser r1 = new OrganizationUser(); r1.AccountId = 20; r1.AccountName = "room1_fabrikam"; @@ -1206,7 +1206,7 @@ namespace WebsitePanel.EnterpriseServer r1.DisplayName = "Meeting Room 1"; r1.PrimaryEmailAddress = "room1@fabrikam.net"; demoAccounts.Add(r1); - + OrganizationUser e1 = new OrganizationUser(); e1.AccountId = 21; e1.AccountName = "projector_fabrikam"; @@ -1219,14 +1219,14 @@ namespace WebsitePanel.EnterpriseServer return res; } #endregion - + string accountTypes = string.Format("{0}, {1}, {2}, {3}", ((int)ExchangeAccountType.User), ((int)ExchangeAccountType.Mailbox), ((int)ExchangeAccountType.Room), ((int)ExchangeAccountType.Equipment)); - - + + DataSet ds = DataProvider.GetExchangeAccountsPaged(SecurityContext.User.UserId, itemId, accountTypes, filterColumn, filterValue, sortColumn, startRow, maximumRows); - + OrganizationUsersPaged result = new OrganizationUsersPaged(); result.RecordsCount = (int)ds.Tables[0].Rows[0][0]; @@ -1249,10 +1249,10 @@ namespace WebsitePanel.EnterpriseServer } - + private static bool EmailAddressExists(string emailAddress) { - return DataProvider.ExchangeAccountEmailAddressExists(emailAddress); + return DataProvider.ExchangeAccountEmailAddressExists(emailAddress); } @@ -1268,7 +1268,7 @@ namespace WebsitePanel.EnterpriseServer //string []parts = loginName.Split('@'); //return parts != null && parts.Length > 1 ? parts[0] : loginName; return loginName; - + } public static int CreateUser(int itemId, string displayName, string name, string domain, string password, string subscriberNumber, bool enabled, bool sendNotification, string to, out string accountName) @@ -1509,7 +1509,7 @@ namespace WebsitePanel.EnterpriseServer /// The account name with organization Id. private static string BuildAccountNameWithOrgId(string orgId, string name, int serviceId) { - name = name.Length > 5 ? name.Substring(0, 5) : name; + name = ((orgId.Length + name.Length) > 19 && name.Length > 9) ? name.Substring(0, (19 - orgId.Length) < 10 ? 10 : 19 - orgId.Length) : name; orgId = (orgId.Length + name.Length) > 19 ? orgId.Substring(0, 19 - name.Length) : orgId; @@ -1583,7 +1583,7 @@ namespace WebsitePanel.EnterpriseServer try { - Guid crmUserId = CRMController.GetCrmUserId( accountId); + Guid crmUserId = CRMController.GetCrmUserId(accountId); if (crmUserId != Guid.Empty) { return BusinessErrorCodes.CURRENT_USER_IS_CRM_USER; @@ -1592,12 +1592,12 @@ namespace WebsitePanel.EnterpriseServer if (DataProvider.CheckOCSUserExists(accountId)) { - return BusinessErrorCodes.CURRENT_USER_IS_OCS_USER; + return BusinessErrorCodes.CURRENT_USER_IS_OCS_USER; } if (DataProvider.CheckLyncUserExists(accountId)) { - return BusinessErrorCodes.CURRENT_USER_IS_LYNC_USER; + return BusinessErrorCodes.CURRENT_USER_IS_LYNC_USER; } @@ -1608,11 +1608,11 @@ namespace WebsitePanel.EnterpriseServer // load account OrganizationUser user = GetAccount(itemId, accountId); - + Organizations orgProxy = GetOrganizationProxy(org.ServiceId); string account = GetAccountName(user.AccountName); - + if (user.AccountType == ExchangeAccountType.User) { //Delete user from AD @@ -1620,8 +1620,8 @@ namespace WebsitePanel.EnterpriseServer // unregister account DeleteUserFromMetabase(itemId, accountId); } - else - { + else + { //Delete mailbox with AD user ExchangeServerController.DeleteMailbox(itemId, accountId); } @@ -1638,7 +1638,7 @@ namespace WebsitePanel.EnterpriseServer } public static OrganizationUser GetAccount(int itemId, int userId) - { + { OrganizationUser account = ObjectUtils.FillObjectFromDataReader( DataProvider.GetExchangeAccount(itemId, userId)); @@ -1669,7 +1669,7 @@ namespace WebsitePanel.EnterpriseServer if (GetOrganization(itemId) == null) return; - DataProvider.DeleteExchangeAccount(itemId, accountId); + DataProvider.DeleteExchangeAccount(itemId, accountId); } public static OrganizationUser GetUserGeneralSettings(int itemId, int accountId) @@ -1697,7 +1697,7 @@ namespace WebsitePanel.EnterpriseServer // load account account = GetAccount(itemId, accountId); } - catch (Exception){} + catch (Exception) { } try { @@ -1764,10 +1764,10 @@ namespace WebsitePanel.EnterpriseServer string accountName = GetAccountName(account.AccountName); // get mailbox settings - Organizations orgProxy = GetOrganizationProxy(org.ServiceId); - // external email - string externalEmailAddress = (account.AccountType == ExchangeAccountType.User ) ? externalEmail : account.PrimaryEmailAddress; - + Organizations orgProxy = GetOrganizationProxy(org.ServiceId); + // external email + string externalEmailAddress = (account.AccountType == ExchangeAccountType.User) ? externalEmail : account.PrimaryEmailAddress; + orgProxy.SetUserGeneralSettings( org.OrganizationId, accountName, @@ -1796,21 +1796,21 @@ namespace WebsitePanel.EnterpriseServer pager, webPage, notes, - externalEmailAddress); + externalEmailAddress); // update account account.DisplayName = displayName; account.SubscriberNumber = subscriberNumber; - + //account. if (!String.IsNullOrEmpty(password)) account.AccountPassword = CryptoUtils.Encrypt(password); - else + else account.AccountPassword = null; UpdateAccount(account); - + return 0; } catch (Exception ex) @@ -1837,7 +1837,7 @@ namespace WebsitePanel.EnterpriseServer try { - + // load organization Organization org = GetOrganization(itemId); @@ -1871,7 +1871,7 @@ namespace WebsitePanel.EnterpriseServer return BusinessErrorCodes.ERROR_EXCHANGE_EMAIL_EXISTS; } } - + Organizations orgProxy = GetOrganizationProxy(org.ServiceId); orgProxy.SetUserPrincipalName(org.OrganizationId, @@ -1951,7 +1951,7 @@ namespace WebsitePanel.EnterpriseServer Organizations orgProxy = GetOrganizationProxy(org.ServiceId); - orgProxy.SetUserPassword( org.OrganizationId, + orgProxy.SetUserPassword(org.OrganizationId, accountName, password); @@ -1978,18 +1978,18 @@ namespace WebsitePanel.EnterpriseServer private static void UpdateAccount(ExchangeAccount account) - { + { DataProvider.UpdateExchangeAccount(account.AccountId, account.AccountName, account.AccountType, account.DisplayName, account.PrimaryEmailAddress, account.MailEnabledPublicFolder, - account.MailboxManagerActions.ToString(), account.SamAccountName, account.AccountPassword, account.MailboxPlanId, + account.MailboxManagerActions.ToString(), account.SamAccountName, account.AccountPassword, account.MailboxPlanId, (string.IsNullOrEmpty(account.SubscriberNumber) ? null : account.SubscriberNumber.Trim())); } public static List SearchAccounts(int itemId, - - string filterColumn, string filterValue, string sortColumn, bool includeMailboxes ) + + string filterColumn, string filterValue, string sortColumn, bool includeMailboxes) { #region Demo Mode if (IsDemoMode) @@ -1998,38 +1998,38 @@ namespace WebsitePanel.EnterpriseServer OrganizationUser m1 = new OrganizationUser(); - m1.AccountId = 1; - m1.AccountName = "john_fabrikam"; - m1.AccountType = ExchangeAccountType.Mailbox; - m1.DisplayName = "John Smith"; - m1.PrimaryEmailAddress = "john@fabrikam.net"; - - if (includeMailboxes) - demoAccounts.Add(m1); + m1.AccountId = 1; + m1.AccountName = "john_fabrikam"; + m1.AccountType = ExchangeAccountType.Mailbox; + m1.DisplayName = "John Smith"; + m1.PrimaryEmailAddress = "john@fabrikam.net"; - OrganizationUser m2 = new OrganizationUser(); - m2.AccountId = 2; - m2.AccountName = "jack_fabrikam"; - m2.AccountType = ExchangeAccountType.User; - m2.DisplayName = "Jack Brown"; - m2.PrimaryEmailAddress = "jack@fabrikam.net"; - demoAccounts.Add(m2); + if (includeMailboxes) + demoAccounts.Add(m1); + + OrganizationUser m2 = new OrganizationUser(); + m2.AccountId = 2; + m2.AccountName = "jack_fabrikam"; + m2.AccountType = ExchangeAccountType.User; + m2.DisplayName = "Jack Brown"; + m2.PrimaryEmailAddress = "jack@fabrikam.net"; + demoAccounts.Add(m2); + + OrganizationUser m3 = new OrganizationUser(); + m3.AccountId = 3; + m3.AccountName = "marry_fabrikam"; + m3.AccountType = ExchangeAccountType.Mailbox; + m3.DisplayName = "Marry Smith"; + m3.PrimaryEmailAddress = "marry@fabrikam.net"; + + if (includeMailboxes) + demoAccounts.Add(m3); - OrganizationUser m3 = new OrganizationUser(); - m3.AccountId = 3; - m3.AccountName = "marry_fabrikam"; - m3.AccountType = ExchangeAccountType.Mailbox; - m3.DisplayName = "Marry Smith"; - m3.PrimaryEmailAddress = "marry@fabrikam.net"; - - if (includeMailboxes) - demoAccounts.Add(m3); - return demoAccounts; } #endregion - + List Tmpaccounts = ObjectUtils.CreateListFromDataReader( DataProvider.SearchOrganizationAccounts(SecurityContext.User.UserId, itemId, filterColumn, filterValue, sortColumn, includeMailboxes)); @@ -2043,7 +2043,7 @@ namespace WebsitePanel.EnterpriseServer return Accounts; } - + public static int GetAccountIdByUserPrincipalName(int itemId, string userPrincipalName) { // place log record @@ -2107,8 +2107,8 @@ namespace WebsitePanel.EnterpriseServer return demoDomains; } #endregion - - + + // load organization Organization org = (Organization)PackageController.GetPackageItem(itemId); if (org == null) @@ -2134,14 +2134,14 @@ namespace WebsitePanel.EnterpriseServer private static OrganizationUser GetDemoUserGeneralSettings() { OrganizationUser user = new OrganizationUser(); - user.DisplayName = "John Smith"; + user.DisplayName = "John Smith"; user.AccountName = "john_fabrikam"; user.FirstName = "John"; user.LastName = "Smith"; - user.AccountType = ExchangeAccountType.Mailbox; + user.AccountType = ExchangeAccountType.Mailbox; return user; } - + private static bool IsDemoMode { get @@ -2153,7 +2153,7 @@ namespace WebsitePanel.EnterpriseServer public static PasswordPolicyResult GetPasswordPolicy(int itemId) { - PasswordPolicyResult res = new PasswordPolicyResult {IsSuccess = true}; + PasswordPolicyResult res = new PasswordPolicyResult { IsSuccess = true }; try { Organization org = GetOrganization(itemId); @@ -2169,7 +2169,7 @@ namespace WebsitePanel.EnterpriseServer { orgProxy = GetOrganizationProxy(org.ServiceId); } - catch(Exception ex) + catch (Exception ex) { res.IsSuccess = false; res.ErrorCodes.Add(ErrorCodes.CANNOT_GET_ORGANIZATION_PROXY); @@ -2177,17 +2177,17 @@ namespace WebsitePanel.EnterpriseServer return res; } - PasswordPolicyResult policyRes = orgProxy.GetPasswordPolicy(); - res.ErrorCodes.AddRange(policyRes.ErrorCodes); - if (!policyRes.IsSuccess) - { - res.IsSuccess = false; - return res; - } - + PasswordPolicyResult policyRes = orgProxy.GetPasswordPolicy(); + res.ErrorCodes.AddRange(policyRes.ErrorCodes); + if (!policyRes.IsSuccess) + { + res.IsSuccess = false; + return res; + } + res.Value = policyRes.Value; } - catch(Exception ex) + catch (Exception ex) { TaskManager.WriteError(ex); res.IsSuccess = false; @@ -2263,7 +2263,7 @@ namespace WebsitePanel.EnterpriseServer Organizations orgProxy = GetOrganizationProxy(org.ServiceId); - string groupName = BuildAccountNameWithOrgId(org.OrganizationId, displayName, org.ServiceId); + string groupName = BuildAccountNameWithOrgId(org.OrganizationId, displayName.Replace(" ", ""), org.ServiceId); TaskManager.Write("accountName :" + groupName); @@ -2332,9 +2332,9 @@ namespace WebsitePanel.EnterpriseServer securityGroup.IsDefault = account.AccountType == ExchangeAccountType.DefaultSecurityGroup; - List members = new List(); + List members = new List(); - foreach (OrganizationUser user in securityGroup.MembersAccounts) + foreach (ExchangeAccount user in securityGroup.MembersAccounts) { OrganizationUser userAccount = GetAccountByAccountName(itemId, user.SamAccountName); @@ -2342,6 +2342,7 @@ namespace WebsitePanel.EnterpriseServer { user.AccountId = userAccount.AccountId; user.AccountName = userAccount.AccountName; + user.DisplayName = userAccount.DisplayName; user.PrimaryEmailAddress = userAccount.PrimaryEmailAddress; user.AccountType = userAccount.AccountType; @@ -2385,7 +2386,7 @@ namespace WebsitePanel.EnterpriseServer Organizations orgProxy = GetOrganizationProxy(org.ServiceId); orgProxy.DeleteSecurityGroup(account.AccountName, org.OrganizationId); - + DeleteUserFromMetabase(itemId, accountId); return 0; @@ -2480,7 +2481,7 @@ namespace WebsitePanel.EnterpriseServer res.PageItems = demoSecurityGroups.ToArray(); res.RecordsCount = res.PageItems.Length; - + return res; } #endregion @@ -2610,16 +2611,20 @@ namespace WebsitePanel.EnterpriseServer // load account ExchangeAccount account = ExchangeServerController.GetAccount(itemId, accountId); - List SecurytyGroups = ExchangeServerController.GetAccounts(itemId, ExchangeAccountType.SecurityGroup); - foreach (ExchangeAccount SecurytyGroupAccount in SecurytyGroups) - { - OrganizationSecurityGroup SecurytyGroup = GetSecurityGroupGeneralSettings(itemId, SecurytyGroupAccount.AccountId); + List securytyGroups = ExchangeServerController.GetAccounts(itemId, ExchangeAccountType.SecurityGroup); - foreach (OrganizationUser member in SecurytyGroup.MembersAccounts) + //load default group + securytyGroups.AddRange(ExchangeServerController.GetAccounts(itemId, ExchangeAccountType.DefaultSecurityGroup)); + + foreach (ExchangeAccount securityGroupAccount in securytyGroups) + { + OrganizationSecurityGroup securityGroup = GetSecurityGroupGeneralSettings(itemId, securityGroupAccount.AccountId); + + foreach (ExchangeAccount member in securityGroup.MembersAccounts) { if (member.AccountName == account.AccountName) { - ret.Add(SecurytyGroupAccount); + ret.Add(securityGroupAccount); break; } @@ -2638,39 +2643,83 @@ namespace WebsitePanel.EnterpriseServer } } - public static List SearchSecurityGroups(int itemId, string filterColumn, string filterValue, string sortColumn) + public static List SearchOrganizationAccounts(int itemId, string filterColumn, string filterValue, + string sortColumn, bool includeOnlySecurityGroups) { #region Demo Mode if (IsDemoMode) { - List demoSecurityGroups = new List(); + List demoAccounts = new List(); + + 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 m2 = new ExchangeAccount(); + m2.AccountId = 2; + m2.AccountName = "jack_fabrikam"; + m2.AccountType = ExchangeAccountType.User; + m2.DisplayName = "Jack Brown"; + m2.PrimaryEmailAddress = "jack@fabrikam.net"; + demoAccounts.Add(m2); + + 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); ExchangeAccount r1 = new ExchangeAccount(); r1.AccountId = 20; r1.AccountName = "group1_fabrikam"; r1.AccountType = ExchangeAccountType.SecurityGroup; r1.DisplayName = "Group 1"; - demoSecurityGroups.Add(r1); + demoAccounts.Add(r1); ExchangeAccount r2 = new ExchangeAccount(); r1.AccountId = 21; r1.AccountName = "group2_fabrikam"; r1.AccountType = ExchangeAccountType.SecurityGroup; r1.DisplayName = "Group 2"; - demoSecurityGroups.Add(r2); + demoAccounts.Add(r2); - return demoSecurityGroups; + return demoAccounts; } #endregion - List accounts = ObjectUtils.CreateListFromDataReader( - DataProvider.SearchExchangeAccounts( - SecurityContext.User.UserId, itemId, false, false, false, false, false, filterColumn, filterValue, sortColumn)); + string accountTypes = string.Format("{0}", ((int)ExchangeAccountType.SecurityGroup)); - return accounts.Where(x => x.AccountType == ExchangeAccountType.SecurityGroup).ToList(); + if (!includeOnlySecurityGroups) + { + accountTypes = string.Format("{0}, {1}, {2}, {3}, {4}", accountTypes, ((int)ExchangeAccountType.User), ((int)ExchangeAccountType.Mailbox), + ((int)ExchangeAccountType.Room), ((int)ExchangeAccountType.Equipment)); + } + + List tmpAccounts = ObjectUtils.CreateListFromDataReader( + DataProvider.SearchExchangeAccountsByTypes(SecurityContext.User.UserId, itemId, + accountTypes, filterColumn, filterValue, sortColumn)); + + List accounts = new List(); + + foreach (ExchangeAccount tmpAccount in tmpAccounts.ToArray()) + { + if (tmpAccount.AccountType == ExchangeAccountType.SecurityGroup + ? GetSecurityGroupGeneralSettings(itemId, tmpAccount.AccountId) != null + : GetUserGeneralSettings(itemId, tmpAccount.AccountId) != null) + { + accounts.Add(tmpAccount); + } + } + + return accounts; } } - } diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esExchangeServer.asmx.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esExchangeServer.asmx.cs index 0d43f107..0e201812 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esExchangeServer.asmx.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esExchangeServer.asmx.cs @@ -190,12 +190,12 @@ namespace WebsitePanel.EnterpriseServer [WebMethod] public List SearchAccounts(int itemId, bool includeMailboxes, bool includeContacts, bool includeDistributionLists, - bool includeRooms, bool includeEquipment, + bool includeRooms, bool includeEquipment, bool includeSecurityGroups, string filterColumn, string filterValue, string sortColumn) { return ExchangeServerController.SearchAccounts(itemId, includeMailboxes, includeContacts, includeDistributionLists, - includeRooms, includeEquipment, + includeRooms, includeEquipment, includeSecurityGroups, filterColumn, filterValue, sortColumn); } diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esOrganizations.asmx.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esOrganizations.asmx.cs index 821196d0..54d3fa82 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esOrganizations.asmx.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esOrganizations.asmx.cs @@ -214,7 +214,7 @@ namespace WebsitePanel.EnterpriseServer { return OrganizationController.SetUserPassword(itemId, accountId, password); } - + [WebMethod] @@ -290,15 +290,17 @@ namespace WebsitePanel.EnterpriseServer [WebMethod] public ExchangeAccount[] GetSecurityGroupsByMember(int itemId, int accountId) { - return OrganizationController.GetSecurityGroupsByMember(itemId, accountId); + return OrganizationController.GetSecurityGroupsByMember(itemId, accountId); } [WebMethod] - public List SearchSecurityGroups(int itemId, string filterColumn, string filterValue, string sortColumn) + public List SearchOrganizationAccounts(int itemId, string filterColumn, string filterValue, + string sortColumn, bool includeOnlySecurityGroups) { - return OrganizationController.SearchSecurityGroups(itemId, filterColumn, filterValue, sortColumn); + return OrganizationController.SearchOrganizationAccounts(itemId, filterColumn, filterValue, sortColumn, + includeOnlySecurityGroups); } - + #endregion } diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/ADAttributes.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/ADAttributes.cs index 9ef289cb..2f4cad16 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/ADAttributes.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/ADAttributes.cs @@ -58,7 +58,7 @@ namespace WebsitePanel.Providers.HostedSolution public const string UserPrincipalName = "UserPrincipalName"; public const string GroupType = "GroupType"; public const string Name = "Name"; - public const string ExternalEmail = "mail"; + public const string ExternalEmail = "mail"; public const string CustomAttribute2 = "extensionAttribute2"; public const string DistinguishedName = "distinguishedName"; diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/ActiveDirectoryUtils.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/ActiveDirectoryUtils.cs index 195ccdba..b6dc0c92 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/ActiveDirectoryUtils.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/ActiveDirectoryUtils.cs @@ -44,21 +44,21 @@ namespace WebsitePanel.Providers.HostedSolution return de; } - public static string[] GetUsersGroup(string group) + public static string[] GetGroupObjects(string group, string objectType) { List rets = new List(); DirectorySearcher deSearch = new DirectorySearcher { Filter = - "(&(objectClass=user))" + "(&(objectClass=" + objectType + "))" }; - SearchResultCollection srcUsers = deSearch.FindAll(); + SearchResultCollection srcObjects = deSearch.FindAll(); - foreach (SearchResult srcUser in srcUsers) + foreach (SearchResult srcObject in srcObjects) { - DirectoryEntry de = srcUser.GetDirectoryEntry(); + DirectoryEntry de = srcObject.GetDirectoryEntry(); PropertyValueCollection props = de.Properties["memberOf"]; foreach (string str in props) @@ -371,20 +371,20 @@ namespace WebsitePanel.Providers.HostedSolution newGroupObject.CommitChanges(); } - public static void AddUserToGroup(string userPath, string groupPath) + public static void AddObjectToGroup(string objectPath, string groupPath) { - DirectoryEntry user = new DirectoryEntry(userPath); + DirectoryEntry obj = new DirectoryEntry(objectPath); DirectoryEntry group = new DirectoryEntry(groupPath); - group.Invoke("Add", user.Path); + group.Invoke("Add", obj.Path); } - public static void RemoveUserFromGroup(string userPath, string groupPath) + public static void RemoveObjectFromGroup(string obejctPath, string groupPath) { - DirectoryEntry user = new DirectoryEntry(userPath); + DirectoryEntry obj = new DirectoryEntry(obejctPath); DirectoryEntry group = new DirectoryEntry(groupPath); - group.Invoke("Remove", user.Path); + group.Invoke("Remove", obj.Path); } public static bool AdObjectExists(string path) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/IOrganization.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/IOrganization.cs index 0409fb33..02a86255 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/IOrganization.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/IOrganization.cs @@ -66,7 +66,7 @@ namespace WebsitePanel.Providers.HostedSolution void SetUserPassword(string organizationId, string accountName, string password); void SetUserPrincipalName(string organizationId, string accountName, string userPrincipalName); - + bool OrganizationExists(string organizationId); void DeleteOrganizationDomain(string organizationDistinguishedName, string domain); diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/OrganizationSecurityGroup.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/OrganizationSecurityGroup.cs index b1b503bc..ab410547 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/OrganizationSecurityGroup.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/OrganizationSecurityGroup.cs @@ -19,7 +19,7 @@ namespace WebsitePanel.Providers.HostedSolution set; } - public OrganizationUser[] MembersAccounts + public ExchangeAccount[] MembersAccounts { get; set; diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/OrganizationProvider.cs b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/OrganizationProvider.cs index 541d4545..82bba885 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/OrganizationProvider.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/OrganizationProvider.cs @@ -102,6 +102,20 @@ namespace WebsitePanel.Providers.HostedSolution return sb.ToString(); } + private string GetObjectPath(string organizationId, string objName) + { + StringBuilder sb = new StringBuilder(); + // append provider + AppendProtocol(sb); + AppendDomainController(sb); + AppendCNPath(sb, objName); + AppendOUPath(sb, organizationId); + AppendOUPath(sb, RootOU); + AppendDomainPath(sb, RootDomain); + + return sb.ToString(); + } + private string GetGroupPath(string organizationId, string groupName) { StringBuilder sb = new StringBuilder(); @@ -404,7 +418,7 @@ namespace WebsitePanel.Providers.HostedSolution HostedSolutionLog.DebugInfo("Group retrieved: {0}", groupPath); - ActiveDirectoryUtils.AddUserToGroup(userPath, groupPath); + ActiveDirectoryUtils.AddObjectToGroup(userPath, groupPath); HostedSolutionLog.DebugInfo("Added to group: {0}", groupPath); } catch (Exception e) @@ -668,7 +682,7 @@ namespace WebsitePanel.Providers.HostedSolution { string path = GetUserPath(organizationId, accountName); DirectoryEntry entry = ActiveDirectoryUtils.GetADObject(path); - + if (!string.IsNullOrEmpty(password)) entry.Invoke(ADAttributes.SetPassword, password); @@ -760,8 +774,8 @@ namespace WebsitePanel.Providers.HostedSolution SearchResult resCollection = searcher.FindOne(); if (resCollection != null) { - if(resCollection.Properties["samaccountname"] != null) - bFound = true; + if (resCollection.Properties["samaccountname"] != null) + bFound = true; } } catch (Exception e) @@ -848,13 +862,13 @@ namespace WebsitePanel.Providers.HostedSolution { string path = GetOrganizationPath(organizationId); groupPath = GetGroupPath(organizationId, groupName); - + if (!ActiveDirectoryUtils.AdObjectExists(groupPath)) { ActiveDirectoryUtils.CreateGroup(path, groupName); groupCreated = true; - + HostedSolutionLog.DebugInfo("Security Group created: {0}", groupName); } else @@ -910,15 +924,32 @@ namespace WebsitePanel.Providers.HostedSolution OrganizationSecurityGroup securityGroup = new OrganizationSecurityGroup(); securityGroup.Notes = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Notes); - + securityGroup.AccountName = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.SAMAccountName); securityGroup.SAMAccountName = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.SAMAccountName); - List members = new List(); + List members = new List(); - foreach (string userPath in ActiveDirectoryUtils.GetUsersGroup(groupName)) + foreach (string userPath in ActiveDirectoryUtils.GetGroupObjects(groupName, "user")) { - members.Add(GetUser(userPath)); + OrganizationUser tmpUser = GetUser(userPath); + + members.Add(new ExchangeAccount + { + AccountName = tmpUser.AccountName, + SamAccountName = tmpUser.SamAccountName + }); + } + + foreach (string groupPath in ActiveDirectoryUtils.GetGroupObjects(groupName, "group")) + { + DirectoryEntry groupEntry = ActiveDirectoryUtils.GetADObject(groupPath); + + members.Add(new ExchangeAccount + { + AccountName = ActiveDirectoryUtils.GetADObjectStringProperty(groupEntry, ADAttributes.SAMAccountName), + SamAccountName = ActiveDirectoryUtils.GetADObjectStringProperty(groupEntry, ADAttributes.SAMAccountName) + }); } securityGroup.MembersAccounts = members.ToArray(); @@ -955,7 +986,7 @@ namespace WebsitePanel.Providers.HostedSolution public void SetSecurityGroupGeneralSettings(string organizationId, string groupName, string[] memberAccounts, string notes) { - + SetSecurityGroupGeneralSettingsInternal(organizationId, groupName, memberAccounts, notes); } @@ -977,15 +1008,22 @@ namespace WebsitePanel.Providers.HostedSolution ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Notes, notes); - foreach(string userPath in ActiveDirectoryUtils.GetUsersGroup(groupName)) { - ActiveDirectoryUtils.RemoveUserFromGroup(userPath, path); + foreach (string userPath in ActiveDirectoryUtils.GetGroupObjects(groupName, "user")) + { + ActiveDirectoryUtils.RemoveObjectFromGroup(userPath, path); } - foreach(string user in memberAccounts) { - string userPath = GetUserPath(organizationId, user); - ActiveDirectoryUtils.AddUserToGroup(userPath, path); + foreach (string groupPath in ActiveDirectoryUtils.GetGroupObjects(groupName, "group")) + { + ActiveDirectoryUtils.RemoveObjectFromGroup(groupPath, path); } - + + foreach (string obj in memberAccounts) + { + string objPath = GetObjectPath(organizationId, obj); + ActiveDirectoryUtils.AddObjectToGroup(objPath, path); + } + entry.CommitChanges(); } @@ -1014,7 +1052,7 @@ namespace WebsitePanel.Providers.HostedSolution string groupPath = GetGroupPath(organizationId, groupName); - ActiveDirectoryUtils.AddUserToGroup(userPath, groupPath); + ActiveDirectoryUtils.AddObjectToGroup(userPath, groupPath); } public void DeleteUserFromSecurityGroup(string organizationId, string loginName, string groupName) @@ -1042,7 +1080,7 @@ namespace WebsitePanel.Providers.HostedSolution string groupPath = GetGroupPath(organizationId, groupName); - ActiveDirectoryUtils.RemoveUserFromGroup(userPath, groupPath); + ActiveDirectoryUtils.RemoveObjectFromGroup(userPath, groupPath); } #endregion diff --git a/WebsitePanel/Sources/WebsitePanel.Server.Client/OrganizationProxy.cs b/WebsitePanel/Sources/WebsitePanel.Server.Client/OrganizationProxy.cs index 04015f9c..260fba07 100644 --- a/WebsitePanel/Sources/WebsitePanel.Server.Client/OrganizationProxy.cs +++ b/WebsitePanel/Sources/WebsitePanel.Server.Client/OrganizationProxy.cs @@ -51,7 +51,7 @@ namespace WebsitePanel.Providers.HostedSolution using WebsitePanel.Providers.Common; using WebsitePanel.Providers.ResultObjects; - + /// [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")] diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/ExchangeDistributionListMemberOf.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/ExchangeDistributionListMemberOf.ascx index 3ee22461..e55e65e6 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/ExchangeDistributionListMemberOf.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/ExchangeDistributionListMemberOf.ascx @@ -39,7 +39,8 @@ MailboxesEnabled="false" EnableMailboxOnly="true" ContactsEnabled="false" - DistributionListsEnabled="true" /> + DistributionListsEnabled="true" + SecurityGroupsEnabled="true" /> diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/ExchangeMailboxMemberOf.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/ExchangeMailboxMemberOf.ascx index aa56e6a5..9e8c82cb 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/ExchangeMailboxMemberOf.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/ExchangeMailboxMemberOf.ascx @@ -41,7 +41,8 @@ MailboxesEnabled="false" EnableMailboxOnly="true" ContactsEnabled="false" - DistributionListsEnabled="true" /> + DistributionListsEnabled="true" + SecurityGroupsEnabled="true" /> diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/AccountsList.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/AccountsList.ascx index 4b772a77..d0a54064 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/AccountsList.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/AccountsList.ascx @@ -69,6 +69,8 @@ meta:resourcekey="chkIncludeContacts" AutoPostBack="true" CssClass="Normal" OnCheckedChanged="chkIncludeMailboxes_CheckedChanged" /> +
diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/AccountsList.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/AccountsList.ascx.cs index 24b053ee..6884ce2c 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/AccountsList.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/AccountsList.ascx.cs @@ -67,6 +67,12 @@ namespace WebsitePanel.Portal.ExchangeServer.UserControls set { ViewState["DistributionListsEnabled"] = value; } } + public bool SecurityGroupsEnabled + { + get { return ViewState["SecurityGroupsEnabled"] != null ? (bool)ViewState["SecurityGroupsEnabled"] : false; } + set { ViewState["SecurityGroupsEnabled"] = value; } + } + public int ExcludeAccountId { get { return PanelRequest.AccountID; } @@ -109,6 +115,9 @@ namespace WebsitePanel.Portal.ExchangeServer.UserControls chkIncludeContacts.Checked = ContactsEnabled; chkIncludeLists.Visible = DistributionListsEnabled; chkIncludeLists.Checked = DistributionListsEnabled; + + chkIncludeGroups.Visible = SecurityGroupsEnabled; + chkIncludeGroups.Checked = SecurityGroupsEnabled; } // register javascript @@ -131,14 +140,16 @@ namespace WebsitePanel.Portal.ExchangeServer.UserControls { ExchangeAccountType accountType = (ExchangeAccountType)accountTypeId; string imgName = "mailbox_16.gif"; - if (accountType == ExchangeAccountType.Contact) - imgName = "contact_16.gif"; - else if (accountType == ExchangeAccountType.DistributionList) - imgName = "dlist_16.gif"; + if (accountType == ExchangeAccountType.Contact) + imgName = "contact_16.gif"; + else if (accountType == ExchangeAccountType.DistributionList) + imgName = "dlist_16.gif"; else if (accountType == ExchangeAccountType.Room) imgName = "room_16.gif"; else if (accountType == ExchangeAccountType.Equipment) imgName = "equipment_16.gif"; + else if (accountType == ExchangeAccountType.Equipment) + imgName = "dlist_16.gif"; return GetThemedImage("Exchange/" + imgName); } @@ -174,7 +185,7 @@ namespace WebsitePanel.Portal.ExchangeServer.UserControls { ExchangeAccount[] accounts = ES.Services.ExchangeServer.SearchAccounts(PanelRequest.ItemID, chkIncludeMailboxes.Checked, chkIncludeContacts.Checked, chkIncludeLists.Checked, - chkIncludeRooms.Checked, chkIncludeEquipment.Checked, + chkIncludeRooms.Checked, chkIncludeEquipment.Checked, chkIncludeGroups.Checked, ddlSearchColumn.SelectedValue, txtSearchValue.Text + "%", ""); if (ExcludeAccountId > 0) diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/AccountsList.ascx.designer.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/AccountsList.ascx.designer.cs index 706f9ee3..39eb5f24 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/AccountsList.ascx.designer.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/AccountsList.ascx.designer.cs @@ -1,22 +1,15 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:2.0.50727.832 // // Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// the code is regenerated. // //------------------------------------------------------------------------------ namespace WebsitePanel.Portal.ExchangeServer.UserControls { - /// - /// AccountsList class. - /// - /// - /// Auto-generated class. - /// public partial class AccountsList { /// @@ -136,6 +129,15 @@ namespace WebsitePanel.Portal.ExchangeServer.UserControls { /// protected global::System.Web.UI.WebControls.CheckBox chkIncludeLists; + /// + /// chkIncludeGroups control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.CheckBox chkIncludeGroups; + /// /// SearchPanel control. /// diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/AccountsListWithPermissions.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/AccountsListWithPermissions.ascx.cs index 3cc8f1a4..94351768 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/AccountsListWithPermissions.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/AccountsListWithPermissions.ascx.cs @@ -184,7 +184,7 @@ namespace WebsitePanel.Portal.ExchangeServer.UserControls { ExchangeAccount[] accounts = ES.Services.ExchangeServer.SearchAccounts(PanelRequest.ItemID, chkIncludeMailboxes.Checked, chkIncludeContacts.Checked, chkIncludeLists.Checked, - chkIncludeRooms.Checked, chkIncludeEquipment.Checked, + chkIncludeRooms.Checked, chkIncludeEquipment.Checked, false, ddlSearchColumn.SelectedValue, txtSearchValue.Text + "%", ""); if (ExcludeAccountId > 0) diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/App_LocalResources/AccountsList.ascx.resx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/App_LocalResources/AccountsList.ascx.resx index 624c5b9d..e8f53b78 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/App_LocalResources/AccountsList.ascx.resx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/App_LocalResources/AccountsList.ascx.resx @@ -112,10 +112,10 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Add... @@ -135,6 +135,9 @@ Equipment + + Groups + Distribution Lists diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/GroupsList.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/GroupsList.ascx.cs index 85508aec..ffc23fdf 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/GroupsList.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/GroupsList.ascx.cs @@ -116,8 +116,8 @@ namespace WebsitePanel.Portal.ExchangeServer.UserControls private void BindPopupAccounts() { - ExchangeAccount[] accounts = ES.Services.Organizations.SearchSecurityGroups(PanelRequest.ItemID, - ddlSearchColumn.SelectedValue, txtSearchValue.Text + "%", ""); + ExchangeAccount[] accounts = ES.Services.Organizations.SearchOrganizationAccounts(PanelRequest.ItemID, + ddlSearchColumn.SelectedValue, txtSearchValue.Text + "%", "", true); accounts = accounts.Where(x => !GetAccounts().Contains(x.AccountName)).ToArray(); @@ -158,6 +158,8 @@ namespace WebsitePanel.Portal.ExchangeServer.UserControls gvGroups.DataSource = accounts; gvGroups.DataBind(); + UpdateGridViewAccounts(gvGroups); + btnDelete.Visible = gvGroups.Rows.Count > 0; } @@ -184,6 +186,39 @@ namespace WebsitePanel.Portal.ExchangeServer.UserControls return accounts; } + private void UpdateGridViewAccounts(GridView gv) + { + CheckBox chkSelectAll = (CheckBox)gv.HeaderRow.FindControl("chkSelectAll"); + + for (int i = 0; i < gv.Rows.Count; i++) + { + GridViewRow row = gv.Rows[i]; + CheckBox chkSelect = (CheckBox)row.FindControl("chkSelect"); + if (chkSelect == null) + { + continue; + } + + ExchangeAccountType exAccountType = (ExchangeAccountType)Enum.Parse(typeof(ExchangeAccountType), ((Literal)row.FindControl("litAccountType")).Text); + + if (exAccountType != ExchangeAccountType.DefaultSecurityGroup) + { + chkSelectAll = null; + chkSelect.Enabled = true; + } + else + { + chkSelect.Enabled = false; + } + } + + if (chkSelectAll != null) + { + chkSelectAll.Enabled = false; + } + + } + protected void chkIncludeMailboxes_CheckedChanged(object sender, EventArgs e) { BindPopupAccounts(); diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/MailboxSelector.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/MailboxSelector.ascx.cs index 62431785..561d897c 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/MailboxSelector.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/MailboxSelector.ascx.cs @@ -157,7 +157,7 @@ namespace WebsitePanel.Portal.ExchangeServer.UserControls { ExchangeAccount[] accounts = ES.Services.ExchangeServer.SearchAccounts(PanelRequest.ItemID, chkIncludeMailboxes.Checked, chkIncludeContacts.Checked, chkIncludeLists.Checked, - chkIncludeRooms.Checked, chkIncludeEquipment.Checked, + chkIncludeRooms.Checked, chkIncludeEquipment.Checked, false, ddlSearchColumn.SelectedValue, txtSearchValue.Text + "%", ""); if (ExcludeAccountId > 0) diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/UsersList.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/UsersList.ascx.cs index b8311fd5..ec47b2e2 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/UsersList.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/UserControls/UsersList.ascx.cs @@ -54,79 +54,12 @@ namespace WebsitePanel.Portal.ExchangeServer.UserControls Unselected } - public bool IncludeMailboxes - { - get - { - object ret = ViewState["IncludeMailboxes"]; - return (ret != null) ? (bool)ret : false; - } - set - { - ViewState["IncludeMailboxes"] = value; - } - } - - public bool IncludeMailboxesOnly - { - get - { - object ret = ViewState["IncludeMailboxesOnly"]; - return (ret != null) ? (bool)ret : false; - } - set - { - ViewState["IncludeMailboxesOnly"] = value; - } - } - - - public bool ExcludeOCSUsers - { - get - { - object ret = ViewState["ExcludeOCSUsers"]; - return (ret != null) ? (bool)ret : false; - } - set - { - ViewState["ExcludeOCSUsers"] = value; - } - } - - public bool ExcludeLyncUsers - { - get - { - object ret = ViewState["ExcludeLyncUsers"]; - return (ret != null) ? (bool)ret : false; - } - set - { - ViewState["ExcludeLyncUsers"] = value; - } - } - - - public bool ExcludeBESUsers - { - get - { - object ret = ViewState["ExcludeBESUsers"]; - return (ret != null) ? (bool)ret : false; - } - set - { - ViewState["ExcludeBESUsers"] = value; - } - } - public int ExcludeAccountId { get { return PanelRequest.AccountID; } } - public void SetAccounts(OrganizationUser[] accounts) + public void SetAccounts(ExchangeAccount[] accounts) { BindAccounts(accounts, false); } @@ -134,10 +67,10 @@ namespace WebsitePanel.Portal.ExchangeServer.UserControls public string[] GetAccounts() { // get selected accounts - List selectedAccounts = GetGridViewAccounts(gvAccounts, SelectedState.All); + List selectedAccounts = GetGridViewAccounts(gvAccounts, SelectedState.All); List accountNames = new List(); - foreach (OrganizationUser account in selectedAccounts) + foreach (ExchangeAccount account in selectedAccounts) accountNames.Add(account.AccountName); return accountNames.ToArray(); @@ -178,7 +111,7 @@ namespace WebsitePanel.Portal.ExchangeServer.UserControls protected void btnDelete_Click(object sender, EventArgs e) { // get selected accounts - List selectedAccounts = GetGridViewAccounts(gvAccounts, SelectedState.Unselected); + List selectedAccounts = GetGridViewAccounts(gvAccounts, SelectedState.Unselected); // add to the main list BindAccounts(selectedAccounts.ToArray(), false); @@ -187,7 +120,7 @@ namespace WebsitePanel.Portal.ExchangeServer.UserControls protected void btnAddSelected_Click(object sender, EventArgs e) { // get selected accounts - List selectedAccounts = GetGridViewAccounts(gvPopupAccounts, SelectedState.Selected); + List selectedAccounts = GetGridViewAccounts(gvPopupAccounts, SelectedState.Selected); // add to the main list BindAccounts(selectedAccounts.ToArray(), true); @@ -206,6 +139,9 @@ namespace WebsitePanel.Portal.ExchangeServer.UserControls case ExchangeAccountType.Equipment: imgName = "equipment_16.gif"; break; + case ExchangeAccountType.SecurityGroup: + imgName = "dlist_16.gif"; + break; default: imgName = "admin_16.png"; break; @@ -216,58 +152,23 @@ namespace WebsitePanel.Portal.ExchangeServer.UserControls private void BindPopupAccounts() { - OrganizationUser[] accounts = ES.Services.Organizations.SearchAccounts(PanelRequest.ItemID, - ddlSearchColumn.SelectedValue, txtSearchValue.Text + "%", "", IncludeMailboxes); + ExchangeAccount[] accounts = ES.Services.Organizations.SearchOrganizationAccounts(PanelRequest.ItemID, + ddlSearchColumn.SelectedValue, txtSearchValue.Text + "%", "", false); - List newAccounts = new List(); + List newAccounts = new List(); accounts = accounts.Where(x => !GetAccounts().Contains(x.AccountName)).ToArray(); if (ExcludeAccountId > 0) { - List updatedAccounts = new List(); - foreach (OrganizationUser account in accounts) + List updatedAccounts = new List(); + foreach (ExchangeAccount account in accounts) if (account.AccountId != ExcludeAccountId) updatedAccounts.Add(account); accounts = updatedAccounts.ToArray(); } - if (IncludeMailboxesOnly) - { - - List updatedAccounts = new List(); - foreach (OrganizationUser account in accounts) - { - bool addUser = false; - if (account.ExternalEmail != string.Empty) addUser = true; - if ((account.IsBlackBerryUser) & (ExcludeBESUsers)) addUser = false; - if ((account.IsLyncUser) & (ExcludeLyncUsers)) addUser = false; - - if (addUser) updatedAccounts.Add(account); - } - - accounts = updatedAccounts.ToArray(); - } - else - if ((ExcludeOCSUsers) | (ExcludeBESUsers) | (ExcludeLyncUsers)) - { - - List updatedAccounts = new List(); - foreach (OrganizationUser account in accounts) - { - bool addUser = true; - if ((account.IsOCSUser) & (ExcludeOCSUsers)) addUser = false; - if ((account.IsLyncUser) & (ExcludeLyncUsers)) addUser = false; - if ((account.IsBlackBerryUser) & (ExcludeBESUsers)) addUser = false; - - if (addUser) updatedAccounts.Add(account); - } - - accounts = updatedAccounts.ToArray(); - } - - Array.Sort(accounts, CompareAccount); if (Direction == SortDirection.Ascending) { @@ -281,21 +182,21 @@ namespace WebsitePanel.Portal.ExchangeServer.UserControls gvPopupAccounts.DataBind(); } - private void BindAccounts(OrganizationUser[] newAccounts, bool preserveExisting) + private void BindAccounts(ExchangeAccount[] newAccounts, bool preserveExisting) { // get binded addresses - List accounts = new List(); + List accounts = new List(); if(preserveExisting) accounts.AddRange(GetGridViewAccounts(gvAccounts, SelectedState.All)); // add new accounts if (newAccounts != null) { - foreach (OrganizationUser newAccount in newAccounts) + foreach (ExchangeAccount newAccount in newAccounts) { // check if exists bool exists = false; - foreach (OrganizationUser account in accounts) + foreach (ExchangeAccount account in accounts) { if (String.Compare(newAccount.AccountName, account.AccountName, true) == 0) { @@ -317,9 +218,9 @@ namespace WebsitePanel.Portal.ExchangeServer.UserControls btnDelete.Visible = gvAccounts.Rows.Count > 0; } - private List GetGridViewAccounts(GridView gv, SelectedState state) + private List GetGridViewAccounts(GridView gv, SelectedState state) { - List accounts = new List(); + List accounts = new List(); for (int i = 0; i < gv.Rows.Count; i++) { GridViewRow row = gv.Rows[i]; @@ -327,7 +228,7 @@ namespace WebsitePanel.Portal.ExchangeServer.UserControls if (chkSelect == null) continue; - OrganizationUser account = new OrganizationUser(); + ExchangeAccount account = new ExchangeAccount(); account.AccountType = (ExchangeAccountType)Enum.Parse(typeof(ExchangeAccountType), ((Literal)row.FindControl("litAccountType")).Text); account.AccountName = (string)gv.DataKeys[i][0]; account.DisplayName = ((Literal)row.FindControl("litDisplayName")).Text; @@ -352,7 +253,7 @@ namespace WebsitePanel.Portal.ExchangeServer.UserControls set { ViewState[DirectionString] = value; } } - private static int CompareAccount(OrganizationUser user1, OrganizationUser user2) + private static int CompareAccount(ExchangeAccount user1, ExchangeAccount user2) { return string.Compare(user1.DisplayName, user2.DisplayName); }