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

58 lines
2.1 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; }
public string AgentId { get; set; }
public string ConversationId { get; set; }
public string ExecutionResult { get; set; }
public string Cron { get; set; }
2024-12-10 18:30:41 +00:00
public string Title { get; set; }
2024-12-09 00:29:04 +00:00
public string Description { get; set; }
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; }
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,
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,
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
};
}
}