Adding
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
|
||||
namespace LCU.Shared.Collections.RepoApiLib.Hosted
|
||||
{
|
||||
/**
|
||||
* Should be injected as a singleton. Can be used by a controller to queue something.
|
||||
*/
|
||||
public class HostedTaskQueue : IHostedTaskQueue
|
||||
{
|
||||
private readonly BlockingCollection<TaskSettings> _tasks = new BlockingCollection<TaskSettings>();
|
||||
|
||||
// This will not block.
|
||||
public void Enqueue(TaskSettings settings)
|
||||
{
|
||||
_tasks.Add(settings);
|
||||
}
|
||||
|
||||
// This will block.
|
||||
public TaskSettings Dequeue(CancellationToken token)
|
||||
{
|
||||
return _tasks.Take(token);
|
||||
}
|
||||
|
||||
public int GetCount()
|
||||
{
|
||||
return _tasks.Count;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
using System.Threading;
|
||||
|
||||
namespace LCU.Shared.Collections.RepoApiLib.Hosted
|
||||
{
|
||||
public interface IHostedTaskQueue
|
||||
{
|
||||
void Enqueue(TaskSettings settings);
|
||||
TaskSettings Dequeue(CancellationToken token);
|
||||
int GetCount();
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LCU.Shared.Collections.RepoApiLib.Hosted
|
||||
{
|
||||
public class TaskSettings : IValidatableObject
|
||||
{
|
||||
[Required]
|
||||
public DateTime StartDate { get; set; }
|
||||
|
||||
[Required]
|
||||
public DateTime EndDate { get; set; }
|
||||
|
||||
public string TaskUser { get; set; }
|
||||
|
||||
[Required]
|
||||
[MaxLength(25)]
|
||||
[MinLength(3)]
|
||||
public string QueueRoute { get; set; }
|
||||
|
||||
public const string SystemUser = "System";
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
var results = new List<ValidationResult>();
|
||||
|
||||
if (StartDate.Date > DateTime.Today)
|
||||
{
|
||||
results.Add(new ValidationResult("StartDate cannot be in future", new[] { "StartDate" }));
|
||||
}
|
||||
|
||||
if (EndDate.Date < StartDate.Date)
|
||||
{
|
||||
results.Add(new ValidationResult("EndDate cannot be before StartDate", new[] { "EndDate" }));
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user