/// <summary> /// Generate fast transfer stream data. /// </summary> /// <param name="serverId">server id.</param> /// <param name="buffer">Input buffer data.</param> /// <returns>AbstractFastTransferStream object.</returns> private AbstractFastTransferStream GenerateAbstractFastTransferStream( int serverId, byte[] buffer) { using (FastTransferStream fs = new FastTransferStream(buffer, false)) { AbstractFastTransferStream afts; // Record all property list generated while deserializing. SyntacticalBase.AllPropList = new List<PropList>(); int icsStateIndex = -1; switch (this.streamType) { case FastTransferStreamType.state: State s = new State(fs); this.VerifyMarkers(s); // Insert state to the ICSStateContainer icsStateIndex = this.InsertStateDict(s); afts = new AbstractFastTransferStream(); // Get the AbstractState corresponding to the state from the fast transfer stream. AbstractState astate = this.GetAbstractState(serverId, icsStateIndex, s); // Set the AbstractState of the AbstractFastTransferStream. afts.AbstractState = new AbstractState { AbstractICSStateIndex = icsStateIndex, IdSetGiven = astate.IdSetGiven }; //// Other fields of the AbstractState of the AbstractFastTransferStream do not need. afts.StreamType = FastTransferStreamType.state; return afts; case FastTransferStreamType.attachmentContent: AttachmentContent att = new AttachmentContent(fs); this.VerifyMarkers(att); return att.GetAbstractFastTransferStream(); case FastTransferStreamType.contentsSync: ContentsSync cs = new ContentsSync(fs); this.VerifyMarkers(cs); // Insert the state of the contentsSync to the ICSStateContainer icsStateIndex = this.InsertStateDict(cs.State); afts = this.GetAbstractContentSync( serverId, icsStateIndex, cs); return afts; case FastTransferStreamType.folderContent: FolderContent fc = new FolderContent(fs); this.VerifyMarkers(fc); this.VerifyFolderReplicaInfoStructure(fc); afts = fc.GetAbstractFastTransferStream(); if (!this.existNoPermissionFolder) { afts.AbstractFolderContent.IsNoPermissionObjNotOut = false; } this.VerifyMetaProperty(afts); return afts; case FastTransferStreamType.hierarchySync: HierarchySync hs = new HierarchySync(fs); this.VerifyMarkers(hs); if (hs.FolderChangeList.Count > 0) { PropValue property = hs.FolderChangeList[hs.FolderChangeList.Count - 1].PropList.PropValues.Find(p => p.PropInfo.PropID == 0x65e3); if (property != null) { this.lastConflictInfo.PCLXFromServer = ((VarPropTypePropValue)property).ValueArray; this.VerifyPidTagPredecessorChangeList(); } } // Insert state to the ICSStateContainer icsStateIndex = this.InsertStateDict(hs.State); afts = this.GetAbstractHierachySync(serverId, hs, icsStateIndex); return afts; case FastTransferStreamType.MessageContent: MessageContent mc = new MessageContent(fs); for (int i = 0; i < mc.PropList.PropValues.Count; i++) { PropValue propValue = mc.PropList.PropValues[i]; if (propValue.PropType == 0x84b0) { CodePage codePage = new CodePage(); codePage.Deserialize(propValue.PropType); this.VerifyCodePageProperty(codePage); } } this.VerifyMarkers(mc); afts = mc.GetAbstractFastTransferStream(); this.VerifyMetaProperty(afts); return afts; case FastTransferStreamType.MessageList: MessageList ml = new MessageList(fs); afts = ml.GetAbstractFastTransferStream(); this.VerifyMetaProperty(afts); this.VerifyMarkers(ml); return afts; case FastTransferStreamType.TopFolder: TopFolder tf = new TopFolder(fs); this.VerifyMarkers(tf); afts = tf.GetAbstractFastTransferStream(); this.VerifyMetaProperty(afts); return afts; default: AdapterHelper.Site.Assert.Fail("The stream type is invalid, its value is:{0}.", this.streamType); return new AbstractFastTransferStream(); } } }
/// <summary> /// Deserialize fields from a FastTransferStream. /// </summary> /// <param name="stream">A FastTransferStream.</param> public override void Deserialize(FastTransferStream stream) { int count = 0; long lastPosi = stream.Position; this.fxdelPropList = new List<uint>(); this.messageLists = new List<MessageList>(); this.messageTupleList = new List<Tuple<List<uint>, MessageList>>(); while (!stream.IsEndOfStream && count < 2) { lastPosi = stream.Position; List<uint> metaProps = new List<uint>(); while (stream.VerifyMetaProperty(MetaProperties.PidTagFXDelProp)) { stream.ReadMarker(); uint delProp = stream.ReadUInt32(); metaProps.Add(delProp); } if (MessageList.Verify(stream)) { MessageList msgList = new MessageList(stream); this.messageLists.Add(msgList); this.fxdelPropList.AddRange(metaProps); this.messageTupleList.Add(new Tuple<List<uint>, MessageList>( metaProps, msgList)); } else { stream.Position = lastPosi; break; } count++; } }