Esempio n. 1
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId);
            bool           enterpriseVoiceQuota = Utils.CheckQouta(Quotas.LYNC_ENTERPRISEVOICE, cntx);

            bool enterpriseVoice = false;

            SolidCP.Providers.HostedSolution.LyncUserPlan plan = planSelector.plan;
            if (plan != null)
            {
                enterpriseVoice = plan.EnterpriseVoice && enterpriseVoiceQuota && (ddlPhoneNumber.Items.Count > 0);
            }

            pnEnterpriseVoice.Visible = enterpriseVoice;

            if (!enterpriseVoice)
            {
                ddlPhoneNumber.Text = "";
                tbPin.Text          = "";
            }

            if (enterpriseVoice)
            {
                string[] pinPolicy = ES.Services.Lync.GetPolicyList(PanelRequest.ItemID, LyncPolicyType.Pin, "MinPasswordLength");
                if (pinPolicy != null)
                {
                    if (pinPolicy.Length > 0)
                    {
                        int MinPasswordLength = -1;
                        if (int.TryParse(pinPolicy[0], out MinPasswordLength))
                        {
                            PinRegularExpressionValidator.ValidationExpression = "^([0-9]){" + MinPasswordLength.ToString() + ",}$";
                            PinRegularExpressionValidator.ErrorMessage         = "Must contain only numbers. Min. length " + MinPasswordLength.ToString();
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 internal virtual bool SetLyncUserPlanInternal(string organizationId, string userUpn, LyncUserPlan plan, Runspace runspace)
 {
     throw new NotImplementedException();
 }
Esempio n. 3
0
 internal virtual bool CreateUserInternal(string organizationId, string userUpn, LyncUserPlan plan)
 {
     throw new NotImplementedException();
 }
Esempio n. 4
0
 public virtual bool SetLyncUserPlan(string organizationId, string userUpn, LyncUserPlan plan)
 {
     return(SetLyncUserPlanInternal(organizationId, userUpn, plan, null));
 }
Esempio n. 5
0
 public virtual bool CreateUser(string organizationId, string userUpn, LyncUserPlan plan)
 {
     return(CreateUserInternal(organizationId, userUpn, plan));
 }
Esempio n. 6
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);
        }
Esempio n. 7
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());

                string path = string.Empty;
                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);
                Collection <PSObject> result = ExecuteShellCommand(runspace, command, false);

                //set groupingID
                path = AddADPrefix(GetResultObjectDN(result));
                DirectoryEntry user = ActiveDirectoryUtils.GetADObject(path);
                ActiveDirectoryUtils.SetADObjectPropertyValue(user, "msRTCSIP-GroupingID", guid);
                user.CommitChanges();

                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);
        }