示例#1
0
        // properties
        public static WatcherChangeTypes GetChangeType(this DriveItem newDriveItem, DriveItem oldDriveItem = null)
        {
            if (oldDriveItem == null)
            {
                return(WatcherChangeTypes.Created);
            }

            if (newDriveItem.Deleted != null)
            {
                return(WatcherChangeTypes.Deleted);
            }

            else if (oldDriveItem.Id != newDriveItem.Id)
            {
                throw new ArgumentException();
            }

            else if (oldDriveItem.GetItemPath() != newDriveItem.GetItemPath())
            {
                return(WatcherChangeTypes.Renamed);
            }

            else if (newDriveItem.Type() == DriveItemType.File &&
                     (oldDriveItem.LastModified() != newDriveItem.LastModified() ||
                      oldDriveItem.Size != newDriveItem.Size))
            {
                return(WatcherChangeTypes.Changed);
            }

            // no change
            else
            {
                return(0);
            }
        }
示例#2
0
        public Task SetLastWriteTimeUtcAsync(DriveItem driveItem)
        {
            var driveItemPath = driveItem.GetAbsolutePath(this.BasePath);

            switch (driveItem.Type())
            {
            case DriveItemType.Folder:
                Directory.SetLastWriteTimeUtc(driveItemPath, driveItem.LastModified());
                break;

            case DriveItemType.File:
                File.SetLastWriteTimeUtc(driveItemPath, driveItem.LastModified());
                break;

            case DriveItemType.RemoteItem:
            default:
                throw new NotSupportedException();
            }

            return(Task.CompletedTask);
        }
        /* low level */
        private async Task <DriveItem> TransferDriveItem(IDriveProxy sourceDrive, IDriveProxy targetDrive, DriveItem driveItem)
        {
            (var itemName1, var itemName2) = this.GetItemNames(driveItem);
            var isLocal = sourceDrive == _localDrive;

            // item exists on target drive
            if (_syncMode == SyncMode.TwoWay && await targetDrive.ExistsAsync(driveItem))
            {
                // item is unchanged on target drive
                // actions: do nothing
                if (await targetDrive.GetLastWriteTimeUtcAsync(driveItem) == driveItem.LastModified())
                {
                    _logger.LogDebug($"{itemName1} already exists and is unchanged on target drive '{targetDrive.Name}'. Action(s): do nothing.");
                }

                // item was modified on target drive
                else
                {
                    if (!isLocal)
                    {
                        _logger.LogDebug($"{itemName1} already exists and was modified on target drive '{targetDrive.Name}'. Action(s): handle conflict.");
                        await this.EnsureLocalConflict(driveItem);
                    }
                }
            }

            // item does not exist on target drive
            // actions: transfer item
            else
            {
                _logger.LogInformation($"{itemName1} is not available on target drive '{targetDrive.Name}'. Action(s): transfer {itemName2}.");
                return(await this.InternalTransferDriveItem(sourceDrive, targetDrive, driveItem));
            }

            return(driveItem);
        }
示例#4
0
        public static DriveItem ToConflict(this DriveItem driveItem)
        {
            driveItem.Name = driveItem.Name.ToConflictFileName(driveItem.LastModified());

            return(driveItem);
        }