Bamboo.Prevalence.Implementation.CommandLogWriter.WriteCommand C# (CSharp) Method

WriteCommand() public method

Writes a command to the current log file.
public WriteCommand ( ICommand command ) : void
command ICommand serializable command
return void
		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);			
		}