/// <summary> /// Marks a line as having a build error /// </summary> /// <param name="error"></param> public void RecordError(DocumentError error) { if (DocumentErrors.Contains(error, new DocumentErrorComparer()) == false) { DocumentErrors.Add(error); } }
// handle an error while processing the full picture here - the preview will be restarted automatically void IDocumentResultListener.OnPictureProcessingFailure(DocumentError error) { var text = "Error scanning full document. "; var e = error.ToString(); if (e.Equals(DocumentScanView.DocumentError.DocumentNotSharp.ToString())) { text += "Document is not sharp. Please hold the camera steadily and ensure the document is in focus."; } if (e.Equals(DocumentScanView.DocumentError.DocumentSkewTooHigh.ToString())) { text += "Document is skewed. Place the camera directly above the document."; } if (e.Equals(DocumentScanView.DocumentError.DocumentOutlineNotFound.ToString())) { text += "Could not detect document outline."; } if (e.Equals(DocumentScanView.DocumentError.GlareDetected.ToString())) { text += "Please remove the glare."; } if (e.Equals(DocumentScanView.DocumentError.ImageTooDark.ToString())) { text += "The image is too dark. Please ensure there is enough light."; } if (e.Equals(DocumentScanView.DocumentError.Unknown.ToString())) { text += "Unknown Failure."; } _textView.Text = text; }
private List <BuildDiffLine> GetDocumentLines(string file, CodeDocument document) { file = Path.GetFileName(file); List <BuildDiffLine> lines = new List <BuildDiffLine>(); List <DocumentError> fileErrors = DocumentErrors.Where(d => d.FileName == file).ToList(); List <int> linesSurroundingErrors = new List <int>(); if (document == null) { return(lines); } //first pass: build up all lines that are near errors foreach (DocumentError error in fileErrors) { for (int i = error.LineNumber - LineErrorMargin; i < error.LineNumber + LineErrorMargin; i++) { if (linesSurroundingErrors.Contains(i) == false) { linesSurroundingErrors.Add(i); } } } //second pass: connect lines with errors to error source and line content foreach (int lineNumber in linesSurroundingErrors) { string content = document.Lines.ElementAtOrDefault(lineNumber); DocumentError error = fileErrors.Where(e => e.LineNumber == lineNumber).FirstOrDefault(); if (string.IsNullOrEmpty(content) == true) { content = ""; } if (error == null) { error = new DocumentError() { FileName = file, LineNumber = lineNumber, Source = DocumentErrorSource.None }; } BuildDiffLine line = new BuildDiffLine() { Content = content, Error = error }; lines.Add(line); } return(lines); }
public void HandleFailure(DocumentError error) { Console.WriteLine($"Processing {error.Document} failed: {error.Exception.Message}"); if (!(error.Document is FileSystemDocument document)) { throw new InvalidOperationException("Cannot move a document which did not originate from the file system."); } // Move the document to the error box MoveFile(document, _errorBoxPath); // Write a log for the document indicating the failure. var logFile = Path.Combine(_errorBoxPath, $"{document.FilePath.Name}.log"); Console.WriteLine($"Writing error log file to {logFile}"); File.WriteAllText(logFile, error.Exception.Message); }
private BuildDiffViewModel BuildViewModel(BuildEvent first, BuildEvent second, ExceptionEvent firstBuildException = null) { BuildDiffViewModel vm = new BuildDiffViewModel(); diff_match_patch diff = new diff_match_patch(); //loop through each document in the first, original build foreach (BuildDocument doc in first.Documents) { CodeDocument firstDoc = doc.Document; CodeDocument secondDoc = second.Documents.Where(d => d.Document.FileName == doc.Document.FileName).Select(d => d.Document).FirstOrDefault(); if (secondDoc == null) { continue; } //compute the diff List <Diff> diffs = diff.diff_lineMode(firstDoc.Content, secondDoc.Content); StringBuilder firstBuilder = new StringBuilder(); StringBuilder secondBuilder = new StringBuilder(); //loop through each piece in the return list of diffs. Three possibilities: // EQUAL: the documents share the same code, so re-include in both // DELETE: The code existed in the original but not in the modified. Add back to the original (first). // INSERT: The code exists in the modified, but not the original. Add back to the modified (second). foreach (Diff d in diffs) { switch (d.operation) { case Operation.DELETE: //encase the deleted code in a special token so that we can find it more easily later firstBuilder.Append(string.Format("{0}{1}", BuildDiffViewModel.DIFF_ESCAPE, d.text)); break; case Operation.EQUAL: default: firstBuilder.Append(d.text); secondBuilder.Append(d.text); break; case Operation.INSERT: //encase the inserted code in a special token so that we can find it more easily later secondBuilder.Append(string.Format("{0}{1}", BuildDiffViewModel.DIFF_ESCAPE, d.text)); break; } } firstDoc.Content = firstBuilder.ToString(); secondDoc.Content = secondBuilder.ToString(); } //figure out what lines had build errors on them. foreach (BuildEventErrorListItem item in first.CriticalErrorItems) { string fileName = Path.GetFileName(item.ErrorListItem.File); DocumentError error = new DocumentError() { FileName = fileName, LineNumber = item.ErrorListItem.Line - 1, //adjust line number by 1 because c# arrays are 0-based Source = DocumentErrorSource.Build, ErrorMessage = item.ErrorListItem.Description }; vm.RecordError(error); } //now find the line on which any runtime exception occurred on if (firstBuildException != null) { string fileName = Path.GetFileName(firstBuildException.DocumentName); DocumentError error = new DocumentError() { FileName = fileName, LineNumber = firstBuildException.LineNumber - 1, //adjust line number by 1 because c# arrays are 0-based Source = DocumentErrorSource.Debug, ErrorMessage = firstBuildException.ExceptionDescription }; vm.RecordError(error); } vm.OriginalBuild = first; vm.ModifiedBuild = second; return(vm); }
void IDocumentResultListener.OnPictureTransformError(DocumentError error) { // }