private bool NeedProvisionOrganizationRelationship(ICommonSession session, OrganizationRelationship existingOrgRel, IFederationInformation federationInfo, IEnumerable <SmtpDomain> domains, string relationshipName)
 {
     return(existingOrgRel == null || !TaskCommon.ContainsSame <SmtpDomain>(existingOrgRel.DomainNames, domains) || (this.RequiresFederationTrust() && (!string.Equals(TaskCommon.ToStringOrNull(existingOrgRel.TargetApplicationUri), federationInfo.TargetApplicationUri, StringComparison.InvariantCultureIgnoreCase) || !string.Equals(TaskCommon.ToStringOrNull(existingOrgRel.TargetAutodiscoverEpr), federationInfo.TargetAutodiscoverEpr, StringComparison.InvariantCultureIgnoreCase))));
 }
        private static OrganizationRelationship ProvisionOrganizationRelationship(ICommonSession session, OrganizationRelationship existingOrgRel, IFederationInformation federationInfo, IEnumerable <SmtpDomain> domains, string relationshipName)
        {
            if (existingOrgRel != null)
            {
                session.RemoveOrganizationRelationship(existingOrgRel.Identity.ToString());
            }
            string targetApplicationUri  = (federationInfo != null) ? federationInfo.TargetApplicationUri : null;
            string targetAutodiscoverEpr = (federationInfo != null) ? federationInfo.TargetAutodiscoverEpr : null;

            session.NewOrganizationRelationship(relationshipName, targetApplicationUri, targetAutodiscoverEpr, domains);
            existingOrgRel = TaskCommon.GetOrganizationRelationship(session, relationshipName, from d in domains
                                                                    select d.Domain);
            if (existingOrgRel == null)
            {
                throw new LocalizedException(HybridStrings.ErrorOrgRelProvisionFailed(domains.First <SmtpDomain>().ToString()));
            }
            return(existingOrgRel);
        }