Пример #1
0
        private void AddDomainInternal(string domainName)
        {
            HostedSolutionLog.LogStart("AddDomainInternal");
            HostedSolutionLog.DebugInfo("Domain Name: {0}", domainName);
            try
            {
                if (string.IsNullOrEmpty(domainName))
                {
                    throw new ArgumentException("domainName");
                }

                if (GetDomain(domainName) != null)
                {
                    HostedSolutionLog.LogWarning("OCS internal domain '{0}' already exists", domainName);
                }
                else
                {
                    using (ManagementObject newDomain = Wmi.CreateInstance("MSFT_SIPFederationInternalDomainData"))
                    {
                        newDomain["SupportedInternalDomain"] = domainName;
                        newDomain.Put();
                    }
                }
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError("AddDomainInternal", ex);
                throw;
            }
            HostedSolutionLog.LogEnd("AddDomainInternal");
        }
Пример #2
0
        /// <summary> Deletes user.</summary>
        /// <param name="userUpn"> The user UPN.</param>
        /// <returns> The result.</returns>
        internal override bool DeleteUserInternal(string userUpn)
        {
            HostedSolutionLog.LogStart("DeleteUserInternal");
            HostedSolutionLog.DebugInfo("userUpn: {0}", userUpn);
            Runspace runspace = null;

            try
            {
                runspace = OpenRunspace();
                DeleteUser(runspace, userUpn);

                var command = new Command("Get-CsAdUser");
                command.Parameters.Add("Identity", userUpn);
                ExecuteShellCommand(runspace, command, false);

                command = new Command("Update-CsAddressBook");
                ExecuteShellCommand(runspace, command, false);

                command = new Command("Update-CsUserDatabase");
                ExecuteShellCommand(runspace, command, false);
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError("DeleteUserInternal", ex);
                throw;
            }
            finally
            {
                CloseRunspace(runspace);
            }

            HostedSolutionLog.LogEnd("DeleteUserInternal");

            return(true);
        }
Пример #3
0
        /// <summary> Gets allowed domains.</summary>
        /// <param name="organizationId"> The organization identifier.</param>
        /// <returns> Allowed domains.</returns>
        internal override LyncFederationDomain[] GetFederationDomainsInternal(string organizationId)
        {
            HostedSolutionLog.LogStart("GetFederationDomainsInternal");
            HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId);
            LyncFederationDomain[] domains;
            Runspace runspace = null;

            try
            {
                runspace = OpenRunspace();
                domains  = GetFederationDomainsInternal(runspace);
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError("GetFederationDomainsInternal", ex);
                throw;
            }
            finally
            {
                CloseRunspace(runspace);
            }

            HostedSolutionLog.LogEnd("GetFederationDomainsInternal");

            return(domains);
        }
Пример #4
0
        /// <summary> Removes domain from allowed list.</summary>
        /// <param name="organizationId"> The organization identifier.</param>
        /// <param name="domainName"> The domain name.</param>
        /// <returns> The result.</returns>
        internal override bool RemoveFederationDomainInternal(string organizationId, string domainName)
        {
            HostedSolutionLog.LogStart("RemoveFederationDomainInternal");
            HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId);
            HostedSolutionLog.DebugInfo("domainName: {0}", domainName);
            Runspace runspace = null;

            try
            {
                runspace = OpenRunspace();
                var command = new Command("Remove-CsAllowedDomain");
                command.Parameters.Add("Identity", domainName);
                ExecuteShellCommand(runspace, command, false);
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError("RemoveFederationDomainInternal", ex);
                throw;
            }
            finally
            {
                CloseRunspace(runspace);
            }

            HostedSolutionLog.LogEnd("RemoveFederationDomainInternal");

            return(true);
        }
Пример #5
0
        internal void DeleteUserInternal(string loginName, string organizationId)
        {
            HostedSolutionLog.LogStart("DeleteUserInternal");
            HostedSolutionLog.DebugInfo("loginName : {0}", loginName);
            HostedSolutionLog.DebugInfo("organizationId : {0}", organizationId);

            if (string.IsNullOrEmpty(loginName))
            {
                throw new ArgumentNullException("loginName");
            }

            if (string.IsNullOrEmpty(organizationId))
            {
                throw new ArgumentNullException("organizationId");
            }

            string path = GetUserPath(organizationId, loginName);

            if (ActiveDirectoryUtils.AdObjectExists(path))
            {
                ActiveDirectoryUtils.DeleteADObject(path);
            }

            HostedSolutionLog.LogEnd("DeleteUserInternal");
        }
Пример #6
0
        private void DeleteDomainInternal(string domainName)
        {
            HostedSolutionLog.LogStart("DeleteDomainInternal");
            HostedSolutionLog.DebugInfo("Domain Name: {0}", domainName);
            try
            {
                if (string.IsNullOrEmpty(domainName))
                {
                    throw new ArgumentException("domainName");
                }

                using (ManagementObject domainObj = GetDomain(domainName))
                {
                    if (domainObj == null)
                    {
                        HostedSolutionLog.LogWarning("OCS internal domain '{0}' not found", domainName);
                    }
                    else
                    {
                        domainObj.Delete();
                    }
                }
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError("DeleteDomainInternal", ex);
                throw;
            }
            HostedSolutionLog.LogEnd("DeleteDomainInternal");
        }
        /// <summary>Restores site collection under given url from backup.</summary>
        /// <param name="rootWebApplicationUri">Root web application uri.</param>
        /// <param name="siteCollection">Site collection to be restored.</param>
        /// <param name="filename">Backup file name to restore from.</param>
        /// <exception cref="InvalidOperationException">Is thrown in case requested operation fails for any reason.</exception>
        public void RestoreSiteCollection(Uri rootWebApplicationUri, SharePointEnterpriseSiteCollection siteCollection, string filename)
        {
            string url = siteCollection.Url;

            try
            {
                string siteCollectionUrl = String.Format("{0}:{1}", url, rootWebApplicationUri.Port);
                HostedSolutionLog.LogStart("RestoreSiteCollection");
                HostedSolutionLog.DebugInfo("siteCollectionUrl: {0}", siteCollectionUrl);

                HostedSolutionLog.DebugInfo("backupFilePath: {0}", filename);
                Runspace runspace = null;

                try
                {
                    string tempPath     = Path.GetTempPath();
                    string expandedFile = filename;

                    if (Path.GetExtension(filename).ToLower() == ".zip")
                    {
                        expandedFile = FileUtils.UnzipFiles(filename, tempPath)[0];

                        // Delete zip archive.
                        FileUtils.DeleteFile(filename);
                    }

                    runspace = OpenRunspace();
                    DeleteSiteCollection(runspace, siteCollectionUrl, false);
                    var command = new Command("Restore-SPSite");
                    command.Parameters.Add("Identity", siteCollectionUrl);
                    command.Parameters.Add("Path", filename);
                    ExecuteShellCommand(runspace, command);

                    command = new Command("Set-SPSite");
                    command.Parameters.Add("Identity", siteCollectionUrl);
                    command.Parameters.Add("OwnerAlias", siteCollection.OwnerLogin);
                    ExecuteShellCommand(runspace, command);

                    command = new Command("Set-SPUser");
                    command.Parameters.Add("Identity", siteCollection.OwnerLogin);
                    command.Parameters.Add("Email", siteCollection.OwnerEmail);
                    command.Parameters.Add("DisplayName", siteCollection.Name);
                    ExecuteShellCommand(runspace, command);

                    FileUtils.DeleteFile(expandedFile);
                }
                finally
                {
                    CloseRunspace(runspace);
                    HostedSolutionLog.LogEnd("RestoreSiteCollection");
                }
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException("Failed to restore site collection.", ex);
            }
        }
Пример #8
0
        /// <summary> Deletes sip domain.</summary>
        /// <param name="runspace"> The runspace.</param>
        /// <param name="id"> The identifier.</param>
        internal void DeleteSipDomain(Runspace runspace, string id)
        {
            HostedSolutionLog.LogStart("DeleteSipDomain");
            HostedSolutionLog.DebugInfo("SipDomain : {0}", id);
            var command = new Command("Remove-CsSipDomain");

            command.Parameters.Add("Identity", id);
            command.Parameters.Add("Confirm", false);
            command.Parameters.Add("Force", true);
            ExecuteShellCommand(runspace, command, false);
            HostedSolutionLog.LogEnd("DeleteSipDomain");
        }
Пример #9
0
        /// <summary> Deletes user.</summary>
        /// <param name="runspace"> The runspace.</param>
        /// <param name="userUpn"> The user UPN.</param>
        internal void DeleteUser(Runspace runspace, string userUpn)
        {
            HostedSolutionLog.LogStart("DeleteUser");
            HostedSolutionLog.DebugInfo("userUpn : {0}", userUpn);

            var command = new Command("Disable-CsUser");

            command.Parameters.Add("Identity", userUpn);
            command.Parameters.Add("Confirm", false);

            ExecuteShellCommand(runspace, command, false);
            HostedSolutionLog.LogEnd("DeleteUser");
        }
Пример #10
0
        /// <summary> Deletes mobility policy.</summary>
        /// <param name="runspace"> The runspace.</param>
        /// <param name="policyName"> The policy name.</param>
        internal void DeleteMobilityPolicy(Runspace runspace, string policyName)
        {
            HostedSolutionLog.LogStart("DeleteMobilityPolicy");
            HostedSolutionLog.DebugInfo("policyName : {0}", policyName);

            var command = new Command("Remove-CsMobilityPolicy");

            command.Parameters.Add("Identity", policyName);
            command.Parameters.Add("Confirm", false);
            command.Parameters.Add("Force", true);

            ExecuteShellCommand(runspace, command, false);
            HostedSolutionLog.LogEnd("DeleteMobilityPolicy");
        }
        /// <summary> Backups site collection under give url.</summary>
        /// <param name="rootWebApplicationUri">Root web application uri.</param>
        /// <param name="url">Url that uniquely identifies site collection to be deleted.</param>
        /// <param name="filename">Resulting backup file name.</param>
        /// <param name="zip">A value which shows whether created backup must be archived.</param>
        /// <param name="tempPath">Custom temp path for backup</param>
        /// <returns>Full path to created backup.</returns>
        /// <exception cref="InvalidOperationException">Is thrown in case requested operation fails for any reason.</exception>
        public string BackupSiteCollection(Uri rootWebApplicationUri, string url, string filename, bool zip, string tempPath)
        {
            try
            {
                string siteCollectionUrl = String.Format("{0}:{1}", url, rootWebApplicationUri.Port);
                HostedSolutionLog.LogStart("BackupSiteCollection");
                HostedSolutionLog.DebugInfo("siteCollectionUrl: {0}", siteCollectionUrl);

                if (String.IsNullOrEmpty(tempPath))
                {
                    tempPath = Path.GetTempPath();
                }

                string backupFileName = Path.Combine(tempPath, (zip ? StringUtils.CleanIdentifier(siteCollectionUrl) + ".bsh" : StringUtils.CleanIdentifier(filename)));
                HostedSolutionLog.DebugInfo("backupFilePath: {0}", backupFileName);
                Runspace runspace = null;

                try
                {
                    runspace = OpenRunspace();
                    var command = new Command("Backup-SPSite");
                    command.Parameters.Add("Identity", siteCollectionUrl);
                    command.Parameters.Add("Path", backupFileName);
                    ExecuteShellCommand(runspace, command);

                    if (zip)
                    {
                        string zipFile = Path.Combine(tempPath, filename);
                        string zipRoot = Path.GetDirectoryName(backupFileName);

                        FileUtils.ZipFiles(zipFile, zipRoot, new[] { Path.GetFileName(backupFileName) });
                        FileUtils.DeleteFile(backupFileName);

                        backupFileName = zipFile;
                    }

                    return(backupFileName);
                }
                finally
                {
                    CloseRunspace(runspace);
                    HostedSolutionLog.LogEnd("BackupSiteCollection");
                }
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException("Failed to backup site collection.", ex);
            }
        }
Пример #12
0
        internal OrganizationUser GetUserGeneralSettingsInternal(string loginName, string organizationId)
        {
            HostedSolutionLog.LogStart("GetUserGeneralSettingsInternal");
            HostedSolutionLog.DebugInfo("loginName : {0}", loginName);
            HostedSolutionLog.DebugInfo("organizationId : {0}", organizationId);

            if (string.IsNullOrEmpty(loginName))
            {
                throw new ArgumentNullException("loginName");
            }

            string         path  = GetUserPath(organizationId, loginName);
            DirectoryEntry entry = ActiveDirectoryUtils.GetADObject(path);

            OrganizationUser retUser = new OrganizationUser();

            retUser.FirstName         = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.FirstName);
            retUser.LastName          = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.LastName);
            retUser.DisplayName       = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.DisplayName);
            retUser.Initials          = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Initials);
            retUser.JobTitle          = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.JobTitle);
            retUser.Company           = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Company);
            retUser.Department        = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Department);
            retUser.Office            = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Office);
            retUser.BusinessPhone     = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.BusinessPhone);
            retUser.Fax               = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Fax);
            retUser.HomePhone         = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.HomePhone);
            retUser.MobilePhone       = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.MobilePhone);
            retUser.Pager             = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Pager);
            retUser.WebPage           = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.WebPage);
            retUser.Address           = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Address);
            retUser.City              = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.City);
            retUser.State             = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.State);
            retUser.Zip               = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Zip);
            retUser.Country           = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Country);
            retUser.Notes             = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Notes);
            retUser.ExternalEmail     = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.ExternalEmail);
            retUser.Disabled          = (bool)entry.InvokeGet(ADAttributes.AccountDisabled);
            retUser.Manager           = GetManager(entry);
            retUser.DomainUserName    = GetDomainName(loginName);
            retUser.DistinguishedName = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.DistinguishedName);
            retUser.Locked            = (bool)entry.InvokeGet(ADAttributes.AccountLocked);

            HostedSolutionLog.LogEnd("GetUserGeneralSettingsInternal");
            return(retUser);
        }
        /// <summary> Creates site collection within predefined root web application.</summary>
        /// <param name="runspace"> The runspace.</param>
        /// <param name="rootWebApplicationUri">Root web application uri.</param>
        /// <param name="siteCollection">Information about site coolection to be created.</param>
        /// <exception cref="InvalidOperationException">Is thrown in case requested operation fails for any reason.</exception>
        private void CreateCollection(Runspace runspace, Uri rootWebApplicationUri, SharePointEnterpriseSiteCollection siteCollection)
        {
            string siteCollectionUrl = String.Format("{0}:{1}", siteCollection.Url, rootWebApplicationUri.Port);

            HostedSolutionLog.DebugInfo("siteCollectionUrl: {0}", siteCollectionUrl);

            try
            {
                SPWebApplication rootWebApplication = SPWebApplication.Lookup(rootWebApplicationUri);
                rootWebApplication.Sites.Add(siteCollectionUrl, siteCollection.Title, siteCollection.Description, (uint)siteCollection.LocaleId, String.Empty, siteCollection.OwnerLogin, siteCollection.OwnerName, siteCollection.OwnerEmail, null, null, null, true);
                rootWebApplication.Update();
            }
            catch (Exception)
            {
                DeleteSiteCollection(runspace, siteCollectionUrl, true);
                throw;
            }

            try
            {
                GrantAccess(runspace, rootWebApplicationUri);
                var command = new Command("Set-SPSite");
                command.Parameters.Add("Identity", siteCollectionUrl);

                if (siteCollection.MaxSiteStorage != -1)
                {
                    command.Parameters.Add("MaxSize", siteCollection.MaxSiteStorage * 1024 * 1024);
                }

                if (siteCollection.WarningStorage != -1 && siteCollection.MaxSiteStorage != -1)
                {
                    command.Parameters.Add("WarningSize", Math.Min(siteCollection.WarningStorage, siteCollection.MaxSiteStorage) * 1024 * 1024);
                }

                ExecuteShellCommand(runspace, command);
            }
            catch (Exception)
            {
                DeleteQuotaTemplate(siteCollection.Title);
                DeleteSiteCollection(runspace, siteCollectionUrl, true);
                throw;
            }

            AddHostsRecord(siteCollection);
        }
Пример #14
0
        internal void DeleteOrganizationInternal(string organizationId)
        {
            HostedSolutionLog.LogStart("DeleteOrganizationInternal");
            HostedSolutionLog.DebugInfo("OrganizationId : {0}", organizationId);

            if (string.IsNullOrEmpty(organizationId))
            {
                throw new ArgumentNullException("organizationId");
            }

            string groupPath = GetGroupPath(organizationId);

            ActiveDirectoryUtils.DeleteADObject(groupPath);

            string path = GetOrganizationPath(organizationId);

            ActiveDirectoryUtils.DeleteADObject(path, true);



            HostedSolutionLog.LogEnd("DeleteOrganizationInternal");
        }
Пример #15
0
        /// <summary> Gets users general settings.</summary>
        /// <param name="organizationId"> The organization identifier.</param>
        /// <param name="userUpn"> The user UPN.</param>
        /// <returns> User settings.</returns>
        internal override LyncUser GetLyncUserGeneralSettingsInternal(string organizationId, string userUpn)
        {
            HostedSolutionLog.LogStart("GetLyncUserGeneralSettingsInternal");
            HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId);
            HostedSolutionLog.DebugInfo("userUpn: {0}", userUpn);
            var      lyncUser = new LyncUser();
            Runspace runspace = null;

            try
            {
                runspace = OpenRunspace();

                var command = new Command("Get-CsUser");
                command.Parameters.Add("Identity", userUpn);
                Collection <PSObject> result = ExecuteShellCommand(runspace, command, false);
                PSObject user = result[0];

                lyncUser.DisplayName = (string)GetPSObjectProperty(user, "DisplayName");
                lyncUser.SipAddress  = (string)GetPSObjectProperty(user, "SipAddress");
                lyncUser.LineUri     = (string)GetPSObjectProperty(user, "LineURI");

                lyncUser.SipAddress = lyncUser.SipAddress.ToLower().Replace("sip:", "");
                lyncUser.LineUri    = lyncUser.LineUri.ToLower().Replace("tel:+", "");
                lyncUser.LineUri    = lyncUser.LineUri.ToLower().Replace("tel:", "");
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError("GetLyncUserGeneralSettingsInternal", ex);
                throw;
            }
            finally
            {
                CloseRunspace(runspace);
            }

            HostedSolutionLog.LogEnd("GetLyncUserGeneralSettingsInternal");

            return(lyncUser);
        }
        /// <summary>Deletes site collection under given url.</summary>
        /// <param name="rootWebApplicationUri">Root web application uri.</param>
        /// <param name="siteCollection">The site collection to be deleted.</param>
        /// <exception cref="InvalidOperationException">Is thrown in case requested operation fails for any reason.</exception>
        public void DeleteSiteCollection(Uri rootWebApplicationUri, SharePointEnterpriseSiteCollection siteCollection)
        {
            HostedSolutionLog.LogStart("DeleteSiteCollection");
            Runspace runspace = null;

            try
            {
                string siteCollectionUrl = String.Format("{0}:{1}", siteCollection.Url, rootWebApplicationUri.Port);
                HostedSolutionLog.DebugInfo("siteCollectionUrl: {0}", siteCollectionUrl);
                runspace = OpenRunspace();
                DeleteSiteCollection(runspace, siteCollectionUrl, false);
                RemoveHostsRecord(siteCollection);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException("Failed to delete site collection.", ex);
            }
            finally
            {
                CloseRunspace(runspace);
                HostedSolutionLog.LogEnd("DeleteSiteCollection");
            }
        }
        /// <summary>
        /// Creates site collection within predefined root web application.
        /// </summary>
        /// <param name="rootWebApplicationUri">Root web application uri.</param>
        /// <param name="siteCollection">Information about site coolection to be created.</param>
        /// <exception cref="InvalidOperationException">Is thrown in case requested operation fails for any reason.</exception>
        public void CreateSiteCollection(Uri rootWebApplicationUri, SharePointSiteCollection siteCollection)
        {
            WindowsImpersonationContext wic = null;

            HostedSolutionLog.LogStart("CreateSiteCollection");

            try
            {
                wic = WindowsIdentity.GetCurrent().Impersonate();
                SPWebApplication rootWebApplication = SPWebApplication.Lookup(rootWebApplicationUri);
                string           siteCollectionUrl  = String.Format("{0}:{1}", siteCollection.Url, rootWebApplicationUri.Port);

                HostedSolutionLog.DebugInfo("rootWebApplicationUri: {0}", rootWebApplicationUri);
                HostedSolutionLog.DebugInfo("siteCollectionUrl: {0}", siteCollectionUrl);

                SPQuota spQuota;

                SPSite spSite = rootWebApplication.Sites.Add(siteCollectionUrl,
                                                             siteCollection.Title, siteCollection.Description,
                                                             (uint)siteCollection.LocaleId, String.Empty,
                                                             siteCollection.OwnerLogin, siteCollection.OwnerName,
                                                             siteCollection.OwnerEmail,
                                                             null, null, null, true);

                try
                {
                    spQuota = new SPQuota();

                    if (siteCollection.MaxSiteStorage != -1)
                    {
                        spQuota.StorageMaximumLevel = siteCollection.MaxSiteStorage * 1024 * 1024;
                    }

                    if (siteCollection.WarningStorage != -1 && siteCollection.MaxSiteStorage != -1)
                    {
                        spQuota.StorageWarningLevel = Math.Min(siteCollection.WarningStorage, siteCollection.MaxSiteStorage) * 1024 * 1024;
                    }
                }
                catch (Exception)
                {
                    rootWebApplication.Sites.Delete(siteCollectionUrl);
                    throw;
                }

                try
                {
                    rootWebApplication.GrantAccessToProcessIdentity(WindowsIdentity.GetCurrent().Name);
                    spSite.Quota = spQuota;
                }
                catch (Exception)
                {
                    rootWebApplication.Sites.Delete(siteCollectionUrl);
                    DeleteQuotaTemplate(siteCollection.Title);
                    throw;
                }

                rootWebApplication.Update(true);

                try
                {
                    if (siteCollection.RootWebApplicationInteralIpAddress != string.Empty)
                    {
                        string dirPath = FileUtils.EvaluateSystemVariables(@"%windir%\system32\drivers\etc");
                        string path    = dirPath + "\\hosts";

                        if (FileUtils.FileExists(path))
                        {
                            string content = FileUtils.GetFileTextContent(path);
                            content = content.Replace("\r\n", "\n").Replace("\n\r", "\n");
                            string[] contentArr   = content.Split(new char[] { '\n' });
                            bool     bRecordExist = false;
                            foreach (string s in contentArr)
                            {
                                if (s != string.Empty)
                                {
                                    string IPAddr   = string.Empty;
                                    string hostName = string.Empty;
                                    if (s[0] != '#')
                                    {
                                        bool bSeperator = false;
                                        foreach (char c in s)
                                        {
                                            if ((c != ' ') & (c != '\t'))
                                            {
                                                if (bSeperator)
                                                {
                                                    hostName += c;
                                                }
                                                else
                                                {
                                                    IPAddr += c;
                                                }
                                            }
                                            else
                                            {
                                                bSeperator = true;
                                            }
                                        }

                                        if (hostName.ToLower() == siteCollection.RootWebApplicationFQDN.ToLower())
                                        {
                                            bRecordExist = true;
                                            break;
                                        }
                                    }
                                }
                            }

                            if (!bRecordExist)
                            {
                                string outPut = string.Empty;
                                foreach (string o in contentArr)
                                {
                                    if (o != string.Empty)
                                    {
                                        outPut += o + "\r\n";
                                    }
                                }

                                outPut += siteCollection.RootWebApplicationInteralIpAddress + '\t' + siteCollection.RootWebApplicationFQDN + "\r\n";

                                FileUtils.UpdateFileTextContent(path, outPut);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    HostedSolutionLog.LogError(ex);
                }
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError(ex);
                throw;
            }
            finally
            {
                if (wic != null)
                {
                    wic.Undo();
                }

                HostedSolutionLog.LogEnd("CreateSiteCollection");
            }
        }
Пример #18
0
        /// <summary> Creates organization. </summary>
        /// <param name="organizationId"> The organization identifier. </param>
        /// <param name="sipDomain"> The sip domain. </param>
        /// <param name="enableConferencingVideo"> True - if conferencing video should be enabled.</param>
        /// <param name="maxConferenceSize"> The max conference size.</param>
        /// <param name="enabledFederation"> True - if federations should be enabled.</param>
        /// <param name="enabledEnterpriseVoice"> True - if enterprise voice should be enabled.</param>
        /// <returns> The tenant identifier. </returns>
        internal override string CreateOrganizationInternal(string organizationId, string sipDomain, bool enableConferencingVideo, int maxConferenceSize, bool enabledFederation, bool enabledEnterpriseVoice)
        {
            sipDomain = sipDomain.ToLower();
            HostedSolutionLog.LogStart("CreateOrganizationInternal");
            HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId);
            HostedSolutionLog.DebugInfo("sipDomain: {0}", sipDomain);
            string          tenantId;
            LyncTransaction transaction = StartTransaction();
            Runspace        runspace    = null;

            try
            {
                runspace = OpenRunspace();
                var command = new Command("New-CsSipDomain");
                command.Parameters.Add("Identity", sipDomain);
                ExecuteShellCommand(runspace, command, false);
                transaction.RegisterNewSipDomain(sipDomain);
                Guid id = Guid.NewGuid();

                AddAdDomainName(organizationId, sipDomain);

                CreateSimpleUrl(runspace, id);
                transaction.RegisterNewSimpleUrl(sipDomain, id.ToString());

                command = new Command("New-CsConferencingPolicy");
                command.Parameters.Add("Identity", organizationId);
                command.Parameters.Add("MaxMeetingSize", ((maxConferenceSize == -1) | (maxConferenceSize > 250)) ? 250 : maxConferenceSize);
                command.Parameters.Add("AllowIPVideo", enableConferencingVideo);
                ExecuteShellCommand(runspace, command, false);
                transaction.RegisterNewConferencingPolicy(organizationId);

                command = new Command("New-CsExternalAccessPolicy");
                command.Parameters.Add("Identity", organizationId);
                command.Parameters.Add("EnableFederationAccess", true);
                command.Parameters.Add("EnableOutsideAccess", true);
                command.Parameters.Add("EnablePublicCloudAccess", false);
                command.Parameters.Add("EnablePublicCloudAudioVideoAccess", false);
                ExecuteShellCommand(runspace, command, false);
                transaction.RegisterNewCsExternalAccessPolicy(organizationId);

                var allowList = new AllowList();
                var domain    = new DomainPattern(sipDomain);
                allowList.AllowedDomain.Add(domain);

                AddFederationDomainInternal("", domain.Domain, PoolFQDN);

                command = new Command("New-CsMobilityPolicy");
                command.Parameters.Add("Identity", organizationId + " EnableOutSideVoice");
                command.Parameters.Add("EnableMobility", true);
                command.Parameters.Add("EnableOutsideVoice", true);
                ExecuteShellCommand(runspace, command, false);
                transaction.RegisterNewCsMobilityPolicy(organizationId + " EnableOutSideVoice");

                command = new Command("New-CsMobilityPolicy");
                command.Parameters.Add("Identity", organizationId + " DisableOutSideVoice");
                command.Parameters.Add("EnableMobility", true);
                command.Parameters.Add("EnableOutsideVoice", false);
                ExecuteShellCommand(runspace, command, false);
                transaction.RegisterNewCsMobilityPolicy(organizationId + " DisableOutSideVoice");

                command = new Command("Invoke-CsManagementStoreReplication");
                ExecuteShellCommand(runspace, command, false);

                tenantId = id.ToString();
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError("CreateOrganizationInternal", ex);
                RollbackTransaction(transaction);
                throw;
            }
            finally
            {
                CloseRunspace(runspace);
            }

            HostedSolutionLog.LogEnd("CreateOrganizationInternal");

            return(tenantId);
        }
Пример #19
0
        /// <summary> Sets users general settings.</summary>
        /// <param name="organizationId"> The organization identifier.</param>
        /// <param name="userUpn"> The user UPN.</param>
        /// <param name="lyncUser"> The lync user settings.</param>
        /// <returns> The result.</returns>
        internal override bool SetLyncUserGeneralSettingsInternal(string organizationId, string userUpn, LyncUser lyncUser)
        {
            HostedSolutionLog.LogStart("SetLyncUserGeneralSettingsInternal");
            HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId);
            HostedSolutionLog.DebugInfo("userUpn: {0}", userUpn);

            bool            ret         = true;
            Runspace        runspace    = null;
            LyncTransaction transaction = StartTransaction();

            try
            {
                runspace = OpenRunspace();
                Guid     tenantId = GetObjectGuid(organizationId, runspace);
                string[] tmp      = userUpn.Split('@');

                if (tmp.Length < 2)
                {
                    return(false);
                }

                var command = new Command("Get-CsSipDomain");
                Collection <PSObject> sipDomains = ExecuteShellCommand(runspace, command, false);
                bool bSipDomainExists            = sipDomains.Select(domain => (string)GetPSObjectProperty(domain, "Name")).Any(d => d.ToLower() == tmp[1].ToLower());

                if (!bSipDomainExists)
                {
                    command = new Command("New-CsSipDomain");
                    command.Parameters.Add("Identity", tmp[1].ToLower());
                    ExecuteShellCommand(runspace, command, false);

                    transaction.RegisterNewSipDomain(tmp[1].ToLower());

                    string         path      = AddADPrefix(GetOrganizationPath(organizationId));
                    DirectoryEntry ou        = ActiveDirectoryUtils.GetADObject(path);
                    string[]       sipDs     = ActiveDirectoryUtils.GetADObjectPropertyMultiValue(ou, "Url");
                    var            listSipDs = new List <string>();
                    listSipDs.AddRange(sipDs);
                    listSipDs.Add(tmp[1]);

                    ActiveDirectoryUtils.SetADObjectPropertyValue(ou, "Url", listSipDs.ToArray());
                    ou.CommitChanges();

                    CreateSimpleUrl(runspace, tenantId);
                    transaction.RegisterNewSimpleUrl(tmp[1].ToLower(), tenantId.ToString());

                    path = AddADPrefix(GetResultObjectDN(organizationId, runspace));
                    DirectoryEntry user = ActiveDirectoryUtils.GetADObject(path);

                    if (tmp.Length > 0)
                    {
                        string Url = SimpleUrlRoot + tmp[1];
                        ActiveDirectoryUtils.SetADObjectPropertyValue(user, "msRTCSIP-BaseSimpleUrl", Url.ToLower());
                    }

                    user.CommitChanges();
                }

                command = new Command("Set-CsUser");
                command.Parameters.Add("Identity", userUpn);

                if (!string.IsNullOrEmpty(lyncUser.SipAddress))
                {
                    command.Parameters.Add("SipAddress", "SIP:" + lyncUser.SipAddress);
                }

                if (!string.IsNullOrEmpty(lyncUser.LineUri))
                {
                    command.Parameters.Add("LineUri", "TEL:+" + lyncUser.LineUri);
                }
                else
                {
                    command.Parameters.Add("LineUri", null);
                }

                ExecuteShellCommand(runspace, command, false);

                if (!String.IsNullOrEmpty(lyncUser.PIN))
                {
                    command = new Command("Set-CsClientPin");
                    command.Parameters.Add("Identity", userUpn);
                    command.Parameters.Add("Pin", lyncUser.PIN);
                    ExecuteShellCommand(runspace, command, false);
                }

                command = new Command("Update-CsAddressBook");
                ExecuteShellCommand(runspace, command, false);

                command = new Command("Update-CsUserDatabase");
                ExecuteShellCommand(runspace, command, false);
            }
            catch (Exception ex)
            {
                ret = false;
                HostedSolutionLog.LogError("SetLyncUserGeneralSettingsInternal", ex);
                RollbackTransaction(transaction);
            }
            finally
            {
                CloseRunspace(runspace);
            }

            HostedSolutionLog.LogEnd("SetLyncUserGeneralSettingsInternal");

            return(ret);
        }
Пример #20
0
        /// <summary> Creates the user.</summary>
        /// <param name="organizationId"> The organization identifier.</param>
        /// <param name="userUpn"> The user UPN.</param>
        /// <param name="plan"> The Lync user plan.</param>
        /// <returns> The result.</returns>
        internal override bool CreateUserInternal(string organizationId, string userUpn, LyncUserPlan plan)
        {
            HostedSolutionLog.LogStart("CreateUserInternal");
            HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId);
            HostedSolutionLog.DebugInfo("userUpn: {0}", userUpn);
            LyncTransaction transaction = StartTransaction();
            Runspace        runspace    = null;

            try
            {
                runspace = OpenRunspace();
                Guid     guid = GetObjectGuid(organizationId, runspace);
                string[] tmp  = userUpn.Split('@');

                if (tmp.Length < 2)
                {
                    return(false);
                }

                var command = new Command("Get-CsSipDomain");
                Collection <PSObject> sipDomains = ExecuteShellCommand(runspace, command, false);
                bool bSipDomainExists            = sipDomains.Select(domain => (string)GetPSObjectProperty(domain, "Name")).Any(d => d.ToLower() == tmp[1].ToLower());

                if (!bSipDomainExists)
                {
                    command = new Command("New-CsSipDomain");
                    command.Parameters.Add("Identity", tmp[1].ToLower());
                    ExecuteShellCommand(runspace, command, false);
                    transaction.RegisterNewSipDomain(tmp[1].ToLower());
                    AddAdDomainName(organizationId, tmp[1].ToLower());
                    CreateSimpleUrl(runspace, guid);
                    transaction.RegisterNewSimpleUrl(tmp[1].ToLower(), guid.ToString());
                }

                command = new Command("Enable-CsUser");
                command.Parameters.Add("Identity", userUpn);
                command.Parameters.Add("RegistrarPool", PoolFQDN);
                command.Parameters.Add("SipAddressType", "UserPrincipalName");
                ExecuteShellCommand(runspace, command, false);
                transaction.RegisterNewCsUser(userUpn);

                command = new Command("Get-CsAdUser");
                command.Parameters.Add("Identity", userUpn);
                ExecuteShellCommand(runspace, command, false);

                command = new Command("Update-CsAddressBook");
                ExecuteShellCommand(runspace, command, false);
                command = new Command("Update-CsUserDatabase");
                ExecuteShellCommand(runspace, command, false);

                int trySleep = 2000; int tryMaxCount = 10; bool PlanSet = false;
                for (int tryCount = 0; (tryCount < tryMaxCount) && (!PlanSet); tryCount++)
                {
                    try
                    {
                        PlanSet = SetLyncUserPlanInternal(organizationId, userUpn, plan, runspace);
                    }
                    catch { }
                    if (!PlanSet)
                    {
                        System.Threading.Thread.Sleep(trySleep);
                    }
                }
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError("CreateUserInternal", ex);
                RollbackTransaction(transaction);
                throw;
            }
            finally
            {
                CloseRunspace(runspace);
            }

            HostedSolutionLog.LogEnd("CreateUserInternal");

            return(true);
        }
Пример #21
0
        private string CreateUserInternal(string userUpn, string userDistinguishedName)
        {
            HostedSolutionLog.LogStart("CreateUserInternal");
            HostedSolutionLog.DebugInfo("UPN: {0}", userUpn);
            HostedSolutionLog.DebugInfo("User Distinguished Name: {0}", userDistinguishedName);

            try
            {
                if (string.IsNullOrEmpty(userUpn))
                {
                    throw new ArgumentException("userUpn");
                }

                if (string.IsNullOrEmpty(userDistinguishedName))
                {
                    throw new ArgumentException("userDistinguishedName");
                }

                if (string.IsNullOrEmpty(PoolFQDN))
                {
                    throw new Exception("Pool FQDN is not specified");
                }



                string poolDN = GetPoolDistinguishedName(PoolFQDN);
                if (string.IsNullOrEmpty(poolDN))
                {
                    throw new Exception(string.Format("Pool {0} not found", PoolFQDN));
                }

                if (!string.IsNullOrEmpty(FindUserByDistinguishedName(userDistinguishedName)))
                {
                    throw new Exception(string.Format("User with distinguished name '{0}' already exists", userDistinguishedName));
                }

                string primaryUri = "sip:" + userUpn;

                if (!string.IsNullOrEmpty(FindUserByPrimaryUri(primaryUri)))
                {
                    throw new Exception(string.Format("User with primary URI '{0}' already exists", primaryUri));
                }

                using (ManagementObject newUser = Wmi.CreateInstance("MSFT_SIPESUserSetting"))
                {
                    newUser["PrimaryURI"]               = primaryUri;
                    newUser["UserDN"]                   = userDistinguishedName;
                    newUser["HomeServerDN"]             = poolDN;
                    newUser["Enabled"]                  = true;
                    newUser["EnabledForInternetAccess"] = true;
                    newUser.Put();
                }
                string instanceId = null;
                int    attempts   = 0;
                while (true)
                {
                    instanceId = FindUserByPrimaryUri(primaryUri);
                    if (!string.IsNullOrEmpty(instanceId))
                    {
                        break;
                    }

                    if (attempts > 9)
                    {
                        throw new Exception(
                                  string.Format("Could not find OCS user '{0}'", primaryUri));
                    }

                    attempts++;
                    ExchangeLog.LogWarning("Attempt #{0} to create OCS user failed!", attempts);
                    // wait 30 sec
                    System.Threading.Thread.Sleep(1000);
                }

                HostedSolutionLog.LogEnd("CreateUserInternal");

                return(instanceId);
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError("CreateUserInternal", ex);
                throw;
            }
        }
Пример #22
0
        internal int CreateUserInternal(string organizationId, string loginName, string displayName, string upn, string password, bool enabled)
        {
            HostedSolutionLog.LogStart("CreateUserInternal");
            HostedSolutionLog.DebugInfo("organizationId : {0}", organizationId);
            HostedSolutionLog.DebugInfo("loginName : {0}", loginName);
            HostedSolutionLog.DebugInfo("displayName : {0}", displayName);

            if (string.IsNullOrEmpty(organizationId))
            {
                throw new ArgumentNullException("organizationId");
            }

            if (string.IsNullOrEmpty(loginName))
            {
                throw new ArgumentNullException("loginName");
            }

            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException("password");
            }

            bool   userCreated = false;
            string userPath    = null;

            try
            {
                string path = GetOrganizationPath(organizationId);
                userPath = GetUserPath(organizationId, loginName);
                if (!ActiveDirectoryUtils.AdObjectExists(userPath))
                {
                    userPath = ActiveDirectoryUtils.CreateUser(path, loginName, displayName, password, enabled);
                    DirectoryEntry entry = new DirectoryEntry(userPath);
                    ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.UserPrincipalName, upn);
                    entry.CommitChanges();
                    userCreated = true;
                }
                else
                {
                    return(Errors.AD_OBJECT_ALREADY_EXISTS);
                }

                string groupPath = GetGroupPath(organizationId);


                ActiveDirectoryUtils.AddUserToGroup(userPath, groupPath);
            }
            catch (Exception e)
            {
                HostedSolutionLog.LogError(e);
                try
                {
                    if (userCreated)
                    {
                        ActiveDirectoryUtils.DeleteADObject(userPath);
                    }
                }
                catch (Exception ex)
                {
                    HostedSolutionLog.LogError(ex);
                }
            }

            HostedSolutionLog.LogEnd("CreateUserInternal");
            return(Errors.OK);
        }
Пример #23
0
        /// <summary> Sets users lync plan.</summary>
        /// <param name="organizationId"> The organization identifier.</param>
        /// <param name="userUpn"> The user UPN.</param>
        /// <param name="plan"> The lync plan.</param>
        /// <param name="runspace"> The runspace.</param>
        /// <returns> The result.</returns>
        internal override bool SetLyncUserPlanInternal(string organizationId, string userUpn, LyncUserPlan plan, Runspace runspace)
        {
            HostedSolutionLog.LogStart("SetLyncUserPlanInternal");
            HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId);
            HostedSolutionLog.DebugInfo("userUpn: {0}", userUpn);
            bool bCloseRunSpace = false;
            bool ret            = true;

            try
            {
                if (runspace == null)
                {
                    runspace       = OpenRunspace();
                    bCloseRunSpace = true;
                }

                // EnterpriseVoice
                var command = new Command("Set-CsUser");
                command.Parameters.Add("Identity", userUpn);
                command.Parameters.Add("EnterpriseVoiceEnabled", plan.EnterpriseVoice);
                ExecuteShellCommand(runspace, command, false);

                command = new Command("Grant-CsExternalAccessPolicy");
                command.Parameters.Add("Identity", userUpn);
                command.Parameters.Add("PolicyName", plan.Federation ? organizationId : null);
                ExecuteShellCommand(runspace, command, false);

                command = new Command("Grant-CsConferencingPolicy");
                command.Parameters.Add("Identity", userUpn);
                command.Parameters.Add("PolicyName", plan.Federation ? organizationId : null);
                ExecuteShellCommand(runspace, command, false);

                command = new Command("Grant-CsMobilityPolicy");
                command.Parameters.Add("Identity", userUpn);
                if (plan.Mobility)
                {
                    command.Parameters.Add("PolicyName", plan.MobilityEnableOutsideVoice ? organizationId + " EnableOutSideVoice" : organizationId + " DisableOutSideVoice");
                }
                else
                {
                    command.Parameters.Add("PolicyName", null);
                }
                ExecuteShellCommand(runspace, command, false);

                // ArchivePolicy
                command = new Command("Grant-CsArchivingPolicy");
                command.Parameters.Add("Identity", userUpn);
                command.Parameters.Add("PolicyName", string.IsNullOrEmpty(plan.ArchivePolicy) ? null : plan.ArchivePolicy);
                ExecuteShellCommand(runspace, command, false);

                // DialPlan
                command = new Command("Grant-CsDialPlan");
                command.Parameters.Add("Identity", userUpn);
                command.Parameters.Add("PolicyName", string.IsNullOrEmpty(plan.TelephonyDialPlanPolicy) ? null : plan.TelephonyDialPlanPolicy);
                ExecuteShellCommand(runspace, command, false);

                // VoicePolicy
                command = new Command("Grant-CsVoicePolicy");
                command.Parameters.Add("Identity", userUpn);
                command.Parameters.Add("PolicyName", string.IsNullOrEmpty(plan.TelephonyVoicePolicy) ? null : plan.TelephonyVoicePolicy);
                ExecuteShellCommand(runspace, command, false);

                command = new Command("Update-CsUserDatabase");
                ExecuteShellCommand(runspace, command, false);

                ret = false;
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError("SetLyncUserPlanInternal", ex);
                throw;
            }
            finally
            {
                if (bCloseRunSpace)
                {
                    CloseRunspace(runspace);
                }
            }

            HostedSolutionLog.LogEnd("SetLyncUserPlanInternal");

            return(ret);
        }
Пример #24
0
        /// <summary> Deletes organization.</summary>
        /// <param name="organizationId"> The organization identifier.</param>
        /// <param name="sipDomain"> The sip domain.</param>
        /// <returns> The result.</returns>
        internal override bool DeleteOrganizationInternal(string organizationId, string sipDomain)
        {
            HostedSolutionLog.LogStart("DeleteOrganizationInternal");
            HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId);
            HostedSolutionLog.DebugInfo("sipDomain: {0}", sipDomain);
            Runspace runspace = null;

            try
            {
                runspace = OpenRunspace();
                string         path  = AddADPrefix(GetOrganizationPath(organizationId));
                DirectoryEntry ou    = ActiveDirectoryUtils.GetADObject(path);
                string[]       sipDs = ActiveDirectoryUtils.GetADObjectPropertyMultiValue(ou, "Url");

                foreach (string sipD in sipDs)
                {
                    DeleteSipDomain(runspace, sipD);
                }

                try
                {
                    DeleteConferencingPolicy(runspace, organizationId);
                }
                catch (Exception)
                {
                }

                try
                {
                    DeleteExternalAccessPolicy(runspace, organizationId);
                }
                catch (Exception)
                {
                }

                try
                {
                    DeleteMobilityPolicy(runspace, organizationId + " EnableOutSideVoice");
                }
                catch (Exception)
                {
                }

                try
                {
                    DeleteMobilityPolicy(runspace, organizationId + " DisableOutSideVoice");
                }
                catch (Exception)
                {
                }

                var command = new Command("Invoke-CsManagementStoreReplication");
                ExecuteShellCommand(runspace, command, false);
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError("DeleteOrganizationInternal", ex);
                throw;
            }
            finally
            {
                CloseRunspace(runspace);
            }

            HostedSolutionLog.LogEnd("DeleteOrganizationInternal");

            return(true);
        }
Пример #25
0
        internal Organization CreateOrganizationInternal(string organizationId)
        {
            HostedSolutionLog.LogStart("CreateOrganizationInternal");
            HostedSolutionLog.DebugInfo("OrganizationId : {0}", organizationId);

            if (string.IsNullOrEmpty(organizationId))
            {
                throw new ArgumentNullException("organizationId");
            }

            bool ouCreated    = false;
            bool groupCreated = false;

            Organization org;

            try
            {
                string parentPath = GetRootOU();
                string orgPath    = GetOrganizationPath(organizationId);

                //Create OU
                ActiveDirectoryUtils.CreateOrganizationalUnit(organizationId, parentPath);
                ouCreated = true;

                //Create security group
                ActiveDirectoryUtils.CreateGroup(orgPath, organizationId);
                groupCreated = true;


                org = new Organization();
                org.OrganizationId    = organizationId;
                org.DistinguishedName = ActiveDirectoryUtils.RemoveADPrefix(orgPath);
                org.SecurityGroup     = ActiveDirectoryUtils.RemoveADPrefix(GetGroupPath(organizationId));
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError(ex);
                try
                {
                    if (groupCreated)
                    {
                        string groupPath = GetGroupPath(organizationId);
                        ActiveDirectoryUtils.DeleteADObject(groupPath);
                    }
                }
                catch (Exception e)
                {
                    HostedSolutionLog.LogError(e);
                }

                try
                {
                    if (ouCreated)
                    {
                        string orgPath = GetOrganizationPath(organizationId);
                        ActiveDirectoryUtils.DeleteADObject(orgPath);
                    }
                }
                catch (Exception e)
                {
                    HostedSolutionLog.LogError(e);
                }

                throw;
            }

            HostedSolutionLog.LogEnd("CreateOrganizationInternal");

            return(org);
        }