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)); }
private GDriveData.File GetOrCreateFile(StateSyncEntry entry, SyncGetEntryOptions options) { GDriveData.File file; if (entry.Id == null) { if (!options.IsTemporary) { return(null); } // entry is a temporary entry file = Account.GetFilesByName(Account.TempFolderId, entry.Name).FirstOrDefault(); if (file != null) { return(file); } Account.Log(TraceLevel.Warning, "Cannot find temp entry '" + entry.Name + "' with parent temp folder id '" + Account.TempFolderId + "'."); if (!options.CanCreate) { return(null); } return(Account.CreateFile(entry.Name, Account.TempFolderId)); } file = Account.GetFile(entry.Id); if (file != null) { return(file); } Account.Log(TraceLevel.Warning, "Cannot find entry with id '" + entry.Id + "' name '" + entry.Name + "'."); if (!options.CanCreate) { return(null); } // we can't create google docs if (IsGoogleDoc(entry)) { return(null); } return(CreateEntry(entry)); }
public void GetOrCreateEntry(SyncContext context, StateSyncEntry entry, SyncGetEntryOptions options = null) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (entry == null) { throw new ArgumentNullException(nameof(entry)); } options = options ?? new SyncGetEntryOptions(); var file = GetOrCreateFile(entry, options); if (file == null && !options.CanCreate) { return; } CopyToEntry(file, entry); }
public async Task GetOrCreateEntryAsync(SyncContext context, StateSyncEntry entry, SyncGetEntryOptions options = null) { var file = await GetOrCreateFileAsync(entry, options).ConfigureAwait(false); if (file == null && !options.CanCreate) { return; } CopyToEntry(file, entry); }