コード例 #1
0
        public override object LoadChangeData(Microsoft.Synchronization.LoadChangeContext loadChangeContext)
        {
            ItemMetadata item;
            metadataStore.TryGetItem(loadChangeContext.ItemChange.ItemId, out item);
            if (item.IsTombstone)
            {
                throw new InvalidOperationException("Cannot load change data for a deleted item.");
            }

            Stream dataStream = new FileStream(Path.Combine(folderPath, item.Uri), FileMode.Open, FileAccess.Read, FileShare.Read);
            DataTransfer transferMechanism = new DataTransfer(dataStream, item.Uri);

            return transferMechanism;
        }
コード例 #2
0
        public override object LoadChangeData(Microsoft.Synchronization.LoadChangeContext loadChangeContext)
        {
            ItemMetadata item;

            metadataStore.TryGetItem(loadChangeContext.ItemChange.ItemId, out item);

            if (item.IsTombstone)
            {
                throw new InvalidOperationException("Cannot load change data for a deleted item.");
            }

            System.Diagnostics.Debug.WriteLine("Downloading File:" + item.Uri);
            Stream dataStream = service.DownloadFile(item.Uri);

            DataTransfer transferMechanism = new DataTransfer(dataStream, item.Uri);

            return transferMechanism;
        }
コード例 #3
0
ファイル: SyncDetails.cs プロジェクト: labrinth1/RemoteSync
        public ItemMetadata GetItemMetaData(SaveChangeAction saveChangeAction, ItemChange change, DataTransfer data)
        {
            ItemMetadata item;
            if (saveChangeAction == SaveChangeAction.UpdateVersionOnly || ((change.ChangeKind & ChangeKind.Deleted) == ChangeKind.Deleted))
            {
                if (!metadataStore.TryGetItem(change.ItemId, out item))
                {
                    item = new ItemMetadata();
                    item.Uri = String.Empty;
                }
            }
            else
            {
                item = new ItemMetadata();
                item.Uri = data.Uri;
            }

            item.ItemId = change.ItemId;
            item.CreationVersion = change.CreationVersion;
            item.ChangeVersion = change.ChangeVersion;

            if ((change.ChangeKind & ChangeKind.Deleted) == ChangeKind.Deleted)
                item.IsTombstone = true;

            if (!metadataStore.Has(item.ItemId))
            {
                ItemMetadata oldItem;

                if (metadataStore.TryGetItem(item.Uri, out oldItem))
                {

                    if (item.ItemId.CompareTo(oldItem.ItemId) > 0)
                    {
                        oldItem.IsTombstone = true;
                        oldItem.Uri = String.Empty;
                        oldItem.ChangeVersion = new SyncVersion(0, tickCount);
                    }
                    else
                    {
                        item.IsTombstone = true;
                        item.Uri = String.Empty;
                        item.ChangeVersion = new SyncVersion(0, tickCount);
                    }
                    metadataStore.SetItemInfo(item);
                    metadataStore.SetItemInfo(oldItem);
                }
            }
            metadataStore.SetItemInfo(item);

            return item;
        }
コード例 #4
0
ファイル: LocalStore.cs プロジェクト: labrinth1/RemoteSync
        private void UpdateOrCreateFile(DataTransfer data, ItemMetadata item)
        {
            FileInfo fileInfo = new FileInfo(Path.Combine(folderPath, item.Uri));

            if (!fileInfo.Directory.Exists)
                fileInfo.Directory.Create();

            using (FileStream outputStream = new FileStream(Path.Combine(folderPath, item.Uri), FileMode.OpenOrCreate))
            {
                const int copyBlockSize = 4096;
                byte[] buffer = new byte[copyBlockSize];

                int bytesRead;
                while ((bytesRead = data.DataStream.Read(buffer, 0, copyBlockSize)) > 0)
                    outputStream.Write(buffer, 0, bytesRead);

                outputStream.SetLength(outputStream.Position);
            }
            item.LastWriteTimeUtc = fileInfo.LastWriteTimeUtc;

            data.DataStream.Close();
        }