Esempio n. 1
0
        private void StartConsumerLoop(CancellationToken cancellationToken)
        {
            //subcribe duoc nhieu keu
            kafkaConsumer.Subscribe(Channels);

            while (!cancellationToken.IsCancellationRequested)
            {
                try
                {
                    var cr = this.kafkaConsumer.Consume(cancellationToken);
                    if (cr.Topic.Equals("REGISTER_FACE_RESPONSE"))
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("REGISTER_FACE_RESPONSE --- " + cr.Message.Value);
                        Console.ForegroundColor = ConsoleColor.White;
                        RegisterFace registerFace = new RegisterFace();
                        registerFace = JsonConvert.DeserializeObject <RegisterFace>(cr.Message.Value);
                        HandleTaskRegister.Action(registerFace.Record, registerFace);
                    }
                    if (cr.Topic.Equals("DETECT_FACE_RESPONSE"))
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("DETECT_FACE_RESPONSE --- " + cr.Message.Value);
                        Console.ForegroundColor = ConsoleColor.White;
                        DetectFace detectFace = new DetectFace();
                        detectFace = JsonConvert.DeserializeObject <DetectFace>(cr.Message.Value);
                        HandleTaskDetect.Action(detectFace.Record, detectFace);
                    }
                    if (cr.Topic.Equals("REMOVE_TOPIC_RESPONSE"))
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("REMOVE_TOPIC_RESPONSE --- " + cr.Message.Value);
                        Console.ForegroundColor = ConsoleColor.White;
                        DeleteFace deleteFace = new DeleteFace();
                        deleteFace = JsonConvert.DeserializeObject <DeleteFace>(cr.Message.Value);
                        HandleTaskDelete.Action(deleteFace.Id, deleteFace);
                    }
                }
                catch (OperationCanceledException)
                {
                    break;
                }
                catch (ConsumeException e)
                {
                    // Consumer errors should generally be ignored (or logged) unless fatal.
                    Console.WriteLine($"Consume error: {e.Error.Reason}");

                    if (e.Error.IsFatal)
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Unexpected error: {e}");
                    break;
                }
            }
        }
Esempio n. 2
0
        private async void RegisterPerson()
        {
            Message = null;
            ShowBusy("commencing mutant registration...");

            try
            {
                if (Model.Data.Mug == null)
                {
                    Message = "Please add a picture of the mutant first";
                    return;
                }

                if (string.IsNullOrEmpty(Model.Name))
                {
                    Message = "Please add a name for the mutant";
                    return;
                }

                var context = new RegisterFaceContext
                {
                    GroupId    = Constants.GroupId,
                    GroupName  = Constants.GroupName,
                    PersonName = Model.Name,
                    Data       = Model.Data
                };
                var result = await RegisterFace.ExecuteAsync(context);

                if (result.IsValid())
                {
                    Message = "Register Success!";
                }
                else
                {
                    Message = result.Notification.ToString();
                }
            }
            finally
            {
                NotBusy();
            }
        }