本文整理汇总了C#中ICouchbaseListenerContext类的典型用法代码示例。如果您正苦于以下问题:C# ICouchbaseListenerContext类的具体用法?C# ICouchbaseListenerContext怎么用?C# ICouchbaseListenerContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ICouchbaseListenerContext类属于命名空间,在下文中一共展示了ICouchbaseListenerContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetActiveTasks
/// <summary>
/// List of running tasks, including the task type, name, status and process ID
/// </summary>
/// <returns>The response state for further HTTP processing</returns>
/// <param name="context">The context of the Couchbase Lite HTTP request</param>
/// <remarks>
/// http://docs.couchdb.org/en/latest/api/server/common.html#get--_active_tasks
/// <remarks>
public static ICouchbaseResponseState GetActiveTasks(ICouchbaseListenerContext context)
{
// Get the current task info of all replicators:
var activity = new List<object>();
var replicators = new List<Replication>();
foreach (var db in context.DbManager.AllOpenDatabases()) {
foreach (var repl in db.ActiveReplicators) {
replicators.Add(repl);
activity.Add(repl.ActiveTaskInfo);
}
}
if (context.ChangesFeedMode >= ChangesFeedMode.Continuous) {
// Continuous activity feed (this is a CBL-specific API):
var response = context.CreateResponse();
response.WriteHeaders();
response.Chunked = true;
foreach(var item in activity) {
response.SendContinuousLine((IDictionary<string, object>)item, context.ChangesFeedMode);
}
return new ReplicationCouchbaseResponseState(replicators) {
Response = response,
ChangesFeedMode = context.ChangesFeedMode
};
} else {
var response = context.CreateResponse();
response.JsonBody = new Body(activity);
return response.AsDefaultState();
}
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:40,代码来源:ServerMethods.cs
示例2: GetConfiguration
/// <summary>
/// Gets information about the specified database.
/// </summary>
/// <returns>The response state for further HTTP processing</returns>
/// <param name="context">The context of the Couchbase Lite HTTP request</param>
/// <remarks>
/// http://docs.couchdb.org/en/latest/api/database/common.html#get--db
/// </remarks>
public static ICouchbaseResponseState GetConfiguration(ICouchbaseListenerContext context)
{
return PerformLogicWithDatabase(context, true, db =>
{
int numDocs = db.GetDocumentCount();
long updateSequence = db.GetLastSequenceNumber();
if (numDocs < 0 || updateSequence < 0) {
return context.CreateResponse(StatusCode.DbError);
}
var response = context.CreateResponse();
response.JsonBody = new Body(new Dictionary<string, object> {
{ "db_name", db.Name },
{ "db_uuid", db.PublicUUID() },
{ "doc_count", numDocs },
{ "update_seq", updateSequence },
{ "committed_update_seq", updateSequence },
{ "purge_seq", 0 }, //TODO: Implement
{ "disk_size", db.GetTotalDataSize() },
{ "start_time", db.StartTime * 1000 },
{ "revs_limit", db.GetMaxRevTreeDepth() }
});
return response;
}).AsDefaultState();
}
开发者ID:jonfunkhouser,项目名称:couchbase-lite-net,代码行数:34,代码来源:DatabaseMethods.cs
示例3: RegisterFacebookToken
/// <summary>
/// Verifies and registers a facebook token for use in replication authentication
/// </summary>
/// <returns>The response state for further HTTP processing</returns>
/// <param name="context">The context of the Couchbase Lite HTTP request</param>
public static ICouchbaseResponseState RegisterFacebookToken(ICouchbaseListenerContext context)
{
var response = context.CreateResponse();
var body = context.BodyAs<Dictionary<string, object>>();
string email = body.GetCast<string>("email");
string remoteUrl = body.GetCast<string>("remote_url");
string accessToken = body.GetCast<string>("access_token");
if (email != null && remoteUrl != null && accessToken != null) {
Uri siteUrl;
if (!Uri.TryCreate(remoteUrl, UriKind.Absolute, out siteUrl)) {
response.InternalStatus = StatusCode.BadParam;
response.JsonBody = new Body(new Dictionary<string, object> {
{ "error", "invalid remote_url" }
});
} else if (!FacebookAuthorizer.RegisterAccessToken(accessToken, email, siteUrl)) {
response.InternalStatus = StatusCode.BadParam;
response.JsonBody = new Body(new Dictionary<string, object> {
{ "error", "invalid access_token" }
});
} else {
response.JsonBody = new Body(new Dictionary<string, object> {
{ "ok", "registered" },
{ "email", email }
});
}
} else {
response.InternalStatus = StatusCode.BadParam;
response.JsonBody = new Body(new Dictionary<string, object> {
{ "error", "required fields: access_token, email, remote_url" }
});
}
return response.AsDefaultState();
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:40,代码来源:AuthenticationMethods.cs
示例4: Greeting
/// <summary>
/// Returns a JSON structure containing information about the server, including a welcome message and the version of the server.
/// </summary>
/// <returns>The response state for further HTTP processing</returns>
/// <param name="context">The context of the Couchbase Lite HTTP request</param>
/// <remarks>
/// http://docs.couchdb.org/en/latest/api/server/common.html#get--
/// <remarks>
public static ICouchbaseResponseState Greeting(ICouchbaseListenerContext context)
{
var info = new Dictionary<string, object> {
{ "couchdb", "Welcome" }, //for compatibility
{ "CouchbaseLite", "Welcome" },
{ "version", Manager.VersionString },
{ "vendor", new Dictionary<string, object> {
{ "name", "Couchbase Lite (C#)" },
{ "version", Manager.VersionString }
}
}
};
var body = new Body(info);
var couchResponse = context.CreateResponse();
couchResponse.JsonBody = body;
return couchResponse.AsDefaultState();
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:26,代码来源:ServerMethods.cs
示例5: RegisterPersonaToken
/// <summary>
/// Verifies and registers a persona token for use in replication authentication
/// </summary>
/// <returns>The response state for further HTTP processing</returns>
/// <param name="context">The context of the Couchbase Lite HTTP request</param>
public static ICouchbaseResponseState RegisterPersonaToken(ICouchbaseListenerContext context)
{
var response = context.CreateResponse();
var body = context.BodyAs<Dictionary<string, object>>();
string email = PersonaAuthorizer.RegisterAssertion(body.GetCast<string>("assertion"));
if (email != null) {
response.JsonBody = new Body(new Dictionary<string, object> {
{ "ok", "registered" },
{ "email", email }
});
} else {
response.InternalStatus = StatusCode.BadParam;
response.JsonBody = new Body(new Dictionary<string, object> {
{ "error", "invalid assertion" }
});
}
return response.AsDefaultState();
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:25,代码来源:AuthenticationMethods.cs
示例6: QueryDesignDocument
// Performs the actual query logic on a design document
private static CouchbaseLiteResponse QueryDesignDocument(ICouchbaseListenerContext context, IList<object> keys)
{
return DatabaseMethods.PerformLogicWithDatabase(context, true, db =>
{
var view = db.GetView(String.Format("{0}/{1}", context.DesignDocName, context.ViewName));
var status = view.CompileFromDesignDoc();
if(status.IsError) {
return context.CreateResponse(status.Code);
}
var options = context.QueryOptions;
if(options == null) {
return context.CreateResponse(StatusCode.BadRequest);
}
if(keys != null) {
options.Keys = keys;
}
if(options.Stale == IndexUpdateMode.Before || view.LastSequenceIndexed <= 0) {
view.UpdateIndex();
} else if(options.Stale == IndexUpdateMode.After && view.LastSequenceIndexed < db.LastSequenceNumber) {
db.RunAsync(_ => view.UpdateIndex());
}
// Check for conditional GET and set response Etag header:
if(keys == null) {
long eTag = options.IncludeDocs ? db.LastSequenceNumber : view.LastSequenceIndexed;
if(context.CacheWithEtag(eTag.ToString())) {
return context.CreateResponse(StatusCode.NotModified);
}
}
return DatabaseMethods.QueryView(context, db, view, options);
});
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:37,代码来源:ViewMethods.cs
示例7: DoAllDocs
//Do an all document request on the database (i.e. fetch all docs given some options)
private static CouchbaseLiteResponse DoAllDocs(ICouchbaseListenerContext context, Database db, QueryOptions options)
{
var iterator = db.GetAllDocs(options);
if (iterator == null) {
return context.CreateResponse(StatusCode.BadJson);
}
var response = context.CreateResponse();
var result = (from row in iterator
select row.AsJSONDictionary()).ToList();
response.JsonBody = new Body(new NonNullDictionary<string, object> {
{ "rows", result },
{ "total_rows", result.Count },
{ "offset", options.Skip },
{ "update_seq", options.UpdateSeq ? (object)db.GetLastSequenceNumber() : null }
});
return response;
}
开发者ID:jonfunkhouser,项目名称:couchbase-lite-net,代码行数:19,代码来源:DatabaseMethods.cs
示例8: QueryView
/// <summary>
/// Queries the specified view using the specified options
/// </summary>
/// <returns>The HTTP response containing the results of the query</returns>
/// <param name="context">The request context</param>
/// <param name="db">The database to run the query in</param>
/// <param name="view">The view to query</param>
/// <param name="options">The options to apply to the query</param>
public static CouchbaseLiteResponse QueryView(ICouchbaseListenerContext context, Database db, View view, QueryOptions options)
{
var result = view.QueryWithOptions(options);
object updateSeq = options.UpdateSeq ? (object)view.LastSequenceIndexed : null;
var mappedResult = new List<object>();
foreach (var row in result) {
row.Database = db;
var dict = row.AsJSONDictionary();
if (context.ContentOptions != DocumentContentOptions.None) {
var doc = dict.Get("doc").AsDictionary<string, object>();
if (doc != null) {
// Add content options:
RevisionInternal rev = new RevisionInternal(doc);
var status = new Status();
rev = DocumentMethods.ApplyOptions(context.ContentOptions, rev, context, db, status);
if (rev != null) {
dict["doc"] = rev.GetProperties();
}
}
}
mappedResult.Add(dict);
}
var body = new Body(new NonNullDictionary<string, object> {
{ "rows", mappedResult },
{ "total_rows", view.TotalRows },
{ "offset", options.Skip },
{ "update_seq", updateSeq }
});
var retVal = context.CreateResponse();
retVal.JsonBody = body;
return retVal;
}
开发者ID:jonfunkhouser,项目名称:couchbase-lite-net,代码行数:44,代码来源:DatabaseMethods.cs
示例9: Purge
/// <summary>
/// A database purge permanently removes the references to deleted documents from the database.
/// </summary>
/// <returns>The response state for further HTTP processing</returns>
/// <param name="context">The context of the Couchbase Lite HTTP request</param>
/// <remarks>
/// http://docs.couchdb.org/en/latest/api/database/misc.html#post--db-_purge
/// </remarks>
public static ICouchbaseResponseState Purge(ICouchbaseListenerContext context)
{
return PerformLogicWithDatabase(context, true, db =>
{
var body = context.BodyAs<Dictionary<string, IList<string>>>();
if(body == null) {
return context.CreateResponse(StatusCode.BadJson);
}
var purgedRevisions = db.Storage.PurgeRevisions(body);
if(purgedRevisions == null) {
return context.CreateResponse(StatusCode.DbError);
}
var responseBody = new Body(new Dictionary<string, object>
{
{ "purged", purgedRevisions }
});
var retVal = context.CreateResponse();
retVal.JsonBody = responseBody;
return retVal;
}).AsDefaultState();
}
开发者ID:jonfunkhouser,项目名称:couchbase-lite-net,代码行数:32,代码来源:DatabaseMethods.cs
示例10: GetChangesPost
public static ICouchbaseResponseState GetChangesPost(ICouchbaseListenerContext context)
{
DBMonitorCouchbaseResponseState responseState = new DBMonitorCouchbaseResponseState();
var responseObject = PerformLogicWithDatabase(context, true, db =>
{
var response = context.CreateResponse();
responseState.Response = response;
var body = context.BodyAs<Dictionary<string, object>>();
ProcessBody(body);
if (body.GetCast<ChangesFeedMode>("feed") < ChangesFeedMode.Continuous) {
if(context.CacheWithEtag(db.GetLastSequenceNumber().ToString())) {
response.InternalStatus = StatusCode.NotModified;
return response;
}
}
var options = ChangesOptions.Default;
responseState.Db = db;
responseState.ContentOptions = body.GetCast<DocumentContentOptions>("content_options");
responseState.ChangesFeedMode = body.GetCast<ChangesFeedMode>("feed");
responseState.ChangesIncludeDocs = body.GetCast<bool>("include_docs");
options.IncludeDocs = responseState.ChangesIncludeDocs;
responseState.ChangesIncludeConflicts = body.GetCast<string>("style") == "all_docs";
options.IncludeConflicts = responseState.ChangesIncludeConflicts;
options.ContentOptions = responseState.ContentOptions;
options.SortBySequence = !options.IncludeConflicts;
options.Limit = body.GetCast<int>("limit", options.Limit);
int since = body.GetCast<int>("since");
string filterName = body.GetCast<string>("filter");
if(filterName != null) {
Status status = new Status();
responseState.ChangesFilter = db.GetFilter(filterName, status);
if(responseState.ChangesFilter == null) {
return context.CreateResponse(status.Code);
}
responseState.FilterParams = context.GetQueryParams();
}
RevisionList changes = db.ChangesSince(since, options, responseState.ChangesFilter, responseState.FilterParams);
if((responseState.ChangesFeedMode >= ChangesFeedMode.Continuous) ||
(responseState.ChangesFeedMode == ChangesFeedMode.LongPoll && changes.Count == 0)) {
// Response is going to stay open (continuous, or hanging GET):
response.Chunked = true;
if(responseState.ChangesFeedMode == ChangesFeedMode.EventSource) {
response["Content-Type"] = "text/event-stream; charset=utf-8";
}
if(responseState.ChangesFeedMode >= ChangesFeedMode.Continuous) {
response.WriteHeaders();
foreach(var rev in changes) {
response.SendContinuousLine(ChangesDictForRev(rev, responseState), context.ChangesFeedMode);
}
}
responseState.SubscribeToDatabase(db);
int heartbeat = body.GetCast<int>("heartbeat", Int32.MinValue);
if(heartbeat != Int32.MinValue) {
if(heartbeat <= 0) {
responseState.IsAsync = false;
return context.CreateResponse(StatusCode.BadParam);
}
heartbeat = Math.Max(heartbeat, (int)MinHeartbeat.TotalMilliseconds);
string heartbeatResponse = context.ChangesFeedMode == ChangesFeedMode.EventSource ? "\n\n" : "\r\n";
responseState.StartHeartbeat(heartbeatResponse, TimeSpan.FromMilliseconds(heartbeat));
}
return context.CreateResponse();
} else {
if(responseState.ChangesIncludeConflicts) {
response.JsonBody = new Body(ResponseBodyForChanges(changes, since, options.Limit, responseState));
} else {
response.JsonBody = new Body(ResponseBodyForChanges(changes, since, responseState));
}
return response;
}
});
responseState.Response = responseObject;
return responseState;
}
开发者ID:jonfunkhouser,项目名称:couchbase-lite-net,代码行数:86,代码来源:DatabaseMethods.cs
示例11: ProcessDocumentChangeOperations
/// <summary>
/// Create and update multiple documents at the same time within a single request.
/// </summary>
/// <returns>The response state for further HTTP processing</returns>
/// <param name="context">The context of the Couchbase Lite HTTP request</param>
/// <remarks>
/// http://docs.couchdb.org/en/latest/api/database/bulk-api.html#post--db-_bulk_docs
/// </remarks>
public static ICouchbaseResponseState ProcessDocumentChangeOperations(ICouchbaseListenerContext context)
{
return PerformLogicWithDatabase(context, true, db =>
{
var postBody = context.BodyAs<Dictionary<string, object>>();
if(postBody == null) {
return context.CreateResponse(StatusCode.BadJson);
}
if(!postBody.ContainsKey("docs")) {
return context.CreateResponse(StatusCode.BadParam);
}
var docs = postBody["docs"].AsList<IDictionary<string, object>>();
bool allOrNothing;
postBody.TryGetValue<bool>("all_or_nothing", out allOrNothing);
bool newEdits;
postBody.TryGetValue<bool>("new_edits", out newEdits);
var response = context.CreateResponse();
StatusCode status = StatusCode.Ok;
bool success = db.RunInTransaction(() => {
List<IDictionary<string, object>> results = new List<IDictionary<string, object>>(docs.Count);
var castContext = context as ICouchbaseListenerContext2;
var source = castContext != null && !castContext.IsLoopbackRequest ? castContext.Sender : null;
foreach(var doc in docs) {
string docId = doc.CblID();
RevisionInternal rev = null;
Body body = new Body(doc);
if(!newEdits) {
if(!RevisionInternal.IsValid(body)) {
status = StatusCode.BadParam;
} else {
rev = new RevisionInternal(body);
var history = Database.ParseCouchDBRevisionHistory(doc);
try {
db.ForceInsert(rev, history, source);
} catch(CouchbaseLiteException e) {
status = e.Code;
}
}
} else {
status = DocumentMethods.UpdateDocument(context, db, docId, body, false, allOrNothing, out rev);
}
IDictionary<string, object> result = null;
if((int)status < 300) {
Debug.Assert(rev != null && rev.RevID != null);
if(newEdits) {
result = new Dictionary<string, object>
{
{ "id", rev.DocID },
{ "rev", rev.RevID },
{ "status", (int)status }
};
}
} else if((int)status >= 500) {
return false; // abort the whole thing if something goes badly wrong
} else if(allOrNothing) {
return false; // all_or_nothing backs out if there's any error
} else {
var info = Status.ToHttpStatus(status);
result = new Dictionary<string, object>
{
{ "id", docId },
{ "error", info.Item2 },
{ "status", info.Item1 }
};
}
if(result != null) {
results.Add(result);
}
}
response.JsonBody = new Body(results.Cast<object>().ToList());
return true;
});
if(!success) {
response.InternalStatus = status;
}
return response;
}).AsDefaultState();
}
开发者ID:jonfunkhouser,项目名称:couchbase-lite-net,代码行数:96,代码来源:DatabaseMethods.cs
示例12: UpdateAttachment
/// <summary>
/// Uploads the supplied content as an attachment to the specified document.
/// </summary>
/// <returns>The response state for further HTTP processing</returns>
/// <param name="context">The context of the Couchbase Lite HTTP request</param>
/// <remarks>
/// http://docs.couchdb.org/en/latest/api/document/attachments.html#put--db-docid-attname
/// <remarks>
public static ICouchbaseResponseState UpdateAttachment(ICouchbaseListenerContext context)
{
var state = new AsyncOpCouchbaseResponseState();
DatabaseMethods.PerformLogicWithDatabase(context, true, db =>
{
var blob = db.AttachmentWriter;
var httpBody = new byte[context.ContentLength];
context.BodyStream.ReadAsync(httpBody, 0, httpBody.Length).ContinueWith(t => {
if(t.Result == 0) {
state.Response = context.CreateResponse(StatusCode.BadAttachment);
state.SignalFinished();
return;
}
blob.AppendData(httpBody);
blob.Finish();
state.Response = UpdateAttachment(context, db, context.AttachmentName, context.DocumentName, blob);
state.SignalFinished();
});
return null;
});
return state;
}
开发者ID:wilsondy,项目名称:couchbase-lite-net,代码行数:35,代码来源:DocumentMethods.cs
示例13: GetAttachment
/// <summary>
/// Returns the file attachment associated with the document. The raw data of the associated attachment is returned
/// (just as if you were accessing a static file. The returned Content-Type will be the same as the content type
/// set when the document attachment was submitted into the database.
/// </summary>
/// <returns>The response state for further HTTP processing</returns>
/// <param name="context">The context of the Couchbase Lite HTTP request</param>
/// <remarks>
/// http://docs.couchdb.org/en/latest/api/document/attachments.html#get--db-docid-attname
/// <remarks>
public static ICouchbaseResponseState GetAttachment(ICouchbaseListenerContext context)
{
return DatabaseMethods.PerformLogicWithDatabase(context, true, db =>
{
Status status = new Status();
var rev = db.GetDocument(context.DocumentName, context.GetQueryParam("rev"), false,
status);
if(rev ==null) {
return context.CreateResponse(status.Code);
}
if(context.CacheWithEtag(rev.GetRevId())) {
return context.CreateResponse(StatusCode.NotModified);
}
string acceptEncoding = context.RequestHeaders["Accept-Encoding"];
bool acceptEncoded = acceptEncoding != null && acceptEncoding.Contains("gzip") &&
context.RequestHeaders["Range"] == null;
var attachment = db.GetAttachmentForRevision(rev, context.AttachmentName, status);
if(attachment == null) {
return context.CreateResponse(status.Code);
}
var response = context.CreateResponse();
if(context.Method.Equals(HttpMethod.Head)) {
var length = attachment.Length;
if(acceptEncoded && attachment.Encoding == AttachmentEncoding.GZIP &&
attachment.EncodedLength > 0) {
length = attachment.EncodedLength;
}
response["Content-Length"] = length.ToString();
} else {
var contents = acceptEncoded ? attachment.EncodedContent : attachment.Content;
if(contents == null) {
response.InternalStatus = StatusCode.NotFound;
return response;
}
response.BinaryBody = contents;
}
response["Content-Type"] = attachment.ContentType;
if(acceptEncoded && attachment.Encoding == AttachmentEncoding.GZIP) {
response["Content-Encoding"] = "gzip";
}
return response;
}).AsDefaultState();
}
开发者ID:wilsondy,项目名称:couchbase-lite-net,代码行数:61,代码来源:DocumentMethods.cs
示例14: DeleteDocument
/// <summary>
/// Marks the specified document as deleted by adding a field _deleted with the value true.
/// Documents with this field will not be returned within requests anymore, but stay in the database.
/// </summary>
/// <returns>The response state for further HTTP processing</returns>
/// <param name="context">The context of the Couchbase Lite HTTP request</param>
/// <remarks>
/// http://docs.couchdb.org/en/latest/api/document/common.html#delete--db-docid
/// <remarks>
public static ICouchbaseResponseState DeleteDocument(ICouchbaseListenerContext context)
{
return DatabaseMethods.PerformLogicWithDatabase(context, true, db =>
{
string docId = context.DocumentName;
return UpdateDb(context, db, docId, null, true);
}).AsDefaultState();
}
开发者ID:wilsondy,项目名称:couchbase-lite-net,代码行数:17,代码来源:DocumentMethods.cs
示例15: UpdateDocument
/// <summary>
/// Attempt to update a document based on the information in the HTTP request
/// </summary>
/// <returns>The resulting status of the operation</returns>
/// <param name="context">The request context</param>
/// <param name="db">The database in which the document exists</param>
/// <param name="docId">The ID of the document being updated</param>
/// <param name="body">The new document body</param>
/// <param name="deleting">Whether or not the document is being deleted</param>
/// <param name="allowConflict">Whether or not to allow a conflict to be inserted</param>
/// <param name="outRev">The resulting revision of the document</param>
public static StatusCode UpdateDocument(ICouchbaseListenerContext context, Database db, string docId, Body body, bool deleting,
bool allowConflict, out RevisionInternal outRev)
{
outRev = null;
if (body != null && !body.IsValidJSON()) {
return StatusCode.BadJson;
}
string prevRevId;
if (!deleting) {
var properties = body.GetProperties();
deleting = properties.GetCast<bool>("_deleted");
if (docId == null) {
// POST's doc ID may come from the _id field of the JSON body.
docId = properties.GetCast<string>("_id");
if (docId == null && deleting) {
return StatusCode.BadId;
}
}
// PUT's revision ID comes from the JSON body.
prevRevId = properties.GetCast<string>("_rev");
} else {
// DELETE's revision ID comes from the ?rev= query param
prevRevId = context.GetQueryParam("rev");
}
// A backup source of revision ID is an If-Match header:
if (prevRevId == null) {
prevRevId = context.IfMatch();
}
if (docId == null && deleting) {
return StatusCode.BadId;
}
RevisionInternal rev = new RevisionInternal(docId, null, deleting);
rev.SetBody(body);
StatusCode status = StatusCode.Created;
try {
if (docId != null && docId.StartsWith("_local")) {
outRev = db.Storage.PutLocalRevision(rev, prevRevId, true); //TODO: Doesn't match iOS
} else {
Status retStatus = new Status();
outRev = db.PutRevision(rev, prevRevId, allowConflict, retStatus);
status = retStatus.Code;
}
} catch(CouchbaseLiteException e) {
status = e.Code;
}
return status;
}
开发者ID:wilsondy,项目名称:couchbase-lite-net,代码行数:65,代码来源:DocumentMethods.cs
示例16: GetAllDocuments
/// <summary>
/// Returns a JSON structure of all of the documents in a given database.
/// </summary>
/// <returns>The response state for further HTTP processing</returns>
/// <param name="context">The context of the Couchbase Lite HTTP request</param>
/// <remarks>
/// http://docs.couchdb.org/en/latest/api/database/bulk-api.html#get--db-_all_docs
/// </remarks>
public static ICouchbaseResponseState GetAllDocuments(ICouchbaseListenerContext context)
{
return PerformLogicWithDatabase(context, true, db =>
{
if(context.CacheWithEtag(db.GetLastSequenceNumber().ToString())) {
return context.CreateResponse(StatusCode.NotModified);
}
var options = context.QueryOptions;
if(options == null) {
return context.CreateResponse(StatusCode.BadParam);
}
return DoAllDocs(context, db, options);
}).AsDefaultState();
}
开发者ID:jonfunkhouser,项目名称:couchbase-lite-net,代码行数:24,代码来源:DatabaseMethods.cs
示例17: GetAllSpecifiedDocuments
/// <summary>
/// The POST to _all_docs allows to specify multiple keys to be selected from the database.
/// This enables you to request multiple documents in a single request, in place of multiple GET /{db}/{docid} requests.
/// </summary>
/// <returns>The response state for further HTTP processing</returns>
/// <param name="context">The context of the Couchbase Lite HTTP request</param>
/// <remarks>
/// http://docs.couchdb.org/en/latest/api/database/bulk-api.html#post--db-_all_docs
/// </remarks>
public static ICouchbaseResponseState GetAllSpecifiedDocuments(ICouchbaseListenerContext context)
{
return PerformLogicWithDatabase(context, true, db =>
{
var options = context.QueryOptions;
if(options == null) {
return context.CreateResponse(StatusCode.BadParam);
}
var body = context.BodyAs<Dictionary<string, object>>();
if(body == null) {
return context.CreateResponse(StatusCode.BadJson);
}
if(!body.ContainsKey("keys")) {
return context.CreateResponse(StatusCode.BadParam);
}
var keys = body["keys"].AsList<object>();
options.Keys = keys;
return DoAllDocs(context, db, options);
}).AsDefaultState();
}
开发者ID:jonfunkhouser,项目名称:couchbase-lite-net,代码行数:32,代码来源:DatabaseMethods.cs
示例18: DeleteAttachment
/// <summary>
/// Deletes the attachment of the specified doc.
/// </summary>
/// <returns>The response state for further HTTP processing</returns>
/// <param name="context">The context of the Couchbase Lite HTTP request</param>
/// <remarks>
/// http://docs.couchdb.org/en/latest/api/document/attachments.html#delete--db-docid-attname
/// <remarks>
public static ICouchbaseResponseState DeleteAttachment(ICouchbaseListenerContext context)
{
return DatabaseMethods.PerformLogicWithDatabase(context, true, db =>
UpdateAttachment(context, db, context.AttachmentName, context.DocumentName, null)).AsDefaultState();
}
开发者ID:wilsondy,项目名称:couchbase-lite-net,代码行数:13,代码来源:DocumentMethods.cs
示例19: GetChanges
/// <summary>
/// Returns a sorted list of changes made to documents in the database, in time order of application.
/// </summary>
/// <returns>The response state for further HTTP processing</returns>
/// <param name="context">The context of the Couchbase Lite HTTP request</param>
/// <remarks>
/// http://docs.couchdb.org/en/latest/api/database/changes.html#get--db-_changes
/// </remarks>
public static ICouchbaseResponseState GetChanges(ICouchbaseListenerContext context)
{
DBMonitorCouchbaseResponseState responseState = new DBMonitorCouchbaseResponseState();
var responseObject = PerformLogicWithDatabase(context, true, db =>
{
var response = context.CreateResponse();
|
请发表评论