コード例 #1
0
        private Amazon.CloudSearchDomain.Model.UploadDocumentsResponse CallAWSServiceOperation(IAmazonCloudSearchDomain client, Amazon.CloudSearchDomain.Model.UploadDocumentsRequest request)
        {
            Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon CloudSearchDomain", "UploadDocuments");

            try
            {
#if DESKTOP
                return(client.UploadDocuments(request));
#elif CORECLR
                return(client.UploadDocumentsAsync(request).GetAwaiter().GetResult());
#else
#error "Unknown build edition"
#endif
            }
            catch (AmazonServiceException exc)
            {
                var webException = exc.InnerException as System.Net.WebException;
                if (webException != null)
                {
                    throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
                }

                throw;
            }
        }
コード例 #2
0
        /// <summary>
        /// This method uploads a set of documents onto your cloudsearch search domain.
        /// Your objects must already have been converted to the cloudsearch upload format
        /// for document batches (
        /// </summary>
        public bool UploadDocuments(List <AWSCloudSearchDocumentDocumentOperation> documents)
        {
            ClearErrorInfo();

            try
            {
                UploadDocumentsRequest uploadRequest = new UploadDocumentsRequest();
                uploadRequest.ContentType = "application/json";
                uploadRequest.Documents   = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(documents) ?? ""));

                UploadDocumentsResponse uploadResponse = CloudSearchClient.UploadDocuments(uploadRequest);

                // Check response for errors
                if (uploadResponse.HttpStatusCode != HttpStatusCode.OK)
                {
                    ErrorCode    = Convert.ToInt32(uploadResponse.HttpStatusCode);
                    ErrorMessage = "Http Error [" + uploadResponse.HttpStatusCode.ToString() + "]";
                }
            }
            catch (Exception ex)
            {
                ErrorCode    = -1;
                ErrorMessage = ex.Message + "::" + ex.InnerException;
            }

            return(ErrorCode == 0);
        }