Table of Contents

Class JobProcessor

Namespace
DuetControlServer.Files
Assembly
DuetControlServer.dll

Main class dealing with job files

[DiagnosticsPriority(-1)]
public class JobProcessor : BackgroundService, IHostedService, IDisposable, IAsyncDiagnostics
Inheritance
JobProcessor
Implements
Inherited Members

Constructors

Constructor of this class

public JobProcessor(CodeFactory codeFactory, CodeProcessor codeProcessor, EventLogger eventLogger, Expressions expressions, FileFactory fileFactory, FileInfoParser fileInfoParser, LinkInterface linkInterface, ObjectModel model, IHostApplicationLifetime lifetime, ILogger<JobProcessor> logger, IOptions<Settings> settings)

Parameters

codeFactory CodeFactory

Code factory

codeProcessor CodeProcessor

Code processor

eventLogger EventLogger

Event logger

expressions Expressions

Expressions

fileFactory FileFactory

File factory

fileInfoParser FileInfoParser

File info parser

linkInterface LinkInterface

Link interface

model ObjectModel

Object Model

lifetime IHostApplicationLifetime

Host application lifetime

logger ILogger<JobProcessor>

Logger

settings IOptions<Settings>

Settings

Properties

FileLength

Returns the length of the file being printed in bytes

public long FileLength { get; }

Property Value

long

IsAborted

Indicates if the file print has been aborted

public bool IsAborted { get; }

Property Value

bool

IsCancelled

Indicates if the file print has been cancelled

public bool IsCancelled { get; }

Property Value

bool

IsFileSelected

Indicates if a file has been selected for printing

public bool IsFileSelected { get; }

Property Value

bool

IsPaused

Indicates if the file print has been paused

public bool IsPaused { get; }

Property Value

bool

IsProcessing

Indicates if a print is live

public bool IsProcessing { get; }

Property Value

bool

IsSimulating

Indicates if a file is being simulated

public bool IsSimulating { get; }

Property Value

bool

Remarks

This is volatile to allow fast access without locking the class first

Methods

Abort()

Abort the current print asynchronously. This is called when the print could not complete as expected

public void Abort()

Cancel()

Cancel the current print (e.g. when M0/M1 is called)

public void Cancel()

ExecuteAsync(CancellationToken)

Perform actual print jobs

protected override Task ExecuteAsync(CancellationToken stoppingToken)

Parameters

stoppingToken CancellationToken

Returns

Task

ForkAsync(CancellationToken)

Fork the file being processed to execute concurrently

public Task<Message> ForkAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Cancellation token

Returns

Task<Message>

Message result

GetFilePositionAsync(int, CancellationToken)

Get the current file position

public Task<long> GetFilePositionAsync(int motionSystem, CancellationToken cancellationToken)

Parameters

motionSystem int

Motion system

cancellationToken CancellationToken

Cancellation token

Returns

Task<long>

File position

Lock()

Lock this class

public IDisposable Lock()

Returns

IDisposable

Disposable lock

Lock(CancellationToken)

Lock this class

public IDisposable Lock(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Cancellation token

Returns

IDisposable

Disposable lock

LockAsync()

Lock this class asynchronously

public AwaitableDisposable<IDisposable> LockAsync()

Returns

AwaitableDisposable<IDisposable>

Disposable lock

LockAsync(CancellationToken)

Lock this class asynchronously

public AwaitableDisposable<IDisposable> LockAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Cancellation token

Returns

AwaitableDisposable<IDisposable>

Disposable lock

Called when the print is being paused

public void Pause(long? filePosition, long? filePosition2, PrintPausedReason pauseReason)

Parameters

filePosition long?

File position where the print was paused

filePosition2 long?
pauseReason PrintPausedReason

Reason why the print has been paused

PrintDiagnosticsAsync(StringBuilder, CancellationToken)

Print diagnostics of this class

public ValueTask PrintDiagnosticsAsync(StringBuilder builder, CancellationToken cancellationToken)

Parameters

builder StringBuilder

String builder

cancellationToken CancellationToken

Cancellation token

Returns

ValueTask

Asynchronous task

Resume()

Resume a file print

public void Resume()

SelectFileAsync(string, string, bool, CancellationToken)

Select a new file to print asynchronously

public Task SelectFileAsync(string virtualFile, string physicalFile, bool simulating = false, CancellationToken cancellationToken = default)

Parameters

virtualFile string

File to print

physicalFile string

Physical file to print

simulating bool

Whether the file is being simulated

cancellationToken CancellationToken

Returns

Task

Asynchronous task

Remarks

This class has to be locked when this method is called

SetFilePositionAsync(int, long, CancellationToken)

Set the current file position

public Task SetFilePositionAsync(int motionSystem, long filePosition, CancellationToken cancellationToken = default)

Parameters

motionSystem int

Motion system

filePosition long

New file position

cancellationToken CancellationToken

Returns

Task

File position

StartSecondJob()

Start the second file job if applicable

public void StartSecondJob()