private static string GetFileNameFromQrParams( string text, int scale, bool useExtensionUri, QrEncodeMode encoding, QrErrorCorrection errorCorrect, int version) { // Build key string string fileName = string.Format( "QrBarcode[{0},{1},{2},{3}]:{4}", (int)encoding, (int)errorCorrect, version, scale, text); // Return encoded filename based on key return(BuildEncodedFileName(fileName, useExtensionUri)); }
private void DecodeFileName() { string fileName = Path.GetFileNameWithoutExtension(_fileName); // Remove file extension and convert from base64 byte[] encryptedFileName = HttpServerUtility.UrlTokenDecode( fileName); // Create memory stream backed against encrypted form MemoryStream memStm = new MemoryStream(encryptedFileName); // Read from crypto-stream via stream reader in UTF8 StreamReader reader = new StreamReader(memStm, Encoding.UTF8); fileName = reader.ReadToEnd(); // Lets see if we can parse the string Match m = FileNameParser.Match(fileName); if (m.Success) { // Validate the hash-code. string originalFilename = m.Result("${OriginalFilename}"); string hashCode = m.Result("${HashCode}"); if (originalFilename.GetHashCode() != Int32.Parse(hashCode)) { throw new InvalidOperationException("Filename is not valid."); } // Determine encoding system string encoding = m.Result("${EncodingSystem}"); if (!string.IsNullOrEmpty(encoding)) { _encodingScheme = (BarcodeSymbology)Int32.Parse(encoding); } // Determine barcode height string barMinHeight = m.Result("${BarMinHeight}"); if (!string.IsNullOrEmpty(barMinHeight)) { _barMinHeight = Int32.Parse(barMinHeight); } string barMaxHeight = m.Result("${BarMaxHeight}"); if (!string.IsNullOrEmpty(barMaxHeight)) { _barMaxHeight = Int32.Parse(barMaxHeight); } // Determine barcode width string barMinWidth = m.Result("${BarMinWidth}"); if (!string.IsNullOrEmpty(barMinWidth)) { _barMinWidth = Int32.Parse(barMinWidth); } string barMaxWidth = m.Result("${BarMaxWidth}"); if (!string.IsNullOrEmpty(barMaxWidth)) { _barMaxWidth = Int32.Parse(barMaxWidth); } // Determine scale string scale = m.Result("${Scale}"); if (!string.IsNullOrEmpty(scale)) { _scale = Int32.Parse(scale); } // Parse the barcode off the end of this string _text = m.Result("${BarCodePayload}"); return; } m = QrFileNameParser.Match(fileName); if (m.Success) { // Validate the hash-code. string originalFilename = m.Result("${OriginalFilename}"); string hashCode = m.Result("${HashCode}"); if (originalFilename.GetHashCode() != Int32.Parse(hashCode)) { throw new InvalidOperationException("Filename is not valid."); } // Determine encoding system _encodingScheme = BarcodeSymbology.CodeQr; string encoding = m.Result("${EncodeMode}"); if (!string.IsNullOrEmpty(encoding)) { _qrEncodingMode = (QrEncodeMode)Int32.Parse(encoding); } // Determine error correction scheme string errorCorrect = m.Result("${ErrorCorrect}"); if (!string.IsNullOrEmpty(errorCorrect)) { _qrErrorCorrect = (QrErrorCorrection)Int32.Parse(errorCorrect); } // Determine version string version = m.Result("${Version}"); if (!string.IsNullOrEmpty(version)) { _qrVersion = Int32.Parse(version); } // Determine scale string scale = m.Result("${Scale}"); if (!string.IsNullOrEmpty(scale)) { _scale = Int32.Parse(scale); } // Parse the barcode off the end of this string _text = m.Result("${BarCodePayload}"); return; } throw new InvalidOperationException("Filename is not valid."); }
/// <summary> /// Constructor /// </summary> public QRCodeEncoder() { _errorCorrect = QrErrorCorrection.M; _encodeMode = QrEncodeMode.Byte; _version = 7; _structureAppendN = 0; _structureAppendM = 0; _structureAppendParity = 0; //_structureAppendOriginaldata = ""; _scale = 4; _backgroundColor = Color.White; _foregroundColor = Color.Black; //QRCODE_DATA_PATH = Environment.CurrentDirectory + @"\" + DATA_PATH; }
private static string GetFileNameFromQrParams( string text, int scale, bool useExtensionUri, QrEncodeMode encoding, QrErrorCorrection errorCorrect, int version) { // Build key string string fileName = string.Format( "QrBarcode[{0},{1},{2},{3}]:{4}", (int)encoding, (int)errorCorrect, version, scale, text); // Return encoded filename based on key return BuildEncodedFileName(fileName, useExtensionUri); }