Table of Contents

Class FileIntegrityOptions

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

Configuration options for FileInfo.

public class FileIntegrityOptions : FileInfoOptions, IParameterObject
Inheritance
FileIntegrityOptions
Implements
Inherited Members

Examples

The following example demonstrates how to use to configure file integrity checksum computation.

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

namespace MyApp.Examples
{
    public sealed class FileIntegrityOptionsExample
    {
        public void Demonstrate()
        {
            var defaults = new FileIntegrityOptions();
            Console.WriteLine($"Default bytes to read: {defaults.BytesToRead}");

            var path = Path.Combine(AppContext.BaseDirectory, "sample.dat");
            File.WriteAllText(path, "Hello, World!");

            try
            {
                IDataIntegrity integrity = DataIntegrityFactory.CreateIntegrity(new FileInfo(path), options =>
                {
                    options.BytesToRead = 8;
                    options.IntegrityConverter = (file, bytes) => new FilePreviewIntegrity(file.Name, bytes);
                });

                Console.WriteLine($"Checksum: {integrity.Checksum.ToHexadecimalString()}");
            }
            finally
            {
                if (File.Exists(path)) { File.Delete(path); }
            }
        }

        private sealed class FilePreviewIntegrity : IDataIntegrity
        {
            public FilePreviewIntegrity(string fileName, byte[] bytes)
            {
                FileName = fileName;
                Checksum = HashFactory.CreateFnv128().ComputeHash(bytes);
            }

            public string FileName { get; }

            public HashResult Checksum { get; }
        }
    }
}

Constructors

FileIntegrityOptions()

Initializes a new instance of the FileIntegrityOptions class.

public FileIntegrityOptions()

Remarks

The following table shows the initial property values for an instance of FileIntegrityOptions.

PropertyInitial Value
IntegrityConverternull

Properties

IntegrityConverter

Gets or sets the function delegate that will convert an instance of FileInfo and a byte[] into an object implementing the IDataIntegrity interface.

public Func<FileInfo, byte[], IDataIntegrity> IntegrityConverter { get; set; }

Property Value

Func<FileInfo, byte[], IDataIntegrity>

The function delegate that returns an object implementing the IDataIntegrity interface.

Exceptions

ArgumentNullException

value cannot be null.