Table of Contents

Class DataIntegrityFactory

Namespace
Cuemon.Data.Integrity
Assembly
Cuemon.Data.Integrity.dll

Provides access to factory methods for creating and configuring implementations of the IDataIntegrity interface.

public static class DataIntegrityFactory
Inheritance
DataIntegrityFactory

Examples

The following example demonstrates how to create an implementation from a file using . It writes sample data to a temporary file, then calls CreateIntegrity with a custom converter that computes a CRC64 hash over the file content. The resulting checksum and file name are written to the console, showing how to verify file integrity with configurable hashing algorithms.

using System;
using System.IO;
using Cuemon.Data.Integrity;
using Cuemon.Security;

namespace MyApp.Data;

public sealed class DataIntegrityFactoryExample
{
    public void Demonstrate()
    {
        var file = new FileInfo(Path.GetTempFileName());
        try
        {
            File.WriteAllText(file.FullName, "Sample data for integrity check.");

            IDataIntegrity integrity = DataIntegrityFactory.CreateIntegrity(file, options =>
            {
                options.BytesToRead = 1024;
                options.IntegrityConverter = (fi, checksumBytes) =>
                {
                    var hash = HashFactory.CreateCrc64().ComputeHash(checksumBytes);
                    return new DataIntegrity(fi, hash);
                };
            });

            Console.WriteLine($"Integrity: {integrity}");
        }
        finally
        {
            file.Delete();
        }
    }
}

// Minimal IDataIntegrity implementation for demonstration
public class DataIntegrity(FileInfo file, HashResult checksum) : IDataIntegrity
{
    public FileInfo File { get; } = file;

    public HashResult Checksum { get; } = checksum;

    public override string ToString() => $"{File.Name}: {Checksum.ToHexadecimalString()}";
}

Methods

CreateIntegrity(FileInfo, Action<FileIntegrityOptions>)

Creates and returns an object implementing the IDataIntegrity interface from the specified file.

public static IDataIntegrity CreateIntegrity(FileInfo file, Action<FileIntegrityOptions> setup)

Parameters

file FileInfo

The FileInfo to convert.

setup Action<FileIntegrityOptions>

The FileIntegrityOptions which need to be configured.

Returns

IDataIntegrity

An object implementing the IDataIntegrity interface that represents the integrity of file.

Exceptions

ArgumentNullException

file cannot be null.