Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;

namespace Aspire.Hosting.Publishing;

/// <summary>
/// Minimalistic reporter that does nothing.
/// </summary>
[Experimental("ASPIREPUBLISHERS001")]
public sealed class NullPublishingActivityProgressReporter : IPublishingActivityProgressReporter
{
/// <summary>
/// Gets the singleton instance of <see cref="NullPublishingActivityProgressReporter"/>.
/// </summary>
public static NullPublishingActivityProgressReporter Instance { get; } = new NullPublishingActivityProgressReporter();

private NullPublishingActivityProgressReporter()
{
}

/// <inheritdoc/>
public Task<PublishingActivity> CreateActivityAsync(string id, string initialStatusText, bool isPrimary, CancellationToken cancellationToken)
{
var activity = new PublishingActivity(id, isPrimary);
activity.LastStatus = new PublishingActivityStatus
{
Activity = activity,
StatusText = initialStatusText,
IsComplete = false,
IsError = false
};

return Task.FromResult(activity);
}

/// <inheritdoc/>
public Task UpdateActivityStatusAsync(PublishingActivity publishingActivity, Func<PublishingActivityStatus, PublishingActivityStatus> statusUpdate, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ namespace Aspire.Hosting.Publishing;
[Experimental("ASPIREPUBLISHERS001")]
public sealed class PublishingActivity
{
internal PublishingActivity(string id, bool isPrimary = false)
/// <summary>
/// Initializes a new instance of the <see cref="PublishingActivity"/> class.
/// </summary>
/// <param name="id">The unique identifier for the publishing activity.</param>
/// <param name="isPrimary">Indicates whether this activity is the primary activity.</param>
public PublishingActivity(string id, bool isPrimary = false)
{
Id = id;
IsPrimary = isPrimary;
Expand All @@ -33,7 +38,7 @@ internal PublishingActivity(string id, bool isPrimary = false)
/// <summary>
/// The status text of the publishing activity.
/// </summary>
public PublishingActivityStatus? LastStatus { get; internal set; }
public PublishingActivityStatus? LastStatus { get; set; }
}

/// <summary>
Expand Down Expand Up @@ -79,7 +84,7 @@ public interface IPublishingActivityProgressReporter
/// <returns>The publishing activity</returns>
/// <remarks>
/// When an activity is created the <paramref name="isPrimary"/> flag indicates whether this
/// activity is the primary activity. When the primary activity is completed any laumcher
/// activity is the primary activity. When the primary activity is completed any launcher
/// which is reading activities will stop listening for updates.
/// </remarks>
Task<PublishingActivity> CreateActivityAsync(string id, string initialStatusText, bool isPrimary, CancellationToken cancellationToken);
Expand Down Expand Up @@ -152,4 +157,4 @@ public async Task UpdateActivityStatusAsync(PublishingActivity publishingActivit
}

internal Channel<PublishingActivityStatus> ActivityStatusUpdated { get; } = Channel.CreateUnbounded<PublishingActivityStatus>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#pragma warning disable ASPIREPUBLISHERS001

using Aspire.Hosting.Publishing;
using Xunit;

namespace Aspire.Hosting.Tests.Publishing;

public class NullPublishingActivityProgressReporterTests
{
[Fact]
public async Task CanUseNullReporter()
{
var reporter = NullPublishingActivityProgressReporter.Instance;
var activity = await reporter.CreateActivityAsync("1", "initial", isPrimary: true, default);
await reporter.UpdateActivityStatusAsync(activity, (status) => status with { IsComplete = true }, default);

Assert.NotNull(activity);
}
}