mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.6 KiB
55 lines
1.6 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
namespace Squidex.Infrastructure.EventSourcing
|
|
{
|
|
internal sealed class StreamPosition
|
|
{
|
|
public long Timestamp { get; }
|
|
|
|
public long CommitOffset { get; }
|
|
|
|
public long CommitSize { get; }
|
|
|
|
public bool IsEndOfCommit
|
|
{
|
|
get { return CommitOffset == CommitSize - 1; }
|
|
}
|
|
|
|
public StreamPosition(long timestamp, long commitOffset, long commitSize)
|
|
{
|
|
Timestamp = timestamp;
|
|
|
|
CommitOffset = commitOffset;
|
|
CommitSize = commitSize;
|
|
}
|
|
|
|
public static implicit operator string(StreamPosition position)
|
|
{
|
|
var parts = new object[]
|
|
{
|
|
position.Timestamp,
|
|
position.CommitOffset,
|
|
position.CommitSize
|
|
};
|
|
|
|
return string.Join("-", parts);
|
|
}
|
|
|
|
public static implicit operator StreamPosition(string position)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(position))
|
|
{
|
|
var parts = position.Split('-');
|
|
|
|
return new StreamPosition(long.Parse(parts[0]), long.Parse(parts[1]), long.Parse(parts[2]));
|
|
}
|
|
|
|
return new StreamPosition(0, -1, -1);
|
|
}
|
|
}
|
|
}
|
|
|