public RevisionInternal(Body body, Database database) : this((string)body.GetPropertyForKey
     ("_id"), (string)body.GetPropertyForKey("_rev"), (((bool)body.GetPropertyForKey(
     "_deleted") != null) && ((bool)body.GetPropertyForKey("_deleted") == true)), database
     )
 {
     this.body = body;
 }
Exemple #2
0
 public RevisionInternal(Body body, Database database) : this((string)body.GetPropertyForKey
                                                                  ("_id"), (string)body.GetPropertyForKey("_rev"), (((bool)body.GetPropertyForKey(
                                                                                                                         "_deleted") != null) && ((bool)body.GetPropertyForKey("_deleted") == true)), database
                                                              )
 {
     this.body = body;
 }
Exemple #3
0
        public object GetPropertyForKey(string key)
        {
            if (key == "_id")
            {
                return(_docId);
            }

            if (key == "_rev")
            {
                return(_revId);
            }

            if (key == "_deleted")
            {
                return(Deleted ? (object)true : null);
            }

            return(_body?.GetPropertyForKey(key));
        }
Exemple #4
0
 // Used by listener
 public static bool IsValid(Body body)
 {
     return(body.GetPropertyForKey("_id") != null ||
            (body.GetPropertyForKey("_rev") == null && body.GetPropertyForKey("_deleted") == null));
 }
        // Perform a document operation on the specified database
        private static CouchbaseLiteResponse UpdateDb(ICouchbaseListenerContext context, Database db, string docId, Body body, bool deleting)
        {
            var response = context.CreateResponse();
            if (docId != null) {
                // On PUT/DELETE, get revision ID from either ?rev= query, If-Match: header, or doc body:
                string revParam = context.GetQueryParam("rev");
                string ifMatch = context.RequestHeaders["If-Match"];
                if (ifMatch != null) {
                    if (revParam == null) {
                        revParam = ifMatch;
                    } else if (!revParam.Equals(ifMatch)) {
                        return context.CreateResponse(StatusCode.BadRequest);
                    }
                }

                if (revParam != null && body != null) {
                    var revProp = body.GetPropertyForKey("_rev");
                    if (revProp == null) {
                        // No _rev property in body, so use ?rev= query param instead:
                        var props = body.GetProperties();
                        props["_rev"] = revParam;
                        body = new Body(props);
                    } else if (!revProp.Equals(revParam)) {
                        return context.CreateResponse(StatusCode.BadRequest); // mismatch between _rev and rev
                    }
                }
            }

            RevisionInternal rev;
            StatusCode status = UpdateDocument(context, db, docId, body, deleting, false, out rev);
            if ((int)status < 300) {
                context.CacheWithEtag(rev.GetRevId()); // set ETag
                if (!deleting) {
                    var url = context.RequestUrl;
                    if (docId != null) {
                        response["Location"] = url.AbsoluteUri;
                    }
                }

                response.JsonBody = new Body(new Dictionary<string, object> {
                    { "ok", true },
                    { "id", rev.GetDocId() },
                    { "rev", rev.GetRevId() }
                });
            }

            response.InternalStatus = status;
            return response;
        }
Exemple #6
0
 internal RevisionInternal(Body body)
     : this(body.GetPropertyForKey <string>("_id"), body.GetPropertyForKey <string>("_rev"), body.GetPropertyForKey <bool>("_deleted"))
 {
     this._body = body;
 }
Exemple #7
0
 public RevisionInternal(Body body, Database database)
     : this((string)body.GetPropertyForKey("_id"), (string)body.GetPropertyForKey("_rev"), (body.HasValueForKey("_deleted") && (bool)body.GetPropertyForKey("_deleted")), database)
 {
     this.body = body;
 }
 public RevisionInternal(Body body, Database database)
     : this((string)body.GetPropertyForKey("_id"), (string)body.GetPropertyForKey("_rev"), (body.HasValueForKey("_deleted") && (bool)body.GetPropertyForKey("_deleted")), database)
 {
     this.body = body;
 }
 internal RevisionInternal(Body body)
     : this(body.GetPropertyForKey<string>("_id"), body.GetPropertyForKey<string>("_rev"), body.GetPropertyForKey<bool>("_deleted"))
 {
     this._body = body;
 }
 public static bool IsValid(Body body)
 {
     return body.GetPropertyForKey("_id") != null ||
     (body.GetPropertyForKey("_rev") == null && body.GetPropertyForKey("_deleted") == null);
 }
 internal RevisionInternal(Body body)
     : this((string)body.GetPropertyForKey("_id"), (string)body.GetPropertyForKey("_rev"), (body.HasValueForKey("_deleted") && (bool)body.GetPropertyForKey("_deleted")))
 {
     this.body = body;
 }