This commit is contained in:
Virtuworks 2012-11-22 13:30:35 -05:00
commit 226f94ed56
99 changed files with 3685 additions and 662 deletions

View file

@ -2591,8 +2591,8 @@ namespace WebsitePanel.Providers.HostedSolution
Command cmd = new Command("Set-Mailbox");
cmd.Parameters.Add("Identity", accountName);
cmd.Parameters.Add("PrimarySmtpAddress", primaryEmail);
cmd.Parameters.Add("UserPrincipalName", primaryEmail);
cmd.Parameters.Add("WindowsEmailAddress", primaryEmail);
//cmd.Parameters.Add("UserPrincipalName", primaryEmail);
//cmd.Parameters.Add("WindowsEmailAddress", primaryEmail);
ExecuteShellCommand(runSpace, cmd);
}

View file

@ -607,15 +607,42 @@ namespace WebsitePanel.Providers.HostedSolution
ExchangeLog.LogStart("GetDatabase");
ExchangeLog.LogInfo("DAG: " + dagName);
//Get Dag Servers
// this part of code handles mailboxnames like in the old 2007 provider
// check if DAG is in reality DAG\mailboxdatabase
string dagNameDAG = string.Empty;
string dagNameMBX = string.Empty;
bool isFixedDatabase = false;
if (dagName.Contains("\\"))
{
// split the two parts and extract DAG-Name and mailboxdatabase-name
string[] parts = dagName.Split(new char[] { '\\' }, 2, StringSplitOptions.None);
dagNameDAG = parts[0];
dagNameMBX = parts[1];
// check that we realy have a database name
if (!String.IsNullOrEmpty(dagNameMBX))
{
isFixedDatabase = true;
}
}
else
{
// there is no mailboxdatabase-name use the loadbalancing-code
dagNameDAG = dagName;
isFixedDatabase = false;
}
//Get Dag Servers - with the name of the database availability group
Collection<PSObject> dags = null;
Command cmd = new Command("Get-DatabaseAvailabilityGroup");
cmd.Parameters.Add("Identity", dagName);
cmd.Parameters.Add("Identity", dagNameDAG);
dags = ExecuteShellCommand(runSpace, cmd);
if (htBbalancer == null)
htBbalancer = new Hashtable();
// use fully qualified dagName for loadbalancer. Thus if there are two services and one of them
// contains only the DAG, the "fixed" database could also be used in loadbalancing. If you do not want this,
// set either IsExcludedFromProvisioning or IsSuspendedFromProvisioning - it is not evaluated for fixed databases
if (htBbalancer[dagName] == null)
htBbalancer.Add(dagName, 0);
@ -628,35 +655,56 @@ namespace WebsitePanel.Providers.HostedSolution
{
System.Collections.Generic.List<string> lstDatabase = new System.Collections.Generic.List<string>();
foreach (object objServer in servers)
if (!isFixedDatabase) // "old" loadbalancing code
{
foreach (object objServer in servers)
{
Collection<PSObject> databases = null;
cmd = new Command("Get-MailboxDatabase");
cmd.Parameters.Add("Server", ObjToString(objServer));
databases = ExecuteShellCommand(runSpace, cmd);
foreach (PSObject objDatabase in databases)
{
if (((bool)GetPSObjectProperty(objDatabase, "IsExcludedFromProvisioning") == false) &&
((bool)GetPSObjectProperty(objDatabase, "IsSuspendedFromProvisioning") == false))
{
string db = ObjToString(GetPSObjectProperty(objDatabase, "Identity"));
bool bAdd = true;
foreach (string s in lstDatabase)
{
if (s.ToLower() == db.ToLower())
{
bAdd = false;
break;
}
}
if (bAdd)
{
lstDatabase.Add(db);
ExchangeLog.LogInfo("AddDatabase: " + db);
}
}
}
}
}
else // new fixed database code
{
Collection<PSObject> databases = null;
cmd = new Command("Get-MailboxDatabase");
cmd.Parameters.Add("Server", ObjToString(objServer));
cmd.Parameters.Add("Identity", dagNameMBX);
databases = ExecuteShellCommand(runSpace, cmd);
// do not check "IsExcludedFromProvisioning" or "IsSuspended", just check if it is a member of the DAG
foreach (PSObject objDatabase in databases)
{
if (((bool)GetPSObjectProperty(objDatabase, "IsExcludedFromProvisioning") == false) &&
((bool)GetPSObjectProperty(objDatabase, "IsSuspendedFromProvisioning") == false))
string dagSetting = ObjToString(GetPSObjectProperty(objDatabase, "MasterServerOrAvailabilityGroup"));
if (dagNameDAG.Equals(dagSetting, StringComparison.OrdinalIgnoreCase))
{
string db = ObjToString(GetPSObjectProperty(objDatabase, "Identity"));
bool bAdd = true;
foreach (string s in lstDatabase)
{
if (s.ToLower() == db.ToLower())
{
bAdd = false;
break;
}
}
if (bAdd)
{
lstDatabase.Add(db);
ExchangeLog.LogInfo("AddDatabase: " + db);
}
lstDatabase.Add(dagNameMBX);
ExchangeLog.LogInfo("AddFixedDatabase: " + dagNameMBX);
}
}
}

View file

@ -127,6 +127,12 @@ namespace WebsitePanel.Providers.HostedSolution
return GetLyncUserGeneralSettingsInternal(organizationId, userUpn);
}
public bool SetLyncUserGeneralSettings(string organizationId, string userUpn, LyncUser lyncUser)
{
return SetLyncUserGeneralSettingsInternal(organizationId, userUpn, lyncUser);
}
public bool SetLyncUserPlan(string organizationId, string userUpn, LyncUserPlan plan)
{
return SetLyncUserPlanInternal(organizationId, userUpn, plan, null);
@ -288,11 +294,14 @@ namespace WebsitePanel.Providers.HostedSolution
Guid tenantId = (Guid)GetPSObjectProperty(result[0], "TenantId");
// create sip domain
DeleteSipDomain(runSpace, sipDomain);
//clear the msRTCSIP-Domains, TenantID, ObjectID
string path = AddADPrefix(GetOrganizationPath(organizationId));
DirectoryEntry ou = ActiveDirectoryUtils.GetADObject(path);
string[] sipDs = (string[])ActiveDirectoryUtils.GetADObjectPropertyMultiValue(ou, "msRTCSIP-Domains");
foreach (string sipD in sipDs)
DeleteSipDomain(runSpace, sipD);
//clear the msRTCSIP-Domains, TenantID, ObjectID
ActiveDirectoryUtils.ClearADObjectPropertyValue(ou, "msRTCSIP-Domains");
ActiveDirectoryUtils.ClearADObjectPropertyValue(ou, "msRTCSIP-TenantId");
ActiveDirectoryUtils.ClearADObjectPropertyValue(ou, "msRTCSIP-ObjectId");
@ -383,6 +392,51 @@ namespace WebsitePanel.Providers.HostedSolution
{
tenantId = (Guid)GetPSObjectProperty(result[0], "TenantId");
string[] tmp = userUpn.Split('@');
if (tmp.Length < 2) return false;
// Get SipDomains and verify existence
bool bSipDomainExists = false;
cmd = new Command("Get-CsSipDomain");
Collection<PSObject> sipDomains = ExecuteShellCommand(runSpace, cmd, false);
foreach (PSObject domain in sipDomains)
{
string d = (string)GetPSObjectProperty(domain, "Name");
if (d.ToLower() == tmp[1].ToLower())
{
bSipDomainExists = true;
break;
}
}
string path = string.Empty;
if (!bSipDomainExists)
{
// Create Sip Domain
cmd = new Command("New-CsSipDomain");
cmd.Parameters.Add("Identity", tmp[1].ToLower());
ExecuteShellCommand(runSpace, cmd, false);
transaction.RegisterNewSipDomain(tmp[1].ToLower());
path = AddADPrefix(GetOrganizationPath(organizationId));
DirectoryEntry ou = ActiveDirectoryUtils.GetADObject(path);
string[] sipDs = (string[])ActiveDirectoryUtils.GetADObjectPropertyMultiValue(ou, "msRTCSIP-Domains");
List<string> listSipDs = new List<string>();
listSipDs.AddRange(sipDs);
listSipDs.Add(tmp[1]);
ActiveDirectoryUtils.SetADObjectPropertyValue(ou, "msRTCSIP-Domains", listSipDs.ToArray());
ou.CommitChanges();
//Create simpleurls
CreateSimpleUrl(runSpace, tmp[1].ToLower(), tenantId);
transaction.RegisterNewSimpleUrl(tmp[1].ToLower(), tenantId.ToString());
}
//enable for lync
cmd = new Command("Enable-CsUser");
cmd.Parameters.Add("Identity", userUpn);
@ -397,13 +451,11 @@ namespace WebsitePanel.Providers.HostedSolution
cmd.Parameters.Add("Identity", userUpn);
result = ExecuteShellCommand(runSpace, cmd);
string path = AddADPrefix(GetResultObjectDN(result));
path = AddADPrefix(GetResultObjectDN(result));
DirectoryEntry user = ActiveDirectoryUtils.GetADObject(path);
ActiveDirectoryUtils.SetADObjectPropertyValue(user, "msRTCSIP-GroupingID", tenantId);
ActiveDirectoryUtils.SetADObjectPropertyValue(user, "msRTCSIP-TenantId", tenantId);
string[] tmp = userUpn.Split('@');
if (tmp.Length > 0)
{
string Url = SimpleUrlRoot + tmp[1];
@ -462,8 +514,10 @@ namespace WebsitePanel.Providers.HostedSolution
PSObject user = result[0];
lyncUser.DisplayName = (string)GetPSObjectProperty(user, "DisplayName");
lyncUser.PrimaryUri = (string)GetPSObjectProperty(user, "SipAddress");
lyncUser.SipAddress = (string)GetPSObjectProperty(user, "SipAddress");
lyncUser.LineUri = (string)GetPSObjectProperty(user, "LineURI");
lyncUser.SipAddress = lyncUser.SipAddress.ToLower().Replace("sip:", "");
}
catch (Exception ex)
{
@ -478,6 +532,114 @@ namespace WebsitePanel.Providers.HostedSolution
return lyncUser;
}
private 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;
Guid tenantId = Guid.Empty;
LyncTransaction transaction = StartTransaction();
try
{
runSpace = OpenRunspace();
Command cmd = new Command("Get-CsTenant");
cmd.Parameters.Add("Identity", GetOrganizationPath(organizationId));
Collection<PSObject> result = ExecuteShellCommand(runSpace, cmd, false);
if ((result != null) && (result.Count > 0))
{
tenantId = (Guid)GetPSObjectProperty(result[0], "TenantId");
string[] tmp = userUpn.Split('@');
if (tmp.Length < 2) return false;
// Get SipDomains and verify existence
bool bSipDomainExists = false;
cmd = new Command("Get-CsSipDomain");
Collection<PSObject> sipDomains = ExecuteShellCommand(runSpace, cmd, false);
foreach (PSObject domain in sipDomains)
{
string d = (string)GetPSObjectProperty(domain, "Name");
if (d.ToLower() == tmp[1].ToLower())
{
bSipDomainExists = true;
break;
}
}
string path = string.Empty;
if (!bSipDomainExists)
{
// Create Sip Domain
cmd = new Command("New-CsSipDomain");
cmd.Parameters.Add("Identity", tmp[1].ToLower());
ExecuteShellCommand(runSpace, cmd, false);
transaction.RegisterNewSipDomain(tmp[1].ToLower());
path = AddADPrefix(GetOrganizationPath(organizationId));
DirectoryEntry ou = ActiveDirectoryUtils.GetADObject(path);
string[] sipDs = (string[])ActiveDirectoryUtils.GetADObjectPropertyMultiValue(ou, "msRTCSIP-Domains");
List<string> listSipDs = new List<string>();
listSipDs.AddRange(sipDs);
listSipDs.Add(tmp[1]);
ActiveDirectoryUtils.SetADObjectPropertyValue(ou, "msRTCSIP-Domains", listSipDs.ToArray());
ou.CommitChanges();
//Create simpleurls
CreateSimpleUrl(runSpace, tmp[1].ToLower(), tenantId);
transaction.RegisterNewSimpleUrl(tmp[1].ToLower(), tenantId.ToString());
path = AddADPrefix(GetResultObjectDN(result));
DirectoryEntry user = ActiveDirectoryUtils.GetADObject(path);
if (tmp.Length > 0)
{
string Url = SimpleUrlRoot + tmp[1];
ActiveDirectoryUtils.SetADObjectPropertyValue(user, "msRTCSIP-BaseSimpleUrl", Url.ToLower());
}
user.CommitChanges();
}
}
cmd = new Command("Set-CsUser");
cmd.Parameters.Add("Identity", userUpn);
if (!string.IsNullOrEmpty(lyncUser.SipAddress)) cmd.Parameters.Add("SipAddress", "SIP:"+lyncUser.SipAddress);
if (!string.IsNullOrEmpty(lyncUser.SipAddress)) cmd.Parameters.Add("LineUri", lyncUser.LineUri);
ExecuteShellCommand(runSpace, cmd, false);
//initiate addressbook generation
cmd = new Command("Update-CsAddressBook");
ExecuteShellCommand(runSpace, cmd, false);
//initiate user database replication
cmd = new Command("Update-CsUserDatabase");
ExecuteShellCommand(runSpace, cmd, false);
}
catch (Exception ex)
{
ret = false;
HostedSolutionLog.LogError("SetLyncUserGeneralSettingsInternal", ex);
RollbackTransaction(transaction);
}
finally
{
CloseRunspace(runSpace);
}
HostedSolutionLog.LogEnd("SetLyncUserGeneralSettingsInternal");
return ret;
}
private bool SetLyncUserPlanInternal(string organizationId, string userUpn, LyncUserPlan plan, Runspace runSpace)
{

View file

@ -529,6 +529,7 @@ namespace WebsitePanel.Providers.HostedSolution
retUser.DomainUserName = GetDomainName(ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.SAMAccountName));
retUser.DistinguishedName = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.DistinguishedName);
retUser.Locked = (bool)entry.InvokeGet(ADAttributes.AccountLocked);
retUser.UserPrincipalName = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.UserPrincipalName);
HostedSolutionLog.LogEnd("GetUserGeneralSettingsInternal");
return retUser;