// // no need to delete the actual file by fid // - Drupal 7 auto-deletes it when losing the reference to a node // public async Task<bool> DeleteFile(int fid, CancellationToken cancelToken) { if (!IsLoggedIn) throw Error.BadAct($"‹{this.GetType().Name}› is not logged in."); var req = _auth.Req.DELETE(URL.Api_FileX, fid); Trace_n("Deleting file from server...", "fid: " + fid); IResponseShim resp = null; try { resp = await _client.Send(req, cancelToken); } catch (Exception ex) { OnUnhandled.Err(this, ex); } if (resp == null) return Error_(false, "Unexpected NULL response.", "IResponseShim".Guillemets()); if (!resp.IsSuccess) return OnFileDelete.Err(this, (RestServiceException)resp.Error); if (resp.Content != "[true]") return Error_(false, "File probably in use by a node.", resp.Content); return Trace_n("File successfully deleted from server.", resp.Content); }
public void DoBackup(string sourceFolder, string destFolder, bool doNotDeleteDestFiles) { var sourceNode = new FolderNode(new DirectoryInfo(sourceFolder)); var destNode = new FolderNode(new DirectoryInfo(destFolder)); var synchronizer = new Synchronizer(); var actions = synchronizer.Synchronize <FolderNode, FileNodeElement>(sourceNode, destNode); var fileSystemActions = new FileSystemActions(); foreach (var action in actions) { switch (action.ActionType) { case ActionType.DeleteDestNodeElement: if (!doNotDeleteDestFiles) { OnFileDelete?.Invoke(this, action.DestinationNodeElement); fileSystemActions.Remove(action.DestinationNodeElement); } break; case ActionType.CopySourceNodeElementToDestination: OnFileCopy?.Invoke(this, new FileCopyArgs(action.SourceNodeElement, action.DestinationNode)); fileSystemActions.Add(action.DestinationNode, action.SourceNodeElement); break; case ActionType.DeleteDestNode: if (!doNotDeleteDestFiles) { OnFolderDelete?.Invoke(this, action.DestinationNode); fileSystemActions.Remove(action.DestinationNode); } break; case ActionType.CopySourceNodeToDestination: OnFolderCopy?.Invoke(this, new FolderCopyArgs(action.SourceNode, action.DestinationNode)); fileSystemActions.Add(action.DestinationNode, action.SourceNode); break; } } }
private void OnChanged(object sender, FileSystemEventArgs e) { if (e.FullPath.Contains("~") && e.FullPath.Contains("TMP")) { return; } if (string.IsNullOrWhiteSpace(Path.GetFileName(e.FullPath))) { return; } switch (e.ChangeType) { case WatcherChangeTypes.Created: OnFileCreate?.Invoke(e); break; case WatcherChangeTypes.Deleted: OnFileDelete?.Invoke(e); break; case WatcherChangeTypes.Changed: OnFileChange?.Invoke(e); break; case WatcherChangeTypes.Renamed: break; case WatcherChangeTypes.All: break; default: return; } }