private void HandleFailedCompany(string operationName, EhfCompanyItem company, CompanyResponseInfo response, ref int transientFailureCount, ref int permanentFailureCount) { if (response.Status == ResponseStatus.TransientFailure) { transientFailureCount++; } else { permanentFailureCount++; } string text = (company.Company != null) ? company.Company.Name : "not available"; string responseTargetValuesString = EhfProvisioningService.GetResponseTargetValuesString(response); EdgeSyncDiag diagSession = base.DiagSession; string messageFormat = "Failed to {0}: FaultId={1}; FaultType={2}; FaultDetail={3}; Target={4}; TargetValues=({5}); DN=({6}); AD-Name={7}; EHF-Name={8}; AD-GUID=({9}); EHF-GUID=({10}); EHF-ID={11}"; object[] array = new object[12]; array[0] = operationName; array[1] = response.Fault.Id; array[2] = response.Status; array[3] = (response.Fault.Detail ?? "null"); array[4] = response.Target; array[5] = responseTargetValuesString; array[6] = company.DistinguishedName; array[7] = text; array[8] = (response.CompanyName ?? "null"); array[9] = company.GetCompanyGuid(); object[] array2 = array; int num = 10; Guid? companyGuid = response.CompanyGuid; array2[num] = ((companyGuid != null) ? companyGuid.GetValueOrDefault() : "null"); array[11] = response.CompanyId; company.AddSyncError(diagSession.LogAndTraceError(messageFormat, array)); }
public void CreateOrModifyEhfCompany(ExSearchResultEntry entry) { EhfCompanyItem ehfCompanyItem = EhfCompanyItem.CreateForActive(entry, base.DiagSession, base.Config.ResellerId); if (ehfCompanyItem.PreviouslySynced) { if (!ehfCompanyItem.EhfConfigSyncEnabled) { base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Medium, "Sync to EHF is disabled for <{0}>. Trying to disable and then delete the company. CompanyId:<{1}>; CompanyGuid:<{2}>;", new object[] { ehfCompanyItem.DistinguishedName, ehfCompanyItem.CompanyId, ehfCompanyItem.GetCompanyGuid() }); this.AddCompanyToDisableBatch(ehfCompanyItem); return; } this.AddCompanyToUpdateBatch(ehfCompanyItem); this.CacheEhfCompanyId(ehfCompanyItem); return; } else { if (!ehfCompanyItem.EhfConfigSyncEnabled) { base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Medium, "Sync to EHF is disabled for <{0}>. Trying to delete the company if it is already present in EHF. CompanyGuid:<{1}>;", new object[] { ehfCompanyItem.DistinguishedName, ehfCompanyItem.GetCompanyGuid() }); this.DeleteEhfCompanyWithoutId(ehfCompanyItem); return; } this.AddCompanyToCreateBatch(ehfCompanyItem); return; } }
private void DeleteEhfCompanyWithoutId(EhfCompanyItem companyItem) { Company company = null; bool companyExists = false; Guid companyGuid = companyItem.GetCompanyGuid(); base.InvokeProvisioningService("Get Company By Guid", delegate { companyExists = this.ProvisioningService.TryGetCompanyByGuid(companyGuid, out company); }, 1); if (!companyExists) { if (!companyItem.EventLogAndTryStoreSyncErrors(base.ADAdapter)) { throw new InvalidOperationException("EventLogAndTryStoreSyncErrors() returned false for a deleted object"); } base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "EHF company for AD object <{0}> (GUID=<{1}>) has never been created; ignoring the deleted entry", new object[] { companyItem.DistinguishedName, companyGuid }); return; } else { base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "EHF company for AD object <{0}> (GUID=<{1}>) has been retrieved from EHF by GUID", new object[] { companyItem.DistinguishedName, companyGuid }); companyItem.RecoverLostCompanyId(company); if (company.IsEnabled) { this.AddCompanyToDisableBatch(companyItem); return; } this.AddCompanyToDeleteBatch(companyItem); return; } }
public void AddDomainsForNewCompany(EhfCompanyItem company) { if (company.CompanyId == 0) { throw new ArgumentException("Cannot push domains for a company without CompanyId"); } if (company.IsDeleted) { throw new ArgumentException("Cannot push domains for a deleted company"); } ADObjectId parent = new ADObjectId(company.DistinguishedName).Parent; this.domainSync.CreateEhfDomainsForNewCompany(parent.DistinguishedName, company.CompanyId, company.GetCompanyGuid()); }
private void CacheEhfCompanyId(EhfCompanyItem companyItem) { this.CacheEhfCompanyIdentity(companyItem.GetConfigUnitDN(), companyItem.CompanyId, companyItem.GetCompanyGuid()); }
private void InvokeEhfDeleteCompanies() { if (this.companiesToDelete == null || this.companiesToDelete.Count == 0) { return; } CompanyResponseInfoSet responseSet = null; base.InvokeProvisioningService("Delete Company", delegate { responseSet = this.ProvisioningService.DeleteCompanies(this.companiesToDelete); }, this.companiesToDelete.Count); int num = 0; int permanentFailureCount = 0; for (int i = 0; i < responseSet.ResponseInfo.Length; i++) { CompanyResponseInfo companyResponseInfo = responseSet.ResponseInfo[i]; EhfCompanyItem ehfCompanyItem = this.companiesToDelete[i]; bool flag = false; if (companyResponseInfo.Status == ResponseStatus.Success) { base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Successfully deleted EHF company: DN=<{0}>; GUID=<{1}>; EHF-ID=<{2}>", new object[] { ehfCompanyItem.DistinguishedName, companyResponseInfo.CompanyGuid.Value, companyResponseInfo.CompanyId }); flag = true; } else if (companyResponseInfo.Fault.Id == FaultId.CompanyDoesNotExist) { base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Attempted to delete a company that does not exist; ignoring the company: DN=<{0}>; GUID=<{1}>; EHF-ID=<{2}>", new object[] { ehfCompanyItem.DistinguishedName, ehfCompanyItem.GetCompanyGuid(), ehfCompanyItem.CompanyId }); flag = true; } else { this.HandleFailedCompany("Delete Company", ehfCompanyItem, companyResponseInfo, ref num, ref permanentFailureCount); if (!ehfCompanyItem.ADEntry.IsDeleted && ehfCompanyItem.TryUpdateAdminSyncEnabledFlag(base.ADAdapter, true) == EhfADResultCode.Failure) { num++; } } if (!ehfCompanyItem.ADEntry.IsDeleted && flag) { if (ehfCompanyItem.TryClearEhfCompanyIdAndDisableAdminSync(base.ADAdapter) == EhfADResultCode.Failure) { num++; } else { this.RemoveCompanyItemFromCache(ehfCompanyItem); } } if (!ehfCompanyItem.EventLogAndTryStoreSyncErrors(base.ADAdapter)) { throw new InvalidOperationException("EventLogAndTryStoreSyncErrors() returned false for a deleted object"); } } base.HandlePerEntryFailureCounts("Delete Company", this.companiesToDelete.Count, num, permanentFailureCount, false); this.companiesToDelete.Clear(); }
private void InvokeEhfDisableCompanies() { if (this.companiesToDisable == null || this.companiesToDisable.Count == 0) { return; } CompanyResponseInfoSet responseSet = null; base.InvokeProvisioningService("Disable Company", delegate { responseSet = this.ProvisioningService.DisableCompanies(this.companiesToDisable); }, this.companiesToDisable.Count); List <EhfCompanyItem> list = new List <EhfCompanyItem>(base.Config.EhfSyncAppConfig.BatchSize); int num = 0; int permanentFailureCount = 0; for (int i = 0; i < responseSet.ResponseInfo.Length; i++) { CompanyResponseInfo companyResponseInfo = responseSet.ResponseInfo[i]; EhfCompanyItem ehfCompanyItem = this.companiesToDisable[i]; if (companyResponseInfo.Status == ResponseStatus.Success) { list.Add(ehfCompanyItem); base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Successfully disabled EHF company: DN=<{0}>; GUID=<{1}>; EHF-ID=<{2}>", new object[] { ehfCompanyItem.DistinguishedName, companyResponseInfo.CompanyGuid.Value, companyResponseInfo.CompanyId }); } else if (companyResponseInfo.Fault.Id == FaultId.CompanyDoesNotExist) { base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Attempted to disable a company that does not exist; ignoring the company: DN=<{0}>; GUID=<{1}>; EHF-ID=<{2}>", new object[] { ehfCompanyItem.DistinguishedName, ehfCompanyItem.GetCompanyGuid(), ehfCompanyItem.CompanyId }); if (!ehfCompanyItem.ADEntry.IsDeleted) { if (ehfCompanyItem.TryClearEhfCompanyIdAndDisableAdminSync(base.ADAdapter) == EhfADResultCode.Failure) { num++; } else { this.RemoveCompanyItemFromCache(ehfCompanyItem); } } } else { this.HandleFailedCompany("Disable Company", ehfCompanyItem, companyResponseInfo, ref num, ref permanentFailureCount); } if (!ehfCompanyItem.EventLogAndTryStoreSyncErrors(base.ADAdapter)) { throw new InvalidOperationException("EventLogAndTryStoreSyncErrors() returned false for a deleted object"); } } base.HandlePerEntryFailureCounts("Disable Company", this.companiesToDisable.Count, num, permanentFailureCount, false); this.companiesToDisable.Clear(); foreach (EhfCompanyItem ehfCompanyItem2 in list) { base.DiagSession.Tracer.TraceDebug <int, string>((long)base.DiagSession.GetHashCode(), "Adding disabled company ID=<{0}> DN=<{1}> to the delete batch", ehfCompanyItem2.CompanyId, ehfCompanyItem2.DistinguishedName); this.AddCompanyToDeleteBatch(ehfCompanyItem2); } }
private void InvokeEhfUpdateCompanies() { if (this.companiesToUpdate == null || this.companiesToUpdate.Count == 0) { return; } CompanyResponseInfoSet responseSet = null; base.InvokeProvisioningService("Update Company", delegate { responseSet = this.ProvisioningService.UpdateCompanies(this.companiesToUpdate); }, this.companiesToUpdate.Count); int num = 0; int permanentFailureCount = 0; List <EhfCompanyItem> list = new List <EhfCompanyItem>(); for (int i = 0; i < responseSet.ResponseInfo.Length; i++) { CompanyResponseInfo companyResponseInfo = responseSet.ResponseInfo[i]; EhfCompanyItem ehfCompanyItem = this.companiesToUpdate[i]; if (companyResponseInfo.Status == ResponseStatus.Success) { base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Successfully updated EHF company: DN=<{0}>; GUID=<{1}>; EHF-ID=<{2}>", new object[] { ehfCompanyItem.DistinguishedName, companyResponseInfo.CompanyGuid.Value, companyResponseInfo.CompanyId }); if (ehfCompanyItem.TryUpdateAdminSyncEnabledFlag(base.ADAdapter, false) != EhfADResultCode.Success) { num++; } } else if (companyResponseInfo.Fault.Id == FaultId.CompanyDoesNotExist) { base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Attempted to update a company that does not exists in EHF: DN=<{0}>; GUID=<{1}>; EHF-ID=<{2}>", new object[] { ehfCompanyItem.DistinguishedName, ehfCompanyItem.GetCompanyGuid(), companyResponseInfo.CompanyId }); list.Add(ehfCompanyItem); } else { this.HandleFailedCompany("Update Company", ehfCompanyItem, companyResponseInfo, ref num, ref permanentFailureCount); } if (!ehfCompanyItem.EventLogAndTryStoreSyncErrors(base.ADAdapter)) { num++; } } base.HandlePerEntryFailureCounts("Create Company", this.companiesToUpdate.Count, num, permanentFailureCount, false); foreach (EhfCompanyItem ehfCompanyItem2 in this.companiesToUpdate) { if (ehfCompanyItem2.IsForcedDomainSyncRequired()) { this.EhfConfigConnection.AddDomainsForNewCompany(ehfCompanyItem2); } } this.companiesToUpdate.Clear(); foreach (EhfCompanyItem ehfCompanyItem3 in list) { base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Trying to re-create the company <{0}>. CompanyId:<{1}>", new object[] { ehfCompanyItem3.DistinguishedName, ehfCompanyItem3.CompanyId }); ehfCompanyItem3.ADEntry.Attributes.Remove("msExchTenantPerimeterSettingsOrgID"); EhfCompanyItem company = EhfCompanyItem.CreateForActive(ehfCompanyItem3.ADEntry, base.DiagSession, base.Config.ResellerId); this.AddCompanyToCreateBatch(company); } }
private void InvokeEhfCreateCompanies() { if (this.companiesToCreate == null || this.companiesToCreate.Count == 0) { return; } CompanyResponseInfoSet responseSet = null; base.InvokeProvisioningService("Create Company", delegate { responseSet = this.ProvisioningService.CreateCompanies(this.companiesToCreate); }, this.companiesToCreate.Count); List <EhfCompanyItem> list = new List <EhfCompanyItem>(base.Config.EhfSyncAppConfig.BatchSize); int num = 0; int permanentFailureCount = 0; for (int i = 0; i < responseSet.ResponseInfo.Length; i++) { CompanyResponseInfo companyResponseInfo = responseSet.ResponseInfo[i]; EhfCompanyItem ehfCompanyItem = this.companiesToCreate[i]; bool flag = false; if (companyResponseInfo.Status == ResponseStatus.Success) { flag = true; base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Successfully created EHF company: DN=<{0}>; Name=<{1}>; GUID=<{2}>; EHF-ID=<{3}>", new object[] { ehfCompanyItem.DistinguishedName, ehfCompanyItem.Company.Name, companyResponseInfo.CompanyGuid.Value, companyResponseInfo.CompanyId }); } else if (companyResponseInfo.Fault.Id == FaultId.CompanyExistsUnderThisReseller) { Guid companyGuid = ehfCompanyItem.GetCompanyGuid(); if (companyResponseInfo.CompanyGuid.Value.Equals(companyGuid)) { flag = true; base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Attempted to create a company that already exists: DN=<{0}>; Name=<{1}>; GUID=<{2}>; EHF-ID=<{3}>", new object[] { ehfCompanyItem.DistinguishedName, ehfCompanyItem.Company.Name, companyGuid, companyResponseInfo.CompanyId }); } else if (!this.handledAllDeletedCompanies) { base.AddItemToLazyList <EhfCompanyItem>(ehfCompanyItem, ref this.companiesToCreateLast); base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Attempted to create a company with the name that already exists but a different GUID: DN=<{0}>; Name=<{1}>; AD-GUID=<{2}>; EHF-GUID=<{3}>; EHF-ID=<{4}>", new object[] { ehfCompanyItem.DistinguishedName, ehfCompanyItem.Company.Name, companyGuid, companyResponseInfo.CompanyGuid.Value, companyResponseInfo.CompanyId }); } else { this.HandleFailedCompany("Create Company", ehfCompanyItem, companyResponseInfo, ref num, ref permanentFailureCount); } } else { this.HandleFailedCompany("Create Company", ehfCompanyItem, companyResponseInfo, ref num, ref permanentFailureCount); } if (flag) { EhfADResultCode ehfADResultCode = ehfCompanyItem.TryStoreEhfCompanyId(companyResponseInfo.CompanyId, base.ADAdapter); switch (ehfADResultCode) { case EhfADResultCode.Failure: num++; break; case EhfADResultCode.NoSuchObject: base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Unable to store EHF company ID {0} in AD for Perimeter Settings object <{1}> because the AD object has been deleted; ignoring the object", new object[] { companyResponseInfo.CompanyId, ehfCompanyItem.DistinguishedName }); break; case EhfADResultCode.Success: list.Add(ehfCompanyItem); this.CacheEhfCompanyId(ehfCompanyItem); break; default: throw new InvalidOperationException("Unexpected EhfADResultCode " + ehfADResultCode); } } if (!ehfCompanyItem.EventLogAndTryStoreSyncErrors(base.ADAdapter)) { num++; } } base.HandlePerEntryFailureCounts("Create Company", this.companiesToCreate.Count, num, permanentFailureCount, true); this.companiesToCreate.Clear(); foreach (EhfCompanyItem ehfCompanyItem2 in list) { base.DiagSession.Tracer.TraceDebug <int, string>((long)base.DiagSession.GetHashCode(), "Adding newly-created company ID=<{0}> DN=<{1}> to the update batch", ehfCompanyItem2.CompanyId, ehfCompanyItem2.DistinguishedName); this.AddCompanyToUpdateBatch(ehfCompanyItem2); } }