protected override bool InternalTryValidate(ADRawEntry adObject, out RuleValidationException validationException) { validationException = null; OrganizationValidationRuleDefinition organizationValidationRuleDefinition = base.RuleDefinition as OrganizationValidationRuleDefinition; if (!Datacenter.IsMultiTenancyEnabled()) { ExTraceGlobals.AccessCheckTracer.TraceDebug <string, bool>((long)this.GetHashCode(), "OrganizationValidationRule.InternalTryValidate('{0}') return '{1}'. - not datacenter mode.", adObject.GetDistinguishedNameOrName(), true); return(true); } OrganizationId organizationId = (OrganizationId)adObject[ADObjectSchema.OrganizationId]; ADSessionSettings sessionSettings = OrganizationId.ForestWideOrgId.Equals(organizationId) ? ADSessionSettings.FromRootOrgScopeSet() : ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(organizationId); IConfigurationSession session = DirectorySessionFactory.Default.CreateTenantConfigurationSession(adObject.OriginatingServer, true, ConsistencyMode.IgnoreInvalid, sessionSettings, 377, "InternalTryValidate", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\ValidationRules\\ValidationRule.cs"); ExchangeConfigurationUnit exchangeConfigurationUnit = ProvisioningCache.Instance.TryAddAndGetOrganizationData <ExchangeConfigurationUnit>(CannedProvisioningCacheKeys.OrganizationCUContainer, organizationId, () => session.Read <ExchangeConfigurationUnit>(organizationId.ConfigurationUnit)); if (exchangeConfigurationUnit == null) { ExTraceGlobals.AccessCheckTracer.TraceDebug <string, bool>((long)this.GetHashCode(), "OrganizationValidationRule.InternalTryValidate('{0}') return '{1}'. - organization (ExchangeConfigurationUnit) object is not found.", adObject.GetDistinguishedNameOrName(), true); return(true); } foreach (ValidationRuleExpression validationRuleExpression in organizationValidationRuleDefinition.OverridingAllowExpressions) { bool flag = true; foreach (PropertyDefinition propertyDefinition in validationRuleExpression.QueryFilter.FilterProperties()) { if (!exchangeConfigurationUnit.propertyBag.Contains((ProviderPropertyDefinition)propertyDefinition)) { ExTraceGlobals.AccessCheckTracer.TraceDebug <string, string>((long)this.GetHashCode(), "ExpressionFilterValidationRule.InternalTryValidate({0}). Missing Property {1}.", exchangeConfigurationUnit.GetDistinguishedNameOrName(), propertyDefinition.Name); flag = false; break; } } if (flag && OpathFilterEvaluator.FilterMatches(validationRuleExpression.QueryFilter, exchangeConfigurationUnit)) { ExTraceGlobals.AccessCheckTracer.TraceDebug <string, bool, string>((long)this.GetHashCode(), "OrganizationValidationRule.InternalTryValidate('{0}') return '{1}'. - matched filter: {2}.", adObject.GetDistinguishedNameOrName(), true, validationRuleExpression.QueryString); return(true); } } foreach (ValidationRuleExpression validationRuleExpression2 in organizationValidationRuleDefinition.RestrictionExpressions) { bool flag2 = true; foreach (PropertyDefinition propertyDefinition2 in validationRuleExpression2.QueryFilter.FilterProperties()) { if (!exchangeConfigurationUnit.propertyBag.Contains((ProviderPropertyDefinition)propertyDefinition2)) { ExTraceGlobals.AccessCheckTracer.TraceDebug <string, string>((long)this.GetHashCode(), "ExpressionFilterValidationRule.InternalTryValidate({0}). Missing Property {1}.", exchangeConfigurationUnit.GetDistinguishedNameOrName(), propertyDefinition2.Name); flag2 = false; break; } } if (flag2 && OpathFilterEvaluator.FilterMatches(validationRuleExpression2.QueryFilter, exchangeConfigurationUnit)) { validationException = new RuleValidationException(base.GetValidationRuleErrorMessage(adObject, validationRuleExpression2.QueryString)); return(false); } } return(true); }
public bool TryValidate(ADRawEntry adObject, out RuleValidationException validationException) { if (adObject == null) { throw new ArgumentNullException("adObject"); } ExTraceGlobals.AccessCheckTracer.TraceDebug <string, string, string>((long)this.GetHashCode(), "Entering {0}.TryValidate({1}). Rule {2}.", base.GetType().Name, adObject.GetDistinguishedNameOrName(), this.ruleDefinition.Name); bool result = this.InternalTryValidate(adObject, out validationException); ExTraceGlobals.AccessCheckTracer.TraceDebug <string, string, string>((long)this.GetHashCode(), "{0}.TryValidate({1}). returns {2}", base.GetType().Name, adObject.GetDistinguishedNameOrName(), result.ToString()); return(result); }
protected override bool InternalTryValidate(ADRawEntry adObject, out RuleValidationException validationException) { validationException = null; if (!base.IsOverridingAllowCapabilityFound(adObject)) { foreach (CapabilityIdentifierEvaluator capabilityIdentifierEvaluator in base.RestrictedCapabilityEvaluators) { switch (capabilityIdentifierEvaluator.Evaluate(adObject)) { case CapabilityEvaluationResult.Yes: validationException = new RuleValidationException(base.GetValidationRuleErrorMessage(adObject, capabilityIdentifierEvaluator.Capability)); return(false); } } return(true); } return(true); }
public void TestMethod2() { var x = new RuleValidationException(typeof(IsNullRule <MyCustomer>), "hello", "customer"); var z = new BinaryFormatter(); var buffer = new MemoryStream(); z.Serialize(buffer, x); var result = new StringBuilder(); foreach (var character in buffer.ToArray()) { if (character > 32 && character < 128) { result.Append(Encoding.ASCII.GetString(new[] { character })); } } Assert.IsTrue(result.ToString().EndsWith("Sem.GenericHelpers.Contracts.Exceptions.RuleValidationExceptionClassNameMessageDataInnerExceptionHelpURLStackTraceStringRemoteStackTraceStringRemoteStackIndexExceptionMethodHResultSourceWatsonBucketsParamNameSystem.Collections.IDictionarySystem.Exception?Sem.GenericHelpers.Contracts.Exceptions.RuleValidationExceptionhelloWcustomer")); }
protected override bool InternalTryValidate(ADRawEntry adObject, out RuleValidationException validationException) { validationException = null; CapabilityIdentifierEvaluator capabilityIdentifierEvaluator = base.RestrictedCapabilityEvaluators.FirstOrDefault((CapabilityIdentifierEvaluator x) => CapabilityEvaluationResult.Yes == x.Evaluate(adObject)); ExTraceGlobals.AccessCheckTracer.TraceDebug <string, string>((long)this.GetHashCode(), "ExpressionFilterValidationRule.InternalTryValidate({0}). CurlpritCapability {1}.", adObject.GetDistinguishedNameOrName(), (capabilityIdentifierEvaluator != null) ? capabilityIdentifierEvaluator.Capability.ToString() : "<NULL>"); if (capabilityIdentifierEvaluator == null) { return(true); } foreach (ValidationRuleExpression validationRuleExpression in base.RuleDefinition.Expressions) { if (validationRuleExpression.ApplicableObjects != null && validationRuleExpression.ApplicableObjects.Count > 0) { Type right = validationRuleExpression.ApplicableObjects.FirstOrDefault((Type x) => x.IsAssignableFrom(adObject.GetType())); if (null == right) { ExTraceGlobals.AccessCheckTracer.TraceDebug <string, Type, string>((long)this.GetHashCode(), "ExpressionFilterValidationRule.InternalTryValidate({0}). Object type '{1}' is not on the list of applicable types for expression {2}.", adObject.GetDistinguishedNameOrName(), adObject.GetType(), validationRuleExpression.QueryString); continue; } } bool flag = true; foreach (PropertyDefinition propertyDefinition in validationRuleExpression.QueryFilter.FilterProperties()) { if (!adObject.propertyBag.Contains((ProviderPropertyDefinition)propertyDefinition)) { ExTraceGlobals.AccessCheckTracer.TraceDebug <string, string>((long)this.GetHashCode(), "ExpressionFilterValidationRule.InternalTryValidate({0}). Missing Property {1}.", adObject.GetDistinguishedNameOrName(), propertyDefinition.Name); flag = false; break; } } if (flag && !OpathFilterEvaluator.FilterMatches(validationRuleExpression.QueryFilter, adObject) && !base.IsOverridingAllowCapabilityFound(adObject)) { validationException = new RuleValidationException(base.GetValidationRuleErrorMessage(adObject, capabilityIdentifierEvaluator.Capability)); return(false); } } return(true); }
protected abstract bool InternalTryValidate(ADRawEntry adObject, out RuleValidationException validationException);