Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
 private void PropertyChanged(DateTime eventTime, ResourceBE prop, UserBE user, ResourceBE.ParentType parentType, XUri parentUri, params string[] path) {
     try {
         string parent = string.Empty;
         switch(parentType) {
         case ResourceBE.ParentType.PAGE:
             parent = PAGES;
             break;
         case ResourceBE.ParentType.FILE:
             parent = FILES;
             break;
         case ResourceBE.ParentType.USER:
             parent = USERS;
             break;
         case ResourceBE.ParentType.SITE:
             parent = SITE;
             break;
         }
         XUri channel = _channel.At(parent).At(PROPERTY).At(path);
         XUri resource = prop.PropertyInfoUri(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.PropertyContentUri(parentUri));
         if(prop.MimeType.MainType == MimeType.TEXT.MainType && prop.Size < 256) {
             doc.Value(ResourceContentBL.Instance.Get(prop).ToText());
         }
         doc.End();
         if(parentType == ResourceBE.ParentType.PAGE) {
             doc.Elem("pageid", prop.ParentPageId ?? 0);
         } else if(parentType == ResourceBE.ParentType.USER) {
             doc.Elem("userid", prop.ParentUserId ?? 0);
         } else if(parentType == ResourceBE.ParentType.FILE) {
             ResourceBE attachment = ResourceBL.Instance.GetResource(prop.ParentId.Value);
             doc.Elem("fileid", attachment.MetaXml.FileId ?? 0);
             PageDependentChanged(eventTime, PageBL.GetPageById(attachment.ParentPageId.Value), 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");
     }
 }