示例#1
0
        public void UpdateEntry(SyncContext context, StateSyncEntry entry, SyncUpdateEntryOptions options = null)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (entry == null)
            {
                throw new ArgumentNullException(nameof(entry));
            }

            // we can't update google docs
            if (IsGoogleDoc(entry))
            {
                return;
            }

            options = options ?? new SyncUpdateEntryOptions();
            var file = Account.GetFile(entry.Id);

            if (file == null)
            {
                if (entry.Id != null)
                {
                    Account.Log(TraceLevel.Warning, "Cannot find entry '" + entry.Id + "' name '" + entry.Name + "'.");
                }
                if (!options.CanCreate)
                {
                    return;
                }

                file = CreateEntry(entry);
            }
            else
            {
                // is this the rename/move case?
                if (!entry.Name.EqualsIgnoreCase(file.Name))
                {
                    file = Account.MoveFile(file.Id, entry.Name, file.Parents.FirstOrDefault(), entry.ParentId);
                }
            }

            // note Google Drive cannot updated the created time of a file
            if (context.MultiPointSynchronizer.NormalizeDateTime(entry.LastWriteTime) != context.MultiPointSynchronizer.NormalizeDateTime(file.ModifiedTime.Value) ||
                entry.Attributes != ToAttributes(file))
            {
                string mimeType = null;
                if (entry.IsDirectory)
                {
                    mimeType = Account.FolderMimeType;
                }

                file = Account.UpdateFile(file.Id, entry.LastWriteTime.LocalDateTime, mimeType);
            }

            // note: unlike Windows on-demand files, we can't update the size w/o uploading a whole file

            CopyToEntry(file, entry);
        }
        public async Task UpdateEntryAsync(SyncContext context, StateSyncEntry entry, SyncUpdateEntryOptions options = null)
        {
            WebItem item;

            if (string.IsNullOrEmpty(entry.Id))
            {
                // no id, it's a temporary file, so get it by its name and parent
                item = await WebApi.GetChildAsync(ToId(entry.ParentId), entry.Name).ConfigureAwait(false);
            }
            else
            {
                item = await WebApi.GetAsync(ToId(entry.Id)).ConfigureAwait(false);
            }

            if (item == null)
            {
                if (entry.Id != null)
                {
                    Logger?.Log(TraceLevel.Warning, "Cannot find entry '" + entry.Id + "' name '" + entry.Name + "'.");
                }
                if (!options.CanCreate)
                {
                    return;
                }

                item = await CreateEntryAsync(entry).ConfigureAwait(false);
            }
            else
            {
                // is this the rename/move case?
                if (!entry.Name.EqualsIgnoreCase(item.Name))
                {
                    item = await WebApi.RenameAsync(item, entry.Name).ConfigureAwait(false);
                }
            }

            // should we update some metadata?
            if (context.MultiPointSynchronizer.NormalizeDateTime(entry.LastWriteTime) != context.MultiPointSynchronizer.NormalizeDateTime(item.LastWriteTimeUtc.ToLocalTime()) ||
                context.MultiPointSynchronizer.NormalizeDateTime(entry.CreationTime) != context.MultiPointSynchronizer.NormalizeDateTime(item.CreationTimeUtc.ToLocalTime()) ||
                entry.Attributes != ToAttributes(item))
            {
                item.Attributes       = ToAttributes(entry);
                item.LastWriteTimeUtc = entry.LastWriteTime.UtcDateTime;
                item.CreationTimeUtc  = entry.CreationTime.UtcDateTime;
                item = await WebApi.UploadAsync(item).ConfigureAwait(false);
            }

            CopyToEntry(item, entry);
        }