本文整理汇总了C#中Document.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Serialize方法的具体用法?C# Document.Serialize怎么用?C# Document.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document
的用法示例。
在下文中一共展示了Document.Serialize方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: addEdge
/// <summary>
/// Stores a new edge with the information contained within the body into the given collection.
/// </summary>
internal Document addEdge(string collectionName, string fromId, string toId, Document edge, bool waitForSync)
{
var request = new Request(RequestType.Collection, HttpMethod.Post);
string uri = string.Join("/", _apiUri, "edge", collectionName);
request.RelativeUri = string.Join("?", uri, "waitForSync=" + waitForSync);
if (edge.ContainsKey("_from")) {
edge.Drop("_from");
}
if (edge.ContainsKey("_to")) {
edge.Drop("_to");
}
Document body = edge;
edge.Add("_from", fromId);
edge.Add("_to", toId);
request.Body = edge.Serialize();
var response = _connection.Process(request);
Document result = new Document();
switch (response.StatusCode)
{
case HttpStatusCode.Accepted:
result = response.Document.Object<Document>("edge");
result.Merge(edge, MergeOptions.MergeFields);
break;
default:
if (response.IsException)
{
throw new ArangoException(
response.StatusCode,
response.Document.String("driverErrorMessage"),
response.Document.String("driverExceptionMessage"),
response.Document.Object<Exception>("driverInnerException")
);
}
break;
}
return result;
}
示例2: Post
internal bool Post(string name, string code)
{
var request = new Request(RequestType.Function, HttpMethod.Post);
request.RelativeUri = _apiUri;
var bodyDocument = new Document();
// set name of the function
bodyDocument.String("name", name);
// set function code
bodyDocument.String("code", code);
request.Body = bodyDocument.Serialize();
var response = _connection.Process(request);
var isSuccess = false;
switch (response.StatusCode)
{
case HttpStatusCode.OK:
case HttpStatusCode.Created:
isSuccess = true;
break;
default:
if (response.IsException)
{
throw new ArangoException(
response.StatusCode,
response.Document.String("driverErrorMessage"),
response.Document.String("driverExceptionMessage"),
response.Document.Object<Exception>("driverInnerException")
);
}
break;
}
return isSuccess;
}
示例3: addEdgeDefinition
/// <summary>
/// Gets the list of all edge collections.
/// </summary>
internal ArangoGraph addEdgeDefinition(ArangoGraphEdgeDefinition edgeDefinition)
{
var request = new Request(RequestType.Collection, HttpMethod.Post);
request.RelativeUri = string.Join("/", _apiUri, "edge");
Document body = new Document();
body.Add("collection", edgeDefinition.collection);
body.Add("from", edgeDefinition.from);
body.Add("to", edgeDefinition.to);
request.Body = body.Serialize();
var response = _connection.Process(request);
ArangoGraph result = new ArangoGraph(_connection, _graphName);
switch (response.StatusCode)
{
case HttpStatusCode.Created:
result = this.responseToGraph(response);
break;
default:
if (response.IsException)
{
throw new ArangoException(
response.StatusCode,
response.Document.String("driverErrorMessage"),
response.Document.String("driverExceptionMessage"),
response.Document.Object<Exception>("driverInnerException")
);
}
break;
}
return result;
}
示例4: updateVertex
/// <summary>
/// Updates a vertex with the given id by adding the content in the body.
/// This will only run successfully if the vertex is contained within the graph.
/// </summary>
internal Document updateVertex(
string collectionName,
string key,
Document vertex,
bool waitForSync,
bool keepNull
)
{
Document result = this.getVertex(collectionName, key);
var request = new Request(RequestType.Collection, HttpMethod.Patch);
string uri = string.Join("/", _apiUri, "vertex", collectionName, key);
request.RelativeUri = string.Join("?", uri, "waitForSync=" + waitForSync + "&keepNull=" + keepNull);
request.Body = vertex.Serialize();
var response = _connection.Process(request);
switch (response.StatusCode)
{
case HttpStatusCode.OK:
result.Merge(vertex, MergeOptions.ReplaceFields);
result.Merge(response.Document.Object<Document>("vertex"), MergeOptions.ReplaceFields);
break;
case HttpStatusCode.NotFound:
result = null;
break;
default:
if (response.IsException)
{
throw new ArangoException(
response.StatusCode,
response.Document.String("driverErrorMessage"),
response.Document.String("driverExceptionMessage"),
response.Document.Object<Exception>("driverInnerException")
);
}
break;
}
return result;
}
示例5: replaceEdge
/// <summary>
/// Replaces an edge with the given id by the content in the body.
/// This will only run successfully if the edge is contained within the graph.
/// </summary>
internal Document replaceEdge(string collectionName, string key, Document edge, bool waitForSync)
{
var request = new Request(RequestType.Collection, HttpMethod.Put);
string uri = string.Join("/", _apiUri, "edge", collectionName, key);
request.RelativeUri = string.Join("?", uri, "waitForSync=" + waitForSync);
request.Body = edge.Serialize();
var response = _connection.Process(request);
Document result = new Document();
switch (response.StatusCode)
{
case HttpStatusCode.Accepted:
result = response.Document.Object<Document>("edge");
result.Merge(edge, MergeOptions.MergeFields);
break;
case HttpStatusCode.NotFound:
result = null;
break;
default:
if (response.IsException)
{
throw new ArangoException(
response.StatusCode,
response.Document.String("driverErrorMessage"),
response.Document.String("driverExceptionMessage"),
response.Document.Object<Exception>("driverInnerException")
);
}
break;
}
return result;
}
示例6: addVertex
/// <summary>
/// Add new vertex to a collection of the graph.
/// </summary>
internal Document addVertex(string collectionName, Document vertex, bool waitForSync)
{
string wFS = "false";
if (waitForSync) {
wFS = "true";
}
var request = new Request(RequestType.Collection, HttpMethod.Post);
string uri = string.Join("/", _apiUri, "vertex", collectionName);
request.RelativeUri = string.Join("?", uri, "waitForSync=" + wFS);
request.Body = vertex.Serialize();
var response = _connection.Process(request);
Document result = new Document();
switch (response.StatusCode)
{
case HttpStatusCode.Accepted:
result = response.Document.Object<Document>("vertex");
result.Merge(vertex, MergeOptions.MergeFields);
break;
case HttpStatusCode.NotFound:
result = null;
break;
default:
if (response.IsException)
{
throw new ArangoException(
response.StatusCode,
response.Document.String("driverErrorMessage"),
response.Document.String("driverExceptionMessage"),
response.Document.Object<Exception>("driverInnerException")
);
}
break;
}
return result;
}
示例7: Post
// only possible from within the _system database
internal bool Post(string databaseName)
{
var request = new Request(RequestType.Document, HttpMethod.Post);
request.RelativeUri = string.Join("/", _apiUri);
var bodyDocument = new Document()
.String("name", databaseName);
request.Body = bodyDocument.Serialize();
var response = _connection.Process(request);
var created = false;
switch (response.StatusCode)
{
// ArangoDB 1.4 returns 200 (Ok)
// whereas ArangoDB 2.0 returns 201 (Created)
case HttpStatusCode.OK:
case HttpStatusCode.Created:
created = response.Document.Bool("result");
break;
default:
if (response.IsException)
{
throw new ArangoException(
response.StatusCode,
response.Document.String("driverErrorMessage"),
response.Document.String("driverExceptionMessage"),
response.Document.Object<Exception>("driverInnerException")
);
}
break;
}
return created;
}
示例8: Post
internal List<object> Post(string query, bool returnCount, out int count, int batchSize, Dictionary<string, object> bindVars)
{
var request = new Request(RequestType.Cursor, HttpMethod.Post);
request.RelativeUri = _apiUri;
var bodyDocument = new Document();
// set AQL string
bodyDocument.String("query", query);
// (optional) set number of found documents
if (returnCount)
{
bodyDocument.Bool("count", returnCount);
}
// (optional) set how much documents should be returned
if (batchSize > 0)
{
bodyDocument.Int("batchSize", batchSize);
}
// (optional) set list of bind parameters
if ((bindVars != null) && (bindVars.Count > 0))
{
var bindVarsDocument = new Document();
foreach (KeyValuePair<string, object> item in bindVars)
{
bindVarsDocument.Object(item.Key, item.Value);
}
bodyDocument.Object("bindVars", bindVarsDocument);
}
request.Body = bodyDocument.Serialize();
var response = _connection.Process(request);
var items = new List<object>();
count = 0;
switch (response.StatusCode)
{
case HttpStatusCode.Created:
items.AddRange(response.Document.List<object>("result"));
// get count of returned document if present
if (returnCount)
{
count = response.Document.Int("count");
}
// get more results if present
if (response.Document.Bool("hasMore"))
{
long cursorId = response.Document.Long("id");
items.AddRange(Put(cursorId));
}
break;
default:
items = null;
if (response.IsException)
{
throw new ArangoException(
response.StatusCode,
response.Document.String("driverErrorMessage"),
response.Document.String("driverExceptionMessage"),
response.Document.Object<Exception>("driverInnerException")
);
}
break;
}
return items;
}
示例9: Post
public QueryParseResult Post(string query)
{
var request = new Request(RequestType.Cursor, HttpMethod.Post);
request.RelativeUri = _apiUri;
var bodyDocument = new Document();
// set AQL string
bodyDocument.String("query", query);
request.Body = bodyDocument.Serialize();
var response = _connection.Process(request);
QueryParseResult parseResult = null;
switch (response.StatusCode)
{
case HttpStatusCode.OK:
parseResult = new QueryParseResult();
parseResult.bindVars = response.Document.List<string>("bindVars");
parseResult.collections = response.Document.List<string>("collections");
// error
parseResult.error = response.Document.Bool("error");
parseResult.code = response.Document.Int("code");
break;
default:
if (response.IsException)
{
throw new ArangoException(
response.StatusCode,
response.Document.String("driverErrorMessage"),
response.Document.String("driverExceptionMessage"),
response.Document.Object<Exception>("driverInnerException")
);
}
break;
}
return parseResult;
}
示例10: Post
internal void Post(string collection, Document document, bool waitForSync, bool createCollection)
{
var request = new Request(RequestType.Document, HttpMethod.Post);
request.RelativeUri = _apiUri;
request.Body = document.Serialize();
if (
request.Body.Contains("_id")
|| request.Body.Contains("_key")
|| request.Body.Contains("_rev")
) {
request.Body = document.Except("_id", "_key", "_rev").Serialize();
}
// set collection name where the document will be created
request.QueryString.Add("collection", collection);
// (optional)
if (createCollection)
{
request.QueryString.Add("createCollection", "true");
}
// (optional)
if (waitForSync)
{
request.QueryString.Add("waitForSync", "true");
}
var response = _connection.Process(request);
switch (response.StatusCode)
{
case HttpStatusCode.Created:
case HttpStatusCode.Accepted:
document.String("_id", response.Document.String("_id"));
document.String("_key", response.Document.String("_key"));
document.String("_rev", response.Document.String("_rev"));
break;
default:
if (response.IsException)
{
throw new ArangoException(
response.StatusCode,
response.Document.String("driverErrorMessage"),
response.Document.String("driverExceptionMessage"),
response.Document.Object<Exception>("driverInnerException")
);
}
break;
}
}