コード例 #1
0
ファイル: SyncDetails.cs プロジェクト: labrinth1/RemoteSync
        private void FindLocalFileChanges(string path)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(path);

            foreach (DirectoryInfo dir in directoryInfo.GetDirectories())
            {
                FindLocalFileChanges(dir.FullName);
            }

            foreach (FileInfo fi in directoryInfo.GetFiles())
            {
                string uri = fi.FullName.Substring(folderPath.Length + 1);
                if (Path.GetExtension(fi.Name).ToUpperInvariant() == ".SYNC")
                {
                    continue;
                }
                else
                {
                    ItemMetadata existingItem;
                    if (!metadataStore.TryGetItem(uri, out existingItem)) //Create
                    {
                        ItemMetadata item = new ItemMetadata();

                        item.Uri = uri;
                        item.IsTombstone = false;

                        item.ItemId = new SyncId(new SyncGlobalId(0, Guid.NewGuid()));
                        System.Diagnostics.Debug.WriteLine("FindLocalFileChanges: Create found for uri:" + uri + " ItemID: " + item.ItemId);
                        item.CreationVersion = new SyncVersion(0, tickCount);

                        item.ChangeVersion = item.CreationVersion;

                        item.LastWriteTimeUtc = fi.LastWriteTimeUtc;

                        metadataStore.SetItemInfo(item);
                    }
                    else
                    {
                        if (existingItem.LastWriteTimeUtc == null || fi.LastWriteTimeUtc > existingItem.LastWriteTimeUtc)
                        {
                            System.Diagnostics.Debug.WriteLine("FindLocalFileChanges: File has been changed:  " + uri);

                            existingItem.ChangeVersion = new SyncVersion(0, tickCount);
                            existingItem.LastWriteTimeUtc = fi.LastWriteTimeUtc;

                            metadataStore.SetItemInfo(existingItem);
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine("No change found for file : " + uri);
                        }
                    }
                }
            }
            List<ItemMetadata> toUpdate = new List<ItemMetadata>();

            foreach (ItemMetadata item in metadataStore)
            {
                if (!File.Exists(Path.Combine(FolderPath, item.Uri)))
                {
                    if (!item.IsTombstone)
                    {
                        item.IsTombstone = true;
                        item.ChangeVersion = new SyncVersion(0, tickCount);
                        toUpdate.Add(item);
                    }
                }
            }
            foreach (ItemMetadata item in toUpdate)
            {
                metadataStore.SetItemInfo(item);
            }
        }
コード例 #2
0
ファイル: SyncDetails.cs プロジェクト: labrinth1/RemoteSync
        public MetadataStore UpdateItemWithReturn(ItemMetadata item)
        {
            metadataStore.SetItemInfo(item);

            return metadataStore;
        }
コード例 #3
0
ファイル: SyncDetails.cs プロジェクト: labrinth1/RemoteSync
 public void UpdateItemItem(ItemMetadata item)
 {
     metadataStore.SetItemInfo(item);
 }
コード例 #4
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;
        }
コード例 #5
0
ファイル: RemoteStore.cs プロジェクト: labrinth1/RemoteSync
        public void SaveItemChange(SaveChangeAction saveChangeAction, ItemChange change, SaveChangeContext context)
        {
            DataTransfer data = context.ChangeData as DataTransfer;

            switch (saveChangeAction)
            {
                case SaveChangeAction.Create:
                    {
                        ItemMetadata item = new ItemMetadata();
                        item.ItemId = change.ItemId;
                        item.ChangeVersion = change.ChangeVersion;
                        item.CreationVersion = change.CreationVersion;
                        item.Uri = data.Uri;

                        data.DataStream.Position = 0;
                        System.Diagnostics.Debug.WriteLine("Uploading File:" + item.Uri);
                        service.UploadFile(data.DataStream.Length, item, data.DataStream);

                        data.DataStream.Close();
                        sync.UpdateItemItem(item);

                        break;
                    }
                case SaveChangeAction.DeleteAndStoreTombstone:
                    {
                        ItemMetadata item = sync.GetItemMetaData(saveChangeAction, change, data);

                        sync.DeleteItem(change.ItemId);
                        service.DeleteFile(change.ItemId, item.Uri);
                        break;
                    }
                default:
                    {
                        throw new NotImplementedException(saveChangeAction + " ChangeAction is not implemented!");
                    }

            }

            context.GetUpdatedDestinationKnowledge(out myKnowledge, out myForgottenKnowledge);
        }
コード例 #6
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();
        }