当前位置: 首页>>代码示例>>C#>>正文


C# Lite.Status类代码示例

本文整理汇总了C#中Couchbase.Lite.Status的典型用法代码示例。如果您正苦于以下问题:C# Status类的具体用法?C# Status怎么用?C# Status使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Status类属于Couchbase.Lite命名空间,在下文中一共展示了Status类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

 public bool Run()
 {
     StringBuilder sb = new StringBuilder();
     for (int i = 0; i < this._enclosing.GetSizeOfAttachment(); i++)
     {
         sb.Append('1');
     }
     byte[] attach1 = Sharpen.Runtime.GetBytesForString(sb.ToString());
     try
     {
         Status status = new Status();
         for (int i_1 = 0; i_1 < this._enclosing.GetNumberOfDocuments(); i_1++)
         {
             IDictionary<string, object> rev1Properties = new Dictionary<string, object>();
             rev1Properties.Put("foo", 1);
             rev1Properties.Put("bar", false);
             RevisionInternal rev1 = this._enclosing.database.PutRevision(new RevisionInternal
                 (rev1Properties, this._enclosing.database), null, false, status);
             NUnit.Framework.Assert.AreEqual(Status.Created, status.GetCode());
             this._enclosing.database.InsertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream
                 (attach1), rev1.GetSequence(), Test3_CreateDocsWithAttachments._testAttachmentName
                 , "text/plain", rev1.GetGeneration());
             NUnit.Framework.Assert.AreEqual(Status.Created, status.GetCode());
         }
     }
     catch (Exception t)
     {
         Log.E(Test3_CreateDocsWithAttachments.Tag, "Document create with attachment failed"
             , t);
         return false;
     }
     return true;
 }
开发者ID:jonlipsky,项目名称:couchbase-lite-net,代码行数:33,代码来源:Test3_CreateDocsWithAttachments.cs

示例2: TestChangeNotification

        public void TestChangeNotification()
        {
            var changeNotifications = 0;

            EventHandler<DatabaseChangeEventArgs> handler
                = (sender, e) => changeNotifications++;

            database.Changed += handler;

            // create a document
            var documentProperties = new Dictionary<string, object>();
            documentProperties["foo"] = 1;
            documentProperties["bar"] = false;
            documentProperties["baz"] = "touch";
            
            var body = new Body(documentProperties);
            var rev1 = new RevisionInternal(body, database);
            
            var status = new Status();
            database.PutRevision(rev1, null, false, status);
            
            Assert.AreEqual(1, changeNotifications);

            // Analysis disable once DelegateSubtraction
            database.Changed -= handler;
        }
开发者ID:FireflyLogic,项目名称:couchbase-lite-net,代码行数:26,代码来源:ChangesTest.cs

示例3: Run

 public bool Run()
 {
     string[] bigObj = new string[this._enclosing.GetSizeOfDocument()];
     for (int i = 0; i < this._enclosing.GetSizeOfDocument(); i++)
     {
         bigObj[i] = Test10_DeleteDB._propertyValue;
     }
     for (int i_1 = 0; i_1 < this._enclosing.GetNumberOfDocuments(); i_1++)
     {
         //create a document
         IDictionary<string, object> props = new Dictionary<string, object>();
         props.Put("bigArray", bigObj);
         Body body = new Body(props);
         RevisionInternal rev1 = new RevisionInternal(body, this._enclosing.database);
         Status status = new Status();
         try
         {
             rev1 = this._enclosing.database.PutRevision(rev1, null, false, status);
         }
         catch (Exception t)
         {
             Log.E(Test10_DeleteDB.Tag, "Document create failed", t);
             return false;
         }
     }
     return true;
 }
开发者ID:jonlipsky,项目名称:couchbase-lite-net,代码行数:27,代码来源:Test10_DeleteDB.cs

示例4: PutDoc

		/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
		private RevisionInternal PutDoc(Database db, IDictionary<string, object> props)
		{
			RevisionInternal rev = new RevisionInternal(props, db);
			Status status = new Status();
			rev = db.PutRevision(rev, null, false, status);
			NUnit.Framework.Assert.IsTrue(status.IsSuccessful());
			return rev;
		}
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:9,代码来源:ViewsTest.cs

示例5: TestChangeNotification

		/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
		public virtual void TestChangeNotification()
		{
			// add listener to database
            database.Changed += (sender, e) => changeNotifications++;
			// create a document
			IDictionary<string, object> documentProperties = new Dictionary<string, object>();
			documentProperties["foo"] = 1;
			documentProperties["bar"] = false;
			documentProperties["baz"] = "touch";
			Body body = new Body(documentProperties);
			RevisionInternal rev1 = new RevisionInternal(body, database);
			Status status = new Status();
			rev1 = database.PutRevision(rev1, null, false, status);
			NUnit.Framework.Assert.AreEqual(1, changeNotifications);
		}
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:16,代码来源:ChangesTest.cs

示例6: TestChangeNotification

		/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
		public virtual void TestChangeNotification()
		{
			Database.ChangeListener changeListener = new _ChangeListener_16(this);
			// add listener to database
			database.AddChangeListener(changeListener);
			// create a document
			IDictionary<string, object> documentProperties = new Dictionary<string, object>();
			documentProperties.Put("foo", 1);
			documentProperties.Put("bar", false);
			documentProperties.Put("baz", "touch");
			Body body = new Body(documentProperties);
			RevisionInternal rev1 = new RevisionInternal(body, database);
			Status status = new Status();
			rev1 = database.PutRevision(rev1, null, false, status);
			NUnit.Framework.Assert.AreEqual(1, changeNotifications);
		}
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:17,代码来源:ChangesTest.cs

示例7: TestLoadDBPerformance

 /// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
 public virtual void TestLoadDBPerformance()
 {
     long startMillis = Runtime.CurrentTimeMillis();
     string[] bigObj = new string[GetSizeOfDocument()];
     for (int i = 0; i < GetSizeOfDocument(); i++)
     {
         bigObj[i] = _propertyValue;
     }
     for (int j = 0; j < GetNumberOfShutAndReloadCycles(); j++)
     {
         //Force close and reopen of manager and database to ensure cold
         //start before doc creation
         try
         {
             TearDown();
             manager = new Manager(new LiteTestContext(), Manager.DefaultOptions);
             database = manager.GetExistingDatabase(DefaultTestDb);
         }
         catch (Exception ex)
         {
             Log.E(Tag, "DB teardown", ex);
             Fail();
         }
         for (int k = 0; k < GetNumberOfDocuments(); k++)
         {
             //create a document
             IDictionary<string, object> props = new Dictionary<string, object>();
             props.Put("bigArray", bigObj);
             Body body = new Body(props);
             RevisionInternal rev1 = new RevisionInternal(body, database);
             Status status = new Status();
             try
             {
                 rev1 = database.PutRevision(rev1, null, false, status);
             }
             catch (Exception t)
             {
                 Log.E(Tag, "Document creation failed", t);
                 Fail();
             }
         }
     }
     Log.V("PerformanceStats", Tag + "," + Sharpen.Extensions.ValueOf(Runtime.CurrentTimeMillis
         () - startMillis).ToString() + "," + GetNumberOfDocuments() + "," + GetSizeOfDocument
         () + ",," + GetNumberOfShutAndReloadCycles());
 }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:47,代码来源:Test9_LoadDB.cs

示例8: TestCreateDocsUnoptimizedWayPerformance

 /// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
 public virtual void TestCreateDocsUnoptimizedWayPerformance()
 {
     long startMillis = Runtime.CurrentTimeMillis();
     string[] bigObj = new string[GetSizeOfDocument()];
     for (int i = 0; i < GetSizeOfDocument(); i++)
     {
         bigObj[i] = _propertyValue;
     }
     for (int i_1 = 0; i_1 < GetNumberOfDocuments(); i_1++)
     {
         //create a document
         IDictionary<string, object> props = new Dictionary<string, object>();
         props.Put("bigArray", bigObj);
         Body body = new Body(props);
         RevisionInternal rev1 = new RevisionInternal(body, database);
         Status status = new Status();
         rev1 = database.PutRevision(rev1, null, false, status);
     }
     Log.V("PerformanceStats", Tag + "," + Sharpen.Extensions.ValueOf(Runtime.CurrentTimeMillis
         () - startMillis).ToString() + "," + GetNumberOfDocuments() + "," + GetSizeOfDocument
         ());
 }
开发者ID:jonlipsky,项目名称:couchbase-lite-net,代码行数:23,代码来源:Test2_CreateDocsUnoptimizedWay.cs

示例9: QueryViewNamed

        internal IEnumerable<QueryRow> QueryViewNamed(String viewName, QueryOptions options, long ifChangedSince, ValueTypePtr<long> outLastSequence, Status outStatus = null)
        {
            if (outStatus == null) {
                outStatus = new Status();
            }

            IEnumerable<QueryRow> iterator = null;
            Status status = null;
            long lastIndexedSequence = 0, lastChangedSequence = 0;
            do {
                if(viewName != null) {
                    var view = GetView(viewName);
                    if(view == null) {
                        outStatus.Code = StatusCode.NotFound;
                        break;
                    }

                    lastIndexedSequence = view.LastSequenceIndexed;
                    if(options.Stale == IndexUpdateMode.Before || lastIndexedSequence <= 0) {
                        status = view.UpdateIndex();
                        if(status.IsError) {
                            Log.W(TAG, "Failed to update index: {0}", status.Code);
                            break;
                        }

                        lastIndexedSequence = view.LastSequenceIndexed;
                    } else if(options.Stale == IndexUpdateMode.After && lastIndexedSequence <= LastSequenceNumber) {
                        RunAsync(d => view.UpdateIndex());
                    }

                    lastChangedSequence = view.LastSequenceChangedAt;
                    iterator = view.QueryWithOptions(options);
                } else { // null view means query _all_docs
                    iterator = GetAllDocs(options);
                    lastIndexedSequence = lastChangedSequence = LastSequenceNumber;
                }

                if(lastChangedSequence <= ifChangedSince) {
                    status = new Status(StatusCode.NotModified);
                }
            } while(false); // just to allow 'break' within the block

            outLastSequence.Value = lastIndexedSequence;
            if (status != null) {
                outStatus.Code = status.Code;
            }

            return iterator;
        }
开发者ID:DotNetEra,项目名称:couchbase-lite-net,代码行数:49,代码来源:Database.cs

示例10: GetFilter

        /// <summary>
        /// Returns the <see cref="ValidateDelegate" /> for the given name, or null if it does not exist.
        /// </summary>
        /// <returns>The <see cref="ValidateDelegate" /> for the given name, or null if it does not exist.</returns>
        /// <param name="name">The name of the validation delegate to get.</param>
        /// <param name="status">The result of the operation</param>
        public FilterDelegate GetFilter(String name, Status status = null) 
        { 
            FilterDelegate result = null;
            if (!Shared.TryGetValue("filter", name, Name, out result)) {
                result = null;
            }

            if (result == null) {
                var filterCompiler = FilterCompiler;
                if (filterCompiler == null) {
                    return null;
                }

                string language = null;
                var sourceCode = GetDesignDocFunction(name, "filters", out language) as string;

                if (sourceCode == null) {
                    if (status != null) {
                        status.Code = StatusCode.NotFound;
                    }
                    return null;
                }

                var filter = filterCompiler.CompileFilter(sourceCode, language);
                if (filter == null) {
                    if (status != null) {
                        status.Code = StatusCode.CallbackError;
                    }
                    Log.W(TAG, string.Format("Filter {0} failed to compile", name));
                    return null;
                }

                SetFilter(name, filter);
                return filter;
            }

            return result;
        }
开发者ID:DotNetEra,项目名称:couchbase-lite-net,代码行数:44,代码来源:Database.cs

示例11: UpdateAttachment

        /// <summary>Updates or deletes an attachment, creating a new document revision in the process.
        ///     </summary>
        /// <remarks>
        /// Updates or deletes an attachment, creating a new document revision in the process.
        /// Used by the PUT / DELETE methods called on attachment URLs.
        /// </remarks>
        /// <exclude></exclude>
        /// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
        internal RevisionInternal UpdateAttachment(string filename, BlobStoreWriter body, string contentType, AttachmentEncoding encoding, string docID, string oldRevID)
        {
            if(StringEx.IsNullOrWhiteSpace(filename) || (body != null && contentType == null) || 
                (oldRevID != null && docID == null) || (body != null && docID == null)) {
                throw new CouchbaseLiteException(StatusCode.BadAttachment);
            }

            var oldRev = new RevisionInternal(docID, oldRevID, false);
            if (oldRevID != null) {
                // Load existing revision if this is a replacement:
                try {
                    oldRev = LoadRevisionBody(oldRev);
                } catch (CouchbaseLiteException e) {
                    if (e.Code == StatusCode.NotFound && GetDocument(docID, null, false) != null) {
                        throw new CouchbaseLiteException(StatusCode.Conflict);
                    }

                    throw;
                }
            } else {
                // If this creates a new doc, it needs a body:
                oldRev.SetBody(new Body(new Dictionary<string, object>()));
            }

            // Update the _attachments dictionary:
            var attachments = oldRev.GetProperties().Get("_attachments").AsDictionary<string, object>();
            if (attachments == null) {
                attachments = new Dictionary<string, object>();
            }

            if (body != null) {
                var key = body.GetBlobKey();
                string digest = key.Base64Digest();
                RememberAttachmentWriter(body);
                string encodingName = (encoding == AttachmentEncoding.GZIP) ? "gzip" : null;
                attachments[filename] = new NonNullDictionary<string, object> {
                    { "digest", digest },
                    { "length", body.GetLength() },
                    { "follows", true },
                    { "content_type", contentType },
                    { "encoding", encodingName }
                };
            } else {
                if (oldRevID != null && attachments.Get(filename) == null) {
                    throw new CouchbaseLiteException(StatusCode.AttachmentNotFound);
                }

                attachments.Remove(filename);
            }

            var properties = oldRev.GetProperties();
            properties["_attachments"] = attachments;
            oldRev.SetProperties(properties);

            Status status = new Status();
            var newRev = PutRevision(oldRev, oldRevID, false, status);
            if (status.IsError) {
                throw new CouchbaseLiteException(status.Code);
            }

            return newRev;
        }
开发者ID:DotNetEra,项目名称:couchbase-lite-net,代码行数:70,代码来源:Database.cs

示例12: GetAttachmentForRevision

        internal AttachmentInternal GetAttachmentForRevision(RevisionInternal rev, string name, Status status = null)
        {
            Debug.Assert(name != null);
            var attachments = rev.GetAttachments();
            if (attachments == null) {
                try {
                    rev = LoadRevisionBody(rev);
                } catch(CouchbaseLiteException e) {
                    if (status != null) {
                        status.Code = e.CBLStatus.Code;
                    }

                    return null;
                }

                attachments = rev.GetAttachments();
                if (attachments == null) {
                    status.Code = StatusCode.NotFound;
                    return null;
                }
            }

            return AttachmentForDict(attachments.Get(name).AsDictionary<string, object>(), name, status);
        }
开发者ID:DotNetEra,项目名称:couchbase-lite-net,代码行数:24,代码来源:Database.cs

示例13: ProcessAttachmentsForRevision

        internal bool ProcessAttachmentsForRevision(RevisionInternal rev, string prevRevId, Status status)
        {
            if (status == null) {
                status = new Status();
            }

            status.Code = StatusCode.Ok;
            var revAttachments = rev.GetAttachments();
            if (revAttachments == null) {
                return true; // no-op: no attachments
            }

            // Deletions can't have attachments:
            if (rev.IsDeleted() || revAttachments.Count == 0) {
                var body = rev.GetProperties();
                body.Remove("_attachments");
                rev.SetProperties(body);
                return true;
            }

            int generation = RevisionInternal.GenerationFromRevID(prevRevId) + 1;
            IDictionary<string, object> parentAttachments = null;
            return rev.MutateAttachments((name, attachInfo) =>
            {
                AttachmentInternal attachment = null;
                try {
                    attachment = new AttachmentInternal(name, attachInfo);
                } catch(CouchbaseLiteException e) {
                    return null;
                }

                if(attachment.EncodedContent != null) {
                    // If there's inline attachment data, decode and store it:
                    BlobKey blobKey = new BlobKey();
                    if(!Attachments.StoreBlob(attachment.EncodedContent.ToArray(), blobKey)) {
                        status.Code = StatusCode.AttachmentError;
                        return null;
                    }

                    attachment.BlobKey = blobKey;
                } else if(attachInfo.GetCast<bool>("follows")) {
                    // "follows" means the uploader provided the attachment in a separate MIME part.
                    // This means it's already been registered in _pendingAttachmentsByDigest;
                    // I just need to look it up by its "digest" property and install it into the store:
                    InstallAttachment(attachment, attachInfo);
                } else if(attachInfo.GetCast<bool>("stub")) {
                    // "stub" on an incoming revision means the attachment is the same as in the parent.
                    if(parentAttachments == null && prevRevId != null) {
                        parentAttachments = GetAttachmentsFromDoc(rev.GetDocId(), prevRevId, status);
                        if(parentAttachments == null) {
                            if(status.Code == StatusCode.Ok || status.Code == StatusCode.NotFound) {
                                status.Code = StatusCode.BadAttachment;
                            }

                            return null;
                        }
                    }

                    var parentAttachment = parentAttachments == null ? null : parentAttachments.Get(name).AsDictionary<string, object>();
                    if(parentAttachment == null) {
                        status.Code = StatusCode.BadAttachment;
                        return null;
                    }

                    return parentAttachment;
                }


                // Set or validate the revpos:
                if(attachment.RevPos == 0) {
                    attachment.RevPos = generation;
                } else if(attachment.RevPos >= generation) {
                    status.Code = StatusCode.BadAttachment;
                    return null;
                }

                Debug.Assert(attachment.IsValid);
                return attachment.AsStubDictionary();
            });
        }
开发者ID:DotNetEra,项目名称:couchbase-lite-net,代码行数:80,代码来源:Database.cs

示例14: ExpandAttachments

        internal bool ExpandAttachments(RevisionInternal rev, int minRevPos, bool allowFollows, 
            bool decodeAttachments, Status outStatus)
        {
            outStatus.Code = StatusCode.Ok;
            rev.MutateAttachments((name, attachment) =>
            {
                var revPos = attachment.GetCast<long>("revpos");
                if(revPos < minRevPos && revPos != 0) {
                    //Stub:
                    return new Dictionary<string, object> { { "stub", true }, { "revpos", revPos } };
                }

                var expanded = new Dictionary<string, object>(attachment);
                expanded.Remove("stub");
                if(decodeAttachments) {
                    expanded.Remove("encoding");
                    expanded.Remove("encoded_length");
                }

                if(allowFollows && SmallestLength(expanded) >= Database.BIG_ATTACHMENT_LENGTH) {
                    //Data will follow (multipart):
                    expanded["follows"] = true;
                    expanded.Remove("data");
                } else {
                    //Put data inline:
                    expanded.Remove("follows");
                    Status status = new Status();
                    var attachObj = AttachmentForDict(attachment, name, status);
                    if(attachObj == null) {
                        Log.W(TAG, "Can't get attachment '{0}' of {1} (status {2})", name, rev, status);
                        outStatus.Code = status.Code;
                        return attachment;
                    }

                    var data = decodeAttachments ? attachObj.Content : attachObj.EncodedContent;
                    if(data == null) {
                        Log.W(TAG, "Can't get binary data of attachment '{0}' of {1}", name, rev);
                        outStatus.Code = StatusCode.NotFound;
                        return attachment;
                    }

                    expanded["data"] = Convert.ToBase64String(data.ToArray());
                }
                    
                return expanded;
            });

            return outStatus.Code == StatusCode.Ok;
        }
开发者ID:DotNetEra,项目名称:couchbase-lite-net,代码行数:49,代码来源:Database.cs

示例15: UpdateAttachment

        /// <summary>Updates or deletes an attachment, creating a new document revision in the process.
        ///     </summary>
        /// <remarks>
        /// Updates or deletes an attachment, creating a new document revision in the process.
        /// Used by the PUT / DELETE methods called on attachment URLs.
        /// </remarks>
        /// <exclude></exclude>
        /// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
        internal RevisionInternal UpdateAttachment(string filename, BlobStoreWriter body, string contentType, AttachmentEncoding encoding, string docID, string oldRevID)
        {
            var isSuccessful = false;
            if (String.IsNullOrEmpty (filename) || (body != null && contentType == null) || (oldRevID != null && docID == null) || (body != null && docID == null))
            {
                throw new CouchbaseLiteException(StatusCode.BadRequest);
            }

            BeginTransaction();

            try
            {
                var oldRev = new RevisionInternal(docID, oldRevID, false, this);
                if (oldRevID != null)
                {
                    // Load existing revision if this is a replacement:
                    try
                    {
                        LoadRevisionBody(oldRev, DocumentContentOptions.None);
                    }
                    catch (CouchbaseLiteException e)
                    {
                        if (e.GetCBLStatus().GetCode() == StatusCode.NotFound && ExistsDocumentWithIDAndRev(docID, null))
                        {
                            throw new CouchbaseLiteException(StatusCode.Conflict);
                        }
                    }
                }
                else
                {
                    // If this creates a new doc, it needs a body:
                    oldRev.SetBody(new Body(new Dictionary<string, object>()));
                }
                // Update the _attachments dictionary:
                var oldRevProps = oldRev.GetProperties();
                IDictionary<string, object> attachments = null;
                if (oldRevProps != null)
                {
                    attachments = (IDictionary<string, object>)oldRevProps.Get("_attachments");
                }
                if (attachments == null)
                {
                    attachments = new Dictionary<string, object>();
                }
                if (body != null)
                {
                    var key = body.GetBlobKey();
                    var digest = key.Base64Digest();

                    var blobsByDigest = new Dictionary<string, BlobStoreWriter>();
                    blobsByDigest.Put(digest, body);

                    RememberAttachmentWritersForDigests(blobsByDigest);

                    var encodingName = (encoding == AttachmentEncoding.AttachmentEncodingGZIP) ? "gzip" : null;
                    var dict = new Dictionary<string, object>();
                    dict.Put("digest", digest);
                    dict.Put("length", body.GetLength());
                    dict.Put("follows", true);
                    dict.Put("content_type", contentType);
                    dict.Put("encoding", encodingName);

                    attachments.Put(filename, dict);
                }
                else
                {
                    if (oldRevID != null && !attachments.ContainsKey(filename))
                    {
                        throw new CouchbaseLiteException(StatusCode.NotFound);
                    }
                    attachments.Remove(filename);
                }

                var properties = oldRev.GetProperties();
                properties.Put("_attachments", attachments);
                oldRev.SetProperties(properties);

                // Create a new revision:
                var putStatus = new Status();
                var newRev = PutRevision(oldRev, oldRevID, false, putStatus);

                isSuccessful = true;

                return newRev;
            }
            catch (SQLException e)
            {
                Log.E(Tag, "Error updating attachment", e);
                throw new CouchbaseLiteException(StatusCode.InternalServerError);
            }
            finally
            {
//.........这里部分代码省略.........
开发者ID:FireflyLogic,项目名称:couchbase-lite-net,代码行数:101,代码来源:Database.cs


注:本文中的Couchbase.Lite.Status类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。