Table of Contents

DataIntegrityFactory Class

Definition

Namespace
Cuemon.Data.Integrity
Assemblies
Cuemon.Data.Integrity.dll
Source
src/Cuemon.Data.Integrity/DataIntegrityFactory.cs

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

public static class DataIntegrityFactory
Inheritance
object
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

Name Description
CreateIntegrity(FileInfo, Action<FileIntegrityOptions>)

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