OptrisOptrisDocumentation

Documentation/OTC SDK/Optris.Sdk — C# API referencev12.0

FileNames

public static class FileNames

The rule the SDK names its own files by, for an application that names its files the same way. Added in 12.0.35.

An alarm's snapshot or recording, and every still of a time-lapse, is named from a pattern such as {rule}_{timestamp}. These are the very functions the SDK uses for them, so a manual snapshot named here looks like an alarm's and stays that way when the rule changes.

The placeholders are {rule}, {region}, {serial}, {model}, {sequence}, {timestamp} (the local date and time as yyyyMMdd_HHmmss, read when the name is made) and {timestamp_us}. Each value goes in once, so a rule named {timestamp} is named that; {{ and }} write a literal brace, and a name in braces that is none of these is written as it stands.

FileNames: methods

public static string Expand(string pattern, FileNameContext context, string fallback = "")

pattern with its placeholders filled in from context, then cleaned as FileNames.Sanitize(…) cleans.

  • pattern: The pattern, without a directory or an extension.
  • context: The values.
  • fallback: What to return when nothing is left; the SDK's alarm actions use "alarm".

Returns: The file name's stem.

Each value is cleaned on its own first, so a rule named ../../etc cannot walk out of a directory.

// "over_temp_000007"
string stem = FileNames.Expand(
    "{rule}_{sequence}",
    new FileNameContext { Rule = "over temp", Sequence = 7 });
public static string Sanitize(string text, string fallback = "")

text as one part of a file name: a slash, a backslash, a colon, *, ?, ", <, >, |, a control character and a space each become _.

  • text: What to clean.
  • fallback: What to return when text is empty.

Returns: The cleaned text, or fallback.

public static string Unique(string directory, string stem, string extension)

directory/stem + extension, or, when that exists, the first of stem-1, stem-2... up to stem-9999 that does not.

  • directory: The directory; empty means the current one.
  • stem: The name without its extension, for example from FileNames.Expand(…).
  • extension: The extension with its dot, for example ".png".

Returns: The path.

Nothing is created, so two programs asking at once can be told the same name.