Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="httpClient">Existing http client object setup with auth headers</param>
        /// <param name="messageSendUri"></param>
        /// <param name="messageResource"></param>
        public static void SendRelease(HttpClient httpClient, Uri messageSendUri, MessageResource messageResource)
        {
            string serializeObject = Serialize(messageResource, HttpClientExtensions.DefaultMediaType(httpClient));

            (" √ serializing request object to " + HttpClientExtensions.DefaultMediaType(httpClient)).ToConsole();

            HttpResponseMessage result = httpClient.PostAsync(messageSendUri, new StringContent(serializeObject, Encoding.UTF8, HttpClientExtensions.DefaultMediaType(httpClient).Description())).Result;

            result.CheckStatus();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an http request that will request attachment metadata for a specific attachment.
        /// </summary>
        /// <param name="httpClient">Existing http client object setup with auth headers</param>
        /// <param name="attachmentsUri"></param>
        /// <returns>application/json</returns>
        public static AttachmentResource RequestAttachmentMetadata(HttpClient httpClient, Uri attachmentsUri)
        {
            // Make a GET request to the document request endpoint.  It will return a collection of document types.
            //  (example is also showing some simple timing diagnostics)
            var stopwatch = new Stopwatch(); stopwatch.Start();
            HttpResponseMessage result = httpClient.GetAsync(attachmentsUri).Result;

            result.CheckStatus();
            var fileBytes = result.Content.ReadAsStringAsync().Result;

            WriteTimingOutput("making attachment request against", attachmentsUri, stopwatch.ElapsedMilliseconds);

            (" √ received " + fileBytes.Length + " bytes from API").ToConsole();

            var attachmentResource = Deserialize <AttachmentResource>(fileBytes, HttpClientExtensions.DefaultMediaType(httpClient));

            return(attachmentResource);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// An example of a intake query request
        /// </summary>
        /// <param name="httpClient">Existing http client object setup with auth headers</param>
        /// <param name="documentsMessagesUri"></param>
        /// <returns></returns>
        public static IEnumerable <MessageResource> RequestUnprocessedIntakeMessages(HttpClient httpClient, Uri documentsMessagesUri)
        {
            IEnumerable <MessageResource> messageResources = Enumerable.Empty <MessageResource>();

            // This example is going to parse the Uri to display the query paramters.
            Uri resource = new Uri(httpClient.BaseAddress, documentsMessagesUri);



            // Make a GET request to the document request endpoint.  It will return a collection of document types.
            //  (example is also showing some simple timing diagnostics)
            var stopwatch = new Stopwatch(); stopwatch.Start();
            HttpResponseMessage result = httpClient.GetAsync(documentsMessagesUri).Result;

            result.CheckStatus();
            string responseJson = result.Content.ReadAsStringAsync().Result;

            WriteTimingOutput("making unprocessed intake messages request against", resource, stopwatch.ElapsedMilliseconds);
            NameValueCollection queryString = resource.ParseQueryString();

            foreach (string key in queryString)
            {
                ("   - " + key + ": " + queryString[key]).ToConsole();
            }



            // parse the response.items for the messages and convert them to message resources
            JToken jToken = JObject.Parse(responseJson);

            if (string.IsNullOrWhiteSpace(responseJson))
            {
                return(messageResources);
            }

            var messages = jToken.SelectToken("items").ToString();

            if (string.IsNullOrWhiteSpace(messages))
            {
                return(messageResources);
            }

            messageResources = Deserialize <IEnumerable <MessageResource> >(messages, HttpClientExtensions.DefaultMediaType(httpClient));

            return(messageResources);
        }