/// <summary> /// Retrieves specified index. /// </summary> /// <exception cref="ArgumentException">Specified id value has invalid format.</exception> public AResult <Dictionary <string, object> > Get(string id) { if (!ADocument.IsID(id)) { throw new ArgumentException("Specified id value (" + id + ") has invalid format."); } var request = new Request(HttpMethod.GET, ApiBaseUri.Index, "/" + id); var response = _connection.Send(request); var result = new AResult <Dictionary <string, object> >(response); switch (response.StatusCode) { case 200: var body = response.ParseBody <Dictionary <string, object> >(); result.Success = (body != null); result.Value = body; break; case 404: default: // Arango error break; } _parameters.Clear(); return(result); }
/// <summary> /// Deletes specified index. /// </summary> /// <exception cref="ArgumentException">Specified id value has invalid format.</exception> public AResult <Dictionary <string, object> > Delete(string id) { if (!ADocument.IsID(id)) { throw new ArgumentException("Specified id value (" + id + ") has invalid format."); } var request = new Request(HttpMethod.DELETE, ApiBaseUri.Index, "/" + id); var response = _connection.Send(request); var result = new AResult <Dictionary <string, object> >(response); switch (response.StatusCode) { case 200: if (response.DataType == DataType.Document) { result.Value = (response.Data as Dictionary <string, object>); result.Success = (result.Value != null); } break; case 400: case 404: default: // Arango error break; } _parameters.Clear(); return(result); }
/// <summary> /// Updates existing edge identified by its handle with new edge data. /// </summary> /// <exception cref="ArgumentException">Specified id value has invalid format.</exception> public AResult <Dictionary <string, object> > Update(string id, string json) { if (!ADocument.IsID(id)) { throw new ArgumentException("Specified id value (" + id + ") has invalid format."); } var request = new Request(HttpMethod.PATCH, ApiBaseUri.Edge, "/" + id); // optional request.TrySetQueryStringParameter(ParameterName.WaitForSync, _parameters); // optional request.TrySetHeaderParameter(ParameterName.IfMatch, _parameters); // optional if (_parameters.Has(ParameterName.IfMatch)) { request.TrySetQueryStringParameter(ParameterName.Policy, _parameters); } // optional request.TrySetQueryStringParameter(ParameterName.KeepNull, _parameters); // optional request.TrySetQueryStringParameter(ParameterName.MergeObjects, _parameters); request.Body = json; var response = _connection.Send(request); var result = new AResult <Dictionary <string, object> >(response); switch (response.StatusCode) { case 201: case 202: if (response.DataType == DataType.Document) { result.Value = (response.Data as Dictionary <string, object>); result.Success = (result.Value != null); } break; case 412: if (response.DataType == DataType.Document) { result.Value = (response.Data as Dictionary <string, object>); } break; case 400: case 404: default: // Arango error break; } _parameters.Clear(); return(result); }
/// <summary> /// Stores `_id` field value. /// </summary> /// <exception cref="ArgumentException">Specified id value has invalid format.</exception> public static Dictionary <string, object> ID(this Dictionary <string, object> dictionary, string id) { if (!ADocument.IsID(id)) { throw new ArgumentException("Specified id value (" + id + ") has invalid format."); } SetFieldValue(dictionary, "_id", id); return(dictionary); }
/// <summary> /// Creates new edge with document data within specified collection between two document vertices in current database context. /// </summary> public AResult <Dictionary <string, object> > Create(string collectionName, string fromID, string toID, string json) { if (!ADocument.IsID(fromID)) { throw new ArgumentException("Specified fromID value (" + fromID + ") has invalid format."); } if (!ADocument.IsID(toID)) { throw new ArgumentException("Specified toID value (" + toID + ") has invalid format."); } var request = new Request(HttpMethod.POST, ApiBaseUri.Edge, ""); // required request.QueryString.Add(ParameterName.Collection, collectionName); // required request.QueryString.Add(ParameterName.From, fromID); // required request.QueryString.Add(ParameterName.To, toID); // optional request.TrySetQueryStringParameter(ParameterName.CreateCollection, _parameters); // optional request.TrySetQueryStringParameter(ParameterName.WaitForSync, _parameters); request.Body = json; var response = _connection.Send(request); var result = new AResult <Dictionary <string, object> >(response); switch (response.StatusCode) { case 201: case 202: if (response.DataType == DataType.Document) { result.Value = (response.Data as Dictionary <string, object>); result.Success = (result.Value != null); } break; case 400: case 404: default: // Arango error break; } _parameters.Clear(); return(result); }
/// <summary> /// Retrieves specified edge. /// </summary> /// <exception cref="ArgumentException">Specified id value has invalid format.</exception> public AResult <Dictionary <string, object> > Get(string id) { if (!ADocument.IsID(id)) { throw new ArgumentException("Specified id value (" + id + ") has invalid format."); } var request = new Request(HttpMethod.GET, ApiBaseUri.Edge, "/" + id); // optional request.TrySetHeaderParameter(ParameterName.IfMatch, _parameters); // optional: If revision is different -> HTTP 200. If revision is identical -> HTTP 304. request.TrySetHeaderParameter(ParameterName.IfNoneMatch, _parameters); var response = _connection.Send(request); var result = new AResult <Dictionary <string, object> >(response); switch (response.StatusCode) { case 200: if (response.DataType == DataType.Document) { result.Value = (response.Data as Dictionary <string, object>); result.Success = (result.Value != null); } break; case 412: if (response.DataType == DataType.Document) { result.Value = (response.Data as Dictionary <string, object>); } break; case 304: case 404: default: // Arango error break; } _parameters.Clear(); return(result); }
/// <summary> /// Checks for existence of specified edge. /// </summary> /// <exception cref="ArgumentException">Specified id value has invalid format.</exception> public AResult <string> Check(string id) { if (!ADocument.IsID(id)) { throw new ArgumentException("Specified id value (" + id + ") has invalid format."); } var request = new Request(HttpMethod.HEAD, ApiBaseUri.Edge, "/" + id); // optional request.TrySetHeaderParameter(ParameterName.IfMatch, _parameters); // optional: If revision is different -> HTTP 200. If revision is identical -> HTTP 304. request.TrySetHeaderParameter(ParameterName.IfNoneMatch, _parameters); var response = _connection.Send(request); var result = new AResult <string>(response); switch (response.StatusCode) { case 200: if ((response.Headers["ETag"] ?? "").Trim().Length > 0) { result.Value = response.Headers["ETag"].Replace("\"", ""); result.Success = (result.Value != null); } break; case 304: case 412: if ((response.Headers["ETag"] ?? "").Trim().Length > 0) { result.Value = response.Headers["ETag"].Replace("\"", ""); } break; case 404: default: // Arango error break; } _parameters.Clear(); return(result); }
/// <summary> /// Retrieves value of `_id` field. If the field is missing or has invalid format null value is returned. /// </summary> public static string ID(this Dictionary <string, object> dictionary) { string id; try { id = String(dictionary, "_id"); if (!ADocument.IsID(id)) { id = null; } } catch (Exception) { id = null; } return(id); }
/// <summary> /// Checks if specified field path has valid document ID value in the format of `collection/key`. /// </summary> public static bool IsID(this Dictionary <string, object> dictionary, string fieldPath) { var isValid = false; try { var fieldValue = GetFieldValue(dictionary, fieldPath); if (fieldValue is string) { return(ADocument.IsID((string)fieldValue)); } } catch (Exception) { isValid = false; } return(isValid); }
/// <summary> /// Retrieves value of `_to` field. If the field is missing or has invalid format null value is returned. /// </summary> public static string To(this Dictionary <string, object> dictionary) { string to; try { to = String(dictionary, "_to"); if (!ADocument.IsID(to)) { to = null; } } catch (Exception) { to = null; } return(to); }
/// <summary> /// Retrieves value of `_from` field. If the field is missing or has invalid format null value is returned. /// </summary> public static string From(this Dictionary <string, object> dictionary) { string from; try { from = String(dictionary, "_from"); if (!ADocument.IsID(from)) { from = null; } } catch (Exception) { from = null; } return(from); }
/// <summary> /// Retrieves list of edges from specified edge type collection to specified document vertex with given direction. /// </summary> public AResult <List <Dictionary <string, object> > > Get(string collectionName, string startVertexID, ADirection direction) { if (!ADocument.IsID(startVertexID)) { throw new ArgumentException("Specified startVertexID value (" + startVertexID + ") has invalid format."); } var request = new Request(HttpMethod.GET, ApiBaseUri.Edges, "/" + collectionName); // required request.QueryString.Add(ParameterName.Vertex, startVertexID); // required request.QueryString.Add(ParameterName.Direction, direction.ToString().ToLower()); var response = _connection.Send(request); var result = new AResult <List <Dictionary <string, object> > >(response); switch (response.StatusCode) { case 200: if (response.DataType == DataType.Document) { result.Value = (response.Data as Dictionary <string, object>).List <Dictionary <string, object> >("edges"); result.Success = (result.Value != null); } break; case 400: case 404: default: // Arango error break; } _parameters.Clear(); return(result); }