private async Task <WebItem> GetOrCreateFileAsync(StateSyncEntry entry, SyncGetEntryOptions options)
        {
            WebItem item;

            if (entry.Id == null)
            {
                // temporary files are used to move content
                if (!options.IsTemporary)
                {
                    return(null);
                }

                // get parent path;
                Guid parentId;
                var  parent = options.JobChange.Change.FilePathSegments.Parent;
                if (parent == null)
                {
                    // root
                    parentId = Guid.Empty;
                }
                else
                {
                    // check entry exists.
                    // it should since we init the endpoint synchronizer with UploadsWaitForParents = true
                    var parentEntry = EndPointSynchronizer.StateProvider.GetEntryByFilePath(options.JobChange.DestinationSynchronizer, parent.ToString());
                    parentId = ToId(parentEntry.Id);
                }

                item = await WebApi.GetChildAsync(parentId, entry.Name).ConfigureAwait(false);

                if (item != null)
                {
                    return(item);
                }

                Logger?.Log(TraceLevel.Warning, "Cannot find temp entry '" + entry.Name + "' with parent id '" + parentId + "'.");
                if (!options.CanCreate)
                {
                    return(null);
                }

                // create temp files as hidden files
                return(await WebApi.CreateAsync(parentId, entry.Name, FileAttributes.Hidden).ConfigureAwait(false));
            }

            item = await WebApi.GetAsync(ToId(entry.Id)).ConfigureAwait(false);

            if (item != null)
            {
                return(item);
            }

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

            return(await CreateEntryAsync(entry).ConfigureAwait(false));
        }
        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);
        }
示例#3
0
        // this is a necessary ShellBoost override for better performance (direct access instead of implicit call to EnumItems)
        // https://www.shellboost.com/Doc/Developer-s-Guide/Items-enumeration
        public override ShellItem GetItem(ShellItemId id)
        {
            var guidPidl = KeyShellItemId.From(id.Data, false) as GuidKeyShellItemId;

            if (guidPidl == null)
            {
                return(null);
            }

            if (guidPidl.Value == Guid.Empty)
            {
                return(Root);
            }

            var apiItem = WebApi.GetAsync(guidPidl.Value).Result;

            return(ShellItemFromApi(apiItem));
        }