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.");
            }
        }
        private void Initialize()
        {
            deferral = backgroundTask.GetDeferral();
            RegisterEventHandlers();

            // Set provider information. This information is localized, so read it from our resources.
            ResourceLoader resourceLoader = ResourceLoader.GetForViewIndependentUse();

            connection.CompanyName = resourceLoader.GetString("Company");
            connection.Name        = resourceLoader.GetString("Product");
            connection.Version     = resourceLoader.GetString("Version");

            decodeEngine = new DecodeEngine();

            // Our decode engine does not support any of these features.
            var attributesBuilder = new BarcodeSymbologyAttributesBuilder
            {
                IsCheckDigitTransmissionSupported = false,
                IsCheckDigitValidationSupported   = false,
                IsDecodeLengthSupported           = false,
            };

            // Tell the system which symbologies we support.
            foreach (uint symbology in decodeEngine.SupportedSymbologies)
            {
                connection.SupportedSymbologies.Add(symbology);

                // Populate a dictionary for tracking symbology attributes for each supported symbology.
                // (This step is unnecessary in the case of this sample because none of these properties
                // is marked as supported in our BarcodeSymbologyAttributesBuilder, but we track them
                // in this sample in order to show how it could be done.)
                BarcodeSymbologyAttributes defaultAttributes = attributesBuilder.CreateAttributes();
                if (attributesBuilder.IsDecodeLengthSupported)
                {
                    // These are the default values, but we set them explicitly for demonstration purposes.
                    defaultAttributes.DecodeLength1    = 0;
                    defaultAttributes.DecodeLength2    = 0;
                    defaultAttributes.DecodeLengthKind = BarcodeSymbologyDecodeLengthKind.AnyLength;
                }
                if (attributesBuilder.IsCheckDigitTransmissionSupported)
                {
                    // This is the default value, but we set it explicitly for demonstration purposes.
                    defaultAttributes.IsCheckDigitTransmissionEnabled = false;
                }
                if (attributesBuilder.IsCheckDigitValidationSupported)
                {
                    // This is the default value, but we set it explicitly for demonstration purposes.
                    defaultAttributes.IsCheckDigitValidationEnabled = false;
                }
                symbologyAttributes.Add(symbology, defaultAttributes);
            }

            // Start the connection after
            // 1. Provider information is set
            // 2. Supported symbologies are added
            // 3. All event handlers are registered
            connection.Start();
        }
 /// <summary>
 /// Adds the barcode symbologies, which have specified attribute.
 /// </summary>
 /// <param name="result">The list to add.</param>
 /// <param name="symbologyAttribute">The barcode symbology attribute.</param>
 private void AddBarcodeSymbologyByAttributes(List <BarcodeSymbology> result, BarcodeSymbologyAttributes symbologyAttribute)
 {
     foreach (BarcodeSymbology barcodeSymbology in _barcodeSymbologies)
     {
         if ((barcodeSymbology.Attributes & symbologyAttribute) != 0)
         {
             result.Add(barcodeSymbology);
         }
     }
 }
        /// <summary>
        /// Event handler for Symbology listbox selection changed.
        /// Get symbology attributes and populate attribute UI components
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private async void SymbologySelection_Changed(object sender, SelectionChangedEventArgs args)
        {
            if (claimedScanner != null)
            {
                SymbologyListEntry symbologyListEntry = (SymbologyListEntry)SymbologyListBox.SelectedItem;
                if (symbologyListEntry != null)
                {
                    SetSymbologyAttributesButton.IsEnabled = false;
                    try
                    {
                        symbologyAttributes = await claimedScanner.GetSymbologyAttributesAsync(symbologyListEntry.Id);
                    }
                    catch (Exception)
                    {
                        symbologyAttributes = null;
                    }

                    if (symbologyAttributes != null)
                    {
                        SetSymbologyAttributesButton.IsEnabled = true;

                        // initialize attributes UIs
                        EnableCheckDigit.IsEnabled     = symbologyAttributes.IsCheckDigitValidationSupported;
                        EnableCheckDigit.IsChecked     = symbologyAttributes.IsCheckDigitValidationEnabled;
                        TransmitCheckDigit.IsEnabled   = symbologyAttributes.IsCheckDigitTransmissionSupported;
                        TransmitCheckDigit.IsChecked   = symbologyAttributes.IsCheckDigitTransmissionEnabled;
                        SetDecodeRangeLimits.IsEnabled = symbologyAttributes.IsDecodeLengthSupported;
                        bool decodeLengthEnabled = (symbologyAttributes.DecodeLengthKind == BarcodeSymbologyDecodeLengthKind.Range);
                        SetDecodeRangeLimits.IsChecked = decodeLengthEnabled;
                        if (decodeLengthEnabled)
                        {
                            MinimumDecodeLength.Value = Math.Min(symbologyAttributes.DecodeLength1, symbologyAttributes.DecodeLength2);
                            MaximumDecodeLength.Value = Math.Max(symbologyAttributes.DecodeLength1, symbologyAttributes.DecodeLength2);
                        }
                    }
                    else
                    {
                        rootPage.NotifyUser("Symbology attributes are not available.", NotifyType.ErrorMessage);
                        EnableCheckDigit.IsEnabled     = false;
                        TransmitCheckDigit.IsEnabled   = false;
                        SetDecodeRangeLimits.IsEnabled = false;
                    }
                }
            }
        }
        /// <summary>
        /// Reset the Scenario state
        /// </summary>
        private void ResetTheScenarioState()
        {
            if (claimedScanner != null)
            {
                // Detach the event handlers
                claimedScanner.DataReceived           -= claimedScanner_DataReceived;
                claimedScanner.ReleaseDeviceRequested -= claimedScanner_ReleaseDeviceRequested;
                // Release the Barcode Scanner and set to null
                claimedScanner.Dispose();
                claimedScanner = null;
            }

            if (scanner != null)
            {
                scanner.Dispose();
                scanner = null;
            }

            symbologyAttributes = null;

            // Reset the UI if we are still the current page.
            if (Frame.Content == this)
            {
                rootPage.NotifyUser("Click the start scanning button to begin.", NotifyType.StatusMessage);
                this.ScenarioOutputScanData.Text      = "No data";
                this.ScenarioOutputScanDataLabel.Text = "No data";
                this.ScenarioOutputScanDataType.Text  = "No data";

                // reset the button state
                ScenarioEndScanButton.IsEnabled        = false;
                ScenarioStartScanButton.IsEnabled      = true;
                SetSymbologyAttributesButton.IsEnabled = false;
                EnableCheckDigit.IsEnabled             = false;
                TransmitCheckDigit.IsEnabled           = false;
                SetDecodeRangeLimits.IsEnabled         = false;

                // reset symbology list
                listOfSymbologies.Clear();
            }
        }