public async void Run([QueueTrigger("collarini-vendrame-queue", Connection = "ITS_Storage")] string myQueueItem, ILogger log)
        {
            log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");

            if (myQueueItem != null)
            {
                string messageTxt           = myQueueItem;
                var    detectionDeserialize = JsonSerializer.Deserialize <Detection>(messageTxt);

                //azure table storage
                var detectionEntity = new DetectionEntity(Guid.NewGuid(),
                                                          detectionDeserialize.ScooterId,
                                                          detectionDeserialize.SensorId,
                                                          detectionDeserialize.SensorValue,
                                                          detectionDeserialize.SensorType,
                                                          detectionDeserialize.SensorDetectionDate
                                                          );
                _detectionRepository.insertDetection(_detectionTable, detectionEntity);

                //influxdb storage
                var detectionInflux = new Detection
                {
                    ScooterId           = detectionDeserialize.ScooterId,
                    SensorId            = detectionDeserialize.SensorId,
                    SensorValue         = detectionDeserialize.SensorValue,
                    SensorType          = detectionDeserialize.SensorType,
                    SensorDetectionDate = detectionDeserialize.SensorDetectionDate
                };

                _influxRepository.insertDetection(detectionInflux, _influxDBClient, bucket, org);
            }
        }
Пример #2
0
        public static DetectionEntity InsertOrMergeEntity(CloudTable table, DetectionEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            try
            {
                // Create the InsertOrReplace table operation
                TableOperation insertOrMergeOperation = TableOperation.Insert(entity);

                // Execute the operation.
                TableResult     result            = table.Execute(insertOrMergeOperation);
                DetectionEntity insertedDetection = result.Result as DetectionEntity;

                if (result.RequestCharge.HasValue)
                {
                    Console.WriteLine("Request Charge of InsertOrMerge Operation: " + result.RequestCharge);
                }
                return(insertedDetection);
            }
            catch (StorageException e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
                throw;
            }
        }
Пример #3
0
        public async Task <IActionResult> OnPostUploadAsync(IFormFile formFile)
        {
            try
            {
                if (formFile.Length > 0)
                {
                    var filePath = Path.GetTempFileName();
                    using (var stream = System.IO.File.Create(filePath))
                    {
                        await formFile.CopyToAsync(stream);
                    }
                    HttpResponseMessage response;
                    response = await _customvision.IdentifyCedula(filePath);

                    string responsecontent = await response.Content.ReadAsStringAsync();

                    DetectionEntity             data       = JsonConvert.DeserializeObject <DetectionEntity>(responsecontent);
                    Dictionary <string, object> dataObject = _firebase.TransformObjectDetection(JsonConvert.SerializeObject(data.id), JsonConvert.SerializeObject(data.predictions));
                    bool saveFirebase = await _firebase.SaveObject("detection-cedula", dataObject);

                    return(new ObjectResult(data)
                    {
                        StatusCode = 200
                    });
                }
                else
                {
                    return(new ObjectResult(new { error = "No se encontro ninguna imagen tipo" })
                    {
                        StatusCode = 500
                    });
                }
            }
            catch (System.Exception error)
            {
                return(new ObjectResult(new { error = error.Message })
                {
                    StatusCode = 500
                });
            }
        }
Пример #4
0
        public async Task <Detection> CreateDetectionAsync(BaseDetection detection, byte[] detectionImageData)
        {
            // Upload person image to known persons blob container
            var detectionImageUrl = await this.blobStorageService.UploadBytesToContainerAsync(detection.Id, detectionImageData, DetectionsContainerName);

            // Enter record in known persons table
            var detectionResult = new Detection {
                Id = detection.Id, ImageReference = detectionImageUrl, DetectionTimestamp = DateTime.UtcNow.ToString()
            };

            var success = await this.tableStorageService.CreateEntityInTableAsync <DetectionEntity>(DetectionEntity.FromDetection(detectionResult), DetectionsTableName);

            return(detectionResult);
        }
 public void insertDetection(CloudTable t, DetectionEntity entity)
 {
     Common.InsertOrMergeEntity(t, entity);
 }