Table of Contents

Class CacheValidatorFactory

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

Provides access to factory methods for creating and configuring CacheValidator instances.

public static class CacheValidatorFactory
Inheritance
CacheValidatorFactory

Examples

The following example demonstrates how to create a from a file using .

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

namespace MyApp.Data;

public sealed class CacheValidatorFactoryExample
{
    public void Demonstrate()
    {
        var file = new FileInfo(Path.GetTempFileName());
        try
        {
            File.WriteAllText(file.FullName, "Hello, world!");

            CacheValidator validator = CacheValidatorFactory.CreateValidator(file);
            Console.WriteLine($"Created (UTC):  {validator.Created:O}");
            Console.WriteLine($"Modified (UTC): {validator.Modified:O}");
            Console.WriteLine($"Validation:     {validator.Validation}");
            Console.WriteLine($"Method:         {validator.Method}");
            Console.WriteLine($"Checksum:       {validator.Checksum.ToHexadecimalString()}");

            // Create validator using a custom hash algorithm
            CacheValidator shaValidator = CacheValidatorFactory.CreateValidator(
                file,
                () => HashFactory.CreateFnv128());
            Console.WriteLine($"SHA-256: {shaValidator.Checksum.ToHexadecimalString()}");
        }
        finally
        {
            file.Delete();
        }
    }
}

Methods

CreateValidator(FileInfo, Func<Hash>, Action<FileChecksumOptions>)

Creates and returns an instance of CacheValidator from the specified file.

public static CacheValidator CreateValidator(FileInfo file, Func<Hash> hashFactory = null, Action<FileChecksumOptions> setup = null)

Parameters

file FileInfo

The FileInfo to convert.

hashFactory Func<Hash>

The function delegate that is invoked to produce the HashResult. Default is CreateFnv128(Action<FowlerNollVoOptions>).

setup Action<FileChecksumOptions>

The FileChecksumOptions which may be configured.

Returns

CacheValidator

A CacheValidator that represents the file.

Exceptions

ArgumentNullException

file cannot be null.

CreateValidator(Assembly, Func<Hash>, Action<FileChecksumOptions>)

Creates and returns an instance of CacheValidator from the specified assembly.

public static CacheValidator CreateValidator(Assembly assembly, Func<Hash> hashFactory = null, Action<FileChecksumOptions> setup = null)

Parameters

assembly Assembly

The Assembly to convert.

hashFactory Func<Hash>

The function delegate that is invoked to produce the HashResult. Default is CreateFnv128(Action<FowlerNollVoOptions>).

setup Action<FileChecksumOptions>

The FileChecksumOptions which may be configured.

Returns

CacheValidator

A CacheValidator that represents the assembly.

Exceptions

ArgumentNullException

assembly cannot be null.