/// <summary> /// Load sync content from the sync command buffer in Fcade.CommandsToSend. /// </summary> /// <param name="syncML"></param> private void LoadSyncContent(SyncMLSyncML syncML) { SyncMLSync syncContent = SyncMLSync.Create(); syncContent.CmdID = syncML.NextCmdID; syncContent.Source.LocURI.Content = Facade.LocalDataSource.DataSourceName; syncContent.Target.LocURI.Content = Facade.ContactDataSourceAtServer; if (numberOfChanges > 0) { syncContent.NumberOfChanges.Content = numberOfChanges.ToString(); } Facade.ExtractNextCommands(syncContent.Commands); foreach (SyncMLCommand command in syncContent.Commands) { command.CmdID = syncML.NextCmdID; //commands from XmlToSyncMLSyncCommands does not contain CmdID CommandAndStatusRegister.Add(command); } syncML.Body.Commands.Add(syncContent); CommandAndStatusRegister.Add(syncContent); numberOfCommandsToSend = syncContent.Commands.Count; }
/// <summary> /// The derived class might need to call CleanUp in ProcessResponse. /// </summary> protected void CleanUp() { if ((!ServerSyncML.Body.HasFinal) && // server should has more (Facade.ResponseCommandPool.Count < 2) && //there's no command to send except the status for server's SyncHdr (ClientSyncML.Body.HasFinal)) // last client message has final { SyncMLAlert alert = SyncMLAlert.Create(); alert.CmdID = ClientSyncML.NextCmdID; alert.Data.Content = "222"; SyncMLItem item = SyncMLItem.Create(); item.Target.LocURI.Content = Facade.ContactDataSourceAtServer; item.Source.LocURI.Content = Facade.LocalDataSource.DataSourceName; alert.ItemCollection.Add(item); Facade.ResponseCommandPool.Add(alert); CommandAndStatusRegister.Add(alert); Facade.clientRequestMore = true; } //7: while (Facade.ResponseCommandPool.Count > 1)//if there's only one which is for Status with Hdr, no need to send back { CleaningUpStep mapStep = new CleaningUpStep(Facade); mapStep.Send(); } }
private SyncMLSyncML CreateSyncRequestMessage(SyncType syncType) { SyncMLAlert alert = CreateSyncAlert(syncType); ClientSyncML.Body.Commands.Add(alert); CommandAndStatusRegister.Add(alert); return(ClientSyncML); }
/// <summary> /// Load sync content from the sync command buffer in Fcade.CommandsToSend. /// </summary> /// <param name="syncML"></param> protected void LoadSyncContent(SyncMLSyncML syncML) { SyncMLSync syncContent = SyncMLSync.Create(); syncContent.CmdID = syncML.NextCmdID; syncContent.Source.LocURI.Content = Facade.LocalDataSource.DataSourceName; syncContent.Target.LocURI.Content = Facade.ContactDataSourceAtServer; syncML.Body.Commands.Add(syncContent); CommandAndStatusRegister.Add(syncContent); }
public override void Send() { CreateSyncRequestMessage(Facade.SyncType); CommandAndStatusRegister.Add( AddGetDeviceInfo(ClientSyncML)); CommandAndStatusRegister.Add( AddPutDeviceInfo(ClientSyncML)); ClientSyncML.Body.MarkFinal(); Debug.WriteLine("Sending LogOn:" + ClientSyncML.Xml.ToString()); string responseText = Facade.Connections.GetResponseText(ClientSyncML.Xml.ToString(SaveOptions.DisableFormatting)); if (String.IsNullOrEmpty(responseText)) { return; } Facade.CurrentMsgID++; ProcessResponse(responseText); }
protected override bool ProcessResponse(string text) { if (!base.ProcessResponse(text)) { return(false); } // So now syncml model is created from text UpdateCurrentURI(ServerSyncML); //0: Always have a status response to the SyncHdr of the server message. However, this status may not be sent back if it is the only one in the queue. SyncMLStatus responseStatus = SyncMLStatus.Create(); responseStatus.MsgRef.Content = ServerSyncML.Hdr.MsgID.Content; responseStatus.Data.Content = "200"; responseStatus.Cmd.Content = "SyncHdr"; responseStatus.CmdRef.Content = "0"; responseStatus.TargetRefCollection.Add(SyncMLSimpleElementFactory.Create <SyncMLTargetRef>(ServerSyncML.Hdr.Target.LocURI.Content)); responseStatus.SourceRefCollection.Add(SyncMLSimpleElementFactory.Create <SyncMLSourceRef>(ServerSyncML.Hdr.Source.LocURI.Content)); Facade.ResponseCommandPool.Add(responseStatus);//respond in next request. //1: Handle returned status commands Collection <SyncMLStatus> serverStatusCommands = AccessBody.GetStatusCommands(ServerSyncML); foreach (SyncMLStatus status in serverStatusCommands) { CommandAndStatusRegister.RegisterStatus(status.CmdRef.Content, status.Data.Content); HandleServerStatus(status); //this fn is still abstract here. Derived classes have different ways of handling. } //2: Prepare status commands for returned Alert commands. Derived classes then handle the alerts all the same way. Collection <SyncMLAlert> serverAlertCommands = AccessBody.GetAlertCommands(ServerSyncML); foreach (SyncMLAlert alert in serverAlertCommands) { Debug.WriteLine("Alert:" + alert.Xml.ToString()); PrepareStatusForReturnedAlert(alert); } //3: Handle returned Sync command. Derived classes handle sync commands the same way. SyncMLSync serverSyncCommand = AccessBody.GetSyncCommand(ServerSyncML); if (serverSyncCommand != null) { string numberOfChangesStr = serverSyncCommand.NumberOfChanges.Content; if (!String.IsNullOrEmpty(numberOfChangesStr)) {//where numberOfChanges > 0, display progress bar in GUI. Facade.totalNumberOfChangesReceiving = Convert.ToInt32(numberOfChangesStr); if (Facade.totalNumberOfChangesReceiving > 0) { Facade.DisplayOperationMessage(String.Format("Total number of changes received from the server: {0}", numberOfChangesStr)); Facade.InitProgressBarReceiving(0, Facade.totalNumberOfChangesReceiving, 1); Facade.DisplayStageMessageReceiving(String.Format("Receiving {0} updates ...", Facade.totalNumberOfChangesReceiving)); } } int numbersOfChangesThisMessage = serverSyncCommand.Commands.Count; // the server might send in multiple messages Facade.numberOfChangesReceived += numbersOfChangesThisMessage; if (Facade.numberOfChangesReceived == Facade.totalNumberOfChangesReceiving) { Facade.DisplayStageMessageReceiving("Receiving Done"); } GenerateStatusCommandsForSyncCommand(serverSyncCommand); if (Facade.GracefulStop) { return(true); // simply return, ture of false is meaningless. } Facade.IncrementProgressBarReceiving(numbersOfChangesThisMessage); ApplySyncCommandToLocal(serverSyncCommand); } //4: Verify if the server return all status codes to commands sent if (!CommandAndStatusRegister.IsAllCommandsReturnedWithStatus()) { Trace.TraceInformation("!!!! Not all commands got status code. Please check the log for details."); Trace.TraceInformation("Commands without status: " + CommandAndStatusRegister.CommandsXmlWithoutStatus); //It is expected CommandAndStatusRegister is not used any more, otherwise, should clear it here. } //5: At the end, do what the server ask to do, likely a new SyncML message to be sent ProcessServerAlertCommands(serverAlertCommands); return(true); }