Headless CMS and Content Managment Hub
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.
 
 
 
 
 

69 lines
1.9 KiB

// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
using Squidex.Infrastructure.Reflection;
namespace Squidex.Infrastructure.EventSourcing.Grains
{
public sealed class EventConsumerState
{
public bool IsStopped { get; set; }
public int Count { get; set; }
public string? Error { get; set; }
public string? Position { get; set; }
public bool IsPaused
{
get { return IsStopped && string.IsNullOrWhiteSpace(Error); }
}
public bool IsFailed
{
get { return IsStopped && !string.IsNullOrWhiteSpace(Error); }
}
public EventConsumerState()
{
}
public EventConsumerState(string? position, int count)
{
Position = position;
Count = count;
}
public EventConsumerState Reset()
{
return new EventConsumerState();
}
public EventConsumerState Handled(string position)
{
return new EventConsumerState(position, Count + 1);
}
public EventConsumerState Stopped(Exception? ex = null)
{
return new EventConsumerState(Position, Count) { IsStopped = true, Error = ex?.ToString() };
}
public EventConsumerState Started()
{
return new EventConsumerState(Position, Count) { IsStopped = false };
}
public EventConsumerInfo ToInfo(string name)
{
return SimpleMapper.Map(this, new EventConsumerInfo { Name = name });
}
}
}