Пример #1
0
        //private void SendEmptySyncContent()
        //{
        //    //1: Generate SyncCommands in a buffer
        //    Facade.CommandsToSend = new DummyEmptyCommandSource();

        //    Facade.totalNumberOfChangesSending = Facade.CommandsToSend.NumberOfChanges;

        //    //2: Send the first batch of sync commands.
        //    SendingSyncMessage sendingSyncStep = new SendingSyncMessage(Facade, Facade.totalNumberOfChangesSending);
        //    sendingSyncStep.Send();
        //}

        /// <summary>
        /// Generate map command through LocalID/ServerID paris.
        /// </summary>
        /// <param name="localIDServerIDPairs">The pairs is returned by local address book.</param>
        /// <param name="previousServerSyncCommand">The map command need to obtain some data from previous sync command.</param>
        /// <returns>The map command to be integrated into next SyncML message sent back to the server. CmdID is not assigned yet.</returns>
        private static SyncMLMap GenerateMapCommand(NameValueCollection localIDServerIDPairs, SyncMLSync previousServerSyncCommand)
        {
            SyncMLMap map = SyncMLMap.Create();

            map.Target.LocURI.Content = previousServerSyncCommand.Source.LocURI.Content;
            map.Source.LocURI.Content = previousServerSyncCommand.Target.LocURI.Content;

            for (int i = 0; i < localIDServerIDPairs.Count; i++)
            {
                SyncMLMapItem mapItem = SyncMLMapItem.Create();
                mapItem.Target.LocURI.Content = localIDServerIDPairs.Get(i);
                mapItem.Source.LocURI.Content = localIDServerIDPairs.GetKey(i);
                map.MapItemCollection.Add(mapItem);
            }

            return(map);
        }
Пример #2
0
        /// <summary>
        /// Process a sync command from server. This will update the local address book, and prepare map commands to be sent back to the server
        /// </summary>
        /// <param name="syncCommand"></param>
        private void ApplySyncCommandToLocal(SyncMLSync syncCommand)
        {
            Collection <SyncMLCommand> commands = syncCommand.Commands;

            if (commands.Count > 0)
            {
                //Step1: Apply the sync command to local through LocalDataSource.
                NameValueCollection localIDServerIDCollection = Facade.LocalDataSource.ApplySyncCommands(commands, Facade.LastAnchorTimeText);

                //Step2: Report error from LocalDataSource if any
                if (!String.IsNullOrEmpty(Facade.LocalDataSource.ErrorMessage))
                {
                    Facade.DisplayOperationMessage("PlatformProvider error: " + Facade.LocalDataSource.ErrorMessage);
                }


                //Step3: Prepare map command for next message to notify the server
                SyncMLMap map = GenerateMapCommand(localIDServerIDCollection, syncCommand);
                if (map.MapItemCollection.Count > 0)
                {
                    Facade.ResponseCommandPool.Add(map);
                }

                //Step4: Report to the end user about updated names
                if (!String.IsNullOrEmpty(Facade.LocalDataSource.NamesOfAddedItems))
                {
                    Facade.DisplayOperationMessage("Items added:");
                    Facade.DisplayOperationMessage(Facade.LocalDataSource.NamesOfAddedItems);
                }

                if (!String.IsNullOrEmpty(Facade.LocalDataSource.NamesOfUpdatedItems))
                {
                    Facade.DisplayOperationMessage("Items updated:");
                    Facade.DisplayOperationMessage(Facade.LocalDataSource.NamesOfUpdatedItems);
                }

                if (!String.IsNullOrEmpty(Facade.LocalDataSource.NamesOfDeletedItems))
                {
                    Facade.DisplayOperationMessage("Items deleted:");
                    Facade.DisplayOperationMessage(Facade.LocalDataSource.NamesOfDeletedItems);
                }
            }
        }