public uint Deserialize(byte[] buffer)
{
BufferReader bufferReader = new BufferReader(buffer);
uint totalBytes = 0;
if (this.CountType == CountByte.TwoBytesCount)
{
this.ActionLength = bufferReader.ReadUInt16();
totalBytes += bufferReader.Position;
bufferReader = new BufferReader(bufferReader.ReadBytes((ushort)this.ActionLength));
}
else if (this.CountType == CountByte.FourBytesCount)
{
this.ActionLength = bufferReader.ReadUInt32();
totalBytes += bufferReader.Position;
bufferReader = new BufferReader(bufferReader.ReadBytes((uint)this.ActionLength));
}
this.ActionType = (ActionType)bufferReader.ReadByte();
this.ActionFlavor = bufferReader.ReadUInt32();
this.ActionFlags = bufferReader.ReadUInt32();
totalBytes += bufferReader.Position;
byte[] tmpArray = null;
byte[] remainBuffer = bufferReader.ReadToEnd();
tmpArray = remainBuffer;
switch (this.ActionType)
{
case ActionType.OP_MOVE:
case ActionType.OP_COPY:
// On Exchange 2013, a redundant "0xff" field may be inserted before the actual Action data.
if (remainBuffer != null && remainBuffer[0] == 0xff)
{
tmpArray = new byte[remainBuffer.Length - 1];
Array.Copy(remainBuffer, 1, tmpArray, 0, remainBuffer.Length - 1);
this.ActionLength = (ushort)this.ActionLength - 1;
}
if (this.CountType == CountByte.TwoBytesCount)
{
this.ActionDataValue = new MoveCopyActionData();
}
else if (this.CountType == CountByte.FourBytesCount)
{
this.ActionDataValue = new MoveCopyActionDataOfExtendedRule();
}
break;
case ActionType.OP_REPLY:
case ActionType.OP_OOF_REPLY:
if (this.CountType == CountByte.TwoBytesCount)
{
this.ActionDataValue = new ReplyActionData();
}
else if (this.CountType == CountByte.FourBytesCount)
{
this.ActionDataValue = new ReplyActionDataOfExtendedRule();
}
break;
case ActionType.OP_DEFER_ACTION:
this.ActionDataValue = new DeferredActionData();
break;
case ActionType.OP_BOUNCE:
this.ActionDataValue = new BounceActionData();
break;
case ActionType.OP_FORWARD:
case ActionType.OP_DELEGATE:
this.ActionDataValue = new ForwardDelegateActionData(this.CountType);
break;
case ActionType.OP_TAG:
this.ActionDataValue = new TagActionData();
break;
case ActionType.OP_DELETE:
case ActionType.OP_MARK_AS_READ:
this.ActionDataValue = new DeleteMarkReadActionData();
break;
}
totalBytes += this.ActionDataValue.Deserialize(tmpArray);
return totalBytes;
}
}