Search Results for

    Show / Hide Table of Contents

    Interface INativeFileSniffer

    A file sniffer is a component that gets invoked to determine if a particular file can be processed.

    If the file is supported, the file sniffer may also detect the language and the encoding of a given file, in addition to any other information that will be useful to set up the parser to correctly process it.

    Namespace: Sdl.FileTypeSupport.Framework.NativeApi
    Assembly: Sdl.FileTypeSupport.Framework.Core.dll
    Syntax
    public interface INativeFileSniffer
    Remarks

    File sniffers allow the framework to distinguish between different file types that use the same file extension. A file sniffer is expected to look at the actual file content to determine if the file is supported.

    The file sniffer implementation should return a SniffInfo instance where the IsSupported is set to true if the file is of the expected type.

    The file sniffer may also attempt to automatically detect the encoding and the source (and target) language of the file. When detecting such things, the file sniffer also specifies a confidence level for the detection, which allows applications to determine whether they may need to ask the user for additional information or not.

    The file type manager invokes the Sniff(String, Language, Codepage, INativeTextLocationMessageReporter, ISettingsGroup) method on a file sniffer associated with a file type definition to determine if the file is of a type that can be processed.

    The file sniffer implementation must be stateless and thread safe, since for performance reasons the file sniffer may be cached and re-used across multiple files, possibly also in a multi-threaded environment. The easiest way to accomplish this is by ensuring that the Sniff(String, Language, Codepage, INativeTextLocationMessageReporter, ISettingsGroup) implementation does not modify any class member fields and to avoid using static variables.

    The file sniffer is also recommended (but not required) to implement IFileTypeDefinitionAware. If this interface is implemented, it will be used by the framework to communicate the file type definition used to instantiate the sniffer.

    Methods

    Sniff(String, Language, Codepage, INativeTextLocationMessageReporter, ISettingsGroup)

    Called by the framework to invoke the file sniffer for a specific file.

    Declaration
    SniffInfo Sniff(string nativeFilePath, Language suggestedSourceLanguage, Codepage suggestedCodepage, INativeTextLocationMessageReporter messageReporter, ISettingsGroup settingsGroup)
    Parameters
    Type Name Description
    System.String nativeFilePath

    Fill path to the file to sniff.

    Language suggestedSourceLanguage

    Expected source language of the file.

    Codepage suggestedCodepage

    Possible suggested codepage of the file (based on its expected language).

    INativeTextLocationMessageReporter messageReporter

    Supplied by the framework to allow file sniffers to report file-related information that may be of interest.

    ISettingsGroup settingsGroup

    Supplied by the framework to allow file sniffers to change their behavior depending on their settings. This parameter is intended as the sole means to gain access to settings in the sniffer - methods used for other components will invalidate the stateless model of file sniffers and should not be used.

    Returns
    Type Description
    SniffInfo

    An instance of a SniffInfo object where the IsSupported property has been set to true or false to indicate if the file is of a supported type. The return value may also indicate the detected encoding, source, and target language, together with the detection confidence levels.

    Remarks

    The implementation of this method must be stateless and thread-safe.

    On this page

    • Methods
      • Sniff(String, Language, Codepage, INativeTextLocationMessageReporter, ISettingsGroup)
    Back to top Generated by DocFX