protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            CameraSource?.Release();
            BarcodeDetector?.Release();
            this.Write($"Disposed");
        }
        public void ReceiveDetections(Detections detections)
        {
            var codes = detections.DetectedItems;

            if (codes.Size() == 0)
            {
                return;
            }

            if (Task != null)
            {
                if (Task.IsCanceled)
                {
                    Task = null;
                    RunOnUiThread(() =>
                    {
                        ShowToastMessage("Task.IsCanceled", ToastLength.Long);
                    });
                    Thread.Sleep(5000);
                    return;
                }
                if (Task.IsFaulted)
                {
                    Task = null;
                    RunOnUiThread(() =>
                    {
                        ShowToastMessage("Task.IsFaulted", ToastLength.Long);
                    });
                    Thread.Sleep(5000);
                    return;
                }
                if (Task.IsCompletedSuccessfully)
                {
                    Task = null;
                    RunOnUiThread(() =>
                    {
                        ShowToastMessage("Task.IsCompletedSuccessfully", ToastLength.Long);
                    });
                    Thread.Sleep(5000);
                    return;
                }
                if (Task.IsCompleted)
                {
                    Task = null;
                    RunOnUiThread(() =>
                    {
                        ShowToastMessage("Task.IsCompleted", ToastLength.Long);
                    });
                    Thread.Sleep(5000);
                    return;
                }

                ShowToastMessage(Task.Status.ToString());
                Thread.Sleep(5000);
                return;
            }

            BarcodeDetector.Release();
            var barcode = (Barcode)codes.ValueAt(0);

            _scannedBarcode = barcode.RawValue;
            CameraPreviewProgressBar.Visibility = ViewStates.Visible;

            RunOnUiThread(() =>
            {
                ShowToastMessage(_scannedBarcode, ToastLength.Long);
            });

            Thread.Sleep(5000);
            if (!_callback)
            {
                Task = Task.Run(async() =>
                {
                    try
                    {
                        var result = await ProductService.GetProductByBarcode(_scannedBarcode);

                        if (result.Error.Any())
                        {
                            var message = Resources.GetString(Resource.String.ProductBarcodeNotFound);

                            RunOnUiThread(() =>
                            {
                                BarcodeDetector.SetProcessor(this);
                                ShowToastMessage(message, ToastLength.Long);
                            });

                            return;
                        }

                        RunOnUiThread(() =>
                        {
                            NavigationManager.GoToProductDetails(result.Data);
                        });
                    }
                    catch (Exception ex)
                    {
                        RunOnUiThread(() =>
                        {
                            BarcodeDetector.SetProcessor(this);
                            ShowToastMessage(ex.Message, ToastLength.Long);
                        });
                    }
                });
            }
            else
            {
                NavigationManager.GoToPrevious();
            }
        }
Ejemplo n.º 3
0
 public override void Dispose()
 {
     TextRecognizer.Release();
     BarcodeDetector.Release();
 }