BotSharp/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/CrontabItemDocument.cs

64 lines
2.5 KiB
C#
Raw Normal View History

2024-12-09 00:29:04 +00:00
using BotSharp.Abstraction.Crontab.Models;
namespace BotSharp.Plugin.MongoStorage.Collections;
public class CrontabItemDocument : MongoBase
{
public string UserId { get; set; } = default!;
public string AgentId { get; set; } = default!;
public string ConversationId { get; set; } = default!;
public string ExecutionResult { get; set; } = default!;
public string Cron { get; set; } = default!;
public string Title { get; set; } = default!;
public string Description { get; set; } = default!;
2024-12-16 16:17:50 +00:00
public int ExecutionCount { get; set; }
public int MaxExecutionCount { get; set; }
2024-12-16 16:18:50 +00:00
public int ExpireSeconds { get; set; }
2025-01-16 22:20:00 +00:00
public DateTime? LastExecutionTime { get; set; }
public bool LessThan60Seconds { get; set; } = false;
2024-12-10 19:45:48 +00:00
public IEnumerable<CronTaskMongoElement> Tasks { get; set; } = [];
2024-12-09 00:29:04 +00:00
public DateTime CreatedTime { get; set; } = DateTime.UtcNow;
public static CrontabItem ToDomainModel(CrontabItemDocument item)
{
return new CrontabItem
{
UserId = item.UserId,
AgentId = item.AgentId,
ConversationId = item.ConversationId,
ExecutionResult = item.ExecutionResult,
Cron = item.Cron,
2024-12-10 18:30:41 +00:00
Title = item.Title,
2024-12-09 00:29:04 +00:00
Description = item.Description,
2024-12-16 16:17:50 +00:00
ExecutionCount = item.ExecutionCount,
MaxExecutionCount = item.MaxExecutionCount,
ExpireSeconds = item.ExpireSeconds,
2025-01-16 22:20:00 +00:00
LastExecutionTime = item.LastExecutionTime,
LessThan60Seconds = item.LessThan60Seconds,
2024-12-10 19:45:48 +00:00
Tasks = item.Tasks?.Select(x => CronTaskMongoElement.ToDomainElement(x))?.ToArray() ?? [],
2024-12-09 00:29:04 +00:00
CreatedTime = item.CreatedTime
};
}
public static CrontabItemDocument ToMongoModel(CrontabItem item)
{
return new CrontabItemDocument
{
UserId = item.UserId,
AgentId = item.AgentId,
ConversationId = item.ConversationId,
ExecutionResult = item.ExecutionResult,
Cron = item.Cron,
2024-12-10 18:30:41 +00:00
Title = item.Title,
2024-12-09 00:29:04 +00:00
Description = item.Description,
2024-12-16 16:17:50 +00:00
ExecutionCount = item.ExecutionCount,
MaxExecutionCount = item.MaxExecutionCount,
ExpireSeconds = item.ExpireSeconds,
2025-01-16 22:20:00 +00:00
LastExecutionTime = item.LastExecutionTime,
LessThan60Seconds = item.LessThan60Seconds,
2024-12-10 19:45:48 +00:00
Tasks = item.Tasks?.Select(x => CronTaskMongoElement.ToMongoElement(x))?.ToList() ?? [],
2024-12-09 00:29:04 +00:00
CreatedTime = item.CreatedTime
};
}
}