/// <summary>
        /// Inserts a Scan batch
        /// </summary>
        /// <param name="scanBatch"></param>
        /// <returns></returns>
        public async Task <bool> InsertScanBatchAsync(ScanBatchModel scanBatch)
        {
            using (HttpClient client = m_httpClientFactory.CreateClient())
            {
                HttpContent content = new StringContent(JsonConvert.SerializeObject(scanBatch));
                content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
                var response = await client.PostAsync(m_scanUrl, content);

                bool parse_success = int.TryParse(await response.Content.ReadAsStringAsync(), out int result);

                return(response.IsSuccessStatusCode);
            }
        }
Пример #2
0
        public async Task <IActionResult> Post([FromBody] ScanBatchModel ScanBatch)
        {
            if (ScanBatch == null || ScanBatch.Scans == null || ScanBatch.Scans.Count == 0)
            {
                return(BadRequest(string.Format("Request is null {0}", ScanBatch == null)));
            }

            m_logger.LogDebug(LogEventId.ScanBatchPostStart, string.Format("Scans Received: From {0}, Number {1}",
                                                                           ScanBatch.DeviceId, ScanBatch.Scans.Count));

            LogScanRequest  Request  = new LogScanRequest(ScanBatch.DeviceId, ScanBatch.Scans);
            LogScanResponse Response = await m_processor.Run(Request);

            m_logger.LogDebug(LogEventId.ScanBatchPostEnd, "Scan Batch processed: {0}.", Response.Success ? "Success" : "fail");

            if (!Response.Success)
            {
                return(BadRequest("Failed to insert into Database"));
            }

            return(Ok());
        }