Exemplo n.º 1
0
        public async Task Handle(OrderProcessedIntegrationEvent result)
        {
            var orderStatus = await _stateStore.GetStateAsync <OrderStatus>(result.OrderId.ToString());

            if (orderStatus != null && orderStatus.Status != "Processed")
            {
                throw new Exception("Could not process order due to invalid status - " + orderStatus.Status);
            }

            var facesData  = result.Faces;
            var rootFolder = AppContext.BaseDirectory;

            Console.WriteLine("Root Directory is - " + rootFolder);
            if (facesData.Count < 1)
            {
                await Console.Out.WriteLineAsync($"No Faces Detected");
            }
            else
            {
                int j = 0;
                foreach (var face in facesData)
                {
                    MemoryStream ms    = new(face);
                    var          image = Image.Load(ms.ToArray());
                    image.Save(rootFolder + "face" + j + ".jpg");
                    j++;
                }
            }
            var dispatchedOrder = new OrderDispatchedIntegrationEvent
            {
                DispachtedDateTime = DateTime.UtcNow,
                OrderId            = result.OrderId
            };
            await _eventBus.PublishAsync <OrderDispatchedIntegrationEvent>(dispatchedOrder);
        }
        public async Task Handle(RegisterOrderIntegrationEvent result)
        {
            if (result.OrderId != Guid.Empty &&
                result.PictureUrl != null &&
                result.ImageData != null &&
                result.UserEmail != null)
            {
                SaveOrder(result);
                var client = DaprClient.CreateInvokeHttpClient(appId: "facesapi");
                Tuple <List <byte[]>, Guid> orderDetail = await GetFacesFromFacesAPIAsync(client, result.ImageData, result.OrderId);

                List <byte[]> faces   = orderDetail.Item1;
                Guid          orderId = orderDetail.Item2;
                SaveOrderDetails(orderId, faces);
                var processedOrder = new OrderProcessedIntegrationEvent
                {
                    OrderId    = result.OrderId,
                    Faces      = faces,
                    UserEmail  = result.UserEmail,
                    PictureUrl = result.PictureUrl
                };
                var bindingEvent = new BindingEvent();
                await _eventBus.PublishAsync <OrderProcessedIntegrationEvent>(processedOrder);

                await _binding.CreateBindingAsync <BindingEvent>(bindingEvent);
            }
        }