示例#1
0
        /// <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();
            }
        }
示例#2
0
        public void TestAlert()
        {
            XElement nav = XElement.Load(CaseFile("Alert.xml"));

            SyncMLAlert f = SyncMLAlert.Create(nav);

            Assert.IsTrue(CompareXml(nav, f.Xml), f.Xml.ToString());
        }
示例#3
0
        /// <summary>
        /// Called by ProcessResponseForXXX in order to create status for Alert returned by server.
        /// </summary>
        /// <param name="alert"></param>
        protected void PrepareStatusForReturnedAlert(SyncMLAlert alert)
        {
            switch (alert.Data.Content)
            {
            case "200":
            case "201":
            case "202":
            case "203":
            case "204":
            case "205":
                SyncMLStatus responseStatus = SyncMLStatus.Create();
                //status.CmdID is not defined here, but only defined right before sending next message
                responseStatus.MsgRef.Content = ServerSyncML.Hdr.MsgID.Content;
                responseStatus.Data.Content   = "200";
                responseStatus.Cmd.Content    = "Alert";
                responseStatus.CmdRef.Content = alert.CmdID.Content;
                responseStatus.TargetRefCollection.Add(SyncMLSimpleElementFactory.Create <SyncMLTargetRef>(Facade.ContactDataSourceAtServer));
                responseStatus.SourceRefCollection.Add(SyncMLSimpleElementFactory.Create <SyncMLSourceRef>(Facade.LocalDataSource.DataSourceName));

                //Get alert anchor next
                SyncMLItem alertItem       = alert.ItemCollection[0]; //assuming there's always one.
                SyncMLMeta alertItemMeta   = alertItem.Meta;          // assuming there's always one.
                MetaParser metaParser      = new MetaParser(alertItemMeta.Xml);
                MetaAnchor alertAnchor     = metaParser.GetMetaAnchor();
                string     alertAnchorNext = alertAnchor.Next.Content;

                SyncMLItem statusItem   = SyncMLItem.Create();
                MetaAnchor statusAnchor = MetaAnchor.Create();
                statusAnchor.Next = SyncMLSimpleElementFactory.Create <MetaNext>(alertAnchorNext);
                statusItem.Data.Xml.Add(statusAnchor.Xml);

                responseStatus.ItemCollection.Add(statusItem);

                Facade.ResponseCommandPool.Add(responseStatus);
                break;

            case "100":
                //Show. The Data element type contains content information that should be processed and displayed through the user agent.
                string serverStatusMessage = alert.ItemCollection[0].Data.Content;
                Facade.DisplayOperationMessage(serverStatusMessage);

                SyncMLStatus statusFor100 = SyncMLStatus.Create();
                statusFor100.MsgRef.Content = ServerSyncML.Hdr.MsgID.Content;
                statusFor100.Data.Content   = "200";
                statusFor100.Cmd.Content    = "Alert";
                statusFor100.CmdRef.Content = alert.CmdID.Content;
                Facade.ResponseCommandPool.Add(statusFor100);

                break;

            default:
                Trace.TraceInformation("Do not know what to do in PrepareStatusForReturnedAlert:");
                Trace.TraceInformation(alert.Xml.ToString());
                break;
            }
        }
示例#4
0
        private SyncMLSyncML CreateSyncRequestMessage(SyncType syncType)
        {
            SyncMLAlert alert = CreateSyncAlert(syncType);

            ClientSyncML.Body.Commands.Add(alert);

            CommandAndStatusRegister.Add(alert);

            return(ClientSyncML);
        }
示例#5
0
        private SyncMLAlert CreateSyncAlert(SyncType syncType)
        {
            //Tell the server what sync type
            SyncMLAlert alert = SyncMLAlert.Create();

            alert.CmdID = ClientSyncML.NextCmdID;

            MetaAnchor anchor;

            Facade.NextAnchor = DateTime.UtcNow.Ticks.ToString();

            switch (syncType)
            {
            case SyncType.TwoWay:
                alert.Data.Content = "200";
                anchor             = MetaAnchor.Create(Facade.NextAnchor, Facade.LastAnchor);
                Facade.DisplayOperationMessage("Last anchor: " + anchor.Last.Content);
                break;

            case SyncType.Slow:
                alert.Data.Content = "201";
                //        anchor = MetaAnchor.Create(DateTime.Now.ToString("yyyyMMddTHHmmssZ"), "0");
                anchor = MetaAnchor.Create(Facade.NextAnchor, Facade.LastAnchor);
                break;

            case SyncType.OneWayFromClient:
                alert.Data.Content = "202";
                anchor             = MetaAnchor.Create(Facade.NextAnchor, Facade.LastAnchor);
                Facade.DisplayOperationMessage("Last anchor: " + anchor.Last.Content);
                break;

            case SyncType.RefreshFromClient:
                alert.Data.Content = "203";
                anchor             = MetaAnchor.Create(Facade.NextAnchor, Facade.LastAnchor);
                Facade.DisplayOperationMessage("Last anchor: " + anchor.Last.Content);
                break;

            case SyncType.OneWayFromServer:
                alert.Data.Content = "204";
                anchor             = MetaAnchor.Create(Facade.NextAnchor, Facade.LastAnchor);
                Facade.DisplayOperationMessage("Last anchor: " + anchor.Last.Content);
                break;

            case SyncType.RefreshFromServer:
                alert.Data.Content = "205";
                anchor             = MetaAnchor.Create(Facade.NextAnchor, Facade.LastAnchor);
                Facade.DisplayOperationMessage("Last anchor: " + anchor.Last.Content);
                break;

            default:
                throw new FacadeErrorException("Unexpected sync type");
            }

            //Tell what to sync
            SyncMLItem item = SyncMLItem.Create();

            item.Target.LocURI.Content = Facade.ContactDataSourceAtServer;
            item.Source.LocURI.Content = Facade.LocalDataSource.DataSourceName;

            //Tell anchors
            item.Meta.Xml.Add(anchor.Xml);

            alert.ItemCollection.Add(item);

            return(alert);
        }