Commit 87ddb8ba authored by Ben Lambell's avatar Ben Lambell

Add support for serializable Actions instead of events

parent b0d63284
using Recurse.Persist.Serializables;
using System;
using System.Runtime.Serialization;
namespace Recurse.Scheduling.Events
{
[Serializable]
public class ActionEvent : SerializableAction, IEvent
{
public ActionEvent(Action action) : base(action)
{
}
public ActionEvent(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public void Occur() => Delegate();
}
}
......@@ -7,6 +7,7 @@
*/
using Recurse.Scheduling.Schedules;
using System;
namespace Recurse.Scheduling.Events.Abstract
{
......@@ -25,6 +26,10 @@ namespace Recurse.Scheduling.Events.Abstract
_event = @event;
}
public Scheduler(Action @event) : this(new ActionEvent(@event))
{
}
public void SetTime(ISchedule<TTime> schedule, TTime time)
{
ClearTime();
......
......@@ -8,6 +8,7 @@
using Recurse.Scheduling.Schedules;
using System;
namespace Recurse.Scheduling.Events.Abstract
{
......@@ -40,6 +41,11 @@ namespace Recurse.Scheduling.Events.Abstract
_event = e;
}
public TimeScheduler(ISchedule<TTime> schedule, Action e)
: this(schedule, new ActionEvent(e))
{
}
public void ClearTime() => Time = null;
}
}
using System;
using Recurse.Scheduling.Events;
using System;
using System.Collections.Generic;
namespace Recurse.Scheduling.Schedules
......@@ -53,6 +54,10 @@ namespace Recurse.Scheduling.Schedules
public bool Occurred { get; set; }
public ScheduledEvent(Action e, TTime time) : this(new ActionEvent(e), time)
{
}
public ScheduledEvent(IEvent e, TTime time)
{
Event = e;
......
using Recurse.Scheduling.Events;
using Recurse.Scheduling.Schedules;
using System;
namespace Recurse.Scheduling
{
public static class SchedulingExtensions
{
public static IScheduledEvent<TTime> SetTime<TTime>(this ISchedule<TTime> schedule, Action e, TTime time)
=> schedule.SetTime(new ActionEvent(e), time);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment