public void WriteCommand(ICommand command)
{
/*
CheckOutputLog();
long current = _output.Position;
try
{
_formatter.Serialize(_output, command);
Flush(_output);
}
catch (Exception)
{
_output.SetLength(current);
throw;
}
*/
// New strategy for dealing with out of space errors,
// sometimes the _output.SetLength above would fail
// leaving the file corrupted.
// This new strategy fixes the problem by always
// growing the file before writing anything to it.
MemoryStream stream = new MemoryStream();
_formatter.Serialize(stream, command);
byte[] bytes = stream.ToArray();
CheckOutputLog();
_output.SetLength(_output.Position + bytes.Length);
_output.Write(bytes, 0, bytes.Length);
Flush(_output);
}