Table of Contents

Class AutomaticOperatingModeBase

Namespace
Loehnert.Lisrt.OperatingMode
Assembly
Loehnert.Lisrt.dll

Represents a base class for an automatic operating mode.

public abstract class AutomaticOperatingModeBase : PropertyChangedBase, INotifyPropertyChangedEx, INotifyPropertyChanged, IOperatingMode, IHasKey
Inheritance
PropertyChangedBase
AutomaticOperatingModeBase
Implements
INotifyPropertyChangedEx
Inherited Members
PropertyChangedBase.Refresh()
PropertyChangedBase.IsNotifying
PropertyChangedBase.PropertyChanged

Examples

This is an example of a customized automatic operating mode:

[Export(typeof(IOperatingMode))]
public class AutomaticOperatingMode : AutomaticOperatingModeBase
{
    private readonly StationModule _station;

    [ImportingConstructor]
    public AutomaticOperatingMode(StationModule station)
    {
        _station = station;
        _station.PropertyChanged += StationPropertyChanged;
    }

    public override bool IsSelectable => CanEnable();

    public override bool CanEnable() => _station.InitializationState = InitializationState.Initialized;

    public override void Disable() => Stop();

    public override void Enable()
    {
        // Add your code here, that should be executed when the operating mode is enabled.
    }

    public override void Start()
    {
        // Add your code here, that should be executed when the operating mode is started by the start action.
        IsStarted = true;
    }

    public override void Stop()
    {
        // Add your code here, that should be executed when the operating mode is stopped by the stop action.
        IsStarted = false;
    }

    protected internal override bool CanStart
    {
        get { /* Add here your logic to decide, whether the mode can be started */ }
    }

    protected internal override bool CanStop
    {
        get { /* Add here your logic to decide, whether the mode can be stopped */ }
    }

    private void StationPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        if (e.PropertyName == nameof(StationModule.InitializationState))
        {
            NotifyOfPropertyChange(nameof(IsSelectable));

            // When CanStart or CanStop changes, it has to be notified.
            NotifyOfPropertyChange(nameof(CanChange));
        }
    }
}

Remarks

This operating mode contains by default a start and stop action.

Change of operating mode

Override the Start() and the Stop() methods to customize the start and stop behavior of the automatic operating mode. Whether the operating mode can be started or stopped can be customized by overriding the CanStart and CanStop methods.

Constructors

AutomaticOperatingModeBase()

Initializes a new instance of the AutomaticOperatingModeBase class.

protected AutomaticOperatingModeBase()

Properties

Actions

Gets the actions for the operating mode.

public virtual ICollection<IActionViewModel> Actions { get; }

Property Value

ICollection<IActionViewModel>

AutomaticOperatingModeKey

Gets the default key for the automatic operating mode.

public static string AutomaticOperatingModeKey { get; }

Property Value

string

CanStart

Gets a value indicating whether the mode can be started via the start action.

protected virtual bool CanStart { get; }

Property Value

bool

Remarks

Notify property changed when CanStart changes.

NotifyOfPropertyChange(nameof(CanStart));

CanStop

Gets a value indicating whether the mode can be stopped via the stop action.

protected virtual bool CanStop { get; }

Property Value

bool

Remarks

Notify property changed when CanStop changes.

NotifyOfPropertyChange(nameof(CanStop));

Description

Gets the localized description for the operating mode.

public virtual ITranslation Description { get; }

Property Value

ITranslation

Icon

Gets the icon.

public virtual Uri Icon { get; }

Property Value

Uri

IsSelectable

Gets or sets a value indicating whether the mode is selectable.

public virtual bool IsSelectable { get; protected set; }

Property Value

bool

IsSpecial

Gets or sets a value indicating whether the mode is a special one.

public bool IsSpecial { get; set; }

Property Value

bool

Remarks

If it is special, it will be just shown in the concealable fly out.

IsStarted

Gets or sets a value indicating whether the mode is started.

public bool IsStarted { get; protected set; }

Property Value

bool

Key

Gets a unique key.

public virtual string Key { get; }

Property Value

string

Methods

CanEnable()

Gets a value indicating whether the mode can be enabled.

public abstract bool CanEnable()

Returns

bool

True if it can be enabled. Otherwise false.

Disable()

Disables the mode.

public abstract void Disable()

Enable()

Enables the mode.

public abstract void Enable()

Start()

Starts the operating mode.

public abstract void Start()

Remarks

This method is executed when the user clicks the start action.

Stop()

Stops the operating mode.

public abstract void Stop()

Remarks

This method is executed when the user clicks the stop action.