/// <summary> /// Creates a new instance of the <see cref="SchematronValidationEventArgs"/>. /// </summary> /// <param name="schematron">The <see cref="SchematronDocument"/> that detected the event.</param> /// <param name="queryEngine">The <see cref="IQueryLanguage"/> that detected the event.</param> /// <param name="pattern">The active <see cref="Pattern"/>.</param> /// <param name="rule">The <see cref="Sepia.Schematron.Rule"/> that caused the event to be raised.</param> /// <param name="assertion">The <see cref="Sepia.Schematron.Assertion"/> that caused the event to be raised.</param> /// <param name="context">An <see cref="object"/> that provides the context for the <paramref name="rule"/> and <paramref name="assertion"/>.</param> /// <param name="instance">An <see cref="XPathNavigator"/> to the document node that cause the event to be raised.</param> public SchematronValidationEventArgs(SchematronDocument schematron, IQueryLanguage queryEngine, Pattern pattern, Rule rule, Assertion assertion, object context, XPathNavigator instance) { this.schematron = schematron; this.queryEngine = queryEngine; this.pattern = pattern; this.rule = rule; this.assertion = assertion; this.instance = instance.Clone(); if (assertion == null) { message = "A schematron validation event occured."; } else { message = assertion.Message.ToString(instance, context); } List<string> diagnostics = new List<string>(); if (assertion != null && !string.IsNullOrEmpty(assertion.Diagnostics)) { foreach (string id in assertion.Diagnostics.Split(' ')) { Diagnostic diagnostic = schematron.Diagnostics[id]; diagnostics.Add(diagnostic.Message.ToString(instance, context)); } } this.diagnostics = diagnostics.ToArray(); }
/// <summary> /// DbQueryProvider constrcutor that allows for external control of policy /// to allow for new types of databases. /// </summary> public DbQueryProvider(IDataProvider provider, QueryPolicy paramPolicy, TextWriter log) { _provider = provider; connection = _provider.CreateConnection(); policy = paramPolicy; mapping = policy.Mapping; language = mapping.Language; //log = log; }
public DbQueryProvider(IDataProvider provider) { _provider = provider; IQueryLanguage lang = provider.QueryLanguage; policy = new QueryPolicy(new ImplicitMapping(lang)); mapping = policy.Mapping; language = mapping.Language; }
public static Expression Rewrite(IQueryLanguage language, Expression expression) { return(new ClientJoinedProjectionRewriter(language).Visit(expression)); }
private ClientJoinedProjectionRewriter(IQueryLanguage language) { this.language = language; }
public static Expression Rewrite(IQueryLanguage language, Expression expression) { return(new SingletonProjectionRewriter(language).Visit(expression)); }
protected QueryMapping(IQueryLanguage language) { this.language = language; }
public ImplicitMapping(IQueryLanguage language) : base(language) { }
private SingletonProjectionRewriter(IQueryLanguage language) { this.language = language; }
public static Expression Rewrite(IQueryLanguage language, Expression expression) { return new ClientJoinedProjectionRewriter(language).Visit(expression); }
/// <summary> /// Validates an XML document against the <see cref="SchemaDocument"/>. /// </summary> /// <param name="instance"> /// The <see cref="IXPathNavigable">XML document</see> to validate. /// </param> /// <param name="handler">A <see cref="SchematronValidationEventHandler"/> to receive errors.</param> /// <remarks> /// <b>Validate</b> validates the <paramref name="instance"/> against the <see cref="SchemaDocument"/>. /// <para> /// If an error is detected and /// the <see cref="AssertionFailed"/> event is <b>null</b>, then a <see cref="SchematronValidationException"/>is <c>thrown</c>. /// Otherwise, the <see cref="AssertionFailed"/> event is raised. /// </para> /// </remarks> public void Validate(IXPathNavigable instance, SchematronValidationEventHandler handler = null) { if (instance == null) throw new ArgumentNullException("instance"); if (schematron == null) throw new InvalidOperationException("The schematron document is not specified."); if (SchemaDocument.Patterns == null || SchemaDocument.Patterns.Count == 0) throw new InvalidOperationException("The schematron document has no patterns."); if (handler != null) AssertionFailed += handler; instanceNavigator = instance.CreateNavigator(); if (log.IsDebugEnabled) log.Debug(string.Format("Validating '{0}'", instanceNavigator.BaseURI ?? "some XML document")); // Bind to the query language. if (!Schematron.Default.QueryLanguages.Providers.ContainsKey(schematron.QueryLanguage)) throw new InvalidOperationException(String.Format("'{0}' is an unknown query language.", schematron.QueryLanguage)); queryEngine = Schematron.Default.QueryLanguages.Providers[schematron.QueryLanguage]; queryContext = queryEngine.CreateMatchContext(schematron, instance); // Apply the schema parameters. if (schematron.HasParameters) { foreach (string name in schematron.Parameters) { queryEngine.Let(queryContext, name, schematron.Parameters[name]); } } // Get the patterns to run. PatternCollection activePatterns; string phaseName = ValidationPhase; if (phaseName == Phase.Default) phaseName = schematron.DefaultPhase; if (phaseName == Phase.All) activePatterns = schematron.Patterns; else { Phase phase = schematron.Phases[phaseName]; activePatterns = new PatternCollection(); foreach (ActivePattern activePattern in phase.ActivePatterns) { activePatterns.Add(schematron.Patterns[activePattern.Pattern]); } // Apply the phase parameters. if (phase.HasParameters) { queryEngine.PushScope(queryContext); foreach (string name in phase.Parameters) { queryEngine.Let(queryContext, name, phase.Parameters[name]); } } } // Apply the parameters specified for this validation. if (HasParameters) { queryEngine.PushScope(queryContext); foreach (string name in Parameters) { queryEngine.Let(queryContext, name, Parameters[name]); } } if (log.IsDebugEnabled) log.Debug(String.Format("Schema = '{0}', phase = '{1}'", schematron.Title.ToString(), phaseName)); if (Start != null) Start(this, new SchematronValidationEventArgs(schematron, queryEngine, null, null, null, queryContext, instanceNavigator)); try { foreach (Pattern pattern in activePatterns) { if (log.IsDebugEnabled) log.Debug(string.Format("Running pattern '{0}'", pattern.Title.ToString())); if (ActivePattern != null) ActivePattern(this, new SchematronValidationEventArgs(schematron, queryEngine, pattern, null, null, queryContext, instanceNavigator)); // Apply the parameters queryEngine.PushScope(queryContext); if (pattern.HasParameters) { foreach (string name in pattern.Parameters) { queryEngine.Let(queryContext, name, pattern.Parameters[name]); } } // Run the pattern. bool q = RunPattern(pattern); queryEngine.PopScope(queryContext); if (log.IsDebugEnabled) log.Debug(String.Format("Pattern '{0}' {1}", pattern.Title.ToString(), q ? "succeeds" : "fails")); } } finally { if (End != null) End(this, new SchematronValidationEventArgs(schematron, queryEngine, null, null, null, queryContext, instanceNavigator)); } }
public static Expression Rewrite(IQueryLanguage language, Expression expression) { return new SingletonProjectionRewriter(language).Visit(expression); }