예제 #1
0
        public void TestAnchor()
        {
            XElement   nav = XElement.Load(CaseFile("MetaAnchor.xml"));
            MetaAnchor f   = MetaAnchor.Create(nav);

            Assert.IsTrue(CompareXml(nav, f.Xml), f.Xml.ToString());
        }
예제 #2
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;
            }
        }
예제 #3
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);
        }