Esempio n. 1
0
        /// <summary>VALIDATION</summary>
        /// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
        internal Status ValidateRevision(RevisionInternal newRev, RevisionInternal oldRev, String parentRevId)
        {
            var validations = Shared.GetValues("validation", Name);
            if (validations == null || validations.Count == 0) {
                return new Status(StatusCode.Ok);
            }

            var publicRev = new SavedRevision(this, newRev, parentRevId);
            var context = new ValidationContext(this, oldRev, newRev);
            Status status = new Status(StatusCode.Ok);
            foreach (var validationName in validations.Keys)
            {
                var validation = GetValidation(validationName);
                try {
                    validation(publicRev, context);
                } catch(Exception e) {
                    Log.E(TAG, String.Format("Validation block '{0}'", validationName), e);
                    status.Code = StatusCode.Exception;
                    break;
                }
                    
                if (context.RejectMessage != null) {
                    Log.D(TAG, "Failed update of {0}: {1}:{2} Old doc = {3}{2} New doc = {4}", oldRev, context.RejectMessage,
                            Environment.NewLine, oldRev == null ? null : oldRev.GetProperties(), newRev.GetProperties());
                    status.Code = StatusCode.Forbidden;
                    break;
                }
            }

            return status;
        }
        /// <summary>VALIDATION</summary>
        /// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
        internal void ValidateRevision(RevisionInternal newRev, RevisionInternal oldRev, String parentRevId)
        {
            if (_validations == null || _validations.Count == 0)
            {
                return;
            }

            var publicRev = new SavedRevision(this, newRev);
            publicRev.ParentRevisionID = parentRevId;
            var context = new ValidationContext(this, oldRev, newRev);
            foreach (var validationName in _validations.Keys)
            {
                var validation = GetValidation(validationName);
                validation(publicRev, context);
                if (context.RejectMessage != null)
                {
                    throw new CouchbaseLiteException(context.RejectMessage, StatusCode.Forbidden);
                }
            }
        }
Esempio n. 3
0
			public void Validate(Revision newRevision, ValidationContext context)
			{
				{
					if (newRevision.GetProperty("groovy") == null)
					{
						context.Reject("uncool");
					}
				}
			}
			public void Validate(Revision newRevision, ValidationContext context)
			{
				NUnit.Framework.Assert.IsNotNull(newRevision);
				NUnit.Framework.Assert.IsNotNull(context);
				NUnit.Framework.Assert.IsTrue(newRevision.GetProperties() != null || newRevision.
					IsDeletion());
				this._enclosing.validationCalled = true;
				bool hoopy = newRevision.IsDeletion() || (newRevision.GetProperties().Get("towel"
					) != null);
				Log.V(ValidationsTest.Tag, string.Format("--- Validating %s --> %b", newRevision.
					GetProperties(), hoopy));
				if (!hoopy)
				{
					context.Reject("Where's your towel?");
				}
			}
Esempio n. 5
0
			public void Validate(Revision newRevision, ValidationContext context)
			{
			}