mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Adds the media consumption record aggregate
This commit is contained in:
1 parent
b2d274f609
commit
fa8513cc71
17 files changed
+872
No files matched your search
@@ -0,0 +1,29 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Errors;
|
||||
|
||||
/// <summary>
|
||||
/// Media consumption error types.
|
||||
/// </summary>
|
||||
public static partial class Errors
|
||||
{
|
||||
public static class MediaConsumption
|
||||
{
|
||||
public static Error UnsupportedMediaKind => Error.Validation(description: nameof(UnsupportedMediaKind));
|
||||
public static Error MediaKindCannotStartCompleted => Error.Forbidden(description: nameof(MediaKindCannotStartCompleted));
|
||||
public static Error InvalidMediaPosition => Error.Validation(description: nameof(InvalidMediaPosition));
|
||||
public static Error InvalidProgressFraction => Error.Validation(description: nameof(InvalidProgressFraction));
|
||||
public static Error ConsumedDurationMustBeNonNegative => Error.Validation(description: nameof(ConsumedDurationMustBeNonNegative));
|
||||
public static Error ConsumedDurationCannotDecrease => Error.Forbidden(description: nameof(ConsumedDurationCannotDecrease));
|
||||
public static Error ConsecutivePagesReadMustBeNonNegative => Error.Validation(description: nameof(ConsecutivePagesReadMustBeNonNegative));
|
||||
public static Error ConsecutivePagesReadIsOnlySupportedForPageBasedMedia => Error.Forbidden(description: nameof(ConsecutivePagesReadIsOnlySupportedForPageBasedMedia));
|
||||
public static Error ConsumptionIsNotInProgress => Error.Conflict(description: nameof(ConsumptionIsNotInProgress));
|
||||
public static Error ConsumptionIsAlreadyTerminal => Error.Conflict(description: nameof(ConsumptionIsAlreadyTerminal));
|
||||
public static Error InProgressConsumptionCannotHaveEndTime => Error.Validation(description: nameof(InProgressConsumptionCannotHaveEndTime));
|
||||
public static Error EndedConsumptionMustHaveEndTime => Error.Validation(description: nameof(EndedConsumptionMustHaveEndTime));
|
||||
public static Error LastActivityCannotPrecedeStart => Error.Forbidden(description: nameof(LastActivityCannotPrecedeStart));
|
||||
public static Error EndedConsumptionCannotPrecedeLastActivity => Error.Forbidden(description: nameof(EndedConsumptionCannotPrecedeLastActivity));
|
||||
}
|
||||
}
|
||||
+5
@@ -40,6 +40,11 @@ public abstract class MediaConsumptionRule : ValueObject
|
||||
/// </summary>
|
||||
public bool CanResume => PositionKind.HasValue;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether a consumption session of this kind of media is a one-shot session, which completes at the moment it starts.
|
||||
/// </summary>
|
||||
public abstract bool IsOneShot { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether a consumption session of this kind of media counts towards statistics.
|
||||
/// </summary>
|
||||
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Value Object for the position reached in a media item during a consumption session.
|
||||
/// </summary>
|
||||
public sealed class MediaPosition : ValueObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the kind of representation that the position uses.
|
||||
/// </summary>
|
||||
public MediaPositionKind Kind { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the position within the media item, for positions that are expressed as a time offset.
|
||||
/// </summary>
|
||||
public Optional<TimeSpan> TimeOffset { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the opaque locator within the media item, for positions that are not expressed as a time offset, such as a reading location of a book.
|
||||
/// </summary>
|
||||
public Optional<string> Location { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MediaPosition"/> class.
|
||||
/// </summary>
|
||||
/// <param name="kind">The kind of representation that the position uses.</param>
|
||||
/// <param name="timeOffset">The position within the media item, for positions that are expressed as a time offset.</param>
|
||||
/// <param name="location">The opaque locator within the media item, for positions that are not expressed as a time offset.</param>
|
||||
private MediaPosition(MediaPositionKind kind, Optional<TimeSpan> timeOffset, Optional<string> location)
|
||||
{
|
||||
Kind = kind;
|
||||
TimeOffset = timeOffset;
|
||||
Location = location;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a position expressed as a time offset within the media item.
|
||||
/// </summary>
|
||||
/// <param name="timeOffset">The position within the media item.</param>
|
||||
/// <returns>The created <see cref="MediaPosition"/> instance.</returns>
|
||||
public static MediaPosition CreateTimeOffset(TimeSpan timeOffset)
|
||||
{
|
||||
return new MediaPosition(MediaPositionKind.TimeOffset, Optional<TimeSpan>.Some(timeOffset), Optional<string>.None());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a position expressed as an opaque locator within the media item.
|
||||
/// </summary>
|
||||
/// <param name="location">The opaque locator within the media item.</param>
|
||||
/// <returns>The created <see cref="MediaPosition"/> instance.</returns>
|
||||
public static MediaPosition CreateLocation(string location)
|
||||
{
|
||||
return new MediaPosition(MediaPositionKind.Location, Optional<TimeSpan>.None(), Optional<string>.Some(location));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of items that define equality of the object.
|
||||
/// </summary>
|
||||
/// <returns>A list of items defining the equality.</returns>
|
||||
public override IEnumerable<object?> GetEqualityComponents()
|
||||
{
|
||||
yield return Kind;
|
||||
yield return TimeOffset;
|
||||
yield return Location;
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Domain event raised when a media consumption session completes.
|
||||
/// </summary>
|
||||
/// <param name="Id">The unique identifier of the domain event.</param>
|
||||
/// <param name="MediaConsumptionRecordId">The unique identifier of the consumption record.</param>
|
||||
/// <param name="UserId">The unique identifier of the user that owns the consumption record.</param>
|
||||
/// <param name="LibraryId">The unique identifier of the media library that contains the consumed item.</param>
|
||||
/// <param name="MediaItemId">The unique identifier of the consumed media item.</param>
|
||||
/// <param name="MediaKind">The kind of media that was consumed.</param>
|
||||
/// <param name="LastPosition">The last known position for the media item, if any.</param>
|
||||
/// <param name="LastProgressFraction">The final progress fraction reported for the media item.</param>
|
||||
/// <param name="ConsumedDuration">The active duration consumed by the session.</param>
|
||||
/// <param name="ConsecutivePagesRead">The number of consecutive pages read in the session.</param>
|
||||
/// <param name="OccurredOnUtc">The date and time when the domain event occurred.</param>
|
||||
[DebuggerDisplay("MediaConsumptionRecordId: {MediaConsumptionRecordId.Value}; MediaKind: {MediaKind}")]
|
||||
public record MediaConsumptionCompletedDomainEvent(
|
||||
Guid Id,
|
||||
MediaConsumptionRecordId MediaConsumptionRecordId,
|
||||
UserId UserId,
|
||||
LibraryId LibraryId,
|
||||
MediaItemId MediaItemId,
|
||||
MediaKind MediaKind,
|
||||
Optional<MediaPosition> LastPosition,
|
||||
double LastProgressFraction,
|
||||
TimeSpan ConsumedDuration,
|
||||
int ConsecutivePagesRead,
|
||||
DateTime OccurredOnUtc
|
||||
) : IDomainEvent;
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Domain event raised when a client reports the progress of a media consumption session.
|
||||
/// </summary>
|
||||
/// <param name="Id">The unique identifier of the domain event.</param>
|
||||
/// <param name="MediaConsumptionRecordId">The unique identifier of the consumption record.</param>
|
||||
/// <param name="UserId">The unique identifier of the user that owns the consumption record.</param>
|
||||
/// <param name="LibraryId">The unique identifier of the media library that contains the consumed item.</param>
|
||||
/// <param name="MediaItemId">The unique identifier of the consumed media item.</param>
|
||||
/// <param name="MediaKind">The kind of media that is being consumed.</param>
|
||||
/// <param name="LastPosition">The last known position for the media item, if any.</param>
|
||||
/// <param name="LastProgressFraction">The last progress fraction reported by the client.</param>
|
||||
/// <param name="ConsumedDuration">The active duration consumed so far.</param>
|
||||
/// <param name="ConsecutivePagesRead">The number of consecutive pages read so far.</param>
|
||||
/// <param name="OccurredOnUtc">The date and time when the domain event occurred.</param>
|
||||
[DebuggerDisplay("MediaConsumptionRecordId: {MediaConsumptionRecordId.Value}; LastProgressFraction: {LastProgressFraction}")]
|
||||
public record MediaConsumptionProgressedDomainEvent(
|
||||
Guid Id,
|
||||
MediaConsumptionRecordId MediaConsumptionRecordId,
|
||||
UserId UserId,
|
||||
LibraryId LibraryId,
|
||||
MediaItemId MediaItemId,
|
||||
MediaKind MediaKind,
|
||||
Optional<MediaPosition> LastPosition,
|
||||
double LastProgressFraction,
|
||||
TimeSpan ConsumedDuration,
|
||||
int ConsecutivePagesRead,
|
||||
DateTime OccurredOnUtc
|
||||
) : IDomainEvent;
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Domain event raised when a media consumption session starts.
|
||||
/// </summary>
|
||||
/// <param name="Id">The unique identifier of the domain event.</param>
|
||||
/// <param name="MediaConsumptionRecordId">The unique identifier of the consumption record.</param>
|
||||
/// <param name="UserId">The unique identifier of the user that started the session.</param>
|
||||
/// <param name="LibraryId">The unique identifier of the media library that contains the consumed item.</param>
|
||||
/// <param name="MediaItemId">The unique identifier of the consumed media item.</param>
|
||||
/// <param name="MediaKind">The kind of media that is being consumed.</param>
|
||||
/// <param name="OccurredOnUtc">The date and time when the domain event occurred.</param>
|
||||
[DebuggerDisplay("MediaConsumptionRecordId: {MediaConsumptionRecordId.Value}; MediaKind: {MediaKind}")]
|
||||
public record MediaConsumptionStartedDomainEvent(
|
||||
Guid Id,
|
||||
MediaConsumptionRecordId MediaConsumptionRecordId,
|
||||
UserId UserId,
|
||||
LibraryId LibraryId,
|
||||
MediaItemId MediaItemId,
|
||||
MediaKind MediaKind,
|
||||
DateTime OccurredOnUtc
|
||||
) : IDomainEvent;
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Domain event raised when a media consumption session stops before it completes.
|
||||
/// </summary>
|
||||
/// <param name="Id">The unique identifier of the domain event.</param>
|
||||
/// <param name="MediaConsumptionRecordId">The unique identifier of the consumption record.</param>
|
||||
/// <param name="UserId">The unique identifier of the user that owns the consumption record.</param>
|
||||
/// <param name="LibraryId">The unique identifier of the media library that contains the consumed item.</param>
|
||||
/// <param name="MediaItemId">The unique identifier of the consumed media item.</param>
|
||||
/// <param name="MediaKind">The kind of media that was consumed.</param>
|
||||
/// <param name="LastPosition">The last known position for the media item, if any.</param>
|
||||
/// <param name="LastProgressFraction">The final progress fraction reported for the media item.</param>
|
||||
/// <param name="ConsumedDuration">The active duration consumed by the session.</param>
|
||||
/// <param name="ConsecutivePagesRead">The number of consecutive pages read in the session.</param>
|
||||
/// <param name="OccurredOnUtc">The date and time when the domain event occurred.</param>
|
||||
[DebuggerDisplay("MediaConsumptionRecordId: {MediaConsumptionRecordId.Value}; MediaKind: {MediaKind}")]
|
||||
public record MediaConsumptionStoppedDomainEvent(
|
||||
Guid Id,
|
||||
MediaConsumptionRecordId MediaConsumptionRecordId,
|
||||
UserId UserId,
|
||||
LibraryId LibraryId,
|
||||
MediaItemId MediaItemId,
|
||||
MediaKind MediaKind,
|
||||
Optional<MediaPosition> LastPosition,
|
||||
double LastProgressFraction,
|
||||
TimeSpan ConsumedDuration,
|
||||
int ConsecutivePagesRead,
|
||||
DateTime OccurredOnUtc
|
||||
) : IDomainEvent;
|
||||
+511
@@ -0,0 +1,511 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate;
|
||||
|
||||
/// <summary>
|
||||
/// Aggregate root for a media consumption session.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Id: {Id.Value}; MediaKind: {MediaKind}; Status: {Status}")]
|
||||
public sealed class MediaConsumptionRecord : AggregateRoot<MediaConsumptionRecordId>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the object representing the unique identifier of the user that started the consumption session.
|
||||
/// </summary>
|
||||
public UserId UserId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id of the media library that contains the consumed media item.
|
||||
/// </summary>
|
||||
public LibraryId LibraryId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id of the consumed media item.
|
||||
/// </summary>
|
||||
public MediaItemId MediaItemId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the kind of media that is consumed.
|
||||
/// </summary>
|
||||
public MediaKind MediaKind { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the state of the consumption session.
|
||||
/// </summary>
|
||||
public ConsumptionStatus Status { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time when the consumption session started.
|
||||
/// </summary>
|
||||
public DateTime StartedOnUtc { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time when the consumption session last received activity.
|
||||
/// </summary>
|
||||
public DateTime LastActivityOnUtc { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time when the consumption session completed or stopped, if it has ended.
|
||||
/// </summary>
|
||||
public Optional<DateTime> EndedOnUtc { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the active duration that the user has consumed in the session. It never decreases within one record.
|
||||
/// </summary>
|
||||
public TimeSpan ConsumedDuration { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the last position reported for the media item, if the session has a known position. The position is the latest reported one, so it may
|
||||
/// be earlier in the media item than a previously reported position.
|
||||
/// </summary>
|
||||
public Optional<MediaPosition> LastPosition { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the latest reported progress fraction of the media item. It is the latest reported value, so it may be lower than a previously reported
|
||||
/// fraction.
|
||||
/// </summary>
|
||||
public double LastProgressFraction { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of consecutive pages reported read in the current session. It is zero for every kind of media except books.
|
||||
/// </summary>
|
||||
public int ConsecutivePagesRead { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MediaConsumptionRecord"/> class.
|
||||
/// </summary>
|
||||
/// <param name="id">The object representing the unique identifier of the consumption record.</param>
|
||||
/// <param name="userId">The object representing the unique identifier of the user that started the consumption session.</param>
|
||||
/// <param name="libraryId">The Id of the media library that contains the consumed media item.</param>
|
||||
/// <param name="mediaItemId">The Id of the consumed media item.</param>
|
||||
/// <param name="mediaKind">The kind of media that is consumed.</param>
|
||||
/// <param name="status">The state of the consumption session.</param>
|
||||
/// <param name="startedOnUtc">The date and time when the consumption session started.</param>
|
||||
/// <param name="lastActivityOnUtc">The date and time when the consumption session last received activity.</param>
|
||||
/// <param name="endedOnUtc">The date and time when the consumption session completed or stopped, if it has ended.</param>
|
||||
/// <param name="consumedDuration">The active duration that the user has consumed in the session.</param>
|
||||
/// <param name="lastPosition">The last position reported for the media item, if the session has a known position.</param>
|
||||
/// <param name="lastProgressFraction">The latest reported progress fraction of the media item.</param>
|
||||
/// <param name="consecutivePagesRead">The number of consecutive pages reported read in the current session.</param>
|
||||
private MediaConsumptionRecord(
|
||||
MediaConsumptionRecordId id,
|
||||
UserId userId,
|
||||
LibraryId libraryId,
|
||||
MediaItemId mediaItemId,
|
||||
MediaKind mediaKind,
|
||||
ConsumptionStatus status,
|
||||
DateTime startedOnUtc,
|
||||
DateTime lastActivityOnUtc,
|
||||
Optional<DateTime> endedOnUtc,
|
||||
TimeSpan consumedDuration,
|
||||
Optional<MediaPosition> lastPosition,
|
||||
double lastProgressFraction,
|
||||
int consecutivePagesRead) : base(id)
|
||||
{
|
||||
Id = id;
|
||||
UserId = userId;
|
||||
LibraryId = libraryId;
|
||||
MediaItemId = mediaItemId;
|
||||
MediaKind = mediaKind;
|
||||
Status = status;
|
||||
StartedOnUtc = startedOnUtc;
|
||||
LastActivityOnUtc = lastActivityOnUtc;
|
||||
EndedOnUtc = endedOnUtc;
|
||||
ConsumedDuration = consumedDuration;
|
||||
LastPosition = lastPosition;
|
||||
LastProgressFraction = lastProgressFraction;
|
||||
ConsecutivePagesRead = consecutivePagesRead;
|
||||
CreatedOnUtc = startedOnUtc;
|
||||
UpdatedOnUtc = lastActivityOnUtc > startedOnUtc ? Optional<DateTime>.Some(lastActivityOnUtc) : Optional<DateTime>.None();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts a new consumption session for a media item.
|
||||
/// </summary>
|
||||
/// <param name="userId">The object representing the unique identifier of the user that starts the consumption session.</param>
|
||||
/// <param name="libraryId">The Id of the media library that contains the consumed media item.</param>
|
||||
/// <param name="mediaItemId">The Id of the consumed media item.</param>
|
||||
/// <param name="mediaKind">The kind of media that is consumed.</param>
|
||||
/// <param name="lastPosition">The position to initialize the session with, such as the position of an existing resume point, if any.</param>
|
||||
/// <param name="lastProgressFraction">The progress fraction to initialize the session with, such as the fraction of an existing resume point.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully started <see cref="MediaConsumptionRecord"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<MediaConsumptionRecord> Start(UserId userId, LibraryId libraryId, MediaItemId mediaItemId, MediaKind mediaKind, Optional<MediaPosition> lastPosition, double lastProgressFraction)
|
||||
{
|
||||
Optional<MediaConsumptionRule> ruleResult = MediaConsumptionRule.For(mediaKind);
|
||||
if (!ruleResult.HasValue)
|
||||
return Errors.MediaConsumption.UnsupportedMediaKind;
|
||||
if (!IsProgressFractionValid(lastProgressFraction))
|
||||
return Errors.MediaConsumption.InvalidProgressFraction;
|
||||
if (!DoesPositionMatchRule(ruleResult.Value, lastPosition))
|
||||
return Errors.MediaConsumption.InvalidMediaPosition;
|
||||
|
||||
DateTime occurredOnUtc = DateTime.UtcNow;
|
||||
MediaConsumptionRecord record = new(
|
||||
MediaConsumptionRecordId.CreateUnique(),
|
||||
userId,
|
||||
libraryId,
|
||||
mediaItemId,
|
||||
mediaKind,
|
||||
ConsumptionStatus.InProgress,
|
||||
occurredOnUtc,
|
||||
occurredOnUtc,
|
||||
Optional<DateTime>.None(),
|
||||
TimeSpan.Zero,
|
||||
lastPosition,
|
||||
lastProgressFraction,
|
||||
0);
|
||||
|
||||
record._domainEvents.Add(new MediaConsumptionStartedDomainEvent(
|
||||
Guid.NewGuid(),
|
||||
record.Id,
|
||||
userId,
|
||||
libraryId,
|
||||
mediaItemId,
|
||||
mediaKind,
|
||||
occurredOnUtc));
|
||||
return record;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts and completes a consumption session in the same call, for one-shot discrete kinds of media such as a photo view.
|
||||
/// </summary>
|
||||
/// <param name="userId">The object representing the unique identifier of the user that consumed the media item.</param>
|
||||
/// <param name="libraryId">The Id of the media library that contains the consumed media item.</param>
|
||||
/// <param name="mediaItemId">The Id of the consumed media item.</param>
|
||||
/// <param name="mediaKind">The kind of media that is consumed.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created completed <see cref="MediaConsumptionRecord"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<MediaConsumptionRecord> StartCompleted(UserId userId, LibraryId libraryId, MediaItemId mediaItemId, MediaKind mediaKind)
|
||||
{
|
||||
Optional<MediaConsumptionRule> ruleResult = MediaConsumptionRule.For(mediaKind);
|
||||
if (!ruleResult.HasValue)
|
||||
return Errors.MediaConsumption.UnsupportedMediaKind;
|
||||
if (!ruleResult.Value.IsOneShot)
|
||||
return Errors.MediaConsumption.MediaKindCannotStartCompleted;
|
||||
|
||||
DateTime occurredOnUtc = DateTime.UtcNow;
|
||||
MediaConsumptionRecord record = new(
|
||||
MediaConsumptionRecordId.CreateUnique(),
|
||||
userId,
|
||||
libraryId,
|
||||
mediaItemId,
|
||||
mediaKind,
|
||||
ConsumptionStatus.Completed,
|
||||
occurredOnUtc,
|
||||
occurredOnUtc,
|
||||
Optional<DateTime>.Some(occurredOnUtc),
|
||||
TimeSpan.Zero,
|
||||
Optional<MediaPosition>.None(),
|
||||
1,
|
||||
0);
|
||||
|
||||
record._domainEvents.Add(new MediaConsumptionStartedDomainEvent(
|
||||
Guid.NewGuid(),
|
||||
record.Id,
|
||||
userId,
|
||||
libraryId,
|
||||
mediaItemId,
|
||||
mediaKind,
|
||||
occurredOnUtc));
|
||||
record._domainEvents.Add(new MediaConsumptionCompletedDomainEvent(
|
||||
Guid.NewGuid(),
|
||||
record.Id,
|
||||
userId,
|
||||
libraryId,
|
||||
mediaItemId,
|
||||
mediaKind,
|
||||
record.LastPosition,
|
||||
record.LastProgressFraction,
|
||||
record.ConsumedDuration,
|
||||
record.ConsecutivePagesRead,
|
||||
occurredOnUtc));
|
||||
return record;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="MediaConsumptionRecord"/> class, with pre-existing data.
|
||||
/// </summary>
|
||||
/// <param name="id">The object representing the unique identifier of the consumption record.</param>
|
||||
/// <param name="userId">The object representing the unique identifier of the user that started the consumption session.</param>
|
||||
/// <param name="libraryId">The Id of the media library that contains the consumed media item.</param>
|
||||
/// <param name="mediaItemId">The Id of the consumed media item.</param>
|
||||
/// <param name="mediaKind">The kind of media that is consumed.</param>
|
||||
/// <param name="status">The state of the consumption session.</param>
|
||||
/// <param name="startedOnUtc">The date and time when the consumption session started.</param>
|
||||
/// <param name="lastActivityOnUtc">The date and time when the consumption session last received activity.</param>
|
||||
/// <param name="endedOnUtc">The date and time when the consumption session completed or stopped, if it has ended.</param>
|
||||
/// <param name="consumedDuration">The active duration that the user has consumed in the session.</param>
|
||||
/// <param name="lastPosition">The last position reported for the media item, if the session has a known position.</param>
|
||||
/// <param name="lastProgressFraction">The latest reported progress fraction of the media item.</param>
|
||||
/// <param name="consecutivePagesRead">The number of consecutive pages reported read in the current session.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully reconstituted <see cref="MediaConsumptionRecord"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<MediaConsumptionRecord> Reconstitute(
|
||||
MediaConsumptionRecordId id,
|
||||
UserId userId,
|
||||
LibraryId libraryId,
|
||||
MediaItemId mediaItemId,
|
||||
MediaKind mediaKind,
|
||||
ConsumptionStatus status,
|
||||
DateTime startedOnUtc,
|
||||
DateTime lastActivityOnUtc,
|
||||
Optional<DateTime> endedOnUtc,
|
||||
TimeSpan consumedDuration,
|
||||
Optional<MediaPosition> lastPosition,
|
||||
double lastProgressFraction,
|
||||
int consecutivePagesRead)
|
||||
{
|
||||
Optional<MediaConsumptionRule> ruleResult = MediaConsumptionRule.For(mediaKind);
|
||||
if (!ruleResult.HasValue)
|
||||
return Errors.MediaConsumption.UnsupportedMediaKind;
|
||||
if (consumedDuration < TimeSpan.Zero)
|
||||
return Errors.MediaConsumption.ConsumedDurationMustBeNonNegative;
|
||||
if (!IsProgressFractionValid(lastProgressFraction))
|
||||
return Errors.MediaConsumption.InvalidProgressFraction;
|
||||
if (consecutivePagesRead < 0)
|
||||
return Errors.MediaConsumption.ConsecutivePagesReadMustBeNonNegative;
|
||||
if (consecutivePagesRead > 0 && !IsPageBased(ruleResult.Value))
|
||||
return Errors.MediaConsumption.ConsecutivePagesReadIsOnlySupportedForPageBasedMedia;
|
||||
if (!DoesPositionMatchRule(ruleResult.Value, lastPosition))
|
||||
return Errors.MediaConsumption.InvalidMediaPosition;
|
||||
if (status == ConsumptionStatus.InProgress && endedOnUtc.HasValue)
|
||||
return Errors.MediaConsumption.InProgressConsumptionCannotHaveEndTime;
|
||||
if (status != ConsumptionStatus.InProgress && !endedOnUtc.HasValue)
|
||||
return Errors.MediaConsumption.EndedConsumptionMustHaveEndTime;
|
||||
if (lastActivityOnUtc < startedOnUtc)
|
||||
return Errors.MediaConsumption.LastActivityCannotPrecedeStart;
|
||||
if (status != ConsumptionStatus.InProgress && endedOnUtc.Value < lastActivityOnUtc)
|
||||
return Errors.MediaConsumption.EndedConsumptionCannotPrecedeLastActivity;
|
||||
|
||||
return new MediaConsumptionRecord(
|
||||
id,
|
||||
userId,
|
||||
libraryId,
|
||||
mediaItemId,
|
||||
mediaKind,
|
||||
status,
|
||||
startedOnUtc,
|
||||
lastActivityOnUtc,
|
||||
endedOnUtc,
|
||||
consumedDuration,
|
||||
lastPosition,
|
||||
lastProgressFraction,
|
||||
consecutivePagesRead);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the measured progress of an in-progress consumption session.
|
||||
/// </summary>
|
||||
/// <param name="lastPosition">The last position reported by the client, if the report carries one. When it is absent, the last known position is kept.</param>
|
||||
/// <param name="lastProgressFraction">The last progress fraction reported by the client.</param>
|
||||
/// <param name="consumedDuration">The active duration consumed so far.</param>
|
||||
/// <param name="consecutivePagesRead">The number of consecutive pages read in the current session.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful update, or an error.</returns>
|
||||
public Result<Updated> ReportProgress(Optional<MediaPosition> lastPosition, double lastProgressFraction, TimeSpan consumedDuration, int consecutivePagesRead)
|
||||
{
|
||||
if (Status != ConsumptionStatus.InProgress)
|
||||
return Errors.MediaConsumption.ConsumptionIsNotInProgress;
|
||||
|
||||
Optional<MediaConsumptionRule> ruleResult = MediaConsumptionRule.For(MediaKind);
|
||||
if (!ruleResult.HasValue)
|
||||
return Errors.MediaConsumption.UnsupportedMediaKind;
|
||||
if (!IsProgressFractionValid(lastProgressFraction))
|
||||
return Errors.MediaConsumption.InvalidProgressFraction;
|
||||
if (consumedDuration < TimeSpan.Zero)
|
||||
return Errors.MediaConsumption.ConsumedDurationMustBeNonNegative;
|
||||
if (consumedDuration < ConsumedDuration)
|
||||
return Errors.MediaConsumption.ConsumedDurationCannotDecrease;
|
||||
if (consecutivePagesRead < 0)
|
||||
return Errors.MediaConsumption.ConsecutivePagesReadMustBeNonNegative;
|
||||
if (consecutivePagesRead > 0 && !IsPageBased(ruleResult.Value))
|
||||
return Errors.MediaConsumption.ConsecutivePagesReadIsOnlySupportedForPageBasedMedia;
|
||||
if (!DoesPositionMatchRule(ruleResult.Value, lastPosition))
|
||||
return Errors.MediaConsumption.InvalidMediaPosition;
|
||||
|
||||
if (lastPosition.HasValue)
|
||||
LastPosition = lastPosition;
|
||||
LastProgressFraction = lastProgressFraction;
|
||||
ConsumedDuration = consumedDuration;
|
||||
ConsecutivePagesRead = consecutivePagesRead;
|
||||
|
||||
DateTime occurredOnUtc = GetNextActivityOnUtc();
|
||||
LastActivityOnUtc = occurredOnUtc;
|
||||
UpdatedOnUtc = Optional<DateTime>.Some(occurredOnUtc);
|
||||
_domainEvents.Add(new MediaConsumptionProgressedDomainEvent(
|
||||
Guid.NewGuid(),
|
||||
Id,
|
||||
UserId,
|
||||
LibraryId,
|
||||
MediaItemId,
|
||||
MediaKind,
|
||||
LastPosition,
|
||||
LastProgressFraction,
|
||||
ConsumedDuration,
|
||||
ConsecutivePagesRead,
|
||||
occurredOnUtc));
|
||||
return Result.Updated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks an in-progress consumption session as completed.
|
||||
/// </summary>
|
||||
/// <param name="lastPosition">The final position reported by the client, if the call carries one. When it is absent, the last known position is kept.</param>
|
||||
/// <param name="lastProgressFraction">The final progress fraction reported by the client.</param>
|
||||
/// <param name="consumedDuration">The active duration consumed by the session.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful completion, or an error.</returns>
|
||||
public Result<Updated> Complete(Optional<MediaPosition> lastPosition, double lastProgressFraction, TimeSpan consumedDuration)
|
||||
{
|
||||
if (Status != ConsumptionStatus.InProgress)
|
||||
return Errors.MediaConsumption.ConsumptionIsAlreadyTerminal;
|
||||
|
||||
Optional<MediaConsumptionRule> ruleResult = MediaConsumptionRule.For(MediaKind);
|
||||
if (!ruleResult.HasValue)
|
||||
return Errors.MediaConsumption.UnsupportedMediaKind;
|
||||
if (!IsProgressFractionValid(lastProgressFraction))
|
||||
return Errors.MediaConsumption.InvalidProgressFraction;
|
||||
if (consumedDuration < TimeSpan.Zero)
|
||||
return Errors.MediaConsumption.ConsumedDurationMustBeNonNegative;
|
||||
if (consumedDuration < ConsumedDuration)
|
||||
return Errors.MediaConsumption.ConsumedDurationCannotDecrease;
|
||||
if (!DoesPositionMatchRule(ruleResult.Value, lastPosition))
|
||||
return Errors.MediaConsumption.InvalidMediaPosition;
|
||||
|
||||
if (lastPosition.HasValue)
|
||||
LastPosition = lastPosition;
|
||||
LastProgressFraction = lastProgressFraction;
|
||||
ConsumedDuration = consumedDuration;
|
||||
Status = ConsumptionStatus.Completed;
|
||||
|
||||
DateTime occurredOnUtc = GetNextActivityOnUtc();
|
||||
EndedOnUtc = Optional<DateTime>.Some(occurredOnUtc);
|
||||
LastActivityOnUtc = occurredOnUtc;
|
||||
UpdatedOnUtc = Optional<DateTime>.Some(occurredOnUtc);
|
||||
_domainEvents.Add(new MediaConsumptionCompletedDomainEvent(
|
||||
Guid.NewGuid(),
|
||||
Id,
|
||||
UserId,
|
||||
LibraryId,
|
||||
MediaItemId,
|
||||
MediaKind,
|
||||
LastPosition,
|
||||
LastProgressFraction,
|
||||
ConsumedDuration,
|
||||
ConsecutivePagesRead,
|
||||
occurredOnUtc));
|
||||
return Result.Updated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks an in-progress consumption session as stopped before it completed.
|
||||
/// </summary>
|
||||
/// <param name="lastPosition">The final position reported by the client, if the call carries one. When it is absent, the last known position is kept.</param>
|
||||
/// <param name="lastProgressFraction">The final progress fraction reported by the client.</param>
|
||||
/// <param name="consumedDuration">The active duration consumed by the session.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful stop, or an error.</returns>
|
||||
public Result<Updated> Stop(Optional<MediaPosition> lastPosition, double lastProgressFraction, TimeSpan consumedDuration)
|
||||
{
|
||||
if (Status != ConsumptionStatus.InProgress)
|
||||
return Errors.MediaConsumption.ConsumptionIsAlreadyTerminal;
|
||||
|
||||
Optional<MediaConsumptionRule> ruleResult = MediaConsumptionRule.For(MediaKind);
|
||||
if (!ruleResult.HasValue)
|
||||
return Errors.MediaConsumption.UnsupportedMediaKind;
|
||||
if (!IsProgressFractionValid(lastProgressFraction))
|
||||
return Errors.MediaConsumption.InvalidProgressFraction;
|
||||
if (consumedDuration < TimeSpan.Zero)
|
||||
return Errors.MediaConsumption.ConsumedDurationMustBeNonNegative;
|
||||
if (consumedDuration < ConsumedDuration)
|
||||
return Errors.MediaConsumption.ConsumedDurationCannotDecrease;
|
||||
if (!DoesPositionMatchRule(ruleResult.Value, lastPosition))
|
||||
return Errors.MediaConsumption.InvalidMediaPosition;
|
||||
|
||||
if (lastPosition.HasValue)
|
||||
LastPosition = lastPosition;
|
||||
LastProgressFraction = lastProgressFraction;
|
||||
ConsumedDuration = consumedDuration;
|
||||
Status = ConsumptionStatus.Stopped;
|
||||
|
||||
DateTime occurredOnUtc = GetNextActivityOnUtc();
|
||||
EndedOnUtc = Optional<DateTime>.Some(occurredOnUtc);
|
||||
LastActivityOnUtc = occurredOnUtc;
|
||||
UpdatedOnUtc = Optional<DateTime>.Some(occurredOnUtc);
|
||||
_domainEvents.Add(new MediaConsumptionStoppedDomainEvent(
|
||||
Guid.NewGuid(),
|
||||
Id,
|
||||
UserId,
|
||||
LibraryId,
|
||||
MediaItemId,
|
||||
MediaKind,
|
||||
LastPosition,
|
||||
LastProgressFraction,
|
||||
ConsumedDuration,
|
||||
ConsecutivePagesRead,
|
||||
occurredOnUtc));
|
||||
return Result.Updated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the progress fraction is a finite value between zero and one.
|
||||
/// </summary>
|
||||
/// <param name="progressFraction">The progress fraction to check.</param>
|
||||
/// <returns><see langword="true"/> if the progress fraction is valid, <see langword="false"/> otherwise.</returns>
|
||||
private static bool IsProgressFractionValid(double progressFraction)
|
||||
{
|
||||
return double.IsFinite(progressFraction) && progressFraction >= 0 && progressFraction <= 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the rule of the media kind counts its sessions by the number of consecutive pages read.
|
||||
/// </summary>
|
||||
/// <param name="rule">The consumption rule of the media kind.</param>
|
||||
/// <returns><see langword="true"/> if the rule is page based, <see langword="false"/> otherwise.</returns>
|
||||
private static bool IsPageBased(MediaConsumptionRule rule)
|
||||
{
|
||||
return rule is PageThresholdConsumptionRule;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether a reported position uses the position representation of the consumption rule of the media kind.
|
||||
/// </summary>
|
||||
/// <param name="rule">The consumption rule of the media kind.</param>
|
||||
/// <param name="lastPosition">The reported position, if the report carries one.</param>
|
||||
/// <returns><see langword="true"/> if the position is valid for the media kind, <see langword="false"/> otherwise.</returns>
|
||||
private static bool DoesPositionMatchRule(MediaConsumptionRule rule, Optional<MediaPosition> lastPosition)
|
||||
{
|
||||
if (!lastPosition.HasValue)
|
||||
return true;
|
||||
return rule.PositionKind.HasValue && lastPosition.Value.Kind == rule.PositionKind.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current UTC date and time, advanced past the last recorded activity so that activity timestamps never go backwards. When the last
|
||||
/// recorded activity is already the maximum representable timestamp, that timestamp is returned instead of advancing it.
|
||||
/// </summary>
|
||||
/// <returns>The date and time of the new activity.</returns>
|
||||
private DateTime GetNextActivityOnUtc()
|
||||
{
|
||||
DateTime utcNow = DateTime.UtcNow;
|
||||
if (utcNow > LastActivityOnUtc)
|
||||
return utcNow;
|
||||
if (LastActivityOnUtc == DateTime.MaxValue)
|
||||
return DateTime.MaxValue;
|
||||
return LastActivityOnUtc.AddTicks(1);
|
||||
}
|
||||
}
|
||||
+5
@@ -28,6 +28,11 @@ public sealed class AudiobookConsumptionRule : DurationThresholdConsumptionRule
|
||||
/// </summary>
|
||||
public override Optional<MediaPositionKind> PositionKind { get; } = MediaPositionKind.TimeOffset;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether a consumption session of this kind of media is a one-shot session, which completes at the moment it starts.
|
||||
/// </summary>
|
||||
public override bool IsOneShot { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the minimum consumed duration that a session of this kind of media must reach to be counted, when it is not completed.
|
||||
/// </summary>
|
||||
|
||||
+5
@@ -27,6 +27,11 @@ public sealed class BookConsumptionRule : PageThresholdConsumptionRule
|
||||
/// </summary>
|
||||
public override Optional<MediaPositionKind> PositionKind { get; } = MediaPositionKind.Location;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether a consumption session of this kind of media is a one-shot session, which completes at the moment it starts.
|
||||
/// </summary>
|
||||
public override bool IsOneShot { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the minimum number of consecutive pages that a session of this kind of media must read to be counted, when it is not completed.
|
||||
/// </summary>
|
||||
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Value Object for the Id of a media consumption record.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{Value}")]
|
||||
public sealed class MediaConsumptionRecordId : EntityId<Guid>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MediaConsumptionRecordId"/> class.
|
||||
/// </summary>
|
||||
/// <param name="value">The value representing this object.</param>
|
||||
private MediaConsumptionRecordId(Guid value) : base(value)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="MediaConsumptionRecordId"/> class.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="MediaConsumptionRecordId"/> instance.</returns>
|
||||
public static MediaConsumptionRecordId CreateUnique()
|
||||
{
|
||||
return new MediaConsumptionRecordId(Guid.NewGuid());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="MediaConsumptionRecordId"/> class, from a pre-existing <paramref name="value"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value used to create the <see cref="MediaConsumptionRecordId"/> instance.</param>
|
||||
/// <returns>The created <see cref="MediaConsumptionRecordId"/> instance.</returns>
|
||||
public static MediaConsumptionRecordId Create(Guid value)
|
||||
{
|
||||
return new MediaConsumptionRecordId(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of items that define equality of the object.
|
||||
/// </summary>
|
||||
/// <returns>A list of items defining the equality.</returns>
|
||||
public override IEnumerable<object> GetEqualityComponents()
|
||||
{
|
||||
yield return Value;
|
||||
}
|
||||
}
|
||||
+5
@@ -28,6 +28,11 @@ public sealed class MovieConsumptionRule : DurationThresholdConsumptionRule
|
||||
/// </summary>
|
||||
public override Optional<MediaPositionKind> PositionKind { get; } = MediaPositionKind.TimeOffset;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether a consumption session of this kind of media is a one-shot session, which completes at the moment it starts.
|
||||
/// </summary>
|
||||
public override bool IsOneShot { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the minimum consumed duration that a session of this kind of media must reach to be counted, when it is not completed.
|
||||
/// </summary>
|
||||
|
||||
+5
@@ -28,6 +28,11 @@ public sealed class MusicTrackConsumptionRule : DurationThresholdConsumptionRule
|
||||
/// </summary>
|
||||
public override Optional<MediaPositionKind> PositionKind { get; } = MediaPositionKind.TimeOffset;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether a consumption session of this kind of media is a one-shot session, which completes at the moment it starts.
|
||||
/// </summary>
|
||||
public override bool IsOneShot { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the minimum consumed duration that a session of this kind of media must reach to be counted, when it is not completed.
|
||||
/// </summary>
|
||||
|
||||
+5
@@ -26,4 +26,9 @@ public sealed class PhotoConsumptionRule : EverySessionConsumptionRule
|
||||
/// Gets the kind of position used to resume this kind of media. A photo cannot be resumed, so it has no position kind.
|
||||
/// </summary>
|
||||
public override Optional<MediaPositionKind> PositionKind { get; } = Optional<MediaPositionKind>.None();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether a consumption session of this kind of media is a one-shot session, which completes at the moment it starts.
|
||||
/// </summary>
|
||||
public override bool IsOneShot { get; } = true;
|
||||
}
|
||||
+5
@@ -28,6 +28,11 @@ public sealed class PodcastEpisodeConsumptionRule : DurationThresholdConsumption
|
||||
/// </summary>
|
||||
public override Optional<MediaPositionKind> PositionKind { get; } = MediaPositionKind.TimeOffset;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether a consumption session of this kind of media is a one-shot session, which completes at the moment it starts.
|
||||
/// </summary>
|
||||
public override bool IsOneShot { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the minimum consumed duration that a session of this kind of media must reach to be counted, when it is not completed.
|
||||
/// </summary>
|
||||
|
||||
+5
@@ -28,6 +28,11 @@ public sealed class TvEpisodeConsumptionRule : DurationThresholdConsumptionRule
|
||||
/// </summary>
|
||||
public override Optional<MediaPositionKind> PositionKind { get; } = MediaPositionKind.TimeOffset;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether a consumption session of this kind of media is a one-shot session, which completes at the moment it starts.
|
||||
/// </summary>
|
||||
public override bool IsOneShot { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the minimum consumed duration that a session of this kind of media must reach to be counted, when it is not completed.
|
||||
/// </summary>
|
||||
|
||||
+5
@@ -28,6 +28,11 @@ public sealed class VideoConsumptionRule : DurationThresholdConsumptionRule
|
||||
/// </summary>
|
||||
public override Optional<MediaPositionKind> PositionKind { get; } = MediaPositionKind.TimeOffset;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether a consumption session of this kind of media is a one-shot session, which completes at the moment it starts.
|
||||
/// </summary>
|
||||
public override bool IsOneShot { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the minimum consumed duration that a session of this kind of media must reach to be counted, when it is not completed.
|
||||
/// </summary>
|
||||
|
||||
Reference in new issue
Block a user