public void DeleteFile(ResourceBE attachment, SizeType size) { if (!attachment.IsHeadRevision()) { throw new StorageNonHeadRevisionDeleteFatalException(); } for (int i = 1; i <= attachment.Content.Revision; i++) { string filename = FilePath(attachment, size); try { File.Delete(filename); } catch { } } }
public XUri GetUriInfo(ResourceBE file, bool?includeRevision) { if (includeRevision == null) { includeRevision = !file.IsHeadRevision(); } if (includeRevision.Value) { return(GetUri(file).At("info").With("revision", file.Revision.ToString())); } else { return(GetUri(file).At("info")); } }
public XUri GetUriContent(ResourceBE file, bool?includeRevision) { if (includeRevision == null) { includeRevision = !file.IsHeadRevision(); } XUri uri = GetUri(file); if (includeRevision.Value) { uri = uri.With("revision", file.Revision.ToString()); } uri = uri.At(Title.AsApiParam(file.Name)); return(uri); }
public ResourceBE Resources_UpdateRevision(ResourceBE resource) { //Prepare query for retrieving the resource after updating string selectQuery = new ResourceQuery() .WithResourceId(resource.ResourceId) .WithRevision(resource.Revision) .ToString(); //Note: The resrev_timestamp is not updated in order to preserve the initial timeline of revisions string query = string.Format(@" /* Resources_UpdateRevision */ update resourcerevs set resrev_rev = ?RESREV_REV, resrev_user_id = ?RESREV_USER_ID, resrev_parent_id = ?RESREV_PARENT_ID, resrev_parent_page_id = ?RESREV_PARENT_PAGE_ID, resrev_parent_user_id = ?RESREV_PARENT_USER_ID, resrev_change_mask = ?RESREV_CHANGE_MASK, resrev_name = ?RESREV_NAME, resrev_change_description=?RESREV_CHANGE_DESCRIPTION, resrev_content_id = ?RESREV_CONTENT_ID, resrev_deleted = ?RESREV_DELETED, resrev_changeset_id = ?RESREV_CHANGESET_ID, resrev_size = ?RESREV_SIZE, resrev_mimetype = ?RESREV_MIMETYPE, resrev_language = ?RESREV_LANGUAGE, resrev_is_hidden = ?RESREV_IS_HIDDEN, resrev_meta = ?RESREV_META WHERE resrev_res_id = ?RES_ID AND resrev_rev = ?RESREV_REV; {0} ", selectQuery); ResourceBE[] ret = Resources_ExecuteInsertUpdateQuery(resource, query); if (resource.IsHeadRevision()) { Resources_ResetHeadRevision(resource.ResourceId); } return((ArrayUtil.IsNullOrEmpty(ret)) ? null : ret[0]); }
public bool ValidateEtag(string etag, ResourceBE headResource, bool throwException) { if (!headResource.IsHeadRevision()) { throw new ResourceEtagNotHeadInvalidArgumentException(headResource.ResourceId, headResource.Revision); } bool isValid = false; if (etag != null && StringUtil.EqualsInvariant(etag, headResource.ETag())) { isValid = true; } if (!isValid && throwException) { throw new ResourceEtagConflictException(etag ?? string.Empty, headResource.ResourceId); } return(isValid); }
private XDoc AppendFileXml(XDoc doc, ResourceBE file, string fileSuffix, bool?explicitRevisionInfo, UserBE updatedByUser, PageBE parentPage) { bool requiresEnd = false; string fileElement = string.IsNullOrEmpty(fileSuffix) ? "file" : "file." + fileSuffix; if (doc == null || doc.IsEmpty) { doc = new XDoc(fileElement); } else { doc.Start(fileElement); requiresEnd = true; } doc.Attr("id", file.MetaXml.FileId ?? 0); doc.Attr("revision", file.Revision); doc.Attr("res-id", file.ResourceId); if (file.IsHidden) { doc.Attr("hidden", true); } doc.Attr("href", GetUriInfo(file, explicitRevisionInfo)); doc.Start("filename").Value(file.Name).End(); //Description comes from a property string description = string.Empty; if (!ArrayUtil.IsNullOrEmpty(file.ChildResources)) { ResourceBE descProp = Array.Find(file.ChildResources, p => p != null && p.ResourceType == ResourceBE.Type.PROPERTY && p.Name.EqualsInvariantIgnoreCase(PropertyBL.PROP_DESC)); if (descProp != null) { description = descProp.Content.ToText(); } } doc.Start("description").Value(description).End(); doc.Start("contents") .Attr("type", file.MimeType == null ? null : file.MimeType.ToString()) .Attr("size", file.Size); if ((file.MetaXml.ImageHeight ?? 0) > 0 && (file.MetaXml.ImageWidth ?? 0) > 0) { doc.Attr("width", file.MetaXml.ImageWidth.Value); doc.Attr("height", file.MetaXml.ImageHeight.Value); } doc.Attr("href", GetUriContent(file, explicitRevisionInfo)); doc.End(); //contents if ((file.MetaXml.ImageWidth ?? 0) > 0 && (file.MetaXml.ImageHeight ?? 0) > 0) { string previewMime = AttachmentPreviewBL.ResolvePreviewMime(file.MimeType).ToString(); doc.Start("contents.preview") .Attr("rel", "thumb") .Attr("type", previewMime) .Attr("maxwidth", _dekiContext.Instance.ImageThumbPixels) .Attr("maxheight", _dekiContext.Instance.ImageThumbPixels) .Attr("href", GetUriContent(file, explicitRevisionInfo).With("size", "thumb")); if (!file.IsHeadRevision() || (explicitRevisionInfo ?? false)) { doc.Attr("revision", file.Revision); } doc.End(); //contents.preview: thumb doc.Start("contents.preview") .Attr("rel", "webview") .Attr("type", previewMime) .Attr("maxwidth", _dekiContext.Instance.ImageWebviewPixels) .Attr("maxheight", _dekiContext.Instance.ImageWebviewPixels) .Attr("href", GetUriContent(file, explicitRevisionInfo).With("size", "webview")); if (!file.IsHeadRevision() || (explicitRevisionInfo ?? false)) { doc.Attr("revision", file.Revision); } doc.End(); //contents.preview: webview } doc.Start("date.created").Value(file.Timestamp).End(); if (updatedByUser != null) { doc.Add(UserBL.GetUserXml(updatedByUser, "createdby", Utils.ShowPrivateUserInfo(updatedByUser))); } if (file.ResourceIsDeleted && ((file.ChangeMask & ResourceBE.ChangeOperations.DELETEFLAG) == ResourceBE.ChangeOperations.DELETEFLAG)) { if (updatedByUser != null) { doc.Add(UserBL.GetUserXml(updatedByUser, "deletedby", Utils.ShowPrivateUserInfo(updatedByUser))); } doc.Start("date.deleted").Value(file.Timestamp).End(); } if (file.IsHeadRevision() && !(explicitRevisionInfo ?? false) && !file.ResourceIsDeleted) { uint filteredCount = _session.Resources_GetRevisionCount(file.ResourceId, DEFAULT_REVISION_FILTER); doc.Start("revisions"); doc.Attr("count", filteredCount); doc.Attr("totalcount", file.Revision); doc.Attr("href", GetUri(file).At("revisions")); doc.End(); } else { if (file.ChangeMask != ResourceBE.ChangeOperations.UNDEFINED) { doc.Start("user-action").Attr("type", file.ChangeMask.ToString().ToLowerInvariant()).End(); } } //parent page is passed in for verbose output only if (parentPage != null) { doc.Add(PageBL.GetPageXml(parentPage, "parent")); } if (file.ChildResources != null) { List <ResourceBE> properties = new List <ResourceBE>(); foreach (ResourceBE p in file.ChildResources) { properties.Add(p); } doc = PropertyBL.Instance.GetPropertyXml(properties.ToArray(), GetUri(file), null, null, doc); } if (file.IsHidden) { uint?userIdHiddenBy = file.MetaXml.RevisionHiddenUserId; if (userIdHiddenBy != null) { UserBE userHiddenBy = UserBL.GetUserById(userIdHiddenBy.Value); if (userHiddenBy != null) { doc.Add(UserBL.GetUserXml(userHiddenBy, "hiddenby", Utils.ShowPrivateUserInfo(userHiddenBy))); } } doc.Elem("date.hidden", file.MetaXml.RevisionHiddenTimestamp ?? DateTime.MinValue); doc.Elem("description.hidden", file.MetaXml.RevisionHiddenComment ?? string.Empty); } if (requiresEnd) { doc.End(); //file } return(doc); }
public XUri GetUriInfo(ResourceBE file) { return(GetUriInfo(file, !file.IsHeadRevision())); }
public XUri GetUriContent(ResourceBE file) { return(GetUriContent(file, !file.IsHeadRevision())); }
public ResourceBE Resources_UpdateRevision(ResourceBE resource) { //Prepare query for retrieving the resource after updating string selectQuery = new ResourceQuery() .WithResourceId(resource.ResourceId) .WithRevision(resource.Revision) .ToString(); //Note: The resrev_timestamp is not updated in order to preserve the initial timeline of revisions string query = string.Format(@" /* Resources_UpdateRevision */ update resourcerevs set resrev_rev = ?RESREV_REV, resrev_user_id = ?RESREV_USER_ID, resrev_parent_id = ?RESREV_PARENT_ID, resrev_parent_page_id = ?RESREV_PARENT_PAGE_ID, resrev_parent_user_id = ?RESREV_PARENT_USER_ID, resrev_change_mask = ?RESREV_CHANGE_MASK, resrev_name = ?RESREV_NAME, resrev_change_description=?RESREV_CHANGE_DESCRIPTION, resrev_content_id = ?RESREV_CONTENT_ID, resrev_deleted = ?RESREV_DELETED, resrev_changeset_id = ?RESREV_CHANGESET_ID, resrev_size = ?RESREV_SIZE, resrev_mimetype = ?RESREV_MIMETYPE, resrev_language = ?RESREV_LANGUAGE, resrev_is_hidden = ?RESREV_IS_HIDDEN, resrev_meta = ?RESREV_META WHERE resrev_res_id = ?RES_ID AND resrev_rev = ?RESREV_REV; {0} ", selectQuery); ResourceBE[] ret = Resources_ExecuteInsertUpdateQuery(resource, query); if(resource.IsHeadRevision()) { Resources_ResetHeadRevision(resource.ResourceId); } return (ArrayUtil.IsNullOrEmpty(ret)) ? null : ret[0]; }
private XDoc AppendPropertyXml(XDoc doc, ResourceBE property, XUri parentResourceUri, string propSuffix, bool?explicitRevisionInfo, uint?contentCutoff, Dictionary <uint, UserBE> usersById) { bool requiresEnd = false; explicitRevisionInfo = explicitRevisionInfo ?? false; string propElement = string.IsNullOrEmpty(propSuffix) ? "property" : "property." + propSuffix; if (doc == null || doc.IsEmpty) { doc = new XDoc(propElement); } else { doc.Start(propElement); requiresEnd = true; } //Build the base uri to the property bool includeContents = property.Size <= (contentCutoff ?? DEFAULT_CONTENT_CUTOFF) && (property.MimeType.Match(MimeType.ANY_TEXT) ); //TODO: contents null check doc.Attr("name", property.Name) .Attr("href", /*explicitRevisionInfo.Value ? property.PropertyInfoUri(parentResourceUri, true) : */ property.PropertyInfoUri(parentResourceUri)); if (property.IsHeadRevision()) { doc.Attr("etag", property.ETag()); } /* PROPERTY REVISIONS: if(!property.IsHeadRevision() || explicitRevisionInfo.Value) { * revisions not currently exposed. * doc.Attr("revision", property.Revision); * } */ /* PROPERTY REVISIONS: doc.Start("revisions") * .Attr("count", property.ResourceHeadRevision) * .Attr("href", property.UriRevisions()) * .End(); */ string content = null; if (includeContents) { content = property.Content.ToText(); } doc.Start("contents") .Attr("type", property.MimeType.ToString()) .Attr("size", property.Size) .Attr("href", /*PROPERTY REVISIONS: explicitRevisionInfo.Value ? property.PropertyContentUri(true) : */ property.PropertyContentUri(parentResourceUri)) .Value(content) .End(); doc.Elem("date.modified", property.Timestamp); UserBE userModified; usersById.TryGetValue(property.UserId, out userModified); if (userModified != null) { doc.Add(UserBL.GetUserXml(userModified, "modified", Utils.ShowPrivateUserInfo(userModified))); } doc.Elem("change-description", property.ChangeDescription); if (property.Deleted) { UserBE userDeleted; usersById.TryGetValue(property.UserId, out userDeleted); if (userDeleted != null) { doc.Add(UserBL.GetUserXml(userDeleted, "deleted", Utils.ShowPrivateUserInfo(userDeleted))); } doc.Elem("date.deleted", property.Timestamp); } if (requiresEnd) { doc.End(); //property } return(doc); }