Table of Contents

Class TimeMapping

Namespace
Hi.Mapping
Assembly
HiMech.dll

Provides mapping between machining steps and time-based measurements (shots),

public class TimeMapping : IMakeXmlSource, IDisposable
Inheritance
TimeMapping
Implements
Inherited Members
Extension Methods

Constructors

TimeMapping(Func<string>)

Initializes a new instance of the TimeMapping class with the specified CL strip and tool house.

public TimeMapping(Func<string> baseDirectoryGetter)

Parameters

baseDirectoryGetter Func<string>

The function to get the base directory for file paths.

TimeMapping(XElement, Func<string>)

Initializes a new instance of the TimeMapping class from XML data.

public TimeMapping(XElement src, Func<string> baseDirectoryGetter)

Parameters

src XElement

The XML element containing the mapping data.

baseDirectoryGetter Func<string>

The function to get the base directory for resolving relative file paths.

Remarks

This constructor supports legacy XML formats and automatically converts them to the current format. Legacy formats include:

  • NcMapping with MarkIdToFileTimeSection element
  • Entries with MarkID attributes

Properties

BaseDirectory

Gets or sets the base directory for resolving file paths. All relative file paths in the mapping are resolved against this directory.

public string BaseDirectory { get; }

Property Value

string

BaseDirectoryGetter

Gets or sets the function to get the base directory for resolving file paths.

public Func<string> BaseDirectoryGetter { get; set; }

Property Value

Func<string>

KeyToRelFileTimeSectionDictionary

Gets or sets the dictionary mapping keys to file time sections. Each entry maps a unique identifier to a file time section that specifies which portion of a measurement file corresponds to a particular machining operation.

public Dictionary<string, FileTimeSection> KeyToRelFileTimeSectionDictionary { get; set; }

Property Value

Dictionary<string, FileTimeSection>

RelFileToTimeShotListDictionary

Gets or sets the cache of time shot lists loaded from files. This is a thread-safe dictionary that maps file paths to tasks that load and parse the files. The cache prevents multiple reads of the same file and enables concurrent access.

public ConcurrentDictionary<string, Task<List<ITimeShot>>> RelFileToTimeShotListDictionary { get; set; }

Property Value

ConcurrentDictionary<string, Task<List<ITimeShot>>>

StepToTimeShotListDictionary

Gets a concurrent dictionary mapping step indices to their corresponding time shot lists. This dictionary is populated during the mapping process.

public ConcurrentDictionary<int, List<ITimeShot>> StepToTimeShotListDictionary { get; }

Property Value

ConcurrentDictionary<int, List<ITimeShot>>

XName

Gets the XML element name used for serialization.

public static string XName { get; }

Property Value

string

Remarks

This name is used as the root element when serializing TimeMapping instances to XML. It matches the class name to maintain consistency between code and XML representation.

Methods

CallTimeShotByRelFile(string, IMessageHost, CancellationToken?)

Retrieves time shots from a file, using cached results if available.

public List<ITimeShot> CallTimeShotByRelFile(string relFile, IMessageHost messageHost, CancellationToken? cancellationToken = null)

Parameters

relFile string

The relative path to the file containing time shots.

messageHost IMessageHost
cancellationToken CancellationToken?

Optional token to cancel the loading operation.

Returns

List<ITimeShot>

A list of time shots from the file. The results are cached for subsequent calls. If the file is already being loaded by another thread, waits for that operation to complete.

Remarks

This method is thread-safe and ensures each file is only read once, even with concurrent access. Any exceptions during file reading are captured and can be inspected through the task's exception property.

Clear()

Clears all mappings and data, including the key-to-file time section dictionary.

public void Clear()

ClearCache()

Clears the cache of loaded time shot data, including file-to-time shot list and step-to-time shot list dictionaries.

public void ClearCache()

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

GetShots(int)

Gets the time shots associated with a specific step index.

public List<ITimeShot> GetShots(int stepIndex)

Parameters

stepIndex int

The index of the step to get shots for.

Returns

List<ITimeShot>

A list of time shots associated with the specified step, or null if no shots are found.

LoadTimeShotFiles(IMessageHost, CancellationToken?)

Loads all time shot files referenced in the KeyToFileTimeSectionMapping.

public void LoadTimeShotFiles(IMessageHost messageHost, CancellationToken? cancellationToken = null)

Parameters

messageHost IMessageHost
cancellationToken CancellationToken?

Optional cancellation token to cancel the operation.

MakeXmlSource(string, string, bool)

Creates an XML representation of the time mapping data. relFile is not used in current implementation.

public XElement MakeXmlSource(string baseDirectory, string relFile, bool exhibitionOnly)

Parameters

baseDirectory string

The base directory for resolving relative paths

relFile string

The relative file path for the XML source

exhibitionOnly bool

if true, the extended file creation is suppressed.

Returns

XElement

An XML element containing the complete time mapping data.

Remarks

The XML structure includes:

  • A root TimeMapping element
  • An Entrys element containing Entry elements
  • Each Entry has a Key attribute and FileTimeSection child element

Map(Range<int>, FileTimeSection, CycleSamplingMode, ClStrip, IMessageHost, CancellationToken?)

Maps the specified step section to time shots using the provided file time section and cycle sampling mode. This method is thread-safe and can be called concurrently.

public void Map(Range<int> stepSection, FileTimeSection relFileTimeSection, StepTimeShotUtil.CycleSamplingMode cycleSamplingMode, ClStrip clStrip, IMessageHost messageHost, CancellationToken? cancellationToken = null)

Parameters

stepSection Range<int>

The range of step indices to process.

relFileTimeSection FileTimeSection

The file time section containing file path and time range.

cycleSamplingMode StepTimeShotUtil.CycleSamplingMode

The cycle sampling mode to use.

clStrip ClStrip
messageHost IMessageHost
cancellationToken CancellationToken?

Optional cancellation token to cancel the operation.

MapByActualTime(string, CycleSamplingMode, ClStrip, IMessageHost, CancellationToken?)

Maps steps to time shots based on actual time.

public void MapByActualTime(string timeShotRelFile, StepTimeShotUtil.CycleSamplingMode cycleSamplingMode, ClStrip clStrip, IMessageHost messageHost, CancellationToken? cancellationToken = null)

Parameters

timeShotRelFile string

The relative file path for time shots.

cycleSamplingMode StepTimeShotUtil.CycleSamplingMode

The cycle sampling mode.

clStrip ClStrip
messageHost IMessageHost

The session message host for logging.

cancellationToken CancellationToken?

The cancellation token.

WaitMapping()

Waits for all mapping operations to complete. This method blocks until all concurrent mapping tasks have finished.

public void WaitMapping()