Search Results for

    Show / Hide Table of Contents

    Class TaskRunnerBase

    The base class for processing and executing tasks on either a server process or the client itself

    Inheritance
    object
    TaskRunnerBase
    ClientTaskRunner
    ServerTaskRunner
    Implements
    IDisposable
    ITaskRunner
    IProcessor
    Inherited Members
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: LemonEdge.API.Core.Tasks
    Assembly: LemonEdge.API.dll
    Syntax
    public abstract class TaskRunnerBase : IDisposable, ITaskRunner, IProcessor

    Constructors

    TaskRunnerBase(IServerTask, IEntityUpdater, IReadOnlyCache, UserInfo, BusyProgressReporter, IServiceContext, CancellationTokenSource)

    Creates a new instance of a Task Runner

    Declaration
    protected TaskRunnerBase(IServerTask task, IEntityUpdater updater, IReadOnlyCache cache, UserInfo user, BusyProgressReporter reporter, IServiceContext services, CancellationTokenSource cancelSource)
    Parameters
    Type Name Description
    IServerTask task

    The instance of the task to be processed.

    IEntityUpdater updater

    A context to use by default for processing this task, thought the task can create its own contexts if required.

    IReadOnlyCache cache

    A local context cache

    UserInfo user

    The user this task should be processed under

    BusyProgressReporter reporter

    A class for logging and/or reporting progress of the task back to the client

    IServiceContext services

    The services demanded from the IServiceProvider.

    CancellationTokenSource cancelSource

    Properties

    Cache

    A local cache for performance

    Declaration
    public IReadOnlyCache Cache { get; }
    Property Value
    Type Description
    IReadOnlyCache

    CancelTokenSource

    The cancellation token for cancelling the running task.

    The task process itself must check and respond to this

    Declaration
    public CancellationTokenSource CancelTokenSource { get; }
    Property Value
    Type Description
    CancellationTokenSource

    FailedException

    If the processing of this task failed through an exception being thrown, this holds the failed exception

    Declaration
    public Exception FailedException { get; }
    Property Value
    Type Description
    Exception

    Processor

    The processor responsible for processing the Task

    Declaration
    public ITaskProcessor Processor { get; }
    Property Value
    Type Description
    ITaskProcessor

    Reporter

    A reporter to provide feedback to a log, or client depending on the context the process is running under

    Declaration
    public BusyProgressReporter Reporter { get; set; }
    Property Value
    Type Description
    BusyProgressReporter

    RunningOnServer

    Indicates if this task runner is running on a service directly connected to the database, or through a client

    Declaration
    protected abstract bool RunningOnServer { get; }
    Property Value
    Type Description
    bool

    Services

    Provides the IServiceContext giving access to core LemonEdge components.

    Declaration
    public IServiceContext Services { get; }
    Property Value
    Type Description
    IServiceContext

    Status

    The current status of the task

    Declaration
    public ServerTaskStatusEnum Status { get; }
    Property Value
    Type Description
    ServerTaskStatusEnum

    Task

    The current task being processed by this task runner

    Declaration
    public IServerTask Task { get; }
    Property Value
    Type Description
    IServerTask

    TaskData

    The current task data being processed by this task runner

    Declaration
    public IServerTaskData TaskData { get; }
    Property Value
    Type Description
    IServerTaskData

    TaskIsVirtual

    Indicates the task is a fake task not actually saved in the database, so it should not be updated

    By default this is false, indicating the processor is executing real tasks and should update their status, results, etc when complete

    When true this is used by the client to create virtual tasks to just immediately process certain tasks, but can not have their status/etc updated when complete as they do not exist
    Declaration
    protected virtual bool TaskIsVirtual { get; }
    Property Value
    Type Description
    bool

    TimeCancelled

    If this task has been cancelled this holds the datetime stamp it was cancelled

    Declaration
    public DateTime? TimeCancelled { get; }
    Property Value
    Type Description
    DateTime?

    TimeFinished

    Once this task has completed processing this holds the datetime stamp it completed

    Declaration
    public DateTime? TimeFinished { get; }
    Property Value
    Type Description
    DateTime?

    TimeStarted

    The datetime stamp the processing of this task was started

    Declaration
    public DateTime TimeStarted { get; }
    Property Value
    Type Description
    DateTime

    Updater

    A context to ensure the process can query, load and modify all LemonEdge data

    Declaration
    public IEntityUpdater Updater { get; }
    Property Value
    Type Description
    IEntityUpdater

    User

    The current logged in user the process is running under

    Declaration
    public UserInfo User { get; }
    Property Value
    Type Description
    UserInfo

    Methods

    AbortThread()

    Kills the active thread processing the task if the task was processed from RunOnNewThread()

    Declaration
    public void AbortThread()

    Cancel()

    Cancels the processing of this task. The task processor (ITaskProcessor implementation) itself must respond to the cancellation token.

    Declaration
    public Task Cancel()
    Returns
    Type Description
    Task

    CreateTaskHandler()

    Creates a new handler for processing the results of a task.

    Can be different for client handlers versus server handlers.

    Declaration
    protected abstract ITaskResultHandler CreateTaskHandler()
    Returns
    Type Description
    ITaskResultHandler

    A new handler for processing the results of a task

    CreateUpdater()

    Creates a new instance of a context for the task to process with. The caller is responsible for disposing it after use.

    Declaration
    public Task<IEntityUpdater> CreateUpdater()
    Returns
    Type Description
    Task<IEntityUpdater>

    A new instance of a context for the task to process with

    Dispose()

    Declaration
    public void Dispose()

    Dispose(bool)

    Declaration
    protected void Dispose(bool disposing)
    Parameters
    Type Name Description
    bool disposing

    DisposeManaged()

    Declaration
    protected virtual void DisposeManaged()

    FlushPendingMessages()

    Used for cleaning up a task runner before disposing of it.

    Flushes all messages against the Reporter

    Declaration
    public Task FlushPendingMessages()
    Returns
    Type Description
    Task

    InternalCreateUpdater()

    Creates a new updater context

    Declaration
    protected abstract Task<IEntityUpdater> InternalCreateUpdater()
    Returns
    Type Description
    Task<IEntityUpdater>

    A new updater context

    Kill()

    If cancel does not cancel the task within enough time, kill can be used to set the task status to cancelled preventing any other processing even if the process completes

    Declaration
    public Task Kill()
    Returns
    Type Description
    Task

    A task indicating the completion of the operation

    LogError(Exception, string)

    Writes any error processing the system to the log

    Can be overridden by implementing classes to log errors elsewhere too

    Declaration
    protected virtual void LogError(Exception ex, string msg)
    Parameters
    Type Name Description
    Exception ex

    The exception being logged

    string msg

    The message for the exception

    Run()

    Runs the processing of this Task as a task

    Declaration
    public Task Run()
    Returns
    Type Description
    Task

    A task indicating the completion of processing this Task

    RunInternal()

    Processes the Task, handling reporting, results, exceptions, and status updates

    Declaration
    protected virtual Task RunInternal()
    Returns
    Type Description
    Task

    A task indicating the completion of the Task

    RunOnNewThread()

    Runs the processing of this Task on a new thread

    Declaration
    public void RunOnNewThread()

    SetTaskData(IServerTaskData)

    Adds the specified task data as the data for this task

    Declaration
    protected void SetTaskData(IServerTaskData data)
    Parameters
    Type Name Description
    IServerTaskData data

    Implements

    IDisposable
    ITaskRunner
    IProcessor

    Extension Methods

    LinqExtensions.AsArray<T>(T)
    LinqExtensions.ToArrayOfOne<T>(T)
    LinqExtensions.ToListOfOne<T>(T)
    MiscExtensions.SetIfNotEqual<T, TP>(T, Expression<Func<T, TP>>, TP)
    WeakReferenceExtensions.WeakReference(object)
    SQLExtensions.ToSQLValue(object, bool)
    ReflectionExtensions.ClearEventInvocations(object, string)
    StringExtensions.ToCSVFormatString(object, Type)
    In this article
    Back to top © LemonEdge Technologies. All rights reserved.