共用方式為


AnalysisStatus 類別

表示分析作業的狀態,包括作業成功或失敗、相關警告,以及發生變更 (如果有的話) 的位置相關資訊。

命名空間:  System.Windows.Ink
組件:  IAWinFX (在 IAWinFX.dll 中)

語法

'宣告
Public Class AnalysisStatus
'用途
Dim instance As AnalysisStatus
public class AnalysisStatus
public ref class AnalysisStatus
public class AnalysisStatus
public class AnalysisStatus

範例

在這個範例中,會示範如何在筆墨分析之後尋找警告。當您使用可能尚未安裝的南非荷蘭文辨識器執行分析時,分析會失敗,並出現 AnalysisWarningCodeNoMatchingInkRecognizerFound。在這個範例中,偵錯資訊會透過 DebugWriteLine(),直接傳送至輸出視窗。

' Analyze using Afrikaans recognizer.
' You are unlikely to have this recognizer, so it will raise a warning.
Dim afrikaansInkAnalyzer As New InkAnalyzer()
Dim afrikaansLanguageId As Integer = 1078
afrikaansInkAnalyzer.AddStrokes(theInkCanvas.Strokes, afrikaansLanguageId)
Dim status As AnalysisStatus = afrikaansInkAnalyzer.Analyze()

' Note: We should only expect to see the BackgroundException warning if
' we were performing background analysis.
' Display any warnings
If Not status.Successful Then
    ' Initialize warning message
    Dim message As String = "Analysis resulted in the following warnings:" & Environment.NewLine

    ' Loop through warnings
    Dim warning As AnalysisWarning
    For Each warning In  status.Warnings
        Select Case warning.WarningCode
            Case AnalysisWarningCode.Aborted
                message &= "Analysis operation was aborted. "
            Case AnalysisWarningCode.BackgroundException
                    ' This is a fatal warning. Throw an exception.
                    ' First, attempt to save as much doc state as possible 
                    ' ...
                    ' Rethrow the exception so that it can be caught by an exception
                    ' handler (or if there is no exception handler, a program error 
                    ' debugger such as Dr. Watson can be invoked)
                    Throw warning.BackgroundException
            Case AnalysisWarningCode.ConfirmedWithoutInkRecognition
                message &= "Node was confirmed without ink recognition having been performed. "
            Case AnalysisWarningCode.ContextNodeLocationNotSet
                message &= "Node does not have a proper location set. "
            Case AnalysisWarningCode.FactoidCoercionNotSupported
                message &= "Factoid coercion failed "
                If Not (warning.AnalysisHint Is Nothing) AndAlso _
                   Not (warning.AnalysisHint.Factoid Is Nothing) Then
                    message &= "for factoid: " & warning.AnalysisHint.Factoid & ". "
                End If
            Case AnalysisWarningCode.FactoidNotSupported
                If Not (warning.AnalysisHint Is Nothing) AndAlso _
                   Not (warning.AnalysisHint.Factoid Is Nothing) Then
                    message &= warning.AnalysisHint.Factoid & " factoid was not respected. "
                End If
            Case AnalysisWarningCode.GuideNotSupported
                message &= "Guide was not respected. "
            Case AnalysisWarningCode.AddInkToRecognizerFailed
                message &= "Ink could not be added to the InkRecognizer. "
            Case AnalysisWarningCode.InkRecognizerInitializationFailed
                message &= "The InkRecognizer failed to initialize. "
            Case AnalysisWarningCode.NoMatchingInkRecognizerFound
                message &= "There are no ink recognizers meeting the language or capabilities needed. "
            Case AnalysisWarningCode.LanguageIdNotRespected
                message &= "The language ID set on a stroke did not match the language ID of the InkRecognizer. "
            Case AnalysisWarningCode.PartialDictionaryTermsNotSupported
                message &= "Partial dictionary terms could not be returned from the text recognizer. "
            Case AnalysisWarningCode.TextRecognitionProcessFailed
                message &= "The text recognition process failed. "
            Case AnalysisWarningCode.SetPrefixSuffixFailed
                message &= "The text recognizer was unable to respect either the prefix or suffix. "
                If Not (warning.AnalysisHint Is Nothing) AndAlso _
                   Not (warning.AnalysisHint.PrefixText Is Nothing) Then
                    message &= "Prefix: " & warning.AnalysisHint.PrefixText & ". "
                End If
                If Not (warning.AnalysisHint Is Nothing) AndAlso _
                   Not (warning.AnalysisHint.SuffixText Is Nothing) Then
                    message &= "Suffix: " & warning.AnalysisHint.SuffixText & ". "
                End If
            Case AnalysisWarningCode.WordlistNotSupported
                message &= "Wordlist was not respected. "
            Case AnalysisWarningCode.WordModeNotSupported
                message &= "Word mode was not respected. "
        End Select

        ' Add node id information
        Dim id As Guid
        For Each id In  warning.GetNodeIds()
            message &= "Id: " & id.ToString() & " "
        Next id
        ' Add hint information
        If Not (warning.AnalysisHint Is Nothing) Then
            Dim hint As AnalysisHintNode = warning.AnalysisHint
            message &= Environment.NewLine & "Hint information: "
            message &= "AllowPartialDictionaryTerms"
            If hint.AllowPartialDictionaryTerms Then
                message &= " = true "
            Else
                message &= " = false "
            End If
            message &= "CoerceToFactoid"
            If hint.CoerceToFactoid Then
                message &= " = true "
            Else
                message &= " = false "
            End If
            If Not (hint.Factoid Is Nothing) Then
                message &= "Factoid = " & warning.AnalysisHint.Factoid & " "
            End If
            message &= "Guide Drawn Box = (" _
                    & hint.Guide.DrawnBoxTop.ToString() & ", " _
                    & hint.Guide.DrawnBoxLeft.ToString() & ", " _
                    & hint.Guide.DrawnBoxBottom.ToString() & ", " _
                    & hint.Guide.DrawnBoxRight.ToString() & ", " & ")"
            message &= "Guide Writing Box = (" _
                    & hint.Guide.WritingBoxTop.ToString() & ", " _
                    & hint.Guide.WritingBoxLeft.ToString() & ", " _
                    & hint.Guide.WritingBoxBottom.ToString() & ", " _
                    & hint.Guide.WritingBoxRight.ToString() & ", " & ")"
            If Not (hint.Name Is Nothing) Then
                message &= "Name = " & warning.AnalysisHint.Name & " "
            End If
            If Not (hint.PrefixText Is Nothing) Then
                message &= "PrefixText = " & warning.AnalysisHint.PrefixText & " "
            End If
            If Not (hint.SuffixText Is Nothing) Then
                message &= "SuffixText = " & warning.AnalysisHint.SuffixText & " "
            End If
            message &= "WordMode"
            If hint.WordMode Then
                message &= " = true"
            Else
                message &= " = false"
            End If
        End If
        message &= Environment.NewLine
    Next warning
    ' Show in the output window
    System.Diagnostics.Debug.WriteLine(message)
End If

If status.Successful Then
    MessageBox.Show(afrikaansInkAnalyzer.GetRecognizedString())
End If
// Analyze using Afrikaans recognizer.
// You are unlikely to have this recognizer, so it will raise a warning.
InkAnalyzer afrikaansInkAnalyzer = new InkAnalyzer();
int afrikaansLanguageId = 1078;
afrikaansInkAnalyzer.AddStrokes(theInkCanvas.Strokes, afrikaansLanguageId);
AnalysisStatus status = afrikaansInkAnalyzer.Analyze();

// Note: We should only expect to see the BackgroundException warning if
// we were performing background analysis.
// Display any warnings
if (!status.Successful)
{
    // Initialize warning message
    string message = "Analysis resulted in the following warnings:" + Environment.NewLine;

    // Loop through warnings
    foreach (AnalysisWarning warning in status.Warnings)
    {
        switch (warning.WarningCode)
        {
            case AnalysisWarningCode.Aborted:
                message += "Analysis operation was aborted. ";
                break;
            case AnalysisWarningCode.BackgroundException:
                // This is a fatal warning. Throw an exception.
                // First, attempt to save as much doc state as possible 
                // ...

                // Rethrow the exception so that it can be caught by an exception
                // handler (or if there is no exception handler, a program error 
                // debugger such as Dr. Watson can be invoked)
                throw (warning.BackgroundException);
            case AnalysisWarningCode.ConfirmedWithoutInkRecognition:
                message += "Node was confirmed without ink recognition having been performed. ";
                break;
            case AnalysisWarningCode.ContextNodeLocationNotSet:
                message += "Node does not have a proper location set. ";
                break;
            case AnalysisWarningCode.FactoidCoercionNotSupported:
                message += "Factoid coercion failed ";
                if (warning.AnalysisHint != null && warning.AnalysisHint.Factoid != null)
                {
                    message += "for factoid: " + warning.AnalysisHint.Factoid + ". ";
                }
                break;
            case AnalysisWarningCode.FactoidNotSupported:
                if (warning.AnalysisHint != null && warning.AnalysisHint.Factoid != null)
                {
                    message += warning.AnalysisHint.Factoid + " factoid was not respected. ";
                }
                break;
            case AnalysisWarningCode.GuideNotSupported:
                message += "Guide was not respected. ";
                break;
            case AnalysisWarningCode.AddInkToRecognizerFailed:
                message += "Ink could not be added to the InkRecognizer. ";
                break;
            case AnalysisWarningCode.InkRecognizerInitializationFailed:
                message += "The InkRecognizer failed to initialize. ";
                break;
            case AnalysisWarningCode.NoMatchingInkRecognizerFound:
                message += "There are no ink recognizers meeting the language or capabilities needed. ";
                break;
            case AnalysisWarningCode.LanguageIdNotRespected:
                message += "The language ID set on a stroke did not match the language ID of the InkRecognizer. ";
                break;
            case AnalysisWarningCode.PartialDictionaryTermsNotSupported:
                message += "Partial dictionary terms could not be returned from the text recognizer. ";
                break;
            case AnalysisWarningCode.TextRecognitionProcessFailed:
                message += "The text recognition process failed. ";
                break;
            case AnalysisWarningCode.SetPrefixSuffixFailed:
                message += "The text recognizer was unable to respect either the prefix or suffix. ";
                if (warning.AnalysisHint != null && warning.AnalysisHint.PrefixText != null)
                {
                    message += "Prefix: " + warning.AnalysisHint.PrefixText + ". ";
                }
                if (warning.AnalysisHint != null && warning.AnalysisHint.SuffixText != null)
                {
                    message += "Suffix: " + warning.AnalysisHint.SuffixText + ". ";
                }
                break;
            case AnalysisWarningCode.WordlistNotSupported:
                message += "Wordlist was not respected. ";
                break;
            case AnalysisWarningCode.WordModeNotSupported:
                message += "Word mode was not respected. ";
                break;
        }

        // Add node id information
        foreach (Guid id in warning.GetNodeIds())
            message += "Id: " + id.ToString() + " ";

        // Add hint information
        if (warning.AnalysisHint != null)
        {
            AnalysisHintNode hint = warning.AnalysisHint;
            message += Environment.NewLine + "Hint information: ";
            message += "AllowPartialDictionaryTerms";
            if (hint.AllowPartialDictionaryTerms)
                message += " = true ";
            else
                message += " = false ";
            message += "CoerceToFactoid";
            if (hint.CoerceToFactoid)
                message += " = true ";
            else
                message += " = false ";
            if (hint.Factoid != null)
                message += "Factoid = " + warning.AnalysisHint.Factoid + " ";
            message += "Guide Drawn Box = (" +
                hint.Guide.DrawnBoxTop.ToString() + ", " +
                hint.Guide.DrawnBoxLeft.ToString() + ", " +
                hint.Guide.DrawnBoxBottom.ToString() + ", " +
                hint.Guide.DrawnBoxRight.ToString() + ", " + ")";
            message += "Guide Writing Box = (" +
                hint.Guide.WritingBoxTop.ToString() + ", " +
                hint.Guide.WritingBoxLeft.ToString() + ", " +
                hint.Guide.WritingBoxBottom.ToString() + ", " +
                hint.Guide.WritingBoxRight.ToString() + ", " + ")";
            if (hint.Name != null)
                message += "Name = " + warning.AnalysisHint.Name + " ";
            if (hint.PrefixText != null)
                message += "PrefixText = " + warning.AnalysisHint.PrefixText + " ";
            if (hint.SuffixText != null)
                message += "SuffixText = " + warning.AnalysisHint.SuffixText + " ";
            message += "WordMode";
            if (hint.WordMode)
                message += " = true";
            else
                message += " = false";
        }
        message += Environment.NewLine;
    }

    // Show in the output window
    System.Diagnostics.Debug.WriteLine(message);
}

if (status.Successful)
{
    MessageBox.Show(afrikaansInkAnalyzer.GetRecognizedString());
}

繼承階層架構

System.Object
  System.Windows.Ink.AnalysisStatus

執行緒安全

這個型別的任何 Public static (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。並非所有的執行個體成員都是安全執行緒。

平台

Windows Vista

.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求

版本資訊

.NET Framework

支援版本:3.0

請參閱

參考

AnalysisStatus 成員

System.Windows.Ink 命名空間

InkAnalyzer.Analyze

System.Windows.Ink.ResultsUpdatedEventArgs

System.Windows.Ink.AnalysisWarningCode