protected void Page_PreRender(object sender, EventArgs e) { PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); bool enterpriseVoiceQuota = Utils.CheckQouta(Quotas.SFB_ENTERPRISEVOICE, cntx); bool enterpriseVoice = false; SolidCP.Providers.HostedSolution.SfBUserPlan 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.SfB.GetPolicyList(PanelRequest.ItemID, SfBPolicyType.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(); } } } } }
/// <summary> Sets users sfb plan.</summary> /// <param name="organizationId"> The organization identifier.</param> /// <param name="userUpn"> The user UPN.</param> /// <param name="plan"> The sfb plan.</param> /// <param name="runspace"> The runspace.</param> /// <returns> The result.</returns> internal override bool SetSfBUserPlanInternal(string organizationId, string userUpn, SfBUserPlan plan, Runspace runspace) { HostedSolutionLog.LogStart("SetSfBUserPlanInternal"); HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId); HostedSolutionLog.DebugInfo("userUpn: {0}", userUpn); bool bCloseRunSpace = false; bool res = 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); } catch (Exception ex) { res = false; HostedSolutionLog.LogError("SetSfBUserPlanInternal", ex); throw; } finally { if (bCloseRunSpace) { CloseRunspace(runspace); } } HostedSolutionLog.LogEnd("SetSfBUserPlanInternal"); return(res); }
/// <summary> Creates the user.</summary> /// <param name="organizationId"> The organization identifier.</param> /// <param name="userUpn"> The user UPN.</param> /// <param name="plan"> The SfB user plan.</param> /// <returns> The result.</returns> internal override bool CreateUserInternal(string organizationId, string userUpn, SfBUserPlan plan) { HostedSolutionLog.LogStart("CreateUserInternal"); HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId); HostedSolutionLog.DebugInfo("userUpn: {0}", userUpn); SfBTransaction 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 = SetSfBUserPlanInternal(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); }
internal virtual bool SetSfBUserPlanInternal(string organizationId, string userUpn, SfBUserPlan plan, Runspace runspace) { throw new NotImplementedException(); }
internal virtual bool CreateUserInternal(string organizationId, string userUpn, SfBUserPlan plan) { throw new NotImplementedException(); }
public virtual bool SetSfBUserPlan(string organizationId, string userUpn, SfBUserPlan plan) { return(SetSfBUserPlanInternal(organizationId, userUpn, plan, null)); }
public virtual bool CreateUser(string organizationId, string userUpn, SfBUserPlan plan) { return(CreateUserInternal(organizationId, userUpn, plan)); }