MeshWeaver.Activities.Contract 2.0.3

dotnet add package MeshWeaver.Activities.Contract --version 2.0.3
                    
NuGet\Install-Package MeshWeaver.Activities.Contract -Version 2.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MeshWeaver.Activities.Contract" Version="2.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MeshWeaver.Activities.Contract" Version="2.0.3" />
                    
Directory.Packages.props
<PackageReference Include="MeshWeaver.Activities.Contract" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MeshWeaver.Activities.Contract --version 2.0.3
                    
#r "nuget: MeshWeaver.Activities.Contract, 2.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=MeshWeaver.Activities.Contract&version=2.0.3
                    
Install MeshWeaver.Activities.Contract as a Cake Addin
#tool nuget:?package=MeshWeaver.Activities.Contract&version=2.0.3
                    
Install MeshWeaver.Activities.Contract as a Cake Tool

MeshWeaver.Activities.Contract

MeshWeaver.Activities.Contract defines the core interfaces, models, and contracts for the Activities framework. This library serves as the API contract between activity implementations and consumers.

Overview

The library provides:

  • Core activity interfaces
  • Activity status models
  • Progress tracking contracts
  • Error handling definitions

Core Concepts

Activity

The base unit of work that can be monitored and logged:

public interface IActivity
{
    string Name { get; }
    Task<ActivityLog> Complete(Action<ActivityLog> onComplete = null);
    IActivity StartSubActivity(string name);
    void LogInformation(string message);
}

ActivityLog

Records the state and results of an activity:

public record ActivityLog
{
    public ActivityStatus Status { get; init; }
    public string Message { get; init; }
    public IDictionary<string, ActivityLog> SubActivities { get; init; }
}

ActivityStatus

public enum ActivityStatus
{
    NotStarted,
    InProgress,
    Succeeded,
    Failed,
    Cancelled
}

Usage Examples

Basic Activity

// Create a new activity
var activity = new Activity("MyActivity", messageHub);

// Log information during execution
activity.LogInformation("Processing started");

// Complete the activity
await activity.Complete(log => 
{
    // Log will have Succeeded status
    // Can perform final checks or logging
});

Sub-Activities

// Create main activity
var activity = new Activity("MyActivity", messageHub);

// Create and use a sub-activity
var subActivity = activity.StartSubActivity("SubProcess");
subActivity.LogInformation("Sub-process running");

// Complete sub-activity first
await subActivity.Complete();

// Then complete main activity
await activity.Complete(log => 
{
    // Main activity log will include sub-activity logs
    log.SubActivities.Should().HaveCount(1);
    log.SubActivities.First().Value.Status.Should().Be(ActivityStatus.Succeeded);
});

Auto-Completion

Activities support automatic completion of sub-activities:

var activity = new Activity("MyActivity", messageHub);
var subActivity = activity.StartSubActivity("SubProcess");

// Start completion of main activity
var completionTask = activity.Complete();

// Complete sub-activity
await subActivity.Complete();

// Main activity completes automatically after sub-activity
await activity.Complete(log => 
{
    log.Status.Should().Be(ActivityStatus.Succeeded);
    log.SubActivities.Should().HaveCount(1);
});

Integration

With Message Hub

Activities are designed to work with the MeshWeaver message hub system.


## Related Projects

- [MeshWeaver.Activities](../MeshWeaver.Activities/README.md) - Implementation of the activity framework
- MeshWeaver.Import - Import functionality using activity contracts
- MeshWeaver.Data - Data management with activity tracking
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on MeshWeaver.Activities.Contract:

Package Downloads
MeshWeaver.Messaging.Contract

Package Description

MeshWeaver.Activities

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.3 551 3/24/2025
2.0.2 547 3/24/2025
2.0.1 202 3/21/2025
2.0.0 237 3/20/2025
2.0.0-preview3 191 2/28/2025
2.0.0-Preview2 235 2/10/2025
2.0.0-preview1 227 1/6/2025
1.0.1 283 10/8/2024
1.0.0 269 10/8/2024