diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/ExchangeServer/ExchangeServerController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/ExchangeServer/ExchangeServerController.cs index b80b87d1..ea90728d 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/ExchangeServer/ExchangeServerController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/ExchangeServer/ExchangeServerController.cs @@ -5319,6 +5319,42 @@ namespace WebsitePanel.EnterpriseServer TaskManager.CompleteTask(); } } + + public static string CreateOrganizationRootPublicFolder(int itemId) + { + string res = null; + + // place log record + TaskManager.StartTask("EXCHANGE", "CREATE_ORG_PUBLIC_FOLDER", itemId); + + try + { + // load organization + Organization org = GetOrganization(itemId); + if (org == null) + return null; + + // get mailbox settings + int exchangeServiceId = GetExchangeServiceID(org.PackageId); + ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId); + + if (exchange == null) + return null; + + res = exchange.CreateOrganizationRootPublicFolder(org.OrganizationId, org.DistinguishedName, org.SecurityGroup, org.DefaultDomain); + } + catch (Exception ex) + { + throw TaskManager.WriteError(ex); + } + finally + { + TaskManager.CompleteTask(); + } + + return res; + } + #endregion #region Private Helpers diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/HostedSolution/OrganizationController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/HostedSolution/OrganizationController.cs index 97f29adf..2b8341ab 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/HostedSolution/OrganizationController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/HostedSolution/OrganizationController.cs @@ -419,6 +419,9 @@ namespace WebsitePanel.EnterpriseServer }; PackageController.AddPackageItem(orgDomain); + + ExchangeServerController.CreateOrganizationRootPublicFolder(itemId); + } catch (Exception ex) { diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/IExchangeServer.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/IExchangeServer.cs index 327912c0..10a80103 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/IExchangeServer.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/IExchangeServer.cs @@ -76,6 +76,8 @@ namespace WebsitePanel.Providers.HostedSolution void SetMailboxPermissions(string organizationId, string accountName, string[] sendAsAccounts, string[] fullAccessAccounts); ExchangeMailbox GetMailboxPermissions(string organizationId, string accountName); ExchangeMailboxStatistics GetMailboxStatistics(string accountName); + bool SetDefaultPublicFolderMailbox(string id, string organizationId, string organizationDistinguishedName, out string oldValue, out string newValue); + // Contacts void CreateContact(string organizationId, string organizationDistinguishedName, string contactDisplayName, string contactAccountName, string contactEmail, string defaultOrganizationDomain); @@ -115,6 +117,8 @@ namespace WebsitePanel.Providers.HostedSolution ExchangeItemStatistics[] GetPublicFoldersStatistics(string organizationId, string[] folders); string[] GetPublicFoldersRecursive(string organizationId, string parent); long GetPublicFolderSize(string organizationId, string folder); + string CreateOrganizationRootPublicFolder(string organizationId, string organizationDistinguishedName, string securityGroup, string organizationDomain); + //ActiveSync void CreateOrganizationActiveSyncPolicy(string organizationId); diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution.Exchange2013/Exchange2013.cs b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution.Exchange2013/Exchange2013.cs index 7deb5df1..2fa772e9 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution.Exchange2013/Exchange2013.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution.Exchange2013/Exchange2013.cs @@ -4460,8 +4460,6 @@ namespace WebsitePanel.Providers.HostedSolution ExchangeLog.LogEnd("CheckOrganizationPublicFolderMailbox"); } - - private void CheckOrganizationRootFolder(Runspace runSpace, string folder, string user, string orgCanonicalName, string organizationId) { ExchangeLog.LogStart("CheckOrganizationRootFolder"); @@ -4486,6 +4484,38 @@ namespace WebsitePanel.Providers.HostedSolution ExchangeLog.LogEnd("CheckOrganizationRootFolder"); } + public string CreateOrganizationRootPublicFolder(string organizationId, string organizationDistinguishedName, string securityGroup, string organizationDomain) + { + ExchangeLog.LogStart("AddOrganizationRootPublicFolder"); + + string res = null; + + Runspace runSpace = null; + try + { + runSpace = OpenRunspace(); + + // default public folder + string orgCanonicalName = ConvertADPathToCanonicalName(organizationDistinguishedName); + + //create organization public folder mailbox if required + CheckOrganizationPublicFolderMailbox(runSpace, orgCanonicalName, organizationId, organizationDomain); + + //create organization root folder if required + CheckOrganizationRootFolder(runSpace, organizationId, securityGroup, orgCanonicalName, organizationId); + + res = orgCanonicalName + "/" + GetPublicFolderMailboxName(organizationId); + } + finally + { + CloseRunspace(runSpace); + } + + ExchangeLog.LogEnd("AddOrganizationRootPublicFolder"); + + return res; + } + private string AddPublicFolder(Runspace runSpace, string name, string path, string mailbox) { ExchangeLog.LogStart("CreatePublicFolder"); @@ -5228,6 +5258,50 @@ namespace WebsitePanel.Providers.HostedSolution return size; } + public bool SetDefaultPublicFolderMailbox(string id, string organizationId, string organizationDistinguishedName, out string oldValue, out string newValue) + { + ExchangeLog.LogStart("SetDefaultPublicFolderMailbox"); + + bool res = false; + oldValue = null; + newValue = null; + + Runspace runSpace = null; + try + { + runSpace = OpenRunspace(); + + Command cmd = new Command("Get-Mailbox"); + cmd.Parameters.Add("Identity", id); + Collection result = ExecuteShellCommand(runSpace, cmd); + + if (result != null && result.Count > 0) + { + oldValue = ObjToString(GetPSObjectProperty(result[0], "DefaultPublicFolderMailbox")); + } + + string orgCanonicalName = ConvertADPathToCanonicalName(organizationDistinguishedName); + + newValue = orgCanonicalName + "/" + GetPublicFolderMailboxName(organizationId); + + if (newValue != oldValue) + { + cmd = new Command("Set-Mailbox"); + cmd.Parameters.Add("Identity", id); + cmd.Parameters.Add("DefaultPublicFolderMailbox", newValue); + } + + res = true; + } + finally + { + CloseRunspace(runSpace); + } + ExchangeLog.LogEnd("SetDefaultPublicFolderMailbox"); + return res; + } + + #endregion #region Address Lists (GAL, AL, RAL, OAB, ABP) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Exchange2007.cs b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Exchange2007.cs index cfbb73b4..5d89c254 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Exchange2007.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Exchange2007.cs @@ -4854,6 +4854,21 @@ namespace WebsitePanel.Providers.HostedSolution return size; } + public string CreateOrganizationRootPublicFolder(string organizationId, string organizationDistinguishedName, string securityGroup, string organizationDomain) + { + // not implemented + return null; + } + + public bool SetDefaultPublicFolderMailbox(string id, string organizationId, string organizationDistinguishedName, out string oldValue, out string newValue) + { + // not implemented + oldValue = null; + newValue = null; + return false; + } + + #endregion #region Address Lists (GAL, AL, RAL, OAB, ABP) diff --git a/WebsitePanel/Sources/WebsitePanel.Server.Client/ExchangeServerProxy.cs b/WebsitePanel/Sources/WebsitePanel.Server.Client/ExchangeServerProxy.cs index e1241b9e..5e193efb 100644 --- a/WebsitePanel/Sources/WebsitePanel.Server.Client/ExchangeServerProxy.cs +++ b/WebsitePanel/Sources/WebsitePanel.Server.Client/ExchangeServerProxy.cs @@ -29,7 +29,6 @@ using WebsitePanel.Providers.HostedSolution; using WebsitePanel.Providers.Common; - //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -65,6 +64,8 @@ namespace WebsitePanel.Providers.Exchange public ServiceProviderSettingsSoapHeader ServiceProviderSettingsSoapHeaderValue; + private System.Threading.SendOrPostCallback CreateOrganizationRootPublicFolderOperationCompleted; + private System.Threading.SendOrPostCallback CreateOrganizationActiveSyncPolicyOperationCompleted; private System.Threading.SendOrPostCallback GetActiveSyncPolicyOperationCompleted; @@ -223,6 +224,9 @@ namespace WebsitePanel.Providers.Exchange this.Url = "http://localhost:9004/ExchangeServer.asmx"; } + /// + public event CreateOrganizationRootPublicFolderCompletedEventHandler CreateOrganizationRootPublicFolderCompleted; + /// public event CreateOrganizationActiveSyncPolicyCompletedEventHandler CreateOrganizationActiveSyncPolicyCompleted; @@ -451,6 +455,65 @@ namespace WebsitePanel.Providers.Exchange /// public event GetPublicFolderSizeCompletedEventHandler GetPublicFolderSizeCompleted; + /// + [System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")] + [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/server/CreateOrganizationRootPublicFolder", RequestNamespace = "http://smbsaas/websitepanel/server/", ResponseNamespace = "http://smbsaas/websitepanel/server/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] + public string CreateOrganizationRootPublicFolder(string organizationId, string organizationDistinguishedName, string securityGroup, string organizationDomain) + { + object[] results = this.Invoke("CreateOrganizationRootPublicFolder", new object[] { + organizationId, + organizationDistinguishedName, + securityGroup, + organizationDomain}); + return ((string)(results[0])); + } + + /// + public System.IAsyncResult BeginCreateOrganizationRootPublicFolder(string organizationId, string organizationDistinguishedName, string securityGroup, string organizationDomain, System.AsyncCallback callback, object asyncState) + { + return this.BeginInvoke("CreateOrganizationRootPublicFolder", new object[] { + organizationId, + organizationDistinguishedName, + securityGroup, + organizationDomain}, callback, asyncState); + } + + /// + public string EndCreateOrganizationRootPublicFolder(System.IAsyncResult asyncResult) + { + object[] results = this.EndInvoke(asyncResult); + return ((string)(results[0])); + } + + /// + public void CreateOrganizationRootPublicFolderAsync(string organizationId, string organizationDistinguishedName, string securityGroup, string organizationDomain) + { + this.CreateOrganizationRootPublicFolderAsync(organizationId, organizationDistinguishedName, securityGroup, organizationDomain, null); + } + + /// + public void CreateOrganizationRootPublicFolderAsync(string organizationId, string organizationDistinguishedName, string securityGroup, string organizationDomain, object userState) + { + if ((this.CreateOrganizationRootPublicFolderOperationCompleted == null)) + { + this.CreateOrganizationRootPublicFolderOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCreateOrganizationRootPublicFolderOperationCompleted); + } + this.InvokeAsync("CreateOrganizationRootPublicFolder", new object[] { + organizationId, + organizationDistinguishedName, + securityGroup, + organizationDomain}, this.CreateOrganizationRootPublicFolderOperationCompleted, userState); + } + + private void OnCreateOrganizationRootPublicFolderOperationCompleted(object arg) + { + if ((this.CreateOrganizationRootPublicFolderCompleted != null)) + { + System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg)); + this.CreateOrganizationRootPublicFolderCompleted(this, new CreateOrganizationRootPublicFolderCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState)); + } + } + /// [System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")] [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/server/CreateOrganizationActiveSyncPolicy", RequestNamespace = "http://smbsaas/websitepanel/server/", ResponseNamespace = "http://smbsaas/websitepanel/server/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] @@ -5146,6 +5209,36 @@ namespace WebsitePanel.Providers.Exchange } } + /// + [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")] + public delegate void CreateOrganizationRootPublicFolderCompletedEventHandler(object sender, CreateOrganizationRootPublicFolderCompletedEventArgs e); + + /// + [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")] + [System.Diagnostics.DebuggerStepThroughAttribute()] + [System.ComponentModel.DesignerCategoryAttribute("code")] + public partial class CreateOrganizationRootPublicFolderCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs + { + + private object[] results; + + internal CreateOrganizationRootPublicFolderCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : + base(exception, cancelled, userState) + { + this.results = results; + } + + /// + public string Result + { + get + { + this.RaiseExceptionIfNecessary(); + return ((string)(this.results[0])); + } + } + } + /// [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")] public delegate void CreateOrganizationActiveSyncPolicyCompletedEventHandler(object sender, System.ComponentModel.AsyncCompletedEventArgs e); diff --git a/WebsitePanel/Sources/WebsitePanel.Server/ExchangeServer.asmx.cs b/WebsitePanel/Sources/WebsitePanel.Server/ExchangeServer.asmx.cs index b832d06d..7a4d3e63 100644 --- a/WebsitePanel/Sources/WebsitePanel.Server/ExchangeServer.asmx.cs +++ b/WebsitePanel/Sources/WebsitePanel.Server/ExchangeServer.asmx.cs @@ -1088,6 +1088,23 @@ namespace WebsitePanel.Server throw; } } + + [WebMethod, SoapHeader("settings")] + public string CreateOrganizationRootPublicFolder(string organizationId, string organizationDistinguishedName, string securityGroup, string organizationDomain) + { + try + { + LogStart("CreateOrganizationRootPublicFolder"); + string ret = ES.CreateOrganizationRootPublicFolder(organizationId, organizationDistinguishedName, securityGroup, organizationDomain); + LogEnd("CreateOrganizationRootPublicFolder"); + return ret; + } + catch (Exception ex) + { + Log.WriteError("GetPublicFolderSize", ex); + throw; + } + } #endregion