public void ReplicateAllOrganizations() { if (!FrameworkConfiguration.Current.WebApplication.Integration.Ldap.Enabled) { throw new InvalidOperationException("Ldap integration is not enabled in the application configuration file."); } int replicated = 0; int errors = 0; int count = 0; using (OrganizationsLdapGroupsTableAdapter adapter = new OrganizationsLdapGroupsTableAdapter()) { OrganizationCollection organizationCollection = OrganizationProvider.GetOrganizations(false, false); DateTime startDate = DateTime.UtcNow; LdapInfoProvider.InsertLdapLog(null, false, Resources.LdapProcessLog_ReplicationAllStarted); foreach (Organization org in organizationCollection) { if (String.IsNullOrEmpty(org.LdapServerAddress) == true || String.IsNullOrEmpty(org.LdapServerPort) == true || String.IsNullOrEmpty(org.LdapUserName) == true || String.IsNullOrEmpty(org.LdapPassword) == true || String.IsNullOrEmpty(org.LdapDomain) == true || !org.Beta) { continue; } //Get All Groups DataView dvDomains = LdapInfoProvider.GetDomains(org.OrganizationId); if (dvDomains.Table.Rows.Count > 0) { for (int i = 0; i < dvDomains.Table.Rows.Count; i++) { DataRow drDomain = dvDomains.Table.Rows[i]; DataView dvGroups = LdapInfoProvider.GetGroupsByDomainDistinguishedName(org.OrganizationId, drDomain["DistinguishedName"].ToString()); if (dvGroups.Table.Rows.Count > 0) { adapter.Delete(org.OrganizationId, drDomain["DomainName"].ToString()); for (int j = 0; j < dvGroups.Table.Rows.Count; j++) { DataRow drGroup = dvGroups.Table.Rows[j]; adapter.Insert(Guid.NewGuid(), org.OrganizationId, (Guid)drDomain["Id"], drDomain["DomainName"].ToString(), (Guid)drGroup["Id"], drGroup["GroupName"].ToString(), drGroup["DistinguishedName"].ToString(), DateTime.UtcNow); } } } } count++; RunADReplication(org.OrganizationId, true); Bll.LdapProcess ldapProcess = LdapInfoProvider.LdapProcesses.Find(x => x.ProcessId == string.Format(CultureInfo.InvariantCulture, "RealADReplication_{0}", org.OrganizationId)); if (ldapProcess != null) { if (ldapProcess.ThreadStateType == ThreadStateType.Failed) { replicated++; } else { errors++; } } } LdapInfoProvider.InsertLdapLog(null, false, string.Format(Resources.LdapProcessLog_ReplicationAllFinished, Math.Round((DateTime.UtcNow - startDate).TotalMinutes, 1), count, replicated, errors)); } }
public void ImportLdapGroups(Guid organizationId) { Organization organization = null; DataView dvDomains = null; DataView dvGroups = null; DataRow drDomain = null; DataRow drGroup = null; try { this.ThreadState = ThreadStateType.Running; if (FrameworkConfiguration.Current.WebApplication.Integration.Ldap.Enabled) { organization = OrganizationProvider.GetOrganization(organizationId); if (organization != null) { if (String.IsNullOrEmpty(organization.LdapServerAddress) == true || String.IsNullOrEmpty(organization.LdapServerPort) == true || String.IsNullOrEmpty(organization.LdapUserName) == true || String.IsNullOrEmpty(organization.LdapPassword) == true || String.IsNullOrEmpty(organization.LdapDomain) == true || !organization.Beta) { return; } dvDomains = LdapInfoProvider.GetDomains(organization.OrganizationId); if (dvDomains.Table.Rows.Count > 0) { using (OrganizationsLdapGroupsTableAdapter adapter = new OrganizationsLdapGroupsTableAdapter()) { for (int i = 0; i < dvDomains.Table.Rows.Count; i++) { drDomain = dvDomains.Table.Rows[i]; dvGroups = LdapInfoProvider.GetGroupsByDomainDistinguishedName(organization.OrganizationId, drDomain["DistinguishedName"].ToString()); if (dvGroups.Table.Rows.Count > 0) { adapter.Delete(organization.OrganizationId, drDomain["DomainName"].ToString()); for (int j = 0; j < dvGroups.Table.Rows.Count; j++) { drGroup = dvGroups.Table.Rows[j]; adapter.Insert(Guid.NewGuid(), organization.OrganizationId, (Guid)drDomain["Id"], drDomain["DomainName"].ToString(), (Guid)drGroup["Id"], drGroup["GroupName"].ToString(), drGroup["DistinguishedName"].ToString(), DateTime.UtcNow); } } } } } } } this.ThreadState = ThreadStateType.Finished; } catch (Exception ex) { this.ThreadState = ThreadStateType.Failed; this.ErrorException = ex; LdapInfoProvider.InsertLdapLog(organizationId, true, ex.Message); } finally { organization = null; drDomain = null; if (dvDomains != null) { dvDomains.Dispose(); } if (dvGroups != null) { dvGroups.Dispose(); } } }