Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }