BITKit/Src/Core/Command Pattern/CommandPattern.cs

53 lines
1016 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using Microsoft.SqlServer.Server;
namespace BITKit.CommandPattern
{
public interface ICommand
{
void Execute();
void Undo();
}
public interface ICommandService
{
ICommand[] Commands { get; }
event Action<ICommand> OnExecute;
event Action<ICommand> OnClear;
event Action<ICommand> OnUndo;
event Action<ICommand[]> OnRelease;
void Execute(ICommand command);
void Undo();
void Undo(int count);
void Redo();
void Trace(ICommand command);
void Clear();
void Rebuild();
void Release();
}
public sealed class CommandSequence:List<ICommand>,Microsoft.SqlServer.Server.IBinarySerialize
{
public void Read(BinaryReader r)
{
Clear();
var count = r.ReadInt32();
for (var i = 0; i <count; i++)
{
Add(BITBinary.Read(r).As<ICommand>());
}
}
public void Write(BinaryWriter w)
{
w.Write(Count);
foreach (var x in this)
{
BITBinary.Write(w,x);
}
}
}
}