Ejemplo n.º 1
0
 private async void BarcodeScannerProviderConnection_EnableScannerRequested(BarcodeScannerProviderConnection sender, BarcodeScannerEnableScannerRequestEventArgs args)
 {
     // For BarcodeScannerProviderConnection events,
     // a deferral is not required if the only async operation
     // is ReportCompletedAsync or ReportFailedAsync.
     scannerEnabled = true;
     await args.Request.ReportCompletedAsync();
 }
Ejemplo n.º 2
0
        public Provider(IBackgroundTaskInstance backgroundTask)
        {
            this.backgroundTask = backgroundTask;

            var triggerDetails = (BarcodeScannerProviderTriggerDetails)backgroundTask.TriggerDetails;

            connection = triggerDetails.Connection;

            Initialize();
        }
Ejemplo n.º 3
0
        private async void BarcodeScannerProviderConnection_DisableScannerRequested(BarcodeScannerProviderConnection sender, BarcodeScannerDisableScannerRequestEventArgs args)
        {
            using (args.GetDeferral())
            {
                scannerEnabled = false;

                // Stop frame reader when disabled
                if (frameReader != null)
                {
                    await frameReader.StopAsync();
                }
                await args.Request.ReportCompletedAsync();
            }
        }
Ejemplo n.º 4
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            if (disposing)
            {
                frameReader?.Dispose();
                frameReader = null;

                connection?.Dispose();
                connection = null;

                deferral?.Complete();
                deferral = null;

                disposed = true;
            }
        }
Ejemplo n.º 5
0
        private async void BarcodeScannerProviderConnection_SetActiveSymbologiesRequested(BarcodeScannerProviderConnection sender, BarcodeScannerSetActiveSymbologiesRequestEventArgs args)
        {
            // Ensure all symbologies being set to active are supported.
            foreach (var symbology in args.Request.Symbologies)
            {
                if (!decodeEngine.SupportedSymbologies.Contains(symbology))
                {
                    // Found invalid symbology.
                    await args.Request.ReportFailedAsync();

                    return;
                }
            }
            decodeEngine.ActiveSymbologies = new List <uint>(args.Request.Symbologies);
            await args.Request.ReportCompletedAsync();
        }
Ejemplo n.º 6
0
 private async void BarcodeScannerProviderConnection_HideVideoPreviewRequested(BarcodeScannerProviderConnection sender, BarcodeScannerHideVideoPreviewRequestEventArgs args)
 {
     // There is no video preview running as background task. Simply report completed.
     await args.Request.ReportCompletedAsync();
 }
Ejemplo n.º 7
0
 private async void BarcodeScannerProviderConnection_StopSoftwareTriggerRequested(BarcodeScannerProviderConnection sender, BarcodeScannerStopSoftwareTriggerRequestEventArgs args)
 {
     using (args.GetDeferral())
     {
         if (frameReader != null)
         {
             await frameReader.StopAsync();
         }
         await args.Request.ReportCompletedAsync();
     }
 }
Ejemplo n.º 8
0
        private async void BarcodeScannerProviderConnection_StartSoftwareTriggerRequested(BarcodeScannerProviderConnection sender, BarcodeScannerStartSoftwareTriggerRequestEventArgs args)
        {
            using (args.GetDeferral())
            {
                bool readerStarted = false;

                if (scannerEnabled)
                {
                    if (frameReader == null)
                    {
                        // Create frame reader to read video frames
                        frameReader = await connection.CreateFrameReaderAsync(BitmapPixelFormat.Nv12, new BitmapSize()
                        {
                            Width = 1280, Height = 720
                        });

                        frameReader.FrameArrived += FrameReader_FrameArrived;
                    }

                    readerStarted = await frameReader.StartAsync();
                }

                if (readerStarted)
                {
                    await args.Request.ReportCompletedAsync();
                }
                else
                {
                    await args.Request.ReportFailedAsync();
                }
            }
        }
Ejemplo n.º 9
0
        private async void BarcodeScannerProviderConnection_SetBarcodeSymbologyAttributesRequested(BarcodeScannerProviderConnection sender, BarcodeScannerSetSymbologyAttributesRequestEventArgs args)
        {
            // Update the symbology attributes for the specified symbology.
            BarcodeSymbologyAttributes newAttributes = args.Request.Attributes;
            BarcodeSymbologyAttributes existingAttributes;

            if (symbologyAttributes.TryGetValue(args.Request.Symbology, out existingAttributes))
            {
                // Our sample does not support these properties, but we update them for illustration purposes.
                if (existingAttributes.IsDecodeLengthSupported)
                {
                    existingAttributes.DecodeLength1    = newAttributes.DecodeLength1;
                    existingAttributes.DecodeLength2    = newAttributes.DecodeLength2;
                    existingAttributes.DecodeLengthKind = newAttributes.DecodeLengthKind;
                }
                if (existingAttributes.IsCheckDigitTransmissionSupported)
                {
                    existingAttributes.IsCheckDigitTransmissionEnabled = newAttributes.IsCheckDigitTransmissionEnabled;
                }
                if (existingAttributes.IsCheckDigitValidationSupported)
                {
                    existingAttributes.IsCheckDigitValidationEnabled = newAttributes.IsCheckDigitValidationEnabled;
                }
                // If we supported these properties, we would also have to update the parameters of the decoder
                // at this point.
                await args.Request.ReportCompletedAsync();
            }
            else
            {
                await args.Request.ReportFailedAsync(E_BOUNDS, "The requested symbology is not supported.");
            }
        }
Ejemplo n.º 10
0
        private async void BarcodeScannerProviderConnection_GetBarcodeSymbologyAttributesRequested(BarcodeScannerProviderConnection sender, BarcodeScannerGetSymbologyAttributesRequestEventArgs args)
        {
            BarcodeSymbologyAttributes attributes;

            if (symbologyAttributes.TryGetValue(args.Request.Symbology, out attributes))
            {
                await args.Request.ReportCompletedAsync(attributes);
            }
            else
            {
                await args.Request.ReportFailedAsync(E_BOUNDS, "The requested symbology is not supported.");
            }
        }