public override void HandleDeletedDomain(ExSearchResultEntry entry)
        {
            base.HandleDeletedDomain(entry);
            EhfDomainItem domain = EhfDomainItemVersion2.CreateForOutboundOnlyTombstone(entry, base.DiagSession);

            base.AddDomainToDisableBatch(domain);
        }
 private void AddDomainToCreateWithGuidBatch(EhfDomainItemVersion2 domain)
 {
     base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Medium, "Adding domain <{0}> to CreateWithGuid batch. Name=<{1}>; CreatedWithGuid=<{2}>", new object[]
     {
         domain.DistinguishedName,
         domain.Name,
         domain.DomainCreatedWithGuid
     });
     domain.SetAsGuidDomain();
     base.AddDomainToCreateBatch(domain);
 }
 private void AddDomainToUpdateBatch(EhfDomainItemVersion2 domain)
 {
     base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Medium, "Adding domain <{0}> to Update batch", new object[]
     {
         domain.DistinguishedName
     });
     if (base.AddItemToBatch <EhfDomainItemVersion2>(domain, ref this.domainsToUpdate))
     {
         this.InvokeEhfUpdateDomains(false);
     }
 }
        protected override void HandleCreateDomainResponse(DomainResponseInfoSet responseSet, List <EhfDomainItem> domainsTriedToCreate)
        {
            int num = 0;
            int permanentFailureCount          = 0;
            List <EhfDomainItemVersion2> list  = new List <EhfDomainItemVersion2>();
            List <EhfDomainItemVersion2> list2 = new List <EhfDomainItemVersion2>();

            for (int i = 0; i < responseSet.ResponseInfo.Length; i++)
            {
                DomainResponseInfo    domainResponseInfo   = responseSet.ResponseInfo[i];
                EhfDomainItemVersion2 ehfDomainItemVersion = domainsTriedToCreate[i] as EhfDomainItemVersion2;
                if (ehfDomainItemVersion == null)
                {
                    throw new InvalidOperationException("Version 2 of EhfConnector should be using version 2 of EhfDomainItem");
                }
                if (domainResponseInfo.Status == ResponseStatus.Success)
                {
                    base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Successfully created EHF domain: DN=<{0}>; Name=<{1}>; GUID=<{2}>; EHF-Company-ID=<{3}>", new object[]
                    {
                        ehfDomainItemVersion.DistinguishedName,
                        ehfDomainItemVersion.Domain.Name,
                        domainResponseInfo.DomainGuid.Value,
                        ehfDomainItemVersion.Domain.CompanyId
                    });
                    if (ehfDomainItemVersion.TryClearForceDomainSyncFlagFromPerimeterConfig(base.ADAdapter) == EhfADResultCode.Failure)
                    {
                        num++;
                    }
                    if (!this.UpdateDuplicateDetectedFlag(ehfDomainItemVersion))
                    {
                        num++;
                    }
                }
                else if (domainResponseInfo.Fault.Id == FaultId.DomainExistUnderThisCompany || domainResponseInfo.Fault.Id == FaultId.DomainExistOutsideThisCompany)
                {
                    Guid domainGuid = ehfDomainItemVersion.GetDomainGuid();
                    if (domainResponseInfo.Fault.Id == FaultId.DomainExistUnderThisCompany && domainResponseInfo.DomainGuid.Value.Equals(domainGuid))
                    {
                        if (ehfDomainItemVersion.TriedToUpdateDomain && !ehfDomainItemVersion.DomainCreatedWithGuid)
                        {
                            base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Attempted to create a domain that already exists. Treating this as error since update is already called: DN=<{0}>; Name=<{1}>; GUID=<{2}>; EHF-Company-ID=<{3}>", new object[]
                            {
                                ehfDomainItemVersion.DistinguishedName,
                                ehfDomainItemVersion.Domain.Name,
                                domainGuid,
                                ehfDomainItemVersion.Domain.CompanyId
                            });
                            base.HandleFailedDomain("Create Domain", ehfDomainItemVersion, domainResponseInfo, ref num, ref permanentFailureCount);
                        }
                        else
                        {
                            base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Attempted to create a domain that already exists. Trying to update the domain. DN=<{0}>; Name=<{1}>; GUID=<{2}>; EHF-Company-ID=<{3}>", new object[]
                            {
                                ehfDomainItemVersion.DistinguishedName,
                                ehfDomainItemVersion.Domain.Name,
                                domainGuid,
                                ehfDomainItemVersion.Domain.CompanyId
                            });
                            list.Add(ehfDomainItemVersion);
                        }
                    }
                    else if (domainResponseInfo.Fault.Id == FaultId.DomainExistUnderThisCompany && domainResponseInfo.SourceId == ProvisioningSource.Other && !ehfDomainItemVersion.DomainCreatedWithGuid)
                    {
                        base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "A domain collision is detected for domain: DN=<{0}>; Name=<{1}>; AD-GUID=<{2}>; EHF-Company-ID=<{3}>. Trying to create the domain as OutboundOnly domain.", new object[]
                        {
                            ehfDomainItemVersion.DistinguishedName,
                            ehfDomainItemVersion.Name,
                            domainGuid,
                            ehfDomainItemVersion.Domain.CompanyId
                        });
                        list2.Add(ehfDomainItemVersion);
                    }
                    else if (!base.HandledAllDeletedDomains)
                    {
                        base.AddDomainToCreateLastList(ehfDomainItemVersion);
                        EdgeSyncDiag         diagSession = base.DiagSession;
                        EdgeSyncLoggingLevel level       = EdgeSyncLoggingLevel.Low;
                        string   messageFormat           = "Attempted to create a domain with the name that already exists but a different GUID: DN=<{0}>; Name=<{1}>; AD-GUID=<{2}>; EHF-GUID=<{3}>; EHF-Company-ID=<{4}>";
                        object[] array = new object[5];
                        array[0] = ehfDomainItemVersion.DistinguishedName;
                        array[1] = ehfDomainItemVersion.Name;
                        array[2] = domainGuid;
                        object[] array2      = array;
                        int      num2        = 3;
                        Guid?    domainGuid2 = domainResponseInfo.DomainGuid;
                        array2[num2] = ((domainGuid2 != null) ? domainGuid2.GetValueOrDefault() : "null");
                        array[4]     = ehfDomainItemVersion.Domain.CompanyId;
                        diagSession.LogAndTraceInfo(level, messageFormat, array);
                    }
                    else if (!ehfDomainItemVersion.DomainCreatedWithGuid && domainResponseInfo.Fault.Id == FaultId.DomainExistOutsideThisCompany)
                    {
                        base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "A domain collision is detected for domain: DN=<{0}>; Name=<{1}>; AD-GUID=<{2}>; EHF-Company-ID=<{3}>. Trying to create the domain as OutboundOnly domain.", new object[]
                        {
                            ehfDomainItemVersion.DistinguishedName,
                            ehfDomainItemVersion.Name,
                            domainGuid,
                            ehfDomainItemVersion.Domain.CompanyId
                        });
                        list2.Add(ehfDomainItemVersion);
                    }
                    else
                    {
                        base.HandleFailedDomain("Create Domain", ehfDomainItemVersion, domainResponseInfo, ref num, ref permanentFailureCount);
                    }
                }
                else if (domainResponseInfo.Fault.Id == FaultId.DomainGuidIsNotUnique && !ehfDomainItemVersion.TriedToUpdateDomain)
                {
                    list.Add(ehfDomainItemVersion);
                }
                else
                {
                    base.HandleFailedDomain("Create Domain", ehfDomainItemVersion, domainResponseInfo, ref num, ref permanentFailureCount);
                }
                if (!ehfDomainItemVersion.EventLogAndTryStoreSyncErrors(base.ADAdapter))
                {
                    num++;
                }
            }
            base.HandlePerEntryFailureCounts("Create Domain", domainsTriedToCreate.Count, num, permanentFailureCount, false);
            foreach (EhfDomainItemVersion2 domain in list)
            {
                this.AddDomainToUpdateBatch(domain);
            }
            foreach (EhfDomainItemVersion2 domain2 in list2)
            {
                this.AddDomainToCreateWithGuidBatch(domain2);
            }
        }
 protected override EhfDomainItem CreateDomainItemForNewCompany(ExSearchResultEntry entry, int ehfCompanyId)
 {
     return(EhfDomainItemVersion2.CreateEhfDomainItem(entry, ehfCompanyId, this.GetMailFlowPartnerConnectorIds(entry), base.DiagSession));
 }
        private bool UpdateDuplicateDetectedFlag(EhfDomainItemVersion2 domain)
        {
            bool isDuplicate = domain.DomainCreatedWithGuid && !domain.OutboundOnly;

            return(domain.TrySetDuplicateDomain(base.ADAdapter, isDuplicate) != EhfADResultCode.Failure);
        }
 private EhfDomainItemVersion2 CreateEhfDomainItem(ExSearchResultEntry entry)
 {
     return(EhfDomainItemVersion2.CreateEhfDomainItem(entry, this.GetMailFlowPartnerConnectorIds(entry), base.EhfConnection.DiagSession));
 }
        private void InvokeEhfUpdateDomains(bool finalUpdate)
        {
            if (this.domainsToUpdate == null || this.domainsToUpdate.Count == 0)
            {
                return;
            }
            DomainResponseInfoSet responseSet = null;

            base.InvokeProvisioningService("Update Domain", delegate
            {
                responseSet = this.ProvisioningService.UpdateDomainSettingsByGuids(this.domainsToUpdate);
            }, this.domainsToUpdate.Count);
            int num = 0;
            int permanentFailureCount         = 0;
            List <EhfDomainItemVersion2> list = new List <EhfDomainItemVersion2>();

            for (int i = 0; i < responseSet.ResponseInfo.Length; i++)
            {
                DomainResponseInfo    domainResponseInfo   = responseSet.ResponseInfo[i];
                EhfDomainItemVersion2 ehfDomainItemVersion = this.domainsToUpdate[i];
                ehfDomainItemVersion.TriedToUpdateDomain = true;
                if (domainResponseInfo.Status == ResponseStatus.Success)
                {
                    base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Successfully updated EHF Domain: DN=<{0}>; GUID=<{1}>; Name =<{2}>; OutboundOnly <{3}>", new object[]
                    {
                        ehfDomainItemVersion.DistinguishedName,
                        domainResponseInfo.DomainGuid.Value,
                        ehfDomainItemVersion.Name,
                        ehfDomainItemVersion.OutboundOnly
                    });
                    if (ehfDomainItemVersion.TryClearForceDomainSyncFlagFromPerimeterConfig(base.ADAdapter) == EhfADResultCode.Failure)
                    {
                        num++;
                    }
                    if (!this.UpdateDuplicateDetectedFlag(ehfDomainItemVersion))
                    {
                        num++;
                    }
                }
                else if ((domainResponseInfo.Fault.Id == FaultId.DomainDoesNotExist || domainResponseInfo.Fault.Id == FaultId.DomainExistOutsideThisCompany) && !finalUpdate)
                {
                    base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Update Domain operation failed with FaultId <{0}> for domain: DN=<{1}>; Name=<{2}>", new object[]
                    {
                        domainResponseInfo.Fault.Id,
                        ehfDomainItemVersion.DistinguishedName,
                        ehfDomainItemVersion.Name
                    });
                    list.Add(ehfDomainItemVersion);
                }
                else
                {
                    base.HandleFailedDomain("Update Domain", ehfDomainItemVersion, domainResponseInfo, ref num, ref permanentFailureCount);
                }
                if (!ehfDomainItemVersion.EventLogAndTryStoreSyncErrors(base.ADAdapter))
                {
                    num++;
                }
            }
            base.HandlePerEntryFailureCounts("Update Domain", this.domainsToUpdate.Count, num, permanentFailureCount, false);
            this.domainsToUpdate.Clear();
            foreach (EhfDomainItemVersion2 ehfDomainItemVersion2 in list)
            {
                if (ehfDomainItemVersion2.DomainCreatedWithGuid)
                {
                    base.AddDomainToCreateBatch(ehfDomainItemVersion2);
                }
                else
                {
                    base.AddDomainToCreateLastList(ehfDomainItemVersion2);
                }
            }
        }