Skip to content

AnalysisResult Class

Naveen Dharmathunga edited this page Jan 19, 2026 · 1 revision

AnalysisResult Class

Represents the result of an analysis, including the set of definitions and their associated metadata such as file extensions and MIME types.

Namespace: Rheo.Storage.Analyzing.Models.Result

Assembly: Rheo.Storage.dll

Definition

public class AnalysisResult

Properties

Property Type Description
IsEmpty Boolean Gets a value indicating whether the result contains no definitions.
Definitions ConfidenceStack<Definition> Gets the collection of definitions along with their associated confidence scores.
Extensions ConfidenceStack<String> Gets a stack containing all unique file extensions defined in the current set of definitions.
MimeTypes ConfidenceStack<String> Gets a stack of unique MIME types defined in the current set of definitions.

Remarks

Use this class to access the analyzed definitions along with their unique file extensions and MIME types. The properties provide convenient access to distinct metadata derived from the underlying definitions. The collections exposed by this class are read-only after initialization.

The AnalysisResult is typically returned by the FileAnalyzer class after analyzing a file or stream. It provides confidence-scored results, allowing you to determine the most likely file type.


Property Details

IsEmpty

Gets a value indicating whether the result contains no definitions.

public bool IsEmpty { get; }

Property Value

Boolean

true if the result contains no definitions; otherwise, false.

Remarks

This property is useful for quickly checking whether the file analysis produced any matches before attempting to access the definitions.


Definitions

Gets the collection of definitions along with their associated confidence scores.

public ConfidenceStack<Definition> Definitions { get; init; }

Property Value

ConfidenceStack<Definition>

A confidence stack containing all matched definitions, ordered by confidence score.

Remarks

Use this property to access all available definitions, each paired with a confidence value indicating the reliability or relevance of the definition. The collection is read-only after initialization.

The definitions are automatically sorted by confidence score in descending order, with the most confident match first.


Extensions

Gets a stack containing all unique file extensions defined in the current set of definitions.

public ConfidenceStack<string> Extensions { get; }

Property Value

ConfidenceStack<String>

A confidence stack of unique file extensions.

Remarks

The returned stack includes each extension only once, regardless of how many definitions reference it. The order of extensions in the stack reflects the order in which they are encountered when enumerating the definitions.

This property is computed dynamically each time it is accessed by extracting extensions from all definitions in the result.


MimeTypes

Gets a stack of unique MIME types defined in the current set of definitions.

public ConfidenceStack<string> MimeTypes { get; }

Property Value

ConfidenceStack<String>

A confidence stack of unique MIME types.

Remarks

The returned stack contains one entry for each distinct MIME type present in the definitions, with the most recently added types on top. The order of MIME types in the stack reflects the order in which they are encountered during enumeration.

This property is computed dynamically each time it is accessed.


Examples

Analyzing a File and Accessing Results

The following example demonstrates how to analyze a file and work with the results:

using Rheo.Storage.Analyzing;
using Rheo.Storage.Analyzing.Models.Result;

string filePath = @"C:\Documents\image.png";
AnalysisResult result = FileAnalyzer.AnalyzeFile(filePath);

if (!result.IsEmpty)
{
    // Get the most confident match
    var topMatch = result.Definitions.Peek();
    Console.WriteLine($"File Type: {topMatch.Subject.FileType}");
    Console.WriteLine($"Confidence: {topMatch.Value:F2}%");
    Console.WriteLine($"MIME Type: {topMatch.Subject.MimeType}");
}
else
{
    Console.WriteLine("No file type could be determined.");
}

Displaying All Matched Definitions

The following example shows how to display all matched definitions with their confidence scores:

using Rheo.Storage.Analyzing;
using Rheo.Storage.Analyzing.Models.Result;

string filePath = @"C:\Documents\file.dat";
AnalysisResult result = FileAnalyzer.AnalyzeFile(filePath);

Console.WriteLine($"Found {result.Definitions.Count} possible file types:");
foreach (var confidence in result.Definitions)
{
    Console.WriteLine($"  {confidence.Subject.FileType}: {confidence.Value:F2}%");
}

Working with Extensions and MIME Types

The following example demonstrates how to access unique extensions and MIME types:

using Rheo.Storage.Analyzing;
using Rheo.Storage.Analyzing.Models.Result;

string filePath = @"C:\Documents\archive.zip";
AnalysisResult result = FileAnalyzer.AnalyzeFile(filePath);

// Display possible extensions
Console.WriteLine("Possible extensions:");
foreach (var ext in result.Extensions)
{
    Console.WriteLine($"  {ext.Subject}");
}

// Display possible MIME types
Console.WriteLine("\nPossible MIME types:");
foreach (var mime in result.MimeTypes)
{
    Console.WriteLine($"  {mime.Subject}");
}

Handling Empty Results

The following example shows how to handle cases where no match is found:

using Rheo.Storage.Analyzing;
using Rheo.Storage.Analyzing.Models.Result;

string filePath = @"C:\Documents\unknown.bin";
AnalysisResult result = FileAnalyzer.AnalyzeFile(filePath);

if (result.IsEmpty)
{
    Console.WriteLine("Unable to identify file type.");
}
else
{
    var topMatch = result.Definitions.Peek();
    
    if (topMatch.Value < 50.0)
    {
        Console.WriteLine($"Low confidence match: {topMatch.Subject.FileType} ({topMatch.Value:F2}%)");
        Console.WriteLine("Manual verification recommended.");
    }
    else
    {
        Console.WriteLine($"High confidence match: {topMatch.Subject.FileType} ({topMatch.Value:F2}%)");
    }
}

Filtering Results by Confidence Threshold

The following example demonstrates how to filter results by confidence score:

using Rheo.Storage.Analyzing;
using Rheo.Storage.Analyzing.Models.Result;

string filePath = @"C:\Documents\file.bin";
AnalysisResult result = FileAnalyzer.AnalyzeFile(filePath);

const double confidenceThreshold = 60.0;

var highConfidenceMatches = result.Definitions
    .Where(c => c.Value >= confidenceThreshold)
    .ToList();

if (highConfidenceMatches.Any())
{
    Console.WriteLine($"High confidence matches (>= {confidenceThreshold}%):");
    foreach (var match in highConfidenceMatches)
    {
        Console.WriteLine($"  {match.Subject.FileType}: {match.Value:F2}%");
    }
}
else
{
    Console.WriteLine($"No matches with confidence >= {confidenceThreshold}%");
}

Thread Safety

This class is not thread-safe. When accessing instances from multiple threads, use appropriate synchronization mechanisms.

See Also

Clone this wiki locally