public override SyncEntry CreateSyncEntryForAdapterItem(IAdapterItem item, SyncEntry parentEntry) { OneDriveAdapterItem oneDriveAdapterItem = item as OneDriveAdapterItem; Pre.Assert(oneDriveAdapterItem != null, "oneDriveAdapterItem != null"); Pre.Assert(oneDriveAdapterItem.Item != null, "oneDriveAdapterItem.Item != null"); // Is this always true? Pre.Assert(parentEntry != null, "parentEntry != null"); return(this.CreateEntry(oneDriveAdapterItem.Item, parentEntry)); }
public override IEnumerable <IAdapterItem> GetAdapterItems(IAdapterItem folder) { if (folder == null) { Drive defaultDrive = this.oneDriveClient.GetDefaultDrive().Result; return(new List <OneDriveAdapterItem> { new OneDriveAdapterItem(defaultDrive, this) }); } OneDriveAdapterItem adapterItem = folder as OneDriveAdapterItem; Pre.Assert(adapterItem != null, "adapterItem != null"); IEnumerable <Item> items = this.oneDriveClient.GetChildItems(adapterItem).Result; IEnumerable <OneDriveAdapterItem> adapterItems = items.Select(i => new OneDriveAdapterItem(i, folder, this)); return(adapterItems); }
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); }