Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <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);
        }
Esempio n. 3
0
        /// <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 `_key` field value.
        /// </summary>
        /// <exception cref="ArgumentException">Specified key value has invalid format.</exception>
        public static Dictionary <string, object> Key(this Dictionary <string, object> dictionary, string key)
        {
            if (!ADocument.IsKey(key))
            {
                throw new ArgumentException("Specified key value (" + key + ") has invalid format.");
            }

            SetFieldValue(dictionary, "_key", key);

            return(dictionary);
        }
        /// <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>
        /// Stores `_rev` field value.
        /// </summary>
        /// <exception cref="ArgumentException">Specified rev value has invalid format.</exception>
        public static Dictionary <string, object> Rev(this Dictionary <string, object> dictionary, string rev)
        {
            if (!ADocument.IsRev(rev))
            {
                throw new ArgumentException("Specified rev value (" + rev + ") has invalid format.");
            }

            SetFieldValue(dictionary, "_rev", rev);

            return(dictionary);
        }
Esempio n. 7
0
        /// <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);
        }
Esempio n. 8
0
        /// <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);
        }
Esempio n. 9
0
        /// <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 `_key` field. If the field is missing or has invalid format null value is returned.
        /// </summary>
        public static string Key(this Dictionary <string, object> dictionary)
        {
            string key;

            try
            {
                key = String(dictionary, "_key");

                if (!ADocument.IsKey(key))
                {
                    key = null;
                }
            }
            catch (Exception)
            {
                key = null;
            }

            return(key);
        }
        /// <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 key value.
        /// </summary>
        public static bool IsKey(this Dictionary <string, object> dictionary, string fieldPath)
        {
            var isValid = false;

            try
            {
                var fieldValue = GetFieldValue(dictionary, fieldPath);

                if (fieldValue is string)
                {
                    return(ADocument.IsKey((string)fieldValue));
                }
            }
            catch (Exception)
            {
                isValid = false;
            }

            return(isValid);
        }
        /// <summary>
        /// Retrieves value of `_rev` field. If the field is missing or has invalid format null value is returned.
        /// </summary>
        public static string Rev(this Dictionary <string, object> dictionary)
        {
            string rev;

            try
            {
                rev = String(dictionary, "_rev");

                if (!ADocument.IsRev(rev))
                {
                    rev = null;
                }
            }
            catch (Exception)
            {
                rev = null;
            }

            return(rev);
        }
        /// <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);
        }
Esempio n. 16
0
        /// <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);
        }