コード例 #1
0
        /// <summary>
        /// Gets all entities from database.
        /// </summary>
        /// <typeparam name="TEntity">Each entity will be casted to this type.</typeparam>
        /// <param name="entityListQueryParams">Instance of <see cref="ListQueryParams"/> to be used for filtering.</param>
        /// <returns><see cref="DocListResponse{TEntity}"/> containing list of JSON objects (<typeparamref name="TEntity"/>).</returns>
        /// <exception cref="CouchDBClientException">Error response received from CouchDB server.</exception>
        /// <exception cref="InvalidOperationException">Malformed JSON string received from CouchDB server..</exception>
        public async Task <DocListResponse <TEntity> > GetAllEntitiesAsync <TEntity>(ListQueryParams entityListQueryParams = null)
            where TEntity : IEntity
        {
            if (entityListQueryParams == null)
            {
                entityListQueryParams = new ListQueryParams();
            }

            entityListQueryParams.Include_Docs = true;

            return(await _db.GetAllObjectDocumentsAsync <TEntity>(entityListQueryParams).Safe());
        }
コード例 #2
0
        /// <summary>
        /// Returns a list of all the databases in the CouchDB instance.
        /// </summary>
        /// <returns>String array containing all database names.</returns>
        /// <exception cref="CouchDBClientException">Error response receive from CouchDB server.</exception>
        public async Task <string[]> GetAllDbNamesAsync(ListQueryParams queryParams = null)
        {
            string[] dbNames = null;

            var allDbsQuery = QueryParams.AppendQueryParams("_all_dbs", queryParams);
            var response    = await _handler.SendRequestAsync(allDbsQuery, RequestMethod.GET, Request.Empty).Safe();

            if (response != null)
            {
                dbNames = await response.ReadAsAsync <string[]>(false).Safe();
            }

            return(dbNames);
        }
コード例 #3
0
        /// <summary>
        /// Returns a JSON structure of the documents in a given database, found by ID list.
        /// The information is returned as a JSON structure containing meta information
        /// about the return structure, including a list of all documents and basic contents,
        /// consisting the ID, revision and key. The key is the from the document’s _id.
        /// </summary>
        /// <typeparam name="TDocument">Specifies resulting document object type.</typeparam>
        /// <param name="this">Instance of <see cref="ICouchDBDatabase"/>.</param>
        /// <param name="docIdList">Array of document IDs to be retrieved.</param>
        /// <param name="queryParams">Instance of <see cref="ListQueryParams"/> to be used for filtering.</param>
        /// <param name="deserializer">Provide your own deserializer if you prefer.
        /// By default, it will deserialize by using NewtonSoft.Json methods.
        /// NOTE: if the specified <typeparamref name="TDocument"/> does not have parameterless constructor,
        /// you should specify the deserializer as well. Otherwise, runtime exception will be thrown.</param>
        /// <returns><see cref="DocListResponse{TDOcument}"/> containing list of JSON objects (<typeparamref name="TDocument"/>).</returns>
        /// <exception cref="ArgumentNullException">Required parameter is null or empty.</exception>
        /// <exception cref="CouchDBClientException">Error response received from CouchDB server.</exception>
        /// <exception cref="InvalidOperationException">Malformed JSON string received from CouchDB server..</exception>
        public static async Task <DocListResponse <TDocument> > GetObjectDocumentsAsync <TDocument>(this ICouchDBDatabase @this, string[] docIdList, ListQueryParams queryParams = null, Func <string, TDocument> deserializer = null)
        {
            if (docIdList == null || docIdList.Length == 0)
            {
                throw new ArgumentNullException(nameof(docIdList));
            }

            if (queryParams == null)
            {
                queryParams = new ListQueryParams();
            }

            var stringDocs = await @this.GetStringDocumentsAsync(docIdList, queryParams).Safe();

            return(stringDocs.Cast(deserializer ?? new Func <string, TDocument>(strDoc => !string.IsNullOrWhiteSpace(strDoc) ? JsonConvert.DeserializeObject <TDocument>(strDoc) : default(TDocument))));
        }
コード例 #4
0
        /// <summary>
        /// Returns a JSON structure of documents in a given database, by multiple IDs.
        /// </summary>
        /// <param name="this">Instance of <see cref="ICouchDBDatabase"/>.</param>
        /// <param name="docIdList">Array of document IDs for retrieving documents.</param>
        /// <param name="queryParams">Instance of <see cref="ListQueryParams"/> to be used for filtering.</param>
        /// <returns><see cref="DocListResponse{JObject}"/> containing list of JSON objects (<see cref="JObject"/>).</returns>
        /// <exception cref="ArgumentNullException">Required parameter is null or empty.</exception>
        /// <exception cref="CouchDBClientException">Error response received from CouchDB server.</exception>
        /// <exception cref="InvalidOperationException">Malformed JSON string received from CouchDB server..</exception>
        public static async Task <DocListResponse <JObject> > GetJsonDocumentsAsync(this ICouchDBDatabase @this, string[] docIdList, ListQueryParams queryParams = null)
        {
            if (docIdList == null || docIdList.Length == 0)
            {
                throw new ArgumentNullException(nameof(docIdList));
            }

            if (queryParams == null)
            {
                queryParams = new ListQueryParams();
            }

            var stringDocs = await @this.GetStringDocumentsAsync(docIdList, queryParams).Safe();

            return(stringDocs.Cast(strDoc => !string.IsNullOrWhiteSpace(strDoc) ? JObject.Parse(strDoc) : null));
        }
コード例 #5
0
        /// <summary>
        /// Gets entities from database by list of IDs.
        /// </summary>
        /// <typeparam name="TEntity">Each entity will be casted to this type.</typeparam>
        /// <param name="entityIdList">List if IDs for finding entities.</param>
        /// <param name="entityListQueryParams">Instance of <see cref="ListQueryParams"/> to be used for filtering.</param>
        /// <returns><see cref="DocListResponse{TEntity}"/> containing list of JSON objects (<typeparamref name="TEntity"/>).</returns>
        /// <exception cref="ArgumentNullException">Required parameter is null or empty.</exception>
        /// <exception cref="CouchDBClientException">Error response received from CouchDB server.</exception>
        /// <exception cref="InvalidOperationException">Malformed JSON string received from CouchDB server..</exception>
        public async Task <DocListResponse <TEntity> > GetEntitiesAsync <TEntity>(string[] entityIdList, ListQueryParams entityListQueryParams = null)
        {
            if (entityIdList == null || entityIdList.Length == 0)
            {
                throw new ArgumentNullException(nameof(entityIdList));
            }

            if (entityListQueryParams == null)
            {
                entityListQueryParams = new ListQueryParams();
            }

            entityListQueryParams.Include_Docs = true;

            return(await _db.GetObjectDocumentsAsync <TEntity>(entityIdList, entityListQueryParams).Safe());
        }
コード例 #6
0
        /// <summary>
        /// Returns a JSON structure of all of the documents in a given database.
        /// The information is returned as a JSON structure containing meta information
        /// about the return structure, including a list of all documents and basic contents,
        /// consisting the ID, revision and key. The key is the from the document’s _id.
        /// </summary>
        /// <param name="queryParams">Instance of <see cref="ListQueryParams"/> to be used for filtering.</param>
        /// <returns><see cref="DocListResponse{STRING}"/> containing list of JSON strings.</returns>
        /// <exception cref="CouchDBClientException">Error response received from CouchDB server.</exception>
        /// <exception cref="InvalidOperationException">Malformed JSON string received from CouchDB server..</exception>
        public async Task <DocListResponse <string> > GetAllStringDocumentsAsync(ListQueryParams queryParams = null)
        {
            if (queryParams == null)
            {
                queryParams = new ListQueryParams();
            }

            var allDocsUrl = QueryParams.AppendQueryParams("_all_docs", queryParams);
            var response   = await _handler.SendRequestAsync(allDocsUrl, RequestMethod.GET, Request.Empty).Safe();

            if (response == null)
            {
                return(null);
            }

            var allDocsJsonString = await response.ReadAsStringAsync(false).Safe();

            var docListResponse = DocListResponse <string> .FromJsonToStringList(allDocsJsonString);

            return(docListResponse);
        }
コード例 #7
0
        /// <summary>
        /// Returns a JSON structure of all of the documents in a given database.
        /// The information is returned as a JSON structure containing meta information
        /// about the return structure, including a list of all documents and basic contents,
        /// consisting the ID, revision and key. The key is the from the document’s _id.
        /// </summary>
        /// <param name="this">Instance of <see cref="ICouchDBDatabase"/>.</param>
        /// <typeparam name="TDocument">Specifies resulting document object type.</typeparam>
        /// <param name="queryParams">Instance of <see cref="ListQueryParams"/> to be used for filtering.</param>
        /// <param name="deserializer">Provide your own deserializer if you prefer.
        /// By default, it will deserialize by using NewtonSoft.Json methods.
        /// NOTE: if the specified <typeparamref name="TDocument"/> does not have parameterless constructor,
        /// you should specify the deserializer as well. Otherwise, runtime exception will be thrown.</param>
        /// <returns><see cref="DocListResponse{TDOcument}"/> containing list of JSON objects (<typeparamref name="TDocument"/>).</returns>
        /// <exception cref="CouchDBClientException">Error response received from CouchDB server.</exception>
        /// <exception cref="InvalidOperationException">Malformed JSON string received from CouchDB server..</exception>
        public static async Task <DocListResponse <TDocument> > GetAllObjectDocumentsAsync <TDocument>(this ICouchDBDatabase @this, ListQueryParams queryParams = null, Func <string, TDocument> deserializer = null)
        {
            if (queryParams == null)
            {
                queryParams = new ListQueryParams();
            }

            var jsonDocs = await @this.GetAllStringDocumentsAsync(queryParams).Safe();

            return(jsonDocs.Cast(deserializer ?? new Func <string, TDocument>(json => !string.IsNullOrWhiteSpace(json) ? JsonConvert.DeserializeObject <TDocument>(json) : default(TDocument))));
        }
コード例 #8
0
        /// <summary>
        /// Returns a JSON structure of all of the documents in a given database.
        /// The information is returned as a JSON structure containing meta information
        /// about the return structure, including a list of all documents and basic contents,
        /// consisting the ID, revision and key. The key is the from the document’s _id.
        /// </summary>
        /// <param name="this">Instance of <see cref="ICouchDBDatabase"/>.</param>
        /// <param name="queryParams">Instance of <see cref="ListQueryParams"/> to be used for filtering.</param>
        /// <returns><see cref="DocListResponse{JObject}"/> containing list of JSON objects (<see cref="JObject"/>).</returns>
        /// <exception cref="CouchDBClientException">Error response received from CouchDB server.</exception>
        /// <exception cref="InvalidOperationException">Malformed JSON string received from CouchDB server..</exception>
        public static async Task <DocListResponse <JObject> > GetAllJsonDocumentsAsync(this ICouchDBDatabase @this, ListQueryParams queryParams = null)
        {
            if (queryParams == null)
            {
                queryParams = new ListQueryParams();
            }

            var stringDocs = await @this.GetAllStringDocumentsAsync(queryParams).Safe();

            return(stringDocs.Cast(strDoc => !string.IsNullOrWhiteSpace(strDoc) ? JObject.Parse(strDoc) : null));
        }
コード例 #9
0
        /// <summary>
        /// Returns a JSON structure of the documents in a given database, found by ID list.
        /// The information is returned as a JSON structure containing meta information
        /// about the return structure, including a list of all documents and basic contents,
        /// consisting the ID, revision and key. The key is the from the document’s _id.
        /// </summary>
        /// <param name="docIdList">Array of document IDs to be retrieved.</param>
        /// <param name="queryParams">Instance of <see cref="ListQueryParams"/> to be used for filtering.</param>
        /// <returns><see cref="DocListResponse{STRING}"/> containing list of JSON strings.</returns>
        /// <exception cref="ArgumentNullException">Required parameter is null or empty.</exception>
        /// <exception cref="CouchDBClientException">Error response received from CouchDB server.</exception>
        /// <exception cref="InvalidOperationException">Malformed JSON string received from CouchDB server..</exception>
        public async Task <DocListResponse <string> > GetStringDocumentsAsync(string[] docIdList, ListQueryParams queryParams = null)
        {
            if (docIdList == null || docIdList.Length == 0)
            {
                throw new ArgumentNullException(nameof(docIdList));
            }

            if (queryParams == null)
            {
                queryParams = new ListQueryParams();
            }

            var allDocsUrl         = QueryParams.AppendQueryParams("_all_docs", queryParams);
            var allDocsRequest     = new { keys = docIdList };
            var allDocsJsonRequest = JsonConvert.SerializeObject(allDocsRequest);

            var allDocsResponse = await _handler.SendRequestAsync(allDocsUrl, RequestMethod.POST, Request.JsonString(allDocsJsonRequest)).Safe();

            if (allDocsResponse == null)
            {
                return(null);
            }

            var allDocsJsonString = await allDocsResponse.ReadAsStringAsync(false).Safe();

            var docListResponse = DocListResponse <string> .FromJsonToStringList(allDocsJsonString);

            return(docListResponse);
        }