/// <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); }
internal virtual bool SetLyncUserGeneralSettingsInternal(string organizationId, string userUpn, LyncUser lyncUser) { throw new NotImplementedException(); }
public virtual bool SetLyncUserGeneralSettings(string organizationId, string userUpn, LyncUser lyncUser) { return(SetLyncUserGeneralSettingsInternal(organizationId, userUpn, lyncUser)); }
/// <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); }