/// <summary> /// Send pending commands to the server. If no pending commands, do nothing. /// </summary> public override void Send() { SyncMLSyncML syncml = CreateMessageFromCommandsPool(); // the returned message might contain responses to previous server message. if (syncml == null) // If no more command to send, don't do any thing. { return; } syncml.Hdr.Target.LocURI.Content = Facade.BasicUriText; //Facade.CurrentRespUri; if (!Facade.clientRequestMore) { syncml.Body.MarkFinal();// This is to create Final in body. } else { Facade.clientRequestMore = false; } Debug.WriteLine("Sending Cleaning up:" + syncml.Xml.ToString()); string responseText = Facade.Connections.GetResponseText(syncml.Xml.ToString(SaveOptions.DisableFormatting)); if (String.IsNullOrEmpty(responseText)) { return; } // Increase CurrentMsgID for next message sent to the server Facade.CurrentMsgID++; ProcessResponse(responseText); }
/// <summary> /// Process response from server to establish SyncML models as a SyncMLSyncML object. /// The inherited function should call the base first, then analyze the model. /// If the response has fatal error, it is signaled through serverSyncML== null. /// </summary> /// <param name="text">True if success. If fail, ServerSyncML is null. </param> protected virtual bool ProcessResponse(string text) { Debug.WriteLine("ProcessResponse from server: " + text); try { ServerSyncML = SyncMLSyncML.Create(XElement.Parse(text)); } catch (XmlException) { Trace.TraceInformation("The server returns no SyncML but this: " + text); Facade.DisplayOperationMessage("The connection fail. Please check the server URL."); ServerSyncML = null; } catch (ArgumentNullException) { Trace.TraceInformation("The server return invalid or incomplete SyncML message:" + text); ServerSyncML = null; // up to this point, SyncMLSyncML object has been created though elements are not right. } catch (Exception e) { Trace.TraceWarning("When ProcessResponse (General Exception caught): " + e.ToString()); ServerSyncML = null; // serverSyncML might be created already. } if (ServerSyncML == null) { Facade.SoFarOK = false; return(false); } else { return(true); } }
/// <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; }
protected void AddMD5Credential(SyncMLSyncML syncml) { Debug.WriteLine("Next nonce from server is: " + Facade.Md5NextNonceFromServer); syncml.Hdr.Source.LocName.Content = Facade.User; syncml.Hdr.Cred.Meta.Xml.Add(b64Format); syncml.Hdr.Cred.Meta.Xml.Add(authMd5Type); syncml.Hdr.Cred.Data.Content = CreateMD5Digest(Facade.Md5NextNonceFromServer); }
public void TestSyncML() { XElement nav = XElement.Load(CaseFile("SyncML.xml")); SyncMLSyncML f = SyncMLSyncML.Create(nav); Assert.IsTrue(CompareXml(nav, f.Xml), f.Xml.ToString()); }
/// <summary> /// So URI of Post will likely be using session id returned by the server. /// </summary> /// <param name="syncMLFromServer">SyncML message from the server.</param> private void UpdateCurrentURI(SyncMLSyncML syncMLFromServer) { string newUri = syncMLFromServer.Hdr.RespURI.Content; if (!String.IsNullOrEmpty(newUri)) { Facade.Connections.Uri = newUri; } }
/// <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); }
/// <summary> /// Add Get command to a syncml message /// </summary> /// <param name="syncml"></param> /// <returns>The Get command.</returns> private static SyncMLGet AddGetDeviceInfo(SyncMLSyncML syncml) { SyncMLGet get = SyncMLGet.Create(); get.CmdID = syncml.NextCmdID; get.Meta.Xml.Add(SyncMLSimpleElementFactory.Create <MetaType>("application/vnd.syncml-devinf+xml").Xml); SyncMLItem item = SyncMLItem.Create(); item.Target.LocURI = SyncMLSimpleElementFactory.Create <SyncMLLocURI>("./devinf12"); //The Source element in the Item element MUST have a value ./devinf12. get.ItemCollection.Add(item); syncml.Body.Commands.Add(get); return(get); }
/// <summary> /// Get a syncML command. /// </summary> /// <param name="syncml"></param> /// <returns>Null if no command expected.</returns> public static T GetCommand(SyncMLSyncML syncml) { SyncMLBody body = syncml.Body; foreach (SyncMLComplexElement item in body.Commands) { T r = item as T; if (r != null) { return(r); } } return(null); }
/// <summary> /// Add a Put command to a syncml message /// </summary> /// <param name="syncml"></param> private SyncMLPut AddPutDeviceInfo(SyncMLSyncML syncml) { SyncMLPut put = SyncMLPut.Create(); put.CmdID = syncml.NextCmdID; put.Meta.Xml.Add(SyncMLSimpleElementFactory.Create <MetaType>("application/vnd.syncml-devinf+xml").Xml); SyncMLItem item = SyncMLItem.Create(); item.Source.LocURI = SyncMLSimpleElementFactory.Create <SyncMLLocURI>("./devinf12"); //The Source element in the Item element MUST have a value ./devinf12. item.Data.Xml.Add(Facade.LocalDevinf.Xml); put.ItemCollection.Add(item); syncml.Body.Commands.Add(put); return(put); }
/// <summary> /// Get collection of command T. /// </summary> /// <param name="syncml">SyncML message</param> /// <returns>Collection of coimmand T. If no command, the collection is empty.</returns> public static Collection <T> GetCommands(SyncMLSyncML syncml) { SyncMLBody body = syncml.Body; Collection <T> collection = new Collection <T>(); foreach (SyncMLComplexElement item in body.Commands) { T r = item as T; if (r != null) { collection.Add(r); } } return(collection); }
public override void Send() { SyncMLSyncML syncml = CreateSyncContentMessage(); syncml.Hdr.Target.LocURI.Content = Facade.BasicUriText; //Facade.CurrentRespUri; syncml.Body.MarkFinal(); Debug.WriteLine("Sending EmptySync:" + syncml.Xml.ToString()); string responseText = Facade.Connections.GetResponseText(syncml.Xml.ToString(SaveOptions.DisableFormatting)); if (String.IsNullOrEmpty(responseText)) { return; } Facade.CurrentMsgID++; ProcessResponse(responseText); }
/// <summary> /// Move pending commands in pool into a new message. /// And each command will be assigned with an CmdID. /// When analyzing the response from server, new commands may be generated /// for next message to server. /// /// This function is better to be put at the end of construction of SyncML message. /// </summary> /// <param name="syncML">New message to be amended before sending to the server.</param> ///<returns>Ture if commmands are added from pool; false if no command added.</returns> protected bool MoveCommandsInPoolToMessage(SyncMLSyncML syncML) { if (Facade.ResponseCommandPool.Count > 1)//if there's only one which is for Status with Hdr, no need to send back { foreach (SyncMLCommand command in Facade.ResponseCommandPool) { command.CmdID = syncML.NextCmdID; syncML.Body.Commands.Add(command); } Facade.ResponseCommandPool.Clear(); return(true); } else { return(false); } }
public static Collection <SyncMLAlert> GetAlertCommands(SyncMLSyncML syncml) { return(AccessBodyCommand <SyncMLAlert> .GetCommands(syncml)); }
public static Collection <SyncMLResults> GetResultsCommands(SyncMLSyncML syncml) { return(AccessBodyCommand <SyncMLResults> .GetCommands(syncml)); }
protected void AddBase64Credential(SyncMLSyncML syncml) { syncml.Hdr.Cred.Meta.Xml.Add(b64Format); syncml.Hdr.Cred.Meta.Xml.Add(authBasicType); syncml.Hdr.Cred.Data.Content = UserPasswordBase64Encoded; }
public static SyncMLSync GetSyncCommand(SyncMLSyncML syncml) { return(AccessBodyCommand <SyncMLSync> .GetCommand(syncml)); }