Esempio n. 1
0
        static void CreateIndex()
        {
            string file = InputString("Filename:", "index.json", true);

            if (String.IsNullOrEmpty(file))
            {
                return;
            }

            Index index = DeserializeJson <Index>(File.ReadAllBytes(file));

            _Sdk.CreateIndex(index).Wait();
            Console.WriteLine("Success");
        }
Esempio 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;
            }
        }