public override ParsedResult parse(Result result)
 {
     // Although we should insist on the raw text ending with "END:VCARD", there's no reason
     // to throw out everything else we parsed just because this was omitted. In fact, Eclair
     // is doing just that, and we can't parse its contacts without this leniency.
     string rawText = getMassagedText(result);
       Match m = Regex.Match(rawText, BEGIN_VCARD, RegexOptions.IgnoreCase);
     if (!m.Success || m.Index != 0)
     {
       return null;
     }
     IList<IList<string>> names = matchVCardPrefixedField("FN", rawText, true, false);
     if (names == null)
     {
       // If no display names found, look for regular name fields and format them
       names = matchVCardPrefixedField("N", rawText, true, false);
       formatNames(names);
     }
     IList<IList<string>> phoneNumbers = matchVCardPrefixedField("TEL", rawText, true, false);
     IList<IList<string>> emails = matchVCardPrefixedField("EMAIL", rawText, true, false);
     IList<string> note = matchSingleVCardPrefixedField("NOTE", rawText, false, false);
     IList<IList<string>> addresses = matchVCardPrefixedField("ADR", rawText, true, true);
     IList<string> org = matchSingleVCardPrefixedField("ORG", rawText, true, true);
     IList<string> birthday = matchSingleVCardPrefixedField("BDAY", rawText, true, false);
     if (birthday != null && !isLikeVCardDate(birthday[0]))
     {
       birthday = null;
     }
     IList<string> title = matchSingleVCardPrefixedField("TITLE", rawText, true, false);
     IList<string> url = matchSingleVCardPrefixedField("URL", rawText, true, false);
     IList<string> instantMessenger = matchSingleVCardPrefixedField("IMPP", rawText, true, false);
     return new AddressBookParsedResult(toPrimaryValues(names), null, toPrimaryValues(phoneNumbers), toTypes(phoneNumbers), toPrimaryValues(emails), toTypes(emails), toPrimaryValue(instantMessenger), toPrimaryValue(note), toPrimaryValues(addresses), toTypes(addresses), toPrimaryValue(org), toPrimaryValue(birthday), toPrimaryValue(title), toPrimaryValue(url));
 }
        // public Result decode(BinaryBitmap image, System.Collections.Hashtable hints) // commented by .net follower (http://dotnetfollower.com)
        public Result decode(BinaryBitmap image, System.Collections.Generic.Dictionary <Object, Object> hints) // added by .net follower (http://dotnetfollower.com)
        {
            DecoderResult decoderResult;

            ResultPoint[] points;
            if (hints != null && hints.ContainsKey(DecodeHintType.PURE_BARCODE))
            {
                BitMatrix bits = extractPureBits(image.BlackMatrix);
                decoderResult = decoder.decode(bits);
                points        = NO_POINTS;
            }
            else
            {
                DetectorResult detectorResult = new Detector(image.BlackMatrix).detect();
                decoderResult = decoder.decode(detectorResult.Bits);
                points        = detectorResult.Points;
            }
            Result result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.DATAMATRIX);

            if (decoderResult.ByteSegments != null)
            {
                result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.ByteSegments);
            }
            if (decoderResult.ECLevel != null)
            {
                result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.ECLevel.ToString());
            }
            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 解码操作
        /// </summary>
        private void button3_Click(object sender, EventArgs e)
        {
            lbshow.Text = "";
            if (pictureBox2.Image == null)
            {
                lbshow.Text = "未导入图片!";
                return;
            }

            try
            {
                //构建解码器
                com.google.zxing.MultiFormatReader mutiReader = new com.google.zxing.MultiFormatReader();
                Bitmap img = (Bitmap)pictureBox2.Image; //(Bitmap)Bitmap.FromFile(opFilePath);
                com.google.zxing.LuminanceSource ls = new RGBLuminanceSource(img, img.Width, img.Height);
                com.google.zxing.BinaryBitmap    bb = new com.google.zxing.BinaryBitmap(new com.google.zxing.common.HybridBinarizer(ls));

                //注意  必须是Utf-8编码
                Hashtable hints = new Hashtable();
                hints.Add(com.google.zxing.EncodeHintType.CHARACTER_SET, "UTF-8");
                com.google.zxing.Result r = mutiReader.decode(bb, hints);
                txtmsg2.Text = r.Text;
                lbshow.Text  = "解码成功!";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 4
0
        public static CalendarParsedResult parse(Result result)
        {
            System.String rawText = result.Text;
            if (rawText == null)
            {
                return(null);
            }
            int vEventStart = rawText.IndexOf("BEGIN:VEVENT");

            if (vEventStart < 0)
            {
                return(null);
            }
            int vEventEnd = rawText.IndexOf("END:VEVENT");

            if (vEventEnd < 0)
            {
                return(null);
            }

            System.String summary = VCardResultParser.matchSingleVCardPrefixedField("SUMMARY", rawText, true);
            System.String start   = VCardResultParser.matchSingleVCardPrefixedField("DTSTART", rawText, true);
            System.String end     = VCardResultParser.matchSingleVCardPrefixedField("DTEND", rawText, true);
            try
            {
                return(new CalendarParsedResult(summary, start, end, null, null, null));
            }
            catch (System.ArgumentException iae)
            {
                return(null);
            }
        }
Exemplo n.º 5
0
        public static AddressBookParsedResult parse(Result result)
        {
            System.String rawText = result.Text;
            if (rawText == null || !rawText.StartsWith("MECARD:"))
            {
                return(null);
            }
            System.String[] rawName = matchDoCoMoPrefixedField("N:", rawText, true);
            if (rawName == null)
            {
                return(null);
            }
            System.String   name          = parseName(rawName[0]);
            System.String   pronunciation = matchSingleDoCoMoPrefixedField("SOUND:", rawText, true);
            System.String[] phoneNumbers  = matchDoCoMoPrefixedField("TEL:", rawText, true);
            System.String[] emails        = matchDoCoMoPrefixedField("EMAIL:", rawText, true);
            System.String   note          = matchSingleDoCoMoPrefixedField("NOTE:", rawText, false);
            System.String[] addresses     = matchDoCoMoPrefixedField("ADR:", rawText, true);
            System.String   birthday      = matchSingleDoCoMoPrefixedField("BDAY:", rawText, true);
            if (birthday != null && !isStringOfDigits(birthday, 8))
            {
                // No reason to throw out the whole card because the birthday is formatted wrong.
                birthday = null;
            }
            System.String url = matchSingleDoCoMoPrefixedField("URL:", rawText, true);

            // Although ORG may not be strictly legal in MECARD, it does exist in VCARD and we might as well
            // honor it when found in the wild.
            System.String org = matchSingleDoCoMoPrefixedField("ORG:", rawText, true);

            return(new AddressBookParsedResult(maybeWrap(name), pronunciation, phoneNumbers, emails, note, addresses, org, birthday, null, url));
        }
Exemplo n.º 6
0
        // Treat all UPC and EAN variants as UPCs, in the sense that they are all product barcodes.
        public override ParsedResult parse(Result result)
        {
            BarcodeFormat format = result.BarcodeFormat;

            if (!(format == BarcodeFormat.UPC_A || format == BarcodeFormat.UPC_E || format == BarcodeFormat.EAN_8 || format == BarcodeFormat.EAN_13))
            {
                return(null);
            }
            string rawText = getMassagedText(result);
            int    length  = rawText.Length;

            for (int x = 0; x < length; x++)
            {
                char c = rawText[x];
                if (c < '0' || c > '9')
                {
                    return(null);
                }
            }
            // Not actually checking the checksum again here

            string normalizedProductID;

            // Expand UPC-E for purposes of searching
            if (format == BarcodeFormat.UPC_E)
            {
                normalizedProductID = UPCEReader.convertUPCEtoUPCA(rawText);
            }
            else
            {
                normalizedProductID = rawText;
            }

            return(new ProductParsedResult(rawText, normalizedProductID));
        }
        public override ParsedResult parse(Result result)
        {
            string rawText = getMassagedText(result);
            if (!rawText.StartsWith("MECARD:"))
            {
              return null;
            }
            string[] rawName = matchDoCoMoPrefixedField("N:", rawText, true);
            if (rawName == null)
            {
              return null;
            }
            string name = parseName(rawName[0]);
            string pronunciation = matchSingleDoCoMoPrefixedField("SOUND:", rawText, true);
            string[] phoneNumbers = matchDoCoMoPrefixedField("TEL:", rawText, true);
            string[] emails = matchDoCoMoPrefixedField("EMAIL:", rawText, true);
            string note = matchSingleDoCoMoPrefixedField("NOTE:", rawText, false);
            string[] addresses = matchDoCoMoPrefixedField("ADR:", rawText, true);
            string birthday = matchSingleDoCoMoPrefixedField("BDAY:", rawText, true);
            if (birthday != null && !isStringOfDigits(birthday, 8))
            {
              // No reason to throw out the whole card because the birthday is formatted wrong.
              birthday = null;
            }
            string url = matchSingleDoCoMoPrefixedField("URL:", rawText, true);

            // Although ORG may not be strictly legal in MECARD, it does exist in VCARD and we might as well
            // honor it when found in the wild.
            string org = matchSingleDoCoMoPrefixedField("ORG:", rawText, true);

            return new AddressBookParsedResult(maybeWrap(name), pronunciation, phoneNumbers, null, emails, null, null, note, addresses, null, org, birthday, null, url);
        }
        protected void btnDecode_Click(object sender, EventArgs e)
        {
            if (Convert.ToString(Session["isDefaultImage"]) == "IsDefault")
            {
                lblErrorDecode.Text      = "Upload QR Code First!";
                lblErrorDecode.ForeColor = System.Drawing.Color.Red;
                return;
            }
            property.path = Server.MapPath("~/Images/QR_Codes/" + "img.bmp");
            System.Drawing.Image image = System.Drawing.Image.FromStream(new MemoryStream(File.ReadAllBytes(property.path)));
            Bitmap bitMap = new Bitmap(image);

            try
            {
                com.google.zxing.LuminanceSource source = new RGBLuminanceSource(bitMap, bitMap.Width, bitMap.Height);
                var                     binarizer       = new com.google.zxing.common.HybridBinarizer(source);
                var                     binBitmap       = new com.google.zxing.BinaryBitmap(binarizer);
                QRCodeReader            qrCodeReader    = new QRCodeReader();
                com.google.zxing.Result str             = qrCodeReader.decode(binBitmap);

                txtDecodedOriginalInfo.Text = str.ToString();

                lblErrorDecode.Text      = "Successfully Decoded!";
                lblErrorDecode.ForeColor = System.Drawing.Color.Green;
            }
            catch
            {
            }
        }
Exemplo n.º 9
0
        public virtual Result decode(BinaryBitmap image, Dictionary <object, object> hints)
        {
            DecoderResult decoderResult;

            ResultPoint[] points;
            if (hints != null && hints.ContainsKey(DecodeHintType.PURE_BARCODE))
            {
                BitMatrix bits = extractPureBits(image.BlackMatrix);
                decoderResult = decoder.decode(bits);
                points        = NO_POINTS;
            }
            else
            {
                DetectorResult detectorResult = new Detector(image.BlackMatrix).detect(hints);
                decoderResult = decoder.decode(detectorResult.Bits);
                points        = detectorResult.Points;
            }

            Result result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.QR_CODE);

            if (decoderResult.ByteSegments != null)
            {
                result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.ByteSegments);
            }
            if (decoderResult.ECLevel != null)
            {
                result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.ECLevel.ToString());
            }
            return(result);
        }
        public static CalendarParsedResult parse(Result result)
        {
            System.String rawText = result.Text;
            if (rawText == null)
            {
                return null;
            }
            int vEventStart = rawText.IndexOf("BEGIN:VEVENT");
            if (vEventStart < 0)
            {
                return null;
            }
            int vEventEnd = rawText.IndexOf("END:VEVENT");
            if (vEventEnd < 0)
            {
                return null;
            }

            System.String summary = VCardResultParser.matchSingleVCardPrefixedField("SUMMARY", rawText, true);
            System.String start = VCardResultParser.matchSingleVCardPrefixedField("DTSTART", rawText, true);
            System.String end = VCardResultParser.matchSingleVCardPrefixedField("DTEND", rawText, true);
            try
            {
                return new CalendarParsedResult(summary, start, end, null, null, null);
            }
            catch (System.ArgumentException iae)
            {
                return null;
            }
        }
Exemplo n.º 11
0
 public static ParsedResult parseResult(Result theResult)
 {
     // Simplification of original if - if else logic using Null Coalescing operator ??
     //
     // ?? Simply checks from left to right for a non null object
     // when an object evaluates to null the next object after the ?? is evaluated
     // This continues until a non null value is found or the last object is evaluated
     return
         (BookmarkDoCoMoResultParser.parse(theResult) as ParsedResult ??
          AddressBookDoCoMoResultParser.parse(theResult) as ParsedResult ??
          EmailDoCoMoResultParser.parse(theResult) as ParsedResult ??
          AddressBookAUResultParser.parse(theResult) as ParsedResult ??
          VCardResultParser.parse(theResult) as ParsedResult ??
          BizcardResultParser.parse(theResult) as ParsedResult ??
          VEventResultParser.parse(theResult) as ParsedResult ??
          EmailAddressResultParser.parse(theResult) as ParsedResult ??
          TelResultParser.parse(theResult) as ParsedResult ??
          SMSMMSResultParser.parse(theResult) as ParsedResult ??
          GeoResultParser.parse(theResult) as ParsedResult ??
          URLTOResultParser.parse(theResult) as ParsedResult ??
          URIResultParser.parse(theResult) as ParsedResult ??
          ISBNResultParser.parse(theResult) as ParsedResult ??
          ProductResultParser.parse(theResult) as ParsedResult ??
          new TextParsedResult(theResult.Text, null) as ParsedResult);
 }
Exemplo n.º 12
0
        // ISBN-13 For Dummies
        // http://www.bisg.org/isbn-13/for.dummies.html
        public static ISBNParsedResult parse(Result result)
        {
            BarcodeFormat format = result.BarcodeFormat;

            if (!BarcodeFormat.EAN_13.Equals(format))
            {
                return(null);
            }
            System.String rawText = result.Text;
            if (rawText == null)
            {
                return(null);
            }
            int length = rawText.Length;

            if (length != 13)
            {
                return(null);
            }
            if (!rawText.StartsWith("978") && !rawText.StartsWith("979"))
            {
                return(null);
            }

            return(new ISBNParsedResult(rawText));
        }
Exemplo n.º 13
0
 public static ParsedResult parseResult(Result theResult)
 {
     // Simplification of original if - if else logic using Null Coalescing operator ??
     //
     // ?? Simply checks from left to right for a non null object
     // when an object evaluates to null the next object after the ?? is evaluated
     // This continues until a non null value is found or the last object is evaluated
     return
         BookmarkDoCoMoResultParser.parse(theResult) as ParsedResult ??
         AddressBookDoCoMoResultParser.parse(theResult) as ParsedResult ??
         EmailDoCoMoResultParser.parse(theResult) as ParsedResult ??
         AddressBookAUResultParser.parse(theResult) as ParsedResult ??
         VCardResultParser.parse(theResult) as ParsedResult ??
         BizcardResultParser.parse(theResult) as ParsedResult ??
         VEventResultParser.parse(theResult) as ParsedResult ??
         EmailAddressResultParser.parse(theResult) as ParsedResult ??
         TelResultParser.parse(theResult) as ParsedResult ??
         SMSMMSResultParser.parse(theResult) as ParsedResult ??
         GeoResultParser.parse(theResult) as ParsedResult ??
         URLTOResultParser.parse(theResult) as ParsedResult ??
         URIResultParser.parse(theResult) as ParsedResult ??
         ISBNResultParser.parse(theResult) as ParsedResult ??
         ProductResultParser.parse(theResult) as ParsedResult ??
         new TextParsedResult(theResult.Text, null) as ParsedResult;
 }
        // Treat all UPC and EAN variants as UPCs, in the sense that they are all product barcodes.
        public override ParsedResult parse(Result result)
        {
            BarcodeFormat format = result.BarcodeFormat;
            if (!(format == BarcodeFormat.UPC_A || format == BarcodeFormat.UPC_E || format == BarcodeFormat.EAN_8 || format == BarcodeFormat.EAN_13))
            {
              return null;
            }
            string rawText = getMassagedText(result);
            int length = rawText.Length;
            for (int x = 0; x < length; x++)
            {
              char c = rawText[x];
              if (c < '0' || c > '9')
              {
            return null;
              }
            }
            // Not actually checking the checksum again here

            string normalizedProductID;
            // Expand UPC-E for purposes of searching
            if (format == BarcodeFormat.UPC_E)
            {
              normalizedProductID = UPCEReader.convertUPCEtoUPCA(rawText);
            }
            else
            {
              normalizedProductID = rawText;
            }

            return new ProductParsedResult(rawText, normalizedProductID);
        }
Exemplo n.º 15
0
        // Treat all UPC and EAN variants as UPCs, in the sense that they are all product barcodes.
        public static ProductParsedResult parse(Result result)
        {
            BarcodeFormat format = result.BarcodeFormat;

            if (!(BarcodeFormat.UPC_A.Equals(format) || BarcodeFormat.UPC_E.Equals(format) || BarcodeFormat.EAN_8.Equals(format) || BarcodeFormat.EAN_13.Equals(format)))
            {
                return(null);
            }
            // Really neither of these should happen:
            System.String rawText = result.Text;
            if (rawText == null)
            {
                return(null);
            }

            int length = rawText.Length;

            for (int x = 0; x < length; x++)
            {
                char c = rawText[x];
                if (c < '0' || c > '9')
                {
                    return(null);
                }
            }
            // Not actually checking the checksum again here

            System.String normalizedProductID;
            // Expand UPC-E for purposes of searching

            normalizedProductID = rawText;


            return(new ProductParsedResult(rawText, normalizedProductID));
        }
Exemplo n.º 16
0
		public virtual Result decode(BinaryBitmap image, System.Collections.Hashtable hints)
		{
			DecoderResult decoderResult;
			ResultPoint[] points;
			if (hints != null && hints.ContainsKey(DecodeHintType.PURE_BARCODE))
			{
				BitMatrix bits = extractPureBits(image.BlackMatrix);
				decoderResult = decoder.decode(bits);
				points = NO_POINTS;
			}
			else
			{
				DetectorResult detectorResult = new Detector(image.BlackMatrix).detect(hints);
				decoderResult = decoder.decode(detectorResult.Bits);
				points = detectorResult.Points;
			}
			
			Result result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.QR_CODE);
			if (decoderResult.ByteSegments != null)
			{
				result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.ByteSegments);
			}
			if (decoderResult.ECLevel != null)
			{
				result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.ECLevel.ToString());
			}
			return result;
		}
        public static NDEFSmartPosterParsedResult parse(Result result)
        {
            sbyte[] bytes = result.RawBytes;
            if (bytes == null)
            {
                return null;
            }
            NDEFRecord headerRecord = NDEFRecord.readRecord(bytes, 0);
            // Yes, header record starts and ends a message
            if (headerRecord == null || !headerRecord.MessageBegin || !headerRecord.MessageEnd)
            {
                return null;
            }
            if (!headerRecord.Type.Equals(NDEFRecord.SMART_POSTER_WELL_KNOWN_TYPE))
            {
                return null;
            }

            int offset = 0;
            int recordNumber = 0;
            NDEFRecord ndefRecord = null;
            sbyte[] payload = headerRecord.Payload;
            int action = NDEFSmartPosterParsedResult.ACTION_UNSPECIFIED;
            System.String title = null;
            System.String uri = null;

            while (offset < payload.Length && (ndefRecord = NDEFRecord.readRecord(payload, offset)) != null)
            {
                if (recordNumber == 0 && !ndefRecord.MessageBegin)
                {
                    return null;
                }

                System.String type = ndefRecord.Type;
                if (NDEFRecord.TEXT_WELL_KNOWN_TYPE.Equals(type))
                {
                    System.String[] languageText = NDEFTextResultParser.decodeTextPayload(ndefRecord.Payload);
                    title = languageText[1];
                }
                else if (NDEFRecord.URI_WELL_KNOWN_TYPE.Equals(type))
                {
                    uri = NDEFURIResultParser.decodeURIPayload(ndefRecord.Payload);
                }
                else if (NDEFRecord.ACTION_WELL_KNOWN_TYPE.Equals(type))
                {
                    action = ndefRecord.Payload[0];
                }
                recordNumber++;
                offset += ndefRecord.TotalRecordLength;
            }

            if (recordNumber == 0 || (ndefRecord != null && !ndefRecord.MessageEnd))
            {
                return null;
            }

            return new NDEFSmartPosterParsedResult(action, uri, title);
        }
Exemplo n.º 18
0
 protected internal static string getMassagedText(Result result)
 {
     string text = result.Text;
     if (text.StartsWith(BYTE_ORDER_MARK))
     {
       text = text.Substring(1);
     }
     return text;
 }
        public static ZxingBarcodeResult FromZxingResult(com.google.zxing.Result result)
        {
            var r = new ZxingBarcodeResult();

            r.Value    = result.Text;
            r.Metadata = result.ResultMetadata;
            r.Points   = result.ResultPoints;

            //r.Raw = new sbyte[](result.ResultPoints.Length);
            //result.RawBytes.CopyTo(r.Raw, 0);

            switch (result.BarcodeFormat.Name)
            {
            case "QR_CODE":
                r.Format = ZxingBarcodeFormat.QrCode;
                break;

            case "DATAMATRIX":
                r.Format = ZxingBarcodeFormat.DataMatrix;
                break;

            case "UPC_E":
                r.Format = ZxingBarcodeFormat.UpcE;
                break;

            case "UPC_A":
                r.Format = ZxingBarcodeFormat.UpcA;
                break;

            case "EAN_8":
                r.Format = ZxingBarcodeFormat.Ean8;
                break;

            case "EAN_13":
                r.Format = ZxingBarcodeFormat.Ean13;
                break;

            case "CODE_128":
                r.Format = ZxingBarcodeFormat.Code128;
                break;

            case "CODE_39":
                r.Format = ZxingBarcodeFormat.Code39;
                break;

            case "ITF":
                r.Format = ZxingBarcodeFormat.Itf;
                break;

            case "PDF417":
                r.Format = ZxingBarcodeFormat.Pdf417;
                break;
            }

            return(r);
        }
Exemplo n.º 20
0
 private static Result translateResultPoints(Result result, int xOffset, int yOffset)
 {
     ResultPoint[] oldResultPoints = result.ResultPoints;
     ResultPoint[] newResultPoints = new ResultPoint[oldResultPoints.Length];
     for (int i = 0; i < oldResultPoints.Length; i++)
     {
         ResultPoint oldPoint = oldResultPoints[i];
         newResultPoints[i] = new ResultPoint(oldPoint.X + xOffset, oldPoint.Y + yOffset);
     }
     return(new Result(result.Text, result.RawBytes, newResultPoints, result.BarcodeFormat));
 }
Exemplo n.º 21
0
 public override ParsedResult parse(Result result)
 {
     string rawText = getMassagedText(result);
     // We specifically handle the odd "URL" scheme here for simplicity and add "URI" for fun
     // Assume anything starting this way really means to be a URI
     if (rawText.StartsWith("URL:") || rawText.StartsWith("URI:"))
     {
       return new URIParsedResult(rawText.Substring(4).Trim(), null);
     }
     rawText = rawText.Trim();
     return isBasicallyValidURI(rawText) ? new URIParsedResult(rawText, null) : null;
 }
Exemplo n.º 22
0
 public static ParsedResult parseResult(Result theResult)
 {
     foreach (ResultParser parser in PARSERS)
     {
       ParsedResult result = parser.parse(theResult);
       if (result != null)
       {
     return result;
       }
     }
     return new TextParsedResult(theResult.Text, null);
 }
Exemplo n.º 23
0
		private static Result maybeReturnResult(Result result)
		{
			System.String text = result.Text;
			if (text[0] == '0')
			{
				return new Result(text.Substring(1), null, result.ResultPoints, BarcodeFormat.UPC_A);
			}
			else
			{
				throw ReaderException.Instance;
			}
		}
Exemplo n.º 24
0
 private static Result maybeReturnResult(Result result)
 {
     System.String text = result.Text;
     if (text[0] == '0')
     {
         return(new Result(text.Substring(1), null, result.ResultPoints, BarcodeFormat.UPC_A));
     }
     else
     {
         throw ReaderException.Instance;
     }
 }
Exemplo n.º 25
0
		public static URIParsedResult parse(Result result)
		{
			System.String rawText = result.Text;
			// We specifically handle the odd "URL" scheme here for simplicity
			if (rawText != null && rawText.StartsWith("URL:"))
			{
				rawText = rawText.Substring(4);
			}
			if (!isBasicallyValidURI(rawText))
			{
				return null;
			}
			return new URIParsedResult(rawText, null);
		}
Exemplo n.º 26
0
 public override ParsedResult parse(Result result)
 {
     string rawText = getMassagedText(result);
     if (!rawText.StartsWith("tel:") && !rawText.StartsWith("TEL:"))
     {
       return null;
     }
     // Normalize "TEL:" to "tel:"
     string telURI = rawText.StartsWith("TEL:") ? "tel:" + rawText.Substring(4) : rawText;
     // Drop tel, query portion
     int queryStart = rawText.IndexOf('?', 4);
     string number = queryStart < 0 ? rawText.Substring(4) : rawText.Substring(4, queryStart - 4);
     return new TelParsedResult(number, telURI, null);
 }
Exemplo n.º 27
0
 public static URIParsedResult parse(Result result)
 {
     System.String rawText = result.Text;
     // We specifically handle the odd "URL" scheme here for simplicity
     if (rawText != null && rawText.StartsWith("URL:"))
     {
         rawText = rawText.Substring(4);
     }
     if (!isBasicallyValidURI(rawText))
     {
         return(null);
     }
     return(new URIParsedResult(rawText, null));
 }
Exemplo n.º 28
0
		public static TelParsedResult parse(Result result)
		{
			System.String rawText = result.Text;
			if (rawText == null || (!rawText.StartsWith("tel:") && !rawText.StartsWith("TEL:")))
			{
				return null;
			}
			// Normalize "TEL:" to "tel:"
			System.String telURI = rawText.StartsWith("TEL:")?"tel:" + rawText.Substring(4):rawText;
			// Drop tel, query portion
			//UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
			int queryStart = rawText.IndexOf('?', 4);
			System.String number = queryStart < 0?rawText.Substring(4):rawText.Substring(4, (queryStart) - (4));
			return new TelParsedResult(number, telURI, null);
		}
Exemplo n.º 29
0
        public override ParsedResult parse(Result result)
        {
            string rawText = getMassagedText(result);

            if (!rawText.StartsWith("tel:") && !rawText.StartsWith("TEL:"))
            {
                return(null);
            }
            // Normalize "TEL:" to "tel:"
            string telURI = rawText.StartsWith("TEL:") ? "tel:" + rawText.Substring(4) : rawText;
            // Drop tel, query portion
            int    queryStart = rawText.IndexOf('?', 4);
            string number     = queryStart < 0 ? rawText.Substring(4) : rawText.Substring(4, queryStart - 4);

            return(new TelParsedResult(number, telURI, null));
        }
		public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Hashtable hints)
		{
			System.Collections.ArrayList results = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
			doDecodeMultiple(image, hints, results, 0, 0);
			if ((results.Count == 0))
			{
				throw ReaderException.Instance;
			}
			int numResults = results.Count;
			Result[] resultArray = new Result[numResults];
			for (int i = 0; i < numResults; i++)
			{
				resultArray[i] = (Result) results[i];
			}
			return resultArray;
		}
Exemplo n.º 31
0
 public override ParsedResult parse(Result result)
 {
     string rawText = getMassagedText(result);
     if (!rawText.StartsWith("urlto:") && !rawText.StartsWith("URLTO:"))
     {
       return null;
     }
     int titleEnd = rawText.IndexOf(':', 6);
     if (titleEnd < 0)
     {
       return null;
     }
     string title = titleEnd <= 6 ? null : rawText.Substring(6, titleEnd - 6);
     string uri = rawText.Substring(titleEnd + 1);
     return new URIParsedResult(uri, title);
 }
Exemplo n.º 32
0
        public static TelParsedResult parse(Result result)
        {
            System.String rawText = result.Text;
            if (rawText == null || (!rawText.StartsWith("tel:") && !rawText.StartsWith("TEL:")))
            {
                return(null);
            }
            // Normalize "TEL:" to "tel:"
            System.String telURI = rawText.StartsWith("TEL:")?"tel:" + rawText.Substring(4):rawText;
            // Drop tel, query portion
            //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
            int queryStart = rawText.IndexOf('?', 4);

            System.String number = queryStart < 0?rawText.Substring(4):rawText.Substring(4, (queryStart) - (4));
            return(new TelParsedResult(number, telURI, null));
        }
        public override ParsedResult parse(Result result)
        {
            string rawText = getMassagedText(result);
            if (!(rawText.StartsWith("sms:") || rawText.StartsWith("SMS:") || rawText.StartsWith("mms:") || rawText.StartsWith("MMS:")))
            {
              return null;
            }

            // Check up front if this is a URI syntax string with query arguments
            IDictionary<string, string> nameValuePairs = parseNameValuePairs(rawText);
            string subject = null;
            string body = null;
            bool querySyntax = false;
            if (nameValuePairs != null && nameValuePairs.Count > 0)
            {
              subject = nameValuePairs["subject"];
              body = nameValuePairs["body"];
              querySyntax = true;
            }

            // Drop sms, query portion
            int queryStart = rawText.IndexOf('?', 4);
            string smsURIWithoutQuery;
            // If it's not query syntax, the question mark is part of the subject or message
            if (queryStart < 0 || !querySyntax)
            {
              smsURIWithoutQuery = rawText.Substring(4);
            }
            else
            {
              smsURIWithoutQuery = rawText.Substring(4, queryStart - 4);
            }

            int lastComma = -1;
            int comma;
            List<string> numbers = new List<string>(1);
            List<string> vias = new List<string>(1);
            while ((comma = smsURIWithoutQuery.IndexOf(',', lastComma + 1)) > lastComma)
            {
              string numberPart = smsURIWithoutQuery.Substring(lastComma + 1, comma - (lastComma + 1));
              addNumberVia(numbers, vias, numberPart);
              lastComma = comma;
            }
            addNumberVia(numbers, vias, smsURIWithoutQuery.Substring(lastComma + 1));

            return new SMSParsedResult(numbers.ToArray(), vias.ToArray(), subject, body);
        }
Exemplo n.º 34
0
        public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Hashtable hints)
        {
            System.Collections.ArrayList results = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            doDecodeMultiple(image, hints, results, 0, 0);
            if ((results.Count == 0))
            {
                throw ReaderException.Instance;
            }
            int numResults = results.Count;

            Result[] resultArray = new Result[numResults];
            for (int i = 0; i < numResults; i++)
            {
                resultArray[i] = (Result)results[i];
            }
            return(resultArray);
        }
Exemplo n.º 35
0
 public static URIParsedResult parse(Result result)
 {
     String rawText = result.Text;
     if (rawText == null || (!rawText.StartsWith("urlto:") && !rawText.StartsWith("URLTO:")))
     {
         return null;
     }
     //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
     int titleEnd = rawText.IndexOf(':', 6);
     if (titleEnd < 0)
     {
         return null;
     }
     String title = titleEnd <= 6?null:rawText.Substr(6, (titleEnd) - (6));
     String uri = rawText.Substr(titleEnd + 1);
     return new URIParsedResult(uri, title);
 }
Exemplo n.º 36
0
        // Note that we don't try rotation without the try harder flag, even if rotation was supported.
        public virtual Result decode(BinaryBitmap image, System.Collections.Hashtable hints)
        {
            var retval = doDecode(image, hints);

            if (retval.HasValue())
            {
                return(retval);
            }
            else
            {
                bool tryHarder = hints != null && hints.ContainsKey(DecodeHintType.TRY_HARDER);
                if (tryHarder && image.RotateSupported)
                {
                    BinaryBitmap rotatedImage = image.rotateCounterClockwise();
                    Result       result       = doDecode(rotatedImage, hints);

                    if (result == null)
                    {
                        return(null);
                    }

                    // Record that we found it rotated 90 degrees CCW / 270 degrees CW
                    System.Collections.Hashtable metadata = result.ResultMetadata;
                    int orientation = 270;
                    if (metadata != null && metadata.ContainsKey(ResultMetadataType.ORIENTATION))
                    {
                        // But if we found it reversed in doDecode(), add in that result here:
                        orientation = (orientation + ((System.Int32)metadata[ResultMetadataType.ORIENTATION])) % 360;
                    }
                    result.putMetadata(ResultMetadataType.ORIENTATION, (System.Object)orientation);
                    // Update result points
                    ResultPoint[] points = result.ResultPoints;
                    int           height = rotatedImage.Height;
                    for (int i = 0; i < points.Length; i++)
                    {
                        points[i] = new ResultPoint(height - points[i].Y - 1, points[i].X);
                    }
                    return(result);
                }
                else
                {
                    return(null);
                }
            }
        }
Exemplo n.º 37
0
        private void DisplayResult(com.google.zxing.Result result)
        {
            _reader.Stop();

            successScan = true;

            if (result != null)
            {
                LastScanResult = ZxingBarcodeResult.FromZxingResult(result);
            }
            else
            {
                LastScanResult = null;
            }


            Finish();
        }
Exemplo n.º 38
0
        public Result[] decodeMultiple(BinaryBitmap image, Dictionary <object, object> hints)
        {
            List <object> results = new List <object>();

            doDecodeMultiple(image, hints, results, 0, 0);
            if ((results.Count == 0))
            {
                throw ReaderException.Instance;
            }
            int numResults = results.Count;

            Result[] resultArray = new Result[numResults];
            for (int i = 0; i < numResults; i++)
            {
                resultArray[i] = (Result)results[i];
            }
            return(resultArray);
        }
        public static URIParsedResult parse(Result result)
        {
            System.String rawText = result.Text;
            if (rawText == null || (!rawText.StartsWith("urlto:") && !rawText.StartsWith("URLTO:")))
            {
                return(null);
            }
            //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
            int titleEnd = rawText.IndexOf(':', 6);

            if (titleEnd < 0)
            {
                return(null);
            }
            System.String title = titleEnd <= 6?null:rawText.Substring(6, (titleEnd) - (6));
            System.String uri   = rawText.Substring(titleEnd + 1);
            return(new URIParsedResult(uri, title));
        }
        // public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Hashtable hints) // commented by .net follower (http://dotnetfollower.com)
        public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Generic.Dictionary <Object, Object> hints) // added by .net follower (http://dotnetfollower.com)
        {
            // System.Collections.ArrayList results = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); // commented by .net follower (http://dotnetfollower.com)
            System.Collections.Generic.List <Object> results = new System.Collections.Generic.List <Object>(10); // added by .net follower (http://dotnetfollower.com)
            doDecodeMultiple(image, hints, results, 0, 0);
            if ((results.Count == 0))
            {
                throw ReaderException.Instance;
            }
            int numResults = results.Count;

            Result[] resultArray = new Result[numResults];
            for (int i = 0; i < numResults; i++)
            {
                resultArray[i] = (Result)results[i];
            }
            return(resultArray);
        }
Exemplo n.º 41
0
 public static TextParsedResult parse(Result result)
 {
     sbyte[] bytes = result.RawBytes;
     if (bytes == null)
     {
         return null;
     }
     NDEFRecord ndefRecord = NDEFRecord.readRecord(bytes, 0);
     if (ndefRecord == null || !ndefRecord.MessageBegin || !ndefRecord.MessageEnd)
     {
         return null;
     }
     if (!ndefRecord.Type.Equals(NDEFRecord.TEXT_WELL_KNOWN_TYPE))
     {
         return null;
     }
     System.String[] languageText = decodeTextPayload(ndefRecord.Payload);
     return new TextParsedResult(languageText[0], languageText[1]);
 }
Exemplo n.º 42
0
        public override ParsedResult parse(Result result)
        {
            string rawText = getMassagedText(result);

            if (!rawText.StartsWith("urlto:") && !rawText.StartsWith("URLTO:"))
            {
                return(null);
            }
            int titleEnd = rawText.IndexOf(':', 6);

            if (titleEnd < 0)
            {
                return(null);
            }
            string title = titleEnd <= 6 ? null : rawText.Substring(6, titleEnd - 6);
            string uri   = rawText.Substring(titleEnd + 1);

            return(new URIParsedResult(uri, title));
        }
Exemplo n.º 43
0
 public static URIParsedResult parse(Result result)
 {
     sbyte[] bytes = result.RawBytes;
     if (bytes == null)
     {
         return null;
     }
     NDEFRecord ndefRecord = NDEFRecord.readRecord(bytes, 0);
     if (ndefRecord == null || !ndefRecord.MessageBegin || !ndefRecord.MessageEnd)
     {
         return null;
     }
     if (!(ndefRecord.Type == NDEFRecord.URI_WELL_KNOWN_TYPE))
     {
         return null;
     }
     String fullURI = decodeURIPayload(ndefRecord.Payload);
     return new URIParsedResult(fullURI, null);
 }
Exemplo n.º 44
0
        public override ParsedResult parse(Result result)
        {
            string rawText = result.Text;

            if (!rawText.StartsWith("MEBKM:"))
            {
                return(null);
            }
            string title = matchSingleDoCoMoPrefixedField("TITLE:", rawText, true);

            string[] rawUri = matchDoCoMoPrefixedField("URL:", rawText, true);
            if (rawUri == null)
            {
                return(null);
            }
            string uri = rawUri[0];

            return(URIResultParser.isBasicallyValidURI(uri) ? new URIParsedResult(uri, title) : null);
        }
 public static EmailAddressParsedResult parse(Result result)
 {
     System.String rawText = result.Text;
     if (rawText == null)
     {
         return null;
     }
     System.String emailAddress;
     if (rawText.StartsWith("mailto:") || rawText.StartsWith("MAILTO:"))
     {
         // If it starts with mailto:, assume it is definitely trying to be an email address
         emailAddress = rawText.Substring(7);
         int queryStart = emailAddress.IndexOf('?');
         if (queryStart >= 0)
         {
             emailAddress = emailAddress.Substring(0, (queryStart) - (0));
         }
         // System.Collections.Hashtable nameValues = parseNameValuePairs(rawText); // commented by .net follower (http://dotnetfollower.com)
         System.Collections.Generic.Dictionary<Object, Object> nameValues = parseNameValuePairs(rawText); // added by .net follower (http://dotnetfollower.com)
         System.String subject = null;
         System.String body = null;
         if (nameValues != null)
         {
             if (emailAddress.Length == 0)
             {
                 emailAddress = ((System.String) nameValues["to"]);
             }
             subject = ((System.String) nameValues["subject"]);
             body = ((System.String) nameValues["body"]);
         }
         return new EmailAddressParsedResult(emailAddress, subject, body, rawText);
     }
     else
     {
         if (!EmailDoCoMoResultParser.isBasicallyValidEmailAddress(rawText))
         {
             return null;
         }
         emailAddress = rawText;
         return new EmailAddressParsedResult(emailAddress, null, null, "mailto:" + emailAddress);
     }
 }
Exemplo n.º 46
0
 public Result[] decodeMultiple2(BinaryBitmap image, Dictionary<object, object> hints)
 {
     ArrayList results = new ArrayList();
     DetectorResult[] detectorResult = new MultiDetector(image.BlackMatrix).detectMulti(hints);
     for (int i = 0; i < detectorResult.Length; i++)
     {
         try
         {
             DecoderResult decoderResult = Decoder.decode2(detectorResult[i].Bits);
             ResultPoint[] points = detectorResult[i].Points;
             Result result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.QR_CODE);
             if (decoderResult.ByteSegments != null)
             {
                 result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.ByteSegments);
             }
             if (decoderResult.ECLevel != null)
             {
                 result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.ECLevel.ToString());
             }
             results.Add(result);
         }
         catch (Exception e)
         {
             if (e.Message.IndexOf("ReaderException") < 0)
                 throw e;
             // ignore and continue
         }
     }
     if ((results.Count == 0))
     {
         return EMPTY_RESULT_ARRAY;
     }
     else
     {
         Result[] resultArray = new Result[results.Count];
         for (int i = 0; i < results.Count; i++)
         {
             resultArray[i] = (Result) results[i];
         }
         return resultArray;
     }
 }
Exemplo n.º 47
0
 public static EmailAddressParsedResult parse(Result result)
 {
     System.String rawText = result.Text;
     if (rawText == null)
     {
         return(null);
     }
     System.String emailAddress;
     if (rawText.StartsWith("mailto:") || rawText.StartsWith("MAILTO:"))
     {
         // If it starts with mailto:, assume it is definitely trying to be an email address
         emailAddress = rawText.Substring(7);
         int queryStart = emailAddress.IndexOf('?');
         if (queryStart >= 0)
         {
             emailAddress = emailAddress.Substring(0, (queryStart) - (0));
         }
         // System.Collections.Hashtable nameValues = parseNameValuePairs(rawText); // commented by .net follower (http://dotnetfollower.com)
         System.Collections.Generic.Dictionary <Object, Object> nameValues = parseNameValuePairs(rawText); // added by .net follower (http://dotnetfollower.com)
         System.String subject = null;
         System.String body    = null;
         if (nameValues != null)
         {
             if (emailAddress.Length == 0)
             {
                 emailAddress = ((System.String)nameValues["to"]);
             }
             subject = ((System.String)nameValues["subject"]);
             body    = ((System.String)nameValues["body"]);
         }
         return(new EmailAddressParsedResult(emailAddress, subject, body, rawText));
     }
     else
     {
         if (!EmailDoCoMoResultParser.isBasicallyValidEmailAddress(rawText))
         {
             return(null);
         }
         emailAddress = rawText;
         return(new EmailAddressParsedResult(emailAddress, null, null, "mailto:" + emailAddress));
     }
 }
Exemplo n.º 48
0
        public static GeoParsedResult parse(Result result)
        {
            System.String rawText = result.Text;
            if (rawText == null || (!rawText.StartsWith("geo:") && !rawText.StartsWith("GEO:")))
            {
                return(null);
            }
            // Drop geo, query portion
            //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
            int queryStart = rawText.IndexOf('?', 4);

            System.String geoURIWithoutQuery = queryStart < 0?rawText.Substring(4):rawText.Substring(4, (queryStart) - (4));
            int           latitudeEnd        = geoURIWithoutQuery.IndexOf(',');

            if (latitudeEnd < 0)
            {
                return(null);
            }
            //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
            int    longitudeEnd = geoURIWithoutQuery.IndexOf(',', latitudeEnd + 1);
            double latitude, longitude, altitude;

            try
            {
                latitude = System.Double.Parse(geoURIWithoutQuery.Substring(0, (latitudeEnd) - (0)));
                if (longitudeEnd < 0)
                {
                    longitude = System.Double.Parse(geoURIWithoutQuery.Substring(latitudeEnd + 1));
                    altitude  = 0.0;
                }
                else
                {
                    longitude = System.Double.Parse(geoURIWithoutQuery.Substring(latitudeEnd + 1, (longitudeEnd) - (latitudeEnd + 1)));
                    altitude  = System.Double.Parse(geoURIWithoutQuery.Substring(longitudeEnd + 1));
                }
            }
            catch (System.FormatException)
            {
                return(null);
            }
            return(new GeoParsedResult(rawText.StartsWith("GEO:")?"geo:" + rawText.Substring(4):rawText, latitude, longitude, altitude));
        }
Exemplo n.º 49
0
        // Yes, we extend AbstractDoCoMoResultParser since the format is very much
        // like the DoCoMo MECARD format, but this is not technically one of
        // DoCoMo's proposed formats

        public static AddressBookParsedResult parse(Result result)
        {
            System.String rawText = result.Text;
            if (rawText == null || !rawText.StartsWith("BIZCARD:"))
            {
                return(null);
            }
            System.String   firstName    = matchSingleDoCoMoPrefixedField("N:", rawText, true);
            System.String   lastName     = matchSingleDoCoMoPrefixedField("X:", rawText, true);
            System.String   fullName     = buildName(firstName, lastName);
            System.String   title        = matchSingleDoCoMoPrefixedField("T:", rawText, true);
            System.String   org          = matchSingleDoCoMoPrefixedField("C:", rawText, true);
            System.String[] addresses    = matchDoCoMoPrefixedField("A:", rawText, true);
            System.String   phoneNumber1 = matchSingleDoCoMoPrefixedField("B:", rawText, true);
            System.String   phoneNumber2 = matchSingleDoCoMoPrefixedField("M:", rawText, true);
            System.String   phoneNumber3 = matchSingleDoCoMoPrefixedField("F:", rawText, true);
            System.String   email        = matchSingleDoCoMoPrefixedField("E:", rawText, true);

            return(new AddressBookParsedResult(maybeWrap(fullName), null, buildPhoneNumbers(phoneNumber1, phoneNumber2, phoneNumber3), maybeWrap(email), null, addresses, org, null, title, null));
        }
        // Yes, we extend AbstractDoCoMoResultParser since the format is very much
        // like the DoCoMo MECARD format, but this is not technically one of
        // DoCoMo's proposed formats
        public override ParsedResult parse(Result result)
        {
            string rawText = getMassagedText(result);
            if (!rawText.StartsWith("BIZCARD:"))
            {
              return null;
            }
            string firstName = matchSingleDoCoMoPrefixedField("N:", rawText, true);
            string lastName = matchSingleDoCoMoPrefixedField("X:", rawText, true);
            string fullName = buildName(firstName, lastName);
            string title = matchSingleDoCoMoPrefixedField("T:", rawText, true);
            string org = matchSingleDoCoMoPrefixedField("C:", rawText, true);
            string[] addresses = matchDoCoMoPrefixedField("A:", rawText, true);
            string phoneNumber1 = matchSingleDoCoMoPrefixedField("B:", rawText, true);
            string phoneNumber2 = matchSingleDoCoMoPrefixedField("M:", rawText, true);
            string phoneNumber3 = matchSingleDoCoMoPrefixedField("F:", rawText, true);
            string email = matchSingleDoCoMoPrefixedField("E:", rawText, true);

            return new AddressBookParsedResult(maybeWrap(fullName), null, buildPhoneNumbers(phoneNumber1, phoneNumber2, phoneNumber3), null, maybeWrap(email), null, null, null, addresses, null, org, null, title, null);
        }
Exemplo n.º 51
0
        public static TextParsedResult parse(Result result)
        {
            sbyte[] bytes = result.RawBytes;
            if (bytes == null)
            {
                return(null);
            }
            NDEFRecord ndefRecord = NDEFRecord.readRecord(bytes, 0);

            if (ndefRecord == null || !ndefRecord.MessageBegin || !ndefRecord.MessageEnd)
            {
                return(null);
            }
            if (!ndefRecord.Type.Equals(NDEFRecord.TEXT_WELL_KNOWN_TYPE))
            {
                return(null);
            }
            System.String[] languageText = decodeTextPayload(ndefRecord.Payload);
            return(new TextParsedResult(languageText[0], languageText[1]));
        }
Exemplo n.º 52
0
        /// <summary>
        /// See <a href="http://www.bisg.org/isbn-13/for.dummies.html">ISBN-13 For Dummies</a>
        /// </summary>
        public override ParsedResult parse(Result result)
        {
            BarcodeFormat format = result.BarcodeFormat;
            if (format != BarcodeFormat.EAN_13)
            {
              return null;
            }
            string rawText = getMassagedText(result);
            int length = rawText.Length;
            if (length != 13)
            {
              return null;
            }
            if (!rawText.StartsWith("978") && !rawText.StartsWith("979"))
            {
              return null;
            }

            return new ISBNParsedResult(rawText);
        }
		public static URIParsedResult parse(Result result)
		{
			System.String rawText = result.Text;
			if (rawText == null || !rawText.StartsWith("MEBKM:"))
			{
				return null;
			}
			System.String title = matchSingleDoCoMoPrefixedField("TITLE:", rawText, true);
			System.String[] rawUri = matchDoCoMoPrefixedField("URL:", rawText, true);
			if (rawUri == null)
			{
				return null;
			}
			System.String uri = rawUri[0];
			if (!URIResultParser.isBasicallyValidURI(uri))
			{
				return null;
			}
			return new URIParsedResult(uri, title);
		}
        public static URIParsedResult parse(Result result)
        {
            sbyte[] bytes = result.RawBytes;
            if (bytes == null)
            {
                return(null);
            }
            NDEFRecord ndefRecord = NDEFRecord.readRecord(bytes, 0);

            if (ndefRecord == null || !ndefRecord.MessageBegin || !ndefRecord.MessageEnd)
            {
                return(null);
            }
            if (!ndefRecord.Type.Equals(NDEFRecord.URI_WELL_KNOWN_TYPE))
            {
                return(null);
            }
            System.String fullURI = decodeURIPayload(ndefRecord.Payload);
            return(new URIParsedResult(fullURI, null));
        }
 public static URIParsedResult parse(Result result)
 {
     System.String rawText = result.Text;
     if (rawText == null || !rawText.StartsWith("MEBKM:"))
     {
         return(null);
     }
     System.String   title  = matchSingleDoCoMoPrefixedField("TITLE:", rawText, true);
     System.String[] rawUri = matchDoCoMoPrefixedField("URL:", rawText, true);
     if (rawUri == null)
     {
         return(null);
     }
     System.String uri = rawUri[0];
     if (!URIResultParser.isBasicallyValidURI(uri))
     {
         return(null);
     }
     return(new URIParsedResult(uri, title));
 }
Exemplo n.º 56
0
        // Yes, we extend AbstractDoCoMoResultParser since the format is very much
        // like the DoCoMo MECARD format, but this is not technically one of
        // DoCoMo's proposed formats
        public static AddressBookParsedResult parse(Result result)
        {
            System.String rawText = result.Text;
            if (rawText == null || !rawText.StartsWith("BIZCARD:"))
            {
                return null;
            }
            System.String firstName = matchSingleDoCoMoPrefixedField("N:", rawText, true);
            System.String lastName = matchSingleDoCoMoPrefixedField("X:", rawText, true);
            System.String fullName = buildName(firstName, lastName);
            System.String title = matchSingleDoCoMoPrefixedField("T:", rawText, true);
            System.String org = matchSingleDoCoMoPrefixedField("C:", rawText, true);
            System.String[] addresses = matchDoCoMoPrefixedField("A:", rawText, true);
            System.String phoneNumber1 = matchSingleDoCoMoPrefixedField("B:", rawText, true);
            System.String phoneNumber2 = matchSingleDoCoMoPrefixedField("M:", rawText, true);
            System.String phoneNumber3 = matchSingleDoCoMoPrefixedField("F:", rawText, true);
            System.String email = matchSingleDoCoMoPrefixedField("E:", rawText, true);

            return new AddressBookParsedResult(maybeWrap(fullName), null, buildPhoneNumbers(phoneNumber1, phoneNumber2, phoneNumber3), maybeWrap(email), null, addresses, org, null, title, null);
        }
 public static EmailAddressParsedResult parse(Result result)
 {
     String rawText = result.Text;
     if (rawText == null)
     {
         return null;
     }
     String emailAddress;
     if (rawText.StartsWith("mailto:") || rawText.StartsWith("MAILTO:"))
     {
         // If it starts with mailto:, assume it is definitely trying to be an email address
         emailAddress = rawText.Substr(7);
         int queryStart = emailAddress.IndexOf('?');
         if (queryStart >= 0)
         {
             emailAddress = emailAddress.Substr(0, (queryStart) - (0));
         }
         Dictionary nameValues = parseNameValuePairs(rawText);
         String subject = null;
         String body = null;
         if (nameValues != null)
         {
             if (emailAddress.Length == 0)
             {
                 emailAddress = (string)nameValues["to"];
             }
             subject = (string)nameValues["subject"];
             body = (string)nameValues["body"];
         }
         return new EmailAddressParsedResult(emailAddress, subject, body, rawText);
     }
     else
     {
         if (!EmailDoCoMoResultParser.isBasicallyValidEmailAddress(rawText))
         {
             return null;
         }
         emailAddress = rawText;
         return new EmailAddressParsedResult(emailAddress, null, null, "mailto:" + emailAddress);
     }
 }
Exemplo n.º 58
0
 // added by .net follower (http://dotnetfollower.com)
 // public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Hashtable hints) // commented by .net follower (http://dotnetfollower.com)
 public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Generic.Dictionary<Object, Object> hints)
 {
     // System.Collections.ArrayList results = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); // commented by .net follower (http://dotnetfollower.com)
     System.Collections.Generic.List<Object> results = new System.Collections.Generic.List<Object>(10); // added by .net follower (http://dotnetfollower.com)
     DetectorResult[] detectorResult = new MultiDetector(image.BlackMatrix).detectMulti(hints);
     for (int i = 0; i < detectorResult.Length; i++)
     {
         try
         {
             DecoderResult decoderResult = Decoder.decode(detectorResult[i].Bits);
             ResultPoint[] points = detectorResult[i].Points;
             Result result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.QR_CODE);
             if (decoderResult.ByteSegments != null)
             {
                 result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.ByteSegments);
             }
             if (decoderResult.ECLevel != null)
             {
                 result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.ECLevel.ToString());
             }
             results.Add(result);
         }
         catch (ReaderException re)
         {
             // ignore and continue
         }
     }
     if ((results.Count == 0))
     {
         return EMPTY_RESULT_ARRAY;
     }
     else
     {
         Result[] resultArray = new Result[results.Count];
         for (int i = 0; i < results.Count; i++)
         {
             resultArray[i] = (Result) results[i];
         }
         return resultArray;
     }
 }
 public static EmailAddressParsedResult parse(Result result)
 {
     System.String rawText = result.Text;
     if (rawText == null || !rawText.StartsWith("MATMSG:"))
     {
         return null;
     }
     System.String[] rawTo = matchDoCoMoPrefixedField("TO:", rawText, true);
     if (rawTo == null)
     {
         return null;
     }
     System.String to = rawTo[0];
     if (!isBasicallyValidEmailAddress(to))
     {
         return null;
     }
     System.String subject = matchSingleDoCoMoPrefixedField("SUB:", rawText, false);
     System.String body = matchSingleDoCoMoPrefixedField("BODY:", rawText, false);
     return new EmailAddressParsedResult(to, subject, body, "mailto:" + to);
 }
        public static AddressBookParsedResult parse(Result result)
        {
            String rawText = result.Text;
            // MEMORY is mandatory; seems like a decent indicator, as does end-of-record separator CR/LF
            if (rawText == null || rawText.IndexOf("MEMORY") < 0 || rawText.IndexOf("\r\n") < 0)
            {
                return null;
            }

            // NAME1 and NAME2 have specific uses, namely written name and pronunciation, respectively.
            // Therefore we treat them specially instead of as an array of names.
            String name = matchSinglePrefixedField("NAME1:", rawText, '\r', true);
            String pronunciation = matchSinglePrefixedField("NAME2:", rawText, '\r', true);

            String[] phoneNumbers = matchMultipleValuePrefix("TEL", 3, rawText, true);
            String[] emails = matchMultipleValuePrefix("MAIL", 3, rawText, true);
            String note = matchSinglePrefixedField("MEMORY:", rawText, '\r', false);
            String address = matchSinglePrefixedField("ADD:", rawText, '\r', true);
            String[] addresses = address == null?null:new String[]{address};
            return new AddressBookParsedResult(maybeWrap(name), pronunciation, phoneNumbers, emails, note, addresses, null, null, null, null);
        }