Changes API: How to Subscribe to Operation Changes

The following methods allow you to subscribe to operation changes:

ForOperation

Operation changes for one operation can be observed using the ForOperationId method.

Syntax

IChangesObservable<OperationStatusChange> ForOperationId(long operationId);
Parameters
operationId long ID of an operation for which notifications will be processed.
Return value
IChangesObservable<OperationStatusChange> Observable that allows you to add subscriptions to notifications for an operation with a given ID.

Example

IDisposable subscription = store
    .Changes()
    .ForOperationId(operationId)
    .Subscribe(
        change =>
        {
            switch (change.State.Status)
            {
                case OperationStatus.InProgress:
                    //Do Something
                    break;
                case OperationStatus.Completed:
                    //Do Something
                    break;
                case OperationStatus.Faulted:
                    //Do Something
                    break;
                case OperationStatus.Canceled:
                    //Do Something
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        });

ForAllOperations

Operations changes for all Operations can be observed using the ForAllOperations method.

Return Value
IChangesObservable<OperationStatusChange> Observable that allows to add subscriptions to notifications for all operations.

Syntax

IChangesObservable<OperationStatusChange> ForAllOperations();

Example

IDisposable subscription = store
    .Changes()
    .ForAllOperations()
    .Subscribe(change => Console.WriteLine("Operation #{1} reports progress: {0}", change.State.Progress.ToJson(), change.OperationId));

OperationChange

Properties

Name Type Description
State OperationState Operation state
OperationId long Operation ID

OperationState

Members

Name Type Description
Result IOperationResult Operation result
Progress IOperationProgress Instance of IOperationProgress (json representation of the progress)
Status OperationStatus Operation status

OperationResult

Members

Name Type Description
Message string Operation message
ShouldPersist bool determine whether or not the result should be saved in the storage

OperationStatus

OperationStatus (enum)

Name Description
InProgress Indicates that the operation made progress
Completed Indicates that the operation has completed
Faulted Indicates that the operation is faulted
Canceled Indicates that the operation has been Canceled

Remarks

To get more method overloads, especially ones supporting delegates, please add the System.Reactive.Core package to your project.