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


C# Status.IsSuccessful方法代码示例

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


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

示例1: UpdateIndex


//.........这里部分代码省略.........
                while (!cursor.IsAfterLast())
                {
                    long docID = cursor.GetLong(0);
                    if (docID != lastDocID)
                    {
                        // Only look at the first-iterated revision of any document,
                        // because this is the
                        // one with the highest revid, hence the "winning" revision
                        // of a conflict.
                        lastDocID = docID;
                        // Reconstitute the document as a dictionary:
                        sequence = cursor.GetLong(1);
                        string docId = cursor.GetString(2);
						if (docId.StartsWith("_design/", StringCompare.IgnoreCase))
                        {
                            // design docs don't get indexed!
                            cursor.MoveToNext();
                            continue;
                        }
                        var revId = cursor.GetString(3);
                        var json = cursor.GetBlob(4);
                        var properties = Database.DocumentPropertiesFromJSON(
                            json, docId, revId, false, sequence, EnumSet.NoneOf<TDContentOptions>()
                        );
                        if (properties != null)
                        {
                            // Call the user-defined map() to emit new key/value
                            // pairs from this revision:
                            Log.V(Database.Tag, "  call map for sequence=" + System.Convert.ToString(sequence
                            ));
                            // This is the emit() block, which gets called from within the
                            // user-defined map() block
                            // that's called down below.

                            var enclosingView = this;
                            var thisSequence = sequence;
                            var map = Map;

                            if (map == null)
                                throw new CouchbaseLiteException("Map function is missing.");

                            EmitDelegate emitBlock = (key, value) =>
                            {
                                // TODO: Do we need to do any null checks on key or value?
                                try
                                {
                                    var keyJson = Manager.GetObjectMapper().WriteValueAsString(key);
                                    var valueJson = value == null ? null : Manager.GetObjectMapper().WriteValueAsString(value) ;
                                    Log.V(Database.Tag, String.Format("    emit({0}, {1})", keyJson, valueJson));

                                    var insertValues = new ContentValues();
                                    insertValues.Put("view_id", enclosingView.Id);
                                    insertValues["sequence"] = thisSequence;
                                    insertValues["key"] = keyJson;
                                    insertValues["value"] = valueJson;

                                    enclosingView.Database.StorageEngine.Insert("maps", null, insertValues);
                                }
                                catch (Exception e)
                                {
                                    Log.E(Database.Tag, "Error emitting", e);
                                }
                            };

                            map(properties, emitBlock);
                        }
                    }
                    cursor.MoveToNext();
                }
                // Finally, record the last revision sequence number that was
                // indexed:
                ContentValues updateValues = new ContentValues();
                updateValues["lastSequence"] = dbMaxSequence;
                var whereArgs_1 = new string[] { Sharpen.Extensions.ToString(Id) };
                Database.StorageEngine.Update("views", updateValues, "[email protected]", whereArgs_1);
                // FIXME actually count number added :)
                        Log.V(Database.Tag, "...Finished re-indexing view " + Name + " up to sequence " +
                    System.Convert.ToString(dbMaxSequence) + " (deleted " + deleted + " added " + "?" + ")");
                        result.SetCode(StatusCode.Ok);
            }
            catch (SQLException e)
            {
                throw new CouchbaseLiteException(e, new Status(StatusCode.DbError));
            }
            finally
            {
                if (cursor != null)
                {
                    cursor.Close();
                }
                if (!result.IsSuccessful())
                {
                    Log.W(Database.Tag, "Failed to rebuild view " + Name + ": " + result.GetCode());
                }
                if (Database != null)
                {
                    Database.EndTransaction(result.IsSuccessful());
                }
            }
        }
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:101,代码来源:View.cs

示例2: PutRevision


//.........这里部分代码省略.........
						{
							// Doc doesn't exist at all; create it:
							docNumericID = InsertDocumentID(docId);
							if (docNumericID <= 0)
							{
								return null;
							}
						}
						else
						{
							// Doc ID exists; check whether current winning revision is deleted:
							if (oldWinnerWasDeletion == true)
							{
								prevRevId = oldWinningRevID;
								parentSequence = GetSequenceOfDocument(docNumericID, prevRevId, false);
							}
							else
							{
								if (oldWinningRevID != null)
								{
									// The current winning revision is not deleted, so this is a conflict
									throw new CouchbaseLiteException(Status.Conflict);
								}
							}
						}
					}
					else
					{
						// Inserting first revision, with no docID given (POST): generate a unique docID:
						docId = Database.GenerateDocumentId();
						docNumericID = InsertDocumentID(docId);
						if (docNumericID <= 0)
						{
							return null;
						}
					}
				}
				// There may be a conflict if (a) the document was already in conflict, or
				// (b) a conflict is created by adding a non-deletion child of a non-winning rev.
				inConflict = wasConflicted || (!deleted && prevRevId != null && oldWinningRevID !=
					 null && !prevRevId.Equals(oldWinningRevID));
				//// PART II: In which insertion occurs...
				// Get the attachments:
				IDictionary<string, AttachmentInternal> attachments = GetAttachmentsFromRevision(
					oldRev);
				// Bump the revID and update the JSON:
				string newRevId = GenerateNextRevisionID(prevRevId);
				byte[] data = null;
				if (!oldRev.IsDeleted())
				{
					data = EncodeDocumentJSON(oldRev);
					if (data == null)
					{
						// bad or missing json
						throw new CouchbaseLiteException(Status.BadRequest);
					}
				}
				newRev = oldRev.CopyWithDocID(docId, newRevId);
				StubOutAttachmentsInRevision(attachments, newRev);
				// Now insert the rev itself:
				long newSequence = InsertRevision(newRev, docNumericID, parentSequence, true, data
					);
				if (newSequence == 0)
				{
					return null;
				}
				// Store any attachments:
				if (attachments != null)
				{
					ProcessAttachmentsForRevision(attachments, newRev, parentSequence);
				}
				// Figure out what the new winning rev ID is:
				winningRev = Winner(docNumericID, oldWinningRevID, oldWinnerWasDeletion, newRev);
				// Success!
				if (deleted)
				{
					resultStatus.SetCode(Status.Ok);
				}
				else
				{
					resultStatus.SetCode(Status.Created);
				}
			}
			catch (SQLException e1)
			{
				Log.E(Database.Tag, "Error putting revision", e1);
				return null;
			}
			finally
			{
				if (cursor != null)
				{
					cursor.Close();
				}
				EndTransaction(resultStatus.IsSuccessful());
			}
			//// EPILOGUE: A change notification is sent...
			NotifyChange(newRev, winningRev, null, inConflict);
			return newRev;
		}
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:101,代码来源:Database.cs

示例3: 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

示例4: TestViewIndex

		/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
		public virtual void TestViewIndex()
		{
			int numTimesMapFunctionInvoked = 0;
			IDictionary<string, object> dict1 = new Dictionary<string, object>();
			dict1.Put("key", "one");
			IDictionary<string, object> dict2 = new Dictionary<string, object>();
			dict2.Put("key", "two");
			IDictionary<string, object> dict3 = new Dictionary<string, object>();
			dict3.Put("key", "three");
			IDictionary<string, object> dictX = new Dictionary<string, object>();
			dictX.Put("clef", "quatre");
			RevisionInternal rev1 = PutDoc(database, dict1);
			RevisionInternal rev2 = PutDoc(database, dict2);
			RevisionInternal rev3 = PutDoc(database, dict3);
			PutDoc(database, dictX);
			View view = database.GetView("aview");
			_T1975167965 mapBlock = new _T1975167965(this);
			view.SetMap(mapBlock, "1");
			NUnit.Framework.Assert.AreEqual(1, view.GetViewId());
			NUnit.Framework.Assert.IsTrue(view.IsStale());
			view.UpdateIndex();
			IList<IDictionary<string, object>> dumpResult = view.Dump();
			Log.V(Tag, "View dump: " + dumpResult);
			NUnit.Framework.Assert.AreEqual(3, dumpResult.Count);
			NUnit.Framework.Assert.AreEqual("\"one\"", dumpResult[0].Get("key"));
			NUnit.Framework.Assert.AreEqual(1, dumpResult[0].Get("seq"));
			NUnit.Framework.Assert.AreEqual("\"two\"", dumpResult[2].Get("key"));
			NUnit.Framework.Assert.AreEqual(2, dumpResult[2].Get("seq"));
			NUnit.Framework.Assert.AreEqual("\"three\"", dumpResult[1].Get("key"));
			NUnit.Framework.Assert.AreEqual(3, dumpResult[1].Get("seq"));
			//no-op reindex
			NUnit.Framework.Assert.IsFalse(view.IsStale());
			view.UpdateIndex();
			// Now add a doc and update a doc:
			RevisionInternal threeUpdated = new RevisionInternal(rev3.GetDocId(), rev3.GetRevId
				(), false, database);
			numTimesMapFunctionInvoked = mapBlock.GetNumTimesInvoked();
			IDictionary<string, object> newdict3 = new Dictionary<string, object>();
			newdict3.Put("key", "3hree");
			threeUpdated.SetProperties(newdict3);
			Status status = new Status();
			rev3 = database.PutRevision(threeUpdated, rev3.GetRevId(), false, status);
			NUnit.Framework.Assert.IsTrue(status.IsSuccessful());
			// Reindex again:
			NUnit.Framework.Assert.IsTrue(view.IsStale());
			view.UpdateIndex();
			// Make sure the map function was only invoked one more time (for the document that was added)
			NUnit.Framework.Assert.AreEqual(mapBlock.GetNumTimesInvoked(), numTimesMapFunctionInvoked
				 + 1);
			IDictionary<string, object> dict4 = new Dictionary<string, object>();
			dict4.Put("key", "four");
			RevisionInternal rev4 = PutDoc(database, dict4);
			RevisionInternal twoDeleted = new RevisionInternal(rev2.GetDocId(), rev2.GetRevId
				(), true, database);
			database.PutRevision(twoDeleted, rev2.GetRevId(), false, status);
			NUnit.Framework.Assert.IsTrue(status.IsSuccessful());
			// Reindex again:
			NUnit.Framework.Assert.IsTrue(view.IsStale());
			view.UpdateIndex();
			dumpResult = view.Dump();
			Log.V(Tag, "View dump: " + dumpResult);
			NUnit.Framework.Assert.AreEqual(3, dumpResult.Count);
			NUnit.Framework.Assert.AreEqual("\"one\"", dumpResult[2].Get("key"));
			NUnit.Framework.Assert.AreEqual(1, dumpResult[2].Get("seq"));
			NUnit.Framework.Assert.AreEqual("\"3hree\"", dumpResult[0].Get("key"));
			NUnit.Framework.Assert.AreEqual(5, dumpResult[0].Get("seq"));
			NUnit.Framework.Assert.AreEqual("\"four\"", dumpResult[1].Get("key"));
			NUnit.Framework.Assert.AreEqual(6, dumpResult[1].Get("seq"));
			// Now do a real query:
			IList<QueryRow> rows = view.QueryWithOptions(null);
			NUnit.Framework.Assert.AreEqual(3, rows.Count);
			NUnit.Framework.Assert.AreEqual("one", rows[2].GetKey());
			NUnit.Framework.Assert.AreEqual(rev1.GetDocId(), rows[2].GetDocumentId());
			NUnit.Framework.Assert.AreEqual("3hree", rows[0].GetKey());
			NUnit.Framework.Assert.AreEqual(rev3.GetDocId(), rows[0].GetDocumentId());
			NUnit.Framework.Assert.AreEqual("four", rows[1].GetKey());
			NUnit.Framework.Assert.AreEqual(rev4.GetDocId(), rows[1].GetDocumentId());
			view.DeleteIndex();
		}
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:80,代码来源:ViewsTest.cs

示例5: UpdateIndex


//.........这里部分代码省略.........
                 // because this is the
                 // one with the highest revid, hence the "winning" revision
                 // of a conflict.
                 lastDocID = docID;
                 // Reconstitute the document as a dictionary:
                 sequence = cursor.GetLong(1);
                 string docId = cursor.GetString(2);
                 if (docId.StartsWith("_design/"))
                 {
                     // design docs don't get indexed!
                     keepGoing = cursor.MoveToNext();
                     continue;
                 }
                 string revId = cursor.GetString(3);
                 byte[] json = cursor.GetBlob(4);
                 bool noAttachments = cursor.GetInt(5) > 0;
                 while ((keepGoing = cursor.MoveToNext()) && cursor.GetLong(0) == docID)
                 {
                 }
                 // Skip rows with the same doc_id -- these are losing conflicts.
                 if (lastSequence > 0)
                 {
                     // Find conflicts with documents from previous indexings.
                     string[] selectArgs2 = new string[] { System.Convert.ToString(docID), System.Convert.ToString
                         (lastSequence) };
                     Cursor cursor2 = database.GetDatabase().RawQuery("SELECT revid, sequence FROM revs "
                          + "WHERE doc_id=? AND sequence<=? AND current!=0 AND deleted=0 " + "ORDER BY revID DESC "
                          + "LIMIT 1", selectArgs2);
                     if (cursor2.MoveToNext())
                     {
                         string oldRevId = cursor2.GetString(0);
                         // This is the revision that used to be the 'winner'.
                         // Remove its emitted rows:
                         long oldSequence = cursor2.GetLong(1);
                         string[] args = new string[] { Sharpen.Extensions.ToString(GetViewId()), System.Convert.ToString
                             (oldSequence) };
                         database.GetDatabase().ExecSQL("DELETE FROM maps WHERE view_id=? AND sequence=?", 
                             args);
                         if (RevisionInternal.CBLCompareRevIDs(oldRevId, revId) > 0)
                         {
                             // It still 'wins' the conflict, so it's the one that
                             // should be mapped [again], not the current revision!
                             revId = oldRevId;
                             sequence = oldSequence;
                             string[] selectArgs3 = new string[] { System.Convert.ToString(sequence) };
                             json = Utils.ByteArrayResultForQuery(database.GetDatabase(), "SELECT json FROM revs WHERE sequence=?"
                                 , selectArgs3);
                         }
                     }
                 }
                 // Get the document properties, to pass to the map function:
                 EnumSet<Database.TDContentOptions> contentOptions = EnumSet.NoneOf<Database.TDContentOptions
                     >();
                 if (noAttachments)
                 {
                     contentOptions.AddItem(Database.TDContentOptions.TDNoAttachments);
                 }
                 IDictionary<string, object> properties = database.DocumentPropertiesFromJSON(json
                     , docId, revId, false, sequence, contentOptions);
                 if (properties != null)
                 {
                     // Call the user-defined map() to emit new key/value
                     // pairs from this revision:
                     emitBlock.SetSequence(sequence);
                     mapBlock.Map(properties, emitBlock);
                 }
             }
         }
         // Finally, record the last revision sequence number that was
         // indexed:
         ContentValues updateValues = new ContentValues();
         updateValues.Put("lastSequence", dbMaxSequence);
         string[] whereArgs_1 = new string[] { Sharpen.Extensions.ToString(GetViewId()) };
         database.GetDatabase().Update("views", updateValues, "view_id=?", whereArgs_1);
         // FIXME actually count number added :)
         Log.V(Log.TagView, "Finished re-indexing view: %s " + " up to sequence %s" + " (deleted %s added ?)"
             , name, dbMaxSequence, deleted);
         result.SetCode(Status.Ok);
     }
     catch (SQLException e)
     {
         throw new CouchbaseLiteException(e, new Status(Status.DbError));
     }
     finally
     {
         if (cursor != null)
         {
             cursor.Close();
         }
         if (!result.IsSuccessful())
         {
             Log.W(Log.TagView, "Failed to rebuild view %s.  Result code: %d", name, result.GetCode
                 ());
         }
         if (database != null)
         {
             database.EndTransaction(result.IsSuccessful());
         }
     }
 }
开发者ID:jonlipsky,项目名称:couchbase-lite-net,代码行数:101,代码来源:View.cs


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