private void RaiseValidated(ISyntaxValidationResults results) { DocumentValidatedHandler <T> d = this.Validated; if (d != null) { d(this, new DocumentValidatedEventArgs <T>(this, results)); } }
/// <summary> /// Validates the document /// </summary> /// <returns>Syntax Validation Results if available, null otherwise</returns> public ISyntaxValidationResults Validate() { if (this._validator != null) { ISyntaxValidationResults results = this._validator.Validate(this.Text); this._lastError = results.Error; this.RaiseValidated(results); return(results); } else { return(null); } }
private void HandleTextChanged(Object sender, DocumentChangedEventArgs <TControl> args) { //Update Syntax Validation if appropriate if (args.Document.SyntaxValidator != null && this._options.IsValidateAsYouTypeEnabled) { args.Document.TextEditor.ClearErrorHighlights(); ISyntaxValidationResults results = args.Document.Validate(); if (results != null && this._options.IsHighlightErrorsEnabled) { if (results.Error != null && !results.IsValid) { args.Document.TextEditor.AddErrorHighlight(results.Error); } } } }
/// <summary> /// Invokes Syntax Validation /// </summary> public void DoValidation() { if (this._currValidator == null) { this._lastError = null; this._validatorStatus.Content = "No Validator is available for currently selected Syntax"; } else { ISyntaxValidationResults results = this._currValidator.Validate(this._editor.Text); this._validatorStatus.Content = results.Message; bool shouldReset = (results.Error == null && this._lastError != null); this._lastError = results.Error; ToolTip tip = new ToolTip(); TextBlock block = new TextBlock(); block.TextWrapping = TextWrapping.Wrap; block.Width = 800; block.Text = results.Message; tip.Content = block; this._validatorStatus.ToolTip = tip; //Turn Highlighting Errors on then off to ensure that the editor redraws if (this._highlightErrors && shouldReset) { if (this._editor.TextArea.TextView.ElementGenerators.Any(g => g is ValidationErrorElementGenerator)) { for (int i = 0; i < this._editor.TextArea.TextView.ElementGenerators.Count; i++) { if (this._editor.TextArea.TextView.ElementGenerators[i] is ValidationErrorElementGenerator) { this._editor.TextArea.TextView.ElementGenerators.RemoveAt(i); i--; } } } this._editor.TextArea.TextView.ElementGenerators.Add(new ValidationErrorElementGenerator(this)); } } }
/// <summary> /// Applies reasoning on the Input Graph materialising the generated Triples in the Output Graph. /// </summary> /// <param name="input">Input Graph.</param> /// <param name="output">Output Graph.</param> public void Apply(IGraph input, IGraph output) { TripleStore store = new TripleStore(); store.Add(input); if (!ReferenceEquals(input, output)) { store.Add(output, true); } // Apply each rule in turn foreach (String[] rule in _rules) { // Build the final version of the rule text for the given input and output StringBuilder ruleText = new StringBuilder(); // If there's a Base URI on the Output Graph need a WITH clause if (output.BaseUri != null) { ruleText.AppendLine("WITH <" + _formatter.FormatUri(output.BaseUri) + ">"); } ruleText.AppendLine(rule[0]); // If there's a Base URI on the Input Graph need a USING clause if (input.BaseUri != null) { ruleText.AppendLine("USING <" + _formatter.FormatUri(input.BaseUri) + ">"); } ruleText.AppendLine(rule[1]); ISyntaxValidationResults results = _validator.Validate(ruleText.ToString()); if (results.IsValid) { store.ExecuteUpdate((SparqlUpdateCommandSet)results.Result); } } }
public DocumentValidatedEventArgs(Document <T> doc, ISyntaxValidationResults results) : base(doc) { this._results = results; }
/// <summary> /// Tries to create a Rule. /// </summary> /// <param name="t">Triple.</param> private void TryCreateRule(Triple t) { String[] rule = new String[2]; Dictionary <INode, INode> variableMap = new Dictionary <INode, INode>(); int nextVarID = 1; VariableContext vars = null; if (t.Context != null && t.Context is VariableContext) { vars = (VariableContext)t.Context; } StringBuilder output = new StringBuilder(); // Generate the INSERT part of the Command output.AppendLine("INSERT"); output.AppendLine("{"); foreach (Triple x in ((IGraphLiteralNode)t.Object).SubGraph.Triples) { if (vars == null) { output.AppendLine(_formatter.Format(x)); } else { if (vars.IsVariable(x.Subject)) { if (!variableMap.ContainsKey(x.Subject)) { variableMap.Add(x.Subject, new VariableNode(null, "autoRuleVar" + nextVarID)); nextVarID++; } output.Append(_formatter.Format(variableMap[x.Subject])); } else { output.Append(_formatter.Format(x.Subject)); } output.Append(' '); if (vars.IsVariable(x.Predicate)) { if (!variableMap.ContainsKey(x.Predicate)) { variableMap.Add(x.Predicate, new VariableNode(null, "autoRuleVar" + nextVarID)); nextVarID++; } output.Append(_formatter.Format(variableMap[x.Predicate])); } else { output.Append(_formatter.Format(x.Predicate)); } output.Append(' '); if (vars.IsVariable(x.Object)) { if (!variableMap.ContainsKey(x.Object)) { variableMap.Add(x.Object, new VariableNode(null, "autoRuleVar" + nextVarID)); nextVarID++; } output.Append(_formatter.Format(variableMap[x.Object])); } else { output.Append(_formatter.Format(x.Object)); } output.AppendLine(" ."); } } output.AppendLine("}"); rule[0] = output.ToString(); // Generate the WHERE part of the Command output = new StringBuilder(); output.AppendLine("WHERE"); output.AppendLine("{"); foreach (Triple x in ((IGraphLiteralNode)t.Subject).SubGraph.Triples) { if (vars == null) { output.AppendLine(_formatter.Format(x)); } else { if (vars.IsVariable(x.Subject)) { if (!variableMap.ContainsKey(x.Subject)) { variableMap.Add(x.Subject, new VariableNode(null, "autoRuleVar" + nextVarID)); nextVarID++; } output.Append(_formatter.Format(variableMap[x.Subject])); } else { output.Append(_formatter.Format(x.Subject)); } output.Append(' '); if (vars.IsVariable(x.Predicate)) { if (!variableMap.ContainsKey(x.Predicate)) { variableMap.Add(x.Predicate, new VariableNode(null, "autoRuleVar" + nextVarID)); nextVarID++; } output.Append(_formatter.Format(variableMap[x.Predicate])); } else { output.Append(_formatter.Format(x.Predicate)); } output.Append(' '); if (vars.IsVariable(x.Object)) { if (!variableMap.ContainsKey(x.Object)) { variableMap.Add(x.Object, new VariableNode(null, "autoRuleVar" + nextVarID)); nextVarID++; } output.Append(_formatter.Format(variableMap[x.Object])); } else { output.Append(_formatter.Format(x.Object)); } output.AppendLine(" ."); } } output.AppendLine("}"); rule[1] = output.ToString(); ISyntaxValidationResults results = _validator.Validate(rule[0] + rule[1]); if (results.IsValid) { _rules.Add(rule); } }