// // 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 async Task<bool> Delete(int nid, CancellationToken cancelToken) { if (!IsLoggedIn) throw Error.BadAct($"‹{this.GetType().Name}› is not logged in."); var req = _auth.Req.DELETE(URL.Api_EntityNodeX, nid); Trace_n("Deleting node from server...", "nid: " + nid); IResponseShim resp = null; try { resp = await _client.Send(req, cancelToken); } catch (Exception ex) { OnUnhandled.Err(this, ex); } if (resp == null) return Error_n("Unexpected NULL response.", "‹IResponseShim›"); if (!resp.IsSuccess) return OnNodeDelete.Err(this, (RestServiceException)resp.Error); if (resp.Content != "null") Warn_n("Unexpected response content.", $"“{resp.Content}”"); return Trace_n("Node successfully deleted from server.", resp.Content); }
public async Task<bool> Put (ID7NodeRevision nodeRevision, CancellationToken tkn) { if (!IsLoggedIn) throw Error.BadAct($"‹{this.GetType().Name}› is not logged in."); if (nodeRevision.vid < 1) return Error_n("Invalid node revision format.", "Revision ID (vid) must be set."); var req = _auth.Req.PUT(URL.Api_EntityNodeX, nodeRevision.nid); nodeRevision.uid = this.CurrentUser.uid; req.Body = nodeRevision; //Debug_n($"Updating node [nid:{nodeRevision.nid}]...", ""); IResponseShim resp = null; try { resp = await _client.Send(req, tkn); } catch (RestServiceException ex) { OnNodeEdit.Err(this, ex); } catch (Exception ex) { OnUnhandled.Err(this, ex); } if (resp == null) return Error_n("Failed to update node.", "Response is NULL"); if (!resp.IsSuccess) return Error_n("Failed to update node.", resp.Message); //return Debug_n("Node successfully updated.", ""); return true; }
public static RestServiceException Rest(string msg, IResponseShim resp) { return(Error.Rest(msg, resp.Code, resp.Request.Method, resp.BaseUrl, resp.Request.Resource, resp.Error)); }
public static void Rest(string msg, IResponseShim resp) { throw Error.Rest(msg, resp); }