Denotes a list of changes that is either to be uploaded or downloaded.
示例#1
0
        /// <summary>
        /// OfflineSyncProvider method implementation to return a set of sync changes.
        /// </summary>
        /// <param name="state">A unique identifier for the changes that are uploaded</param>
        /// <returns>The set of incremental changes to send to the service</returns>
        public override ChangeSet GetChangeSet(Guid state)
        {
            var changeSet = new ChangeSet();
            IEnumerable<SqlCeOfflineEntity> changes = _storageHandler.GetChanges(state);

            changeSet.Data = changes.Select(c => (IOfflineEntity) c).ToList();
            changeSet.IsLastBatch = true;
            changeSet.ServerBlob = _storageHandler.GetAnchor();

            return changeSet;
        }
示例#2
0
        private object ProcessDownloadRequest(HttpWebRequest webRequest, CacheRequest request)
        {
            using (Stream memoryStream = new MemoryStream())
            {

                // Create a SyncWriter to write the contents
                this._syncWriter = new ODataAtomWriter(base.BaseUri);

                this._syncWriter.StartFeed(true, request.KnowledgeBlob ?? new byte[0]);

                this._syncWriter.WriteFeed(XmlWriter.Create(memoryStream));
                memoryStream.Flush();

                webRequest.ContentLength = memoryStream.Position;
                Stream requestStream = webRequest.GetRequestStream();
                CopyStreamContent(memoryStream, requestStream);

                requestStream.Flush();
                requestStream.Close();

                // Fire the Before request handler
                this.FirePreRequestHandler(webRequest);
            }

            // Get the response
            HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

            if (webResponse.StatusCode == HttpStatusCode.OK)
            {
                ChangeSet changeSet = new ChangeSet();

                using (Stream responseStream = webResponse.GetResponseStream())
                {
                    // Create the SyncReader
                    this._syncReader = new ODataAtomReader(responseStream, this._knownTypes);

                    // Read the response
                    while (this._syncReader.Next())
                    {
                        switch (this._syncReader.ItemType)
                        {
                            case ReaderItemType.Entry:
                                changeSet.AddItem(this._syncReader.GetItem());
                                break;
                            case ReaderItemType.SyncBlob:
                                changeSet.ServerBlob = this._syncReader.GetServerBlob();
                                break;
                            case ReaderItemType.HasMoreChanges:
                                changeSet.IsLastBatch = !this._syncReader.GetHasMoreChangesValue();
                                break;
                        }
                    }

                    this.FirePostResponseHandler(webResponse);
                }

                webResponse.Close();

                return changeSet;
            }
            else
            {
                throw new CacheControllerException(
                                    string.Format("Remote service returned error status. Status: {0}, Description: {1}",
                                    webResponse.StatusCode,
                                    webResponse.StatusDescription));
            }
        }
示例#3
0
        /// <summary>
        /// OfflineSyncProvider method called to save changes retrieved from the sync service.
        /// </summary>
        /// <param name="changeSet">The set of changes from the service to save. Also contains an updated server
        /// blob.</param>
        public override void SaveChangeSet(ChangeSet changeSet)
        {
            if (null == changeSet)
            {
                throw new ArgumentException("changeSet is null", "changeSet");
            }

            var entities = changeSet.Data.Cast<SqlCeOfflineEntity>();

            _storageHandler.SaveDownloadedChanges(changeSet.ServerBlob, entities);
        }
示例#4
0
 public abstract void SaveChangeSet(ChangeSet changeSet);