private void PropertyChanged(DateTime eventTime, PropertyBE prop, UserBE user, ResourceBE.Type parentType, XUri parentUri, params string[] path) { try { string parent = string.Empty; switch(parentType) { case ResourceBE.Type.PAGE: parent = PAGES; break; case ResourceBE.Type.FILE: parent = FILES; break; case ResourceBE.Type.USER: parent = USERS; break; case ResourceBE.Type.SITE: parent = SITE; break; } XUri channel = _channel.At(parent).At(PROPERTY).At(path); XUri resource = prop.UriInfo(parentUri); string[] origin = new string[] { resource.ToString() }; XDoc doc = new XDoc("deki-event") .Elem("channel", channel) .Elem("name", prop.Name) .Elem("uri", resource) .Start("content") .Attr("mime-type", prop.MimeType.FullType) .Attr("size", prop.Size) .Attr("href", prop.UriContent(parentUri)); if(prop.MimeType.MainType == MimeType.TEXT.MainType && prop.Size < 256) { doc.Value(prop.Content.ToText()); } doc.End(); if(parentType == ResourceBE.Type.PAGE) { doc.Elem("pageid", prop.ParentPageId ?? 0); } else if(parentType == ResourceBE.Type.USER) { doc.Elem("userid", prop.ParentUserId ?? 0); } else if(parentType == ResourceBE.Type.FILE) { AttachmentBE attachment = (AttachmentBE)prop.ParentResource; doc.Elem("fileid", attachment.FileId ?? 0); PageDependentChanged(eventTime, ((PageWrapperBE)attachment.ParentResource).Page, user, ArrayUtil.Concat(new string[] { FILES, PROPERTY }, path)); } Queue(eventTime, channel, resource, origin, doc); } catch(Exception e) { _log.WarnExceptionMethodCall(e, "PropertyChanged", "event couldn't be created"); } }
private void NotifyPropertyParent(DateTime eventTime, PropertyBE prop, UserBE user, ResourceBE.Type parentType, string action) { if(parentType == ResourceBE.Type.PAGE && prop.ParentPageId != null) { PageBE parentPage = PageBL.GetPageById(prop.ParentPageId.Value); if(parentPage != null) { PageDependentChanged(eventTime, parentPage, user, PROPERTY, action); } } else if(parentType == ResourceBE.Type.USER) { // Owner of property may not be same as requesting user. // The dependentschanged event is triggered on the property owner. if(prop.ParentUserId != null) { // Optimization to avoid a db call when operating on your own user property. if(user.ID != prop.ParentUserId.Value) { user = UserBL.GetUserById(prop.ParentUserId.Value); if(user == null) { _log.WarnFormat("Could not find owner user (id: {0}) of user property (key: {1})", prop.ParentUserId.Value, prop.Name); return; } } } UserDependentChanged(eventTime, user, PROPERTY, action); } //TODO (maxm): trigger file property changes }
private void PropertyExport(PageBE page, AttachmentBE file, PropertyBE property) { // Export the property XUri propertyUri = null; string filename = null; if(null != file) { propertyUri = property.UriContent(AttachmentBL.Instance.GetUri(file)); filename = file.Name; } else { propertyUri = property.UriContent(PageBL.GetUriCanonical(page)); } if(!_uris.ContainsKey(propertyUri)) { _uris.Add(propertyUri, null); XDoc manifestDoc = new XDoc("property").Elem("name", property.Name) .Elem("filename", filename) .Elem("path", page.Title.AsRelativePath(_relToTitle)) .Start("contents").Attr("type", property.MimeType.ToString()).End(); Add(propertyUri, manifestDoc); } }
public void PropertyDelete(DateTime eventTime, PropertyBE prop, UserBE user, ResourceBE.Type parentType, XUri parentUri) { NotifyPropertyParent(eventTime, prop, user, parentType, DELETE); PropertyChanged(eventTime, prop, user, parentType, parentUri, DELETE); }
internal Hashtable MakePropertyObject(PropertyBE property) { if(property == null) { return null; } Hashtable result = new Hashtable(StringComparer.OrdinalIgnoreCase); // check permission & set parent reference if(property.ParentPageId != null) { if(!PermissionsBL.IsUserAllowed(DekiContext.Current.User, PageBL.GetPageById(property.ParentPageId.Value), Permissions.READ)) { return result; } // set parent result.Add("page", PropertyAt("$page", property.ParentPageId.Value)); // check if property is head revision (API doesn't support access to older revisions) if(property.IsHeadRevision()) { result.Add("api", property.Uri(Self.At("pages", property.ParentPageId.Value.ToString()))); } } else if(property.ParentUserId != null) { // check that the current user can access the properties of the specified user if((property.ParentUserId != DekiContext.Current.User.ID) && !PermissionsBL.IsUserAllowed(DekiContext.Current.User, Permissions.ADMIN)) { return result; } // set parent result.Add("user", PropertyAt("$user", property.ParentUserId.Value)); // check if property is head revision (API doesn't support access to older revisions) if(property.IsHeadRevision()) { result.Add("api", property.Uri(Self.At("users", property.ParentUserId.Value.ToString()))); } } else if(property.ParentId != null) { // parent must be a file resource, retrieve the parent and check it AttachmentBE parent = AttachmentBL.Instance.GetResource(property.ParentId.Value); // the parent must have a parent page id, o/w something isn't what we expect it to be if(parent == null) { return result; } PageBE page = PageBL.GetPageById(parent.ParentPageId); if(!PermissionsBL.IsUserAllowed(DekiContext.Current.User, page, Permissions.READ)) { return result; } // set parent uint? fileId = ResourceMapBL.GetFileIdByResourceId(property.ParentId.Value); if(fileId != null) { result.Add("file", PropertyAt("$file", fileId.Value)); // check if property is head revision (API doesn't support access to older revisions) if(property.IsHeadRevision()) { result.Add("api", property.Uri(Self.At("files", fileId.Value.ToString()))); } } else { _log.WarnFormat("Could not find parent of property {0} (expected parent to be a file)", property.ResourceId); } } else { // must be a site property if(!PermissionsBL.IsUserAllowed(DekiContext.Current.User, Permissions.ADMIN)) { return result; } } // set property information fields result.Add("editsummary", property.ChangeDescription); result.Add("language", property.Language); result.Add("mime", property.MimeType.FullType); // split name into namespace-name pair int index = property.Name.IndexOf('#'); if(index >= 0) { result.Add("namespace", property.Name.Substring(0, index)); result.Add("name", property.Name.Substring(index + 1)); } else { result.Add("namespace", string.Empty); result.Add("name", property.Name); } // get authorship information result.Add("size", property.Size); result.Add("date", property.Timestamp); result.Add("author", PropertyAt("$user", property.UserId)); result.Add("revision", property.Revision); result.Add("revisions", PropertyAt("$proprevisions", property.ResourceId)); // set content values if(property.MimeType.Match(MimeType.ANY_TEXT)) { result.Add("text", property.Content.ToText()); result.Add("xml", null); } else if(property.MimeType.IsXml) { string text = property.Content.ToText(); result.Add("text", text); result.Add("xml", DekiScriptExpression.Constant(XDocFactory.From(text, MimeType.XML))); } else { // TODO (steveb): binary types are not yet supported result.Add("text", null); result.Add("xml", null); } return result; }