Exemplo n.º 1
0
        /// <summary>
        /// Enumerate source documents in the specified index.
        /// </summary>
        /// <param name="indexName">Name of the index.</param>
        /// <param name="query">Enumeration query.</param>
        /// <param name="token">Cancellation token used to cancel the request.</param>
        /// <returns>Enumeration result.</returns>
        public async Task <EnumerationResult> Enumerate(string indexName, EnumerationQuery query, CancellationToken token = default)
        {
            if (String.IsNullOrEmpty(indexName))
            {
                throw new ArgumentNullException(nameof(indexName));
            }
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            try
            {
                string url = indexName + "?enumerate";

                RestRequest req = new RestRequest(
                    _Endpoint + url,
                    HttpMethod.PUT,
                    _AuthHeaders,
                    "application/json");

                req.IgnoreCertificateErrors = AcceptInvalidCertificates;

                RestResponse resp = await req.SendAsync(KomodoCommon.SerializeJson(query, true), token).ConfigureAwait(false);

                KomodoException e = KomodoException.FromRestResponse(resp);
                if (e != null)
                {
                    throw e;
                }

                if (resp.Data != null && resp.ContentLength > 0)
                {
                    byte[] respData = KomodoCommon.StreamToBytes(resp.Data);
                    return(KomodoCommon.DeserializeJson <EnumerationResult>(respData));
                }

                return(null);
            }
            catch (TaskCanceledException)
            {
                return(null);
            }
            catch (OperationCanceledException)
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates an index.
        /// </summary>
        /// <param name="index">Index.</param>
        /// <param name="token">Cancellation token used to cancel the request.</param>
        public async Task CreateIndex(Index index, CancellationToken token = default)
        {
            if (index == null)
            {
                throw new ArgumentNullException(nameof(index));
            }
            if (String.IsNullOrEmpty(index.Name))
            {
                throw new ArgumentNullException(nameof(index.Name));
            }

            try
            {
                string url = "indices";

                RestRequest req = new RestRequest(
                    _Endpoint + url,
                    HttpMethod.POST,
                    _AuthHeaders,
                    "application/json");

                req.IgnoreCertificateErrors = AcceptInvalidCertificates;

                RestResponse resp = await req.SendAsync(KomodoCommon.SerializeJson(index, true), token).ConfigureAwait(false);

                KomodoException e = KomodoException.FromRestResponse(resp);
                if (e != null)
                {
                    throw e;
                }
            }
            catch (TaskCanceledException)
            {
                return;
            }
            catch (OperationCanceledException)
            {
                return;
            }
        }