private MultiValuedProperty <BindingMetadata> ValidateExchangeBindings(IEnumerable <string> bindings, int maxCount)
        {
            base.WriteVerbose(Strings.VerboseValidatingExchangeBinding);
            MultiValuedProperty <BindingMetadata> multiValuedProperty = new MultiValuedProperty <BindingMetadata>();

            if (bindings.Any <string>())
            {
                List <string> list = (from binding in bindings
                                      where SourceValidator.IsWideScope(binding)
                                      select binding).ToList <string>();
                if (list.Any <string>())
                {
                    throw new ExCannotContainWideScopeBindingsException(string.Join(", ", list));
                }
                this.ExchangeBinding = NewCompliancePolicyBase.ValidateWideScopeBinding(this.ExchangeBinding, "All", "All", new BindingCannotCombineAllWithIndividualBindingsException("Exchange"));
                ExchangeValidator exchangeValidator = this.CreateExchangeValidator(true, "Validating ExchangeBinding");
                multiValuedProperty = exchangeValidator.ValidateRecipients(this.ExchangeBinding);
                if (this.ExchangeBinding.Count <string>() > 1000)
                {
                    throw new BindingCountExceedsLimitException("Exchange", 1000);
                }
            }
            NewCompliancePolicyBase.SetBindingsSubWorkload(multiValuedProperty, Workload.Exchange);
            return(multiValuedProperty);
        }
        private MultiValuedProperty <BindingMetadata> ValidateSharepointSitesForAdd(MultiValuedProperty <BindingMetadata> psObjectBindings, MultiValuedProperty <BindingMetadata> internalRemoveBindings, MultiValuedProperty <string> addBindingParameter, Workload subWorkload)
        {
            base.WriteVerbose(Strings.VerboseValidatingAddSharepointBinding);
            int existingSitesCount = SetCompliancePolicyBase.CalculateBindingCountAfterRemove(psObjectBindings, internalRemoveBindings);
            SharepointValidator sharepointValidator = this.CreateSharepointValidator("Validating AddSharepointBinding", existingSitesCount);
            MultiValuedProperty <BindingMetadata> multiValuedProperty = sharepointValidator.ValidateLocations(addBindingParameter);

            NewCompliancePolicyBase.SetBindingsSubWorkload(multiValuedProperty, subWorkload);
            return(multiValuedProperty);
        }
        private MultiValuedProperty <BindingMetadata> ValidateSharepointBindings(IEnumerable <string> bindings, Workload subWorkload, string workloadName, int maxCount)
        {
            base.WriteVerbose(Strings.VerboseValidatingSharepointBinding(workloadName));
            MultiValuedProperty <BindingMetadata> multiValuedProperty = new MultiValuedProperty <BindingMetadata>();

            if (bindings.Any <string>())
            {
                bindings = NewCompliancePolicyBase.ValidateWideScopeBinding(bindings, "All", "All", new BindingCannotCombineAllWithIndividualBindingsException(workloadName));
                SharepointValidator sharepointValidator = this.CreateSharepointValidator(string.Format("Validating {0} Binding", workloadName));
                multiValuedProperty = sharepointValidator.ValidateLocations(bindings);
                if (multiValuedProperty.Count <BindingMetadata>() > maxCount)
                {
                    throw new BindingCountExceedsLimitException(workloadName, maxCount);
                }
                NewCompliancePolicyBase.SetBindingsSubWorkload(multiValuedProperty, subWorkload);
            }
            return(multiValuedProperty);
        }
 internal static void ValidateAddedSharepointBinding(IEnumerable <string> addedBindings, IEnumerable <string> removedBindings, MultiValuedProperty <BindingMetadata> psObjectBindings, string subWorkloadName)
 {
     if (addedBindings.Any <string>())
     {
         addedBindings = NewCompliancePolicyBase.ValidateWideScopeBinding(addedBindings, "All", "All", new BindingCannotCombineAllWithIndividualBindingsException(subWorkloadName));
         if (NewCompliancePolicyBase.IsBindingEnabled(addedBindings, "All"))
         {
             psObjectBindings.Clear();
             return;
         }
         List <string> bindings = (from b in psObjectBindings
                                   select b.ImmutableIdentity).ToList <string>();
         if (NewCompliancePolicyBase.IsBindingEnabled(bindings, "All") && !NewCompliancePolicyBase.IsBindingEnabled(removedBindings, "All"))
         {
             throw new BindingCannotCombineAllWithIndividualBindingsException(subWorkloadName);
         }
     }
 }
 internal static MultiValuedProperty <string> ValidateWideScopeBinding(IEnumerable <string> bindings, string wideScopeBindingName, string wideScopeBindingValue, Exception validationException)
 {
     if (NewCompliancePolicyBase.IsBindingEnabled(bindings, wideScopeBindingValue) && bindings.Count <string>() > 1)
     {
         throw validationException;
     }
     if (string.Compare(wideScopeBindingName, wideScopeBindingValue, StringComparison.InvariantCultureIgnoreCase) != 0)
     {
         List <string> list = new List <string>(bindings.Count <string>());
         list.AddRange(bindings.Select(delegate(string binding)
         {
             if (string.Compare(binding, wideScopeBindingName, StringComparison.InvariantCultureIgnoreCase) != 0)
             {
                 return(binding);
             }
             return(wideScopeBindingValue);
         }));
         return(new MultiValuedProperty <string>(list));
     }
     return(new MultiValuedProperty <string>(bindings));
 }
 private void ValidateBindingParameterBeforeMerge()
 {
     if (this.AddExchangeBinding.Intersect(this.RemoveExchangeBinding, StringComparer.InvariantCultureIgnoreCase).Any <string>())
     {
         throw new AddRemoveExBindingsOverlappedException(string.Join(",", this.AddExchangeBinding.Intersect(this.RemoveExchangeBinding, StringComparer.InvariantCultureIgnoreCase)));
     }
     if (this.AddSharePointBinding.Intersect(this.RemoveSharePointBinding, StringComparer.InvariantCultureIgnoreCase).Any <string>())
     {
         throw new AddRemoveSpBindingsOverlappedException(string.Join(",", this.AddSharePointBinding.Intersect(this.RemoveSharePointBinding, StringComparer.InvariantCultureIgnoreCase)));
     }
     if (this.AddOneDriveBinding.Intersect(this.RemoveOneDriveBinding, StringComparer.InvariantCultureIgnoreCase).Any <string>())
     {
         throw new AddRemoveSpBindingsOverlappedException(string.Join(",", this.AddOneDriveBinding.Intersect(this.RemoveOneDriveBinding, StringComparer.InvariantCultureIgnoreCase)));
     }
     this.InternalAddExchangeBindings      = new MultiValuedProperty <BindingMetadata>();
     this.InternalRemoveExchangeBindings   = new MultiValuedProperty <BindingMetadata>();
     this.InternalAddSharePointBindings    = new MultiValuedProperty <BindingMetadata>();
     this.InternalRemoveSharePointBindings = new MultiValuedProperty <BindingMetadata>();
     this.InternalAddOneDriveBindings      = new MultiValuedProperty <BindingMetadata>();
     this.InternalRemoveOneDriveBindings   = new MultiValuedProperty <BindingMetadata>();
     if (this.RemoveExchangeBinding.Any <string>())
     {
         this.ValidateRecipientsForRemove();
     }
     if (this.AddExchangeBinding.Any <string>())
     {
         List <string> list = (from b in this.PsPolicyPresentationObject.ExchangeBinding
                               select b.ImmutableIdentity).ToList <string>();
         list.AddRange(this.AddExchangeBinding);
         this.AddExchangeBinding = NewCompliancePolicyBase.ValidateWideScopeBinding(this.AddExchangeBinding, "All", "All", new BindingCannotCombineAllWithIndividualBindingsException("Exchange"));
         this.ExpandGroupsAndValidateRecipientsForAdd();
     }
     this.InternalRemoveSharePointBindings = this.ValidateSharepointSitesForRemove(this.RemoveSharePointBinding);
     SetCompliancePolicyBase.ValidateAddedSharepointBinding(this.AddSharePointBinding, this.RemoveSharePointBinding, this.PsPolicyPresentationObject.SharePointBinding, "Sharepoint");
     this.InternalAddSharePointBindings  = this.ValidateSharepointSitesForAdd(this.PsPolicyPresentationObject.SharePointBinding, this.InternalRemoveSharePointBindings, this.AddSharePointBinding, Workload.SharePoint);
     this.InternalRemoveOneDriveBindings = this.ValidateSharepointSitesForRemove(this.RemoveOneDriveBinding);
     SetCompliancePolicyBase.ValidateAddedSharepointBinding(this.AddOneDriveBinding, this.RemoveOneDriveBinding, this.PsPolicyPresentationObject.OneDriveBinding, "OneDriveBusiness");
     this.InternalAddOneDriveBindings = this.ValidateSharepointSitesForAdd(this.PsPolicyPresentationObject.OneDriveBinding, this.InternalRemoveOneDriveBindings, this.AddOneDriveBinding, Workload.OneDriveForBusiness);
 }