public void Result_Unavailable() { var sut = new RemoteVsLocalFile("file.txt", null, null, SyncDirection.Upload); sut.Comparison.MustBe(FileDiff.Unavailable, "result state"); sut.NextStep.MustBe(FileTask.Analyze); sut.Target.MustBe(Target.Both); }
public void Result_NotInRemote() { var sut = new RemoteVsLocalFile("file.txt", null, new SyncableFileLocal(), SyncDirection.Upload); sut.Comparison.MustBe(FileDiff.NotInRemote, "result state"); sut.NextStep.MustBe(FileTask.Create); sut.Target.MustBe(Target.Remote); }
internal async Task<bool> CreateFile(RemoteVsLocalFile inf, CancellationToken cancelToken) { var locF = _foldr.File(inf.Filename, false); if (locF.Found) return Error_n("File already exists in target folder.", "Use ReplaceFile() method instead."); var b64Dto = await DownloadFile(inf.Remote, cancelToken); if (b64Dto == null) return false; if (!locF.Write(b64Dto.b64.Base64ToBytes())) return false; return VerifyFile(locF, inf.Remote); }
public void Result_Changed_Version() { var sut = new RemoteVsLocalFile("file.txt", new SyncableFileRemote(), new SyncableFileLocal { Version = "v.5" }, SyncDirection.Upload); sut.Comparison.MustBe(FileDiff.Changed, "result state"); sut.OddProperty.MustBe(nameof(SyncableFileBase.Version), "odd property"); sut.NextStep.MustBe(FileTask.Replace); sut.Target.MustBe(Target.Remote); }
internal async Task<bool> ReplaceFile(RemoteVsLocalFile inf, CancellationToken cancelToken) { var locF = _foldr.File(inf.Filename, false); if (!locF.Found) return Error_n("File missing from target folder.", "Use CreateFile() method instead."); if (!TempDir.Create()) return Error_n("Unable to create temporary folder.", TempDir.Path); if (!RelocateActiveFile(locF)) return false; var b64Dto = await DownloadFile(inf.Remote, cancelToken); if (b64Dto == null) return false; if (!locF.Write(b64Dto.b64.Base64ToBytes())) return false; return VerifyFile(locF, inf.Remote); }
public SyncableFileDtoRevision(RemoteVsLocalFile inf, int fileID) : base(inf.Local, fileID) { nid = inf.Remote.Nid; vid = inf.Remote.Vid; }
private async Task<int> UploadLocalFile(RemoteVsLocalFile inf, CancellationToken cancelToken) { inf.Status = "Uploading local file..."; var locFile = _fs.File(inf.Local.Path); return await _client.Post(locFile, cancelToken, _targetDir); }
private async Task<bool> CreateRemoteNode(RemoteVsLocalFile inf, CancellationToken cancelToken) { var newFid = await UploadLocalFile(inf, cancelToken); if (newFid <= 0) return false; inf.Status = "Creating new node..."; var nodeDto = new SyncableFileDto(inf.Local, newFid); var newNode = await _client.Post(nodeDto, cancelToken); if (!newNode.IsValidNode()) return false; if (await AddToFolderNode(newNode.nid)) return false; inf.Status = "File uploaded; node created."; return true; }
private async Task<bool> DeleteRemoteNode(RemoteVsLocalFile inf, CancellationToken cancelToken) { if (!await RemoveFromFolderNode(inf.Remote.Nid)) return false; if (!await SaveFolderNode(cancelToken)) return false; inf.Status = "Deleting remote file node..."; if (!await _client.Delete(inf.Remote.Nid, cancelToken)) return false; // no need to delete the actual file by fid // - Drupal 7 auto-deletes it when losing the reference to a node inf.Status = "Deleted remote file and node."; return true; }
private async Task<bool> ReplaceRemoteNode(RemoteVsLocalFile inf, CancellationToken cancelToken) { if (!await LoadFolderNodeIfNull()) return false; var newFid = await UploadLocalFile(inf, cancelToken); if (newFid <= 0) return false; //inf.Status = "Getting the freshest version of the File node..."; //var node = await _client.Node<SyncableFileDto>(inf.Remote.Nid); //if (!node.IsValidNode()) return false; inf.Status = "Updating node to refer to newly upload file..."; var dto = new SyncableFileDtoRevision(inf, newFid); if ((await _client.Put(dto, cancelToken)).IsValidNode()) { inf.Status = "File uploaded; node updated."; return Debug_n("Successfully updated File node.", ""); } else return Warn_n("Something went wrong in updating File node.", ""); }
private async Task<bool> ActOnRemote(RemoteVsLocalFile item, CancellationToken cancelToken) { switch (item.NextStep) { case FileTask.Ignore: return true; case FileTask.Analyze: return Warn_n("Not yet implemented.", "Analyze in Remote"); case FileTask.Create: return await CreateRemoteNode(item, cancelToken); case FileTask.Replace: return await ReplaceRemoteNode(item, cancelToken); case FileTask.Delete: return await DeleteRemoteNode(item, cancelToken); default: return Warn_n($"Unsupported Remote NextStep: ‹{item.NextStep}›", ""); } }
private async Task<bool> ActOnLocal(RemoteVsLocalFile item, CancellationToken cancelToken) { switch (item.NextStep) { case FileTask.Ignore: return true; case FileTask.Analyze: return Warn_n("Not yet implemented.", "Analyze in Local"); case FileTask.Create: return await _downloadr.CreateFile(item, cancelToken); case FileTask.Replace: HasReplacement = true; return await _downloadr.ReplaceFile(item, cancelToken); case FileTask.Delete: return Warn_h("Task should not be allowed.", "Delete in Local"); default: return Warn_n($"Unsupported Local NextStep: ‹{item.NextStep}›", ""); } }
public void Result_Same() { var rem = new SyncableFileRemote(); var loc = new SyncableFileLocal(); loc.Size = rem.Size = 123; loc.Version = rem.Version = "v.456"; loc.SHA1 = rem.SHA1 = "abc-def-ghi"; var sut = new RemoteVsLocalFile("file.txt", rem, loc, SyncDirection.Upload); sut.Comparison.MustBe(FileDiff.Same, "result state"); sut.OddProperty.MustBe(null, "odd property"); sut.NextStep.MustBe(FileTask.Ignore); sut.Target.MustBe(Target.Both); }