Class TimeMapping
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
TimeMapping(XElement, Func<string>)
Initializes a new instance of the TimeMapping class from XML data.
public TimeMapping(XElement src, Func<string> baseDirectoryGetter)
Parameters
srcXElementThe XML element containing the mapping data.
baseDirectoryGetterFunc<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
BaseDirectoryGetter
Gets or sets the function to get the base directory for resolving file paths.
public Func<string> BaseDirectoryGetter { get; set; }
Property Value
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
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
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
XName
Gets the XML element name used for serialization.
public static string XName { get; }
Property Value
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
relFilestringThe relative path to the file containing time shots.
messageHostIMessageHostcancellationTokenCancellationToken?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
disposingbool
GetShots(int)
Gets the time shots associated with a specific step index.
public List<ITimeShot> GetShots(int stepIndex)
Parameters
stepIndexintThe 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
messageHostIMessageHostcancellationTokenCancellationToken?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
baseDirectorystringThe base directory for resolving relative paths
relFilestringThe relative file path for the XML source
exhibitionOnlyboolif 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
stepSectionRange<int>The range of step indices to process.
relFileTimeSectionFileTimeSectionThe file time section containing file path and time range.
cycleSamplingModeStepTimeShotUtil.CycleSamplingModeThe cycle sampling mode to use.
clStripClStripmessageHostIMessageHostcancellationTokenCancellationToken?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
timeShotRelFilestringThe relative file path for time shots.
cycleSamplingModeStepTimeShotUtil.CycleSamplingModeThe cycle sampling mode.
clStripClStripmessageHostIMessageHostThe session message host for logging.
cancellationTokenCancellationToken?The cancellation token.
WaitMapping()
Waits for all mapping operations to complete. This method blocks until all concurrent mapping tasks have finished.
public void WaitMapping()