public PerformTimerActionCommand(Timer timer, TimerAction action)
        {
            timer.ThrowIfNull("timer");

            _timer = timer;
            _action = action;
        }
        public XElement Serialize(Timer timer, string elementName = "timer")
        {
            timer.ThrowIfNull("timer");
            elementName.ThrowIfNull("elementName");

            return new XElement(
                elementName,
                EventHandlerCollectionSerializer.Instance.Serialize(timer.EventHandlerCollection),
                new XAttribute("id", timer.Id),
                new XAttribute("name", timer.Name),
                new XAttribute("description", timer.Description),
                new XAttribute("interval", timer.Interval.ToString("c")),
                new XAttribute("state", timer.State),
                new XAttribute("elapsed", timer.ElapsedTime.ToString("c")));
        }
        public byte[] Serialize(Timer timer)
        {
            timer.ThrowIfNull("timer");

            var serializer = new CompactSerializer();

            serializer[0] = timer.Id.ToByteArray();
            serializer[1] = Encoding.UTF8.GetBytes(timer.Name);
            serializer[2] = Encoding.UTF8.GetBytes(timer.Description);
            serializer[3] = BitConverter.GetBytes(timer.Interval.Ticks);
            serializer[4] = Encoding.UTF8.GetBytes(timer.State.ToString());
            serializer[5] = BitConverter.GetBytes(timer.ElapsedTime.Ticks);
            serializer[6] = EventHandlerCollectionSerializer.Instance.Serialize(timer.EventHandlerCollection);

            return serializer.Serialize();
        }
Esempio n. 4
0
 public static PerformTimerActionCommand PerformTimerAction(Timer timer, TimerAction action)
 {
     return new PerformTimerActionCommand(timer, action);
 }