Exemple #1
0
        public override bool IsEntryUpdated(SyncEntry childEntry, IAdapterItem adapterItem, out EntryUpdateResult result)
        {
            const long TicksPerMillisecond = 10000;

            // 2017/11/24: There appears to be a discrepency when reading ModifiedDateTimeUtc and CreationTimeUtc
            // from FileSystemInfo objects. The Ticks value is being rounded to the nearest 10000 ticks, causing
            // some directories to appear to be modified. For now, we will set the threshold for an item being
            // changed to 10ms
            const long Epsilon = TicksPerMillisecond * 10;

            FileSystemFolder fileSystemItem = adapterItem as FileSystemFolder;

            if (fileSystemItem == null)
            {
                throw new ArgumentException("The adapter item is not of the correct type.", nameof(adapterItem));
            }

            result = new EntryUpdateResult();

            if (Math.Abs(childEntry.ModifiedDateTimeUtc.Ticks - fileSystemItem.FileSystemInfo.LastWriteTimeUtc.Ticks) > Epsilon)
            {
                result.ChangeFlags |= SyncEntryChangedFlags.ModifiedTimestamp;
                result.ModifiedTime = fileSystemItem.FileSystemInfo.LastWriteTimeUtc;
            }

            if (Math.Abs(childEntry.CreationDateTimeUtc.Ticks - fileSystemItem.FileSystemInfo.CreationTimeUtc.Ticks) > Epsilon)
            {
                result.ChangeFlags |= SyncEntryChangedFlags.CreatedTimestamp;
                result.CreationTime = fileSystemItem.FileSystemInfo.CreationTimeUtc;
            }

            FileInfo      fileInfo = fileSystemItem.FileSystemInfo as FileInfo;
            SyncEntryType fileType = SyncEntryType.Directory;

            if (fileInfo != null)
            {
                fileType = SyncEntryType.File;

                if (fileInfo.Length != childEntry.GetSize(this.Relationship, SyncEntryPropertyLocation.Source))
                {
                    result.ChangeFlags |= SyncEntryChangedFlags.FileSize;
                }
            }

            if (!string.Equals(fileSystemItem.Name, childEntry.Name, StringComparison.Ordinal))
            {
                result.ChangeFlags |= SyncEntryChangedFlags.Renamed;
            }

            // It is possible that a directory was created over a file that previously existed (with the same name). To
            // handle this, we need to check if the type changed.
            if (childEntry.Type != fileType)
            {
                // TODO: Handle this
                throw new NotImplementedException();
            }

            return(result.ChangeFlags != SyncEntryChangedFlags.None);
        }
 public override bool IsEntryUpdated(SyncEntry childEntry, IAdapterItem adapterItem, out EntryUpdateResult result)
 {
     throw new NotImplementedException();
 }
Exemple #3
0
        public override bool IsEntryUpdated(SyncEntry childEntry, IAdapterItem adapterItem, out EntryUpdateResult result)
        {
            const long TicksPerMillisecond = 10000;
            const long Epsilon             = TicksPerMillisecond * 2;

            OneDriveAdapterItem item = adapterItem as OneDriveAdapterItem;

            if (item == null)
            {
                throw new ArgumentException("The adapter item is not of the correct type.", nameof(adapterItem));
            }

            result = new EntryUpdateResult();

            if (item.Item.LastModifiedDateTime != null &&
                Math.Abs(childEntry.ModifiedDateTimeUtc.Ticks - item.Item.LastModifiedDateTime.Value.Ticks) > Epsilon)
            {
                result.ChangeFlags |= SyncEntryChangedFlags.ModifiedTimestamp;
                result.ModifiedTime = item.Item.LastModifiedDateTime.Value;
            }

            if (Math.Abs(childEntry.CreationDateTimeUtc.Ticks - item.Item.CreatedDateTime.Ticks) > Epsilon)
            {
                result.ChangeFlags |= SyncEntryChangedFlags.CreatedTimestamp;
                result.CreationTime = item.Item.CreatedDateTime;
            }

            SyncEntryType fileType = SyncEntryType.Directory;

            if (item.ItemType == SyncAdapterItemType.File)
            {
                fileType = SyncEntryType.File;

                if (item.Item.Size != childEntry.GetSize(this.Relationship, SyncEntryPropertyLocation.Source))
                {
                    // Before reporting the size of the item as changed, check the SHA1 hash. If the hash is unchanged, then the
                    // file is the same as it was before. This is due to a bug in OneDrive where the reported size includes
                    // thumbnails for the file. See https://github.com/OneDrive/onedrive-api-docs/issues/123
                    if (item.Item.File.Hashes != null)
                    {
                        byte[] sha1Hash = HexToBytes(item.Item.File.Hashes.Sha1Hash);
                        if (!sha1Hash.SequenceEqual(childEntry.GetSha1Hash(this.Relationship, SyncEntryPropertyLocation.Source)))
                        {
                            result.ChangeFlags |= SyncEntryChangedFlags.FileSize;
                            result.ChangeFlags |= SyncEntryChangedFlags.Sha1Hash;
                        }
                    }
                }
            }

            if (!string.Equals(item.Item.Name, childEntry.Name, StringComparison.Ordinal))
            {
                result.ChangeFlags |= SyncEntryChangedFlags.Renamed;
            }

            // It is possible that a directory was created over a file that previously existed (with the same name). To
            // handle this, we need to check if the type changed.
            if (childEntry.Type != fileType)
            {
                // TODO: Handle this
                throw new NotImplementedException();
            }

            return(result.ChangeFlags != SyncEntryChangedFlags.None);
        }