public bool Decode(Barcode barcode)
        {
            var text = barcode.Scanned;
            var gs1Barcode = new Gs1128Barcode(barcode);
            // Max lenght for application identifier is four
            var applicationIdentifier = new StringBuilder(4);
            var data = new StringBuilder();
            for (var i = 0; i < text.Length; ++i)
            {
                var character = text[i];
                if (character == '(')
                {
                    // Process application identifier
                    do
                    {
                        character = text[++i];
                        if (character == ')')
                        {
                            break;
                        }
                        applicationIdentifier.Append(character);
                    } while (true);
                }
                // Act upon application identifier and extract that it identifies
                var ai = applicationIdentifier.ToString();
                var processor = Processors[ai];
                processor(data, gs1Barcode, ref i);
                applicationIdentifier.Clear();
            }

            return true;
        }
 public void Decode(string text)
 {
     var decoder = new Gs1128BarcodeTextDecoder();
     var barcode = new Barcode(text, "gs1-128");
     var decoded = decoder.Decode(barcode);
     Assert.True(decoded);
 }
 public bool Decode(Barcode barcode)
 {
     var text = barcode.Scanned;
     if (!(text.Length != 8 || text.Length != 13))
     {
         return false;
     }
     var checkDigit = CalculateCheckDigit(text);
     var lastDigit = text[text.Length - 1] - 0x30;
     if (checkDigit < 0 || checkDigit != lastDigit)
     {
         return false;
     }
     if (text.Length != 13 && !Gtin13Prefixes.Any(prefix => text.StartsWith(prefix)))
     {
         // No data to decode in form of weight or price
         return true;
     }
     var gtin13Barcode = new Gtin13Barcode();
     // Extract data to be decoded and determine type
     var dataText = text.Substring(DataStartIndex, 4);
     var data = float.Parse(dataText);
     if (text.StartsWith("20"))
     {
         data /= 100;
         gtin13Barcode.DataType = Gtin13BarcodeDataType.Price;
     }
     if (text.StartsWith("21"))
     {
         data /= 10;
         gtin13Barcode.DataType = Gtin13BarcodeDataType.Price;
     }
     if (text.StartsWith("22"))
     {
         gtin13Barcode.DataType = Gtin13BarcodeDataType.Price;
     }
     if (text.StartsWith("23"))
     {
         gtin13Barcode.DataType = Gtin13BarcodeDataType.Weight;
         data /= 1000;
     }
     if (text.StartsWith("24"))
     {
         gtin13Barcode.DataType = Gtin13BarcodeDataType.Weight;
         data /= 100;
     }
     if (text.StartsWith("25"))
     {
         gtin13Barcode.DataType = Gtin13BarcodeDataType.Weight;
         data /= 10;
     }
     gtin13Barcode.Data = data;
     var decoded = text.Substring(0, DataStartIndex) + "0000";
     gtin13Barcode.Decoded = decoded + CalculateCheckDigit(decoded, true);
     barcode.Context = gtin13Barcode;
     return true;
 }
示例#4
0
 public Gs1128Barcode(Barcode barcode)
 {
     Scanned = barcode.Scanned;
     Type = barcode.Type;
     barcode.Context = this;
 }