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
        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;
        }